Changeset 122 for tests/testUI.cpp

Show
Ignore:
Timestamp:
06/19/08 22:20:11 (16 years ago)
Author:
mido
Message:

prvni verze UserInfa?<T>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • tests/testUI.cpp

    r90 r122  
    1 #include <itpp/itbase.h> 
    2 #include <fstream> 
    31#include "userinfo.h" 
    42 
    5 //These lines are needed for use of cout and endl 
    6 using namespace std; 
     3class Engine  
     4{ 
     5public: 
     6        string producer; 
     7        double consumption; 
     8 
     9        Engine( string producer, double consumption ) 
     10                : producer( producer ), 
     11                consumption( consumption ) 
     12        { 
     13        } 
     14}; 
     15 
     16//! User info for strings 
     17class EngineUI : public UserInfo<Engine>  
     18{ 
     19public: 
     20        StringAttribute producer; 
     21        DoubleAttribute consumption; 
     22         
     23        EngineUI() 
     24                : UserInfo( "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 
     39class Car 
     40{ 
     41public: 
     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 
     55class CarUI : public UserInfo<Car>  
     56{ 
     57public: 
     58        EngineUI engine; 
     59 
     60        StringAttribute color; 
     61        IntAttribute year; 
     62 
     63        CarUI() 
     64                : UserInfo("car", "type of a car"),  
     65                color( "color"),  
     66                year( "year" ) 
     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}; 
     80 
    781 
    882int main() 
    983{ 
    10         uiscalar<double> uisc("Sc");     
    11         uiscalar<double> uisc2("");      
    12         uivec uiv("VEc"); 
    13         uivec uiv2("V"); 
    14         uistring uist("Str"); 
    15         uistring uist2("S"); 
    16         uimat uim("Mat"); 
    17         uimat uim2("M"); 
    18          
    19         //SET values 
    20          
    21         uisc.set_value(0.5); 
    22         uiv.set_value(itpp::vec_2(1.3,1.7)); 
    23         uist.set_value("Wow this is cool!"); 
    24         uim.set_value(itpp::mat_2x2(1.1,1.2,1.3,1.4)); 
    25          
    26         ofstream OF; 
    27         OF.open("testUI.exb"); 
    28         uisc.save(OF); 
    29         uiv.save(OF); 
    30         uist.save(OF); 
    31         uim.save(OF); 
    32         OF.close(); 
    33          
    34         ifstream IF; 
    35         IF.open("testUI.exb"); 
    36         uisc2.load(IF); 
    37         uiv2.load(IF); 
    38         uist2.load(IF); 
    39         uim2.load(IF); 
    40         IF.close(); 
    41          
    42         //Exit program: 
     84        CarUI car; 
     85 
     86        car.Save( "car.xml" );   
     87 
     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(); 
    4396        return 0; 
     97} 
    4498 
    45 }