Changeset 142 for tests

Show
Ignore:
Timestamp:
08/19/08 16:41:26 (16 years ago)
Author:
mido
Message:

UI - jen jako zaloha, jeste nehotove, nicmene build by mel projit

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • tests/testUI.cpp

    r128 r142  
    11#include "userinfo.h" 
    22 
    3 class Engine  
     3class IntUI: public ValuedUserInfo<int> 
    44{ 
    55public: 
    6         string producer; 
    7         double consumption; 
    86 
    9         Engine( string producer, double consumption ) 
    10                 : producer( producer ), 
    11                 consumption( consumption ) 
     7        void Build(int* &pInstance) 
    128        { 
     9                // KDO SE POSTARA O DEALOKACI TOHOTO? NADRAZENE UI? ASI.. 
     10                // PAK TO CHCE ALE OBDOBNE UDELAT I STRING NIZE, ZKOPIROVAT atd 
     11                pInstance = new int( atoi( value.c_str()) ); 
     12        } 
     13 
     14}; 
     15 
     16const TypedUserInfo<int>& IntUI::instance = IntUI(); 
     17 
     18 
     19class StringUI: public ValuedUserInfo<string> 
     20{ 
     21public: 
     22        void Build(string* &pInstance) 
     23        { 
     24                pInstance  = &value; 
    1325        } 
    1426}; 
    1527 
    16 //! User info for strings 
    17 class EngineUI : public UserInfo<Engine>  
    18 { 
    19 public: 
    20         StringAttribute producer; 
    21         DoubleAttribute consumption; 
    22          
    23         EngineUI() 
    24                 : UserInfo<Engine>( "engine", "type of engine" ), 
    25                 producer( "producer"), 
    26                 consumption( "consumption") 
    27         { 
    28                 producer.Attach( attributes ); 
    29                 consumption.Attach( attributes ); 
    30         } 
    31  
    32         Engine* build() 
    33         {                
    34                 return new Engine( producer.value, consumption.value ); 
    35         } 
    36 }; 
    37  
    38  
    39 class Car 
    40 { 
    41 public: 
    42         string color; 
    43         int year; 
    44         Engine engine; 
    45  
    46         Car( string color, int year, Engine engine) 
    47                 : color( color ), 
    48                 year( year ), 
    49                 engine( engine ) 
    50         { 
    51         } 
    52 }; 
    53  
    54 //! User info for strings 
    55 class CarUI : public UserInfo<Car>  
    56 { 
    57 public: 
    58         EngineUI engine; 
    59  
    60         StringAttribute color; 
    61         IntAttribute year; 
    62  
    63         CarUI() 
    64                 : UserInfo<Car>("car", "type of a car"),  
    65                 color( "color"),  
    66                 year( "color" ) 
    67         { 
    68                 engine.Attach( elements ); 
    69  
    70                 color.Attach( attributes ); 
    71                 year.Attach( attributes ); 
    72         } 
    73  
    74         Car* build() 
    75         {                
    76                 Engine* pEng = engine.build(); 
    77                 return new Car(color.value, year.value,*pEng); 
    78         } 
    79 }; 
     28const TypedUserInfo<string>& StringUI::instance = StringUI(); 
    8029 
    8130 
    8231int main() 
    8332{ 
    84         CarUI car; 
     33        int i = 9, *pi = &i; 
    8534 
    86         car.Save( "car.xml" );   
     35        RootElement root("car.xml"); 
     36        root.Load(); 
    8737 
    88 /* 
    89         car.Load( "car.xml" ); 
    90         Car *pDefaultCar = car.build(); 
    91         cout << "our car has " << pDefaultCar->color << " color"; 
    92         delete pDefaultCar; 
    93 // */ 
    94  
    95         getchar(); 
     38        UserInfo::Assembly("clovek",root,pi); 
     39         
     40        //root.Save();  
     41         
     42        cout << "press any key to quit, pi=" << *pi << endl; 
     43        getchar();  
    9644        return 0; 
    9745} 
    98