Changeset 146 for tests

Show
Ignore:
Timestamp:
08/20/08 17:08:16 (16 years ago)
Author:
mido
Message:

na win32 fungujici verze UI, zbyva jeste ucesat, commit kvuli testum na UNIXu

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • tests/testUI.cpp

    r142 r146  
    44{ 
    55public: 
     6        IntUI():ValuedUserInfo<int>("int") 
     7        { 
     8        } 
    69 
    710        void Build(int* &pInstance) 
    811        { 
    9                 // KDO SE POSTARA O DEALOKACI TOHOTO? NADRAZENE UI? ASI.. 
    10                 // PAK TO CHCE ALE OBDOBNE UDELAT I STRING NIZE, ZKOPIROVAT atd 
    1112                pInstance = new int( atoi( value.c_str()) ); 
    1213        } 
    1314 
     15        void Absorb(int* &pInstance) 
     16        { 
     17                char buff[30]; 
     18                sprintf(buff, "%d", *pInstance ); 
     19                value = buff; 
     20        } 
    1421}; 
    1522 
     
    2027{ 
    2128public: 
     29        StringUI():ValuedUserInfo<string>("string") 
     30        { 
     31        } 
     32 
    2233        void Build(string* &pInstance) 
    2334        { 
    24                 pInstance  = &value; 
     35                pInstance  = new string( value ); 
     36        } 
     37 
     38        void Absorb(string* &pInstance) 
     39        { 
     40                value = *pInstance; 
    2541        } 
    2642}; 
    2743 
    28 const TypedUserInfo<string>& StringUI::instance = StringUI(); 
     44const TypedUserInfo<string>& StringUI::instance = StringUI( ); 
     45 
     46class Car 
     47{ 
     48public: 
     49        int age; 
     50        string brand; 
     51 
     52        Car( int age, string brand) 
     53                : age( age), brand( brand) 
     54        { 
     55        } 
     56}; 
     57 
     58class CarUI: public CompoundUserInfo<Car> 
     59{ 
     60public: 
     61        BindedType<int> age; 
     62        BindedType<string> brand; 
     63 
     64        CarUI() 
     65                :CompoundUserInfo<Car>("car"), 
     66                age( this, "age" ), 
     67                brand( this, "brand") 
     68        { 
     69        } 
     70 
     71        void Build(Car* &pInstance) 
     72        { 
     73                if( age.pInstance == NULL ) age.pInstance = new int (0); 
     74                if( brand.pInstance == NULL ) brand.pInstance = new string("noname"); 
     75                pInstance  = new Car( *age.pInstance, *brand.pInstance ); 
     76        } 
     77 
     78        void Absorb(Car* &pInstance) 
     79        { 
     80                age.pInstance = &pInstance->age; 
     81                brand.pInstance = &pInstance->brand; 
     82        } 
     83}; 
     84 
     85const TypedUserInfo<Car>& CarUI::instance = CarUI( ); 
    2986 
    3087 
    3188int main() 
    3289{ 
    33         int i = 9, *pi = &i; 
     90        /////////////////////////////////// SAVING /////////////////////////// 
     91        Car newCar( 20, "audina" ); 
    3492 
    3593        RootElement root("car.xml"); 
     94        // NESLO BY TAM MISTO POINTERU PRIMO REFERENCI, 
     95        // NEBO TAK NECO?!?! ASI JO..! 
     96        if( !UserInfo::Disassembly( &newCar,root,"kara") ) 
     97        { 
     98                cout << "there was some error!" << endl; 
     99                getchar(); 
     100                return 0;                        
     101        } 
     102 
     103        root.Save(); 
     104        cout << "the new car was saved correctly!" << endl;                              
     105        getchar(); 
     106 
     107        //////////////////////////////////// LOADING //////////////////////////////// 
     108 
     109 
     110        Car *loadedCar; 
    36111        root.Load(); 
    37  
    38         UserInfo::Assembly("clovek",root,pi); 
     112        UserInfo::Assembly(loadedCar,root,"kara"); 
    39113         
    40         //root.Save();  
    41          
    42         cout << "press any key to quit, pi=" << *pi << endl; 
     114        if( loadedCar ) 
     115                cout << "loaded car: age=" << loadedCar->age << ", brand=" << loadedCar->brand << endl; 
     116        else 
     117                cout << "there was some error during car loading!" << endl; 
     118                 
    43119        getchar();  
    44120        return 0;