root/tests/UI/testUI.cpp @ 345

Revision 345, 3.6 kB (checked in by mido, 15 years ago)

dodelano user_info, castecne predelano podle stabni kultury, zbyva otestovat a udelat dokumentaci

  • Property svn:eol-style set to native
Line 
1#include <user_info.h>
2#include <string>
3
4using std::string;
5using namespace std;
6using namespace bdm;
7
8class Transport : public bdmroot
9{
10public:
11        int year;
12        string manufacturer;
13
14        Transport()
15        {
16                year = 1900;
17                manufacturer = "unknown";
18        }
19
20        Transport( int year, string manufacturer )
21                : year( year ), manufacturer( manufacturer )
22        {
23        }
24
25        virtual void from_setting( const Setting &root )
26        {
27                root.lookupValue( "year", year );
28                root.lookupValue( "manufacturer", manufacturer );
29        }
30
31        virtual void to_setting( Setting &root ) 
32        {       
33                Setting &year_setting = root.add("year", Setting::TypeInt );
34                year_setting = year;
35
36                Setting &manufacturer_setting = root.add("manufacturer", Setting::TypeString );
37                manufacturer_setting = manufacturer;   
38        }
39};
40
41class Car : public Transport
42{
43public:
44        int kilometers;
45
46        Car() : Transport()               
47        {
48                kilometers = 0;
49        }
50
51
52        Car( int year, string manufacturer, int kilometers )
53                : Transport( year, manufacturer ), kilometers( kilometers )
54        {
55        }
56
57        virtual void from_setting( const Setting &root ) 
58        {       
59                Transport::from_setting( root );
60
61                root.lookupValue( "kilometers", kilometers );
62        }
63
64        virtual void to_setting( Setting &root ) 
65        {       
66                Transport::to_setting( root );
67
68                Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt );
69                kilometers_setting = kilometers;
70        }
71
72        string ToString()
73        {
74                stringstream stream;
75                stream << "a car made in " << year << " by " << manufacturer << ", having " << kilometers << " kilometers on the clock.";
76                return stream.str();
77        }
78};
79
80UIREGISTER(Car);
81
82class Bike : public Transport
83{
84public:
85        bool electricLights;
86        mat matr;
87
88        Bike() : Transport(), matr("2,2;3,4")
89        {
90                electricLights = false;         
91        }
92
93        Bike( int year, string manufacturer, bool electricLights )
94                : Transport( year, manufacturer ), electricLights( electricLights )
95        {
96        }
97
98        ~Bike()
99        {
100        }
101
102        void from_setting( const Setting &root ) 
103        {       
104                Transport::from_setting( root );
105
106                root.lookupValue( "electricLights", electricLights );
107
108                UI::get( matr, root, "matr" );
109        }
110
111        void to_setting( Setting &root ) 
112        {       
113                Transport::to_setting( root );
114
115                Setting &electricLights_setting = root.add("electricLights", Setting::TypeBoolean );
116                electricLights_setting = electricLights;
117
118                UI::save( matr, root, "matr" );
119        }
120
121        string ToString()
122        {
123                stringstream stream;
124                stream << "a bike made in " << year << " by " << manufacturer;
125                if( electricLights ) stream << " with electric lights included";                                               
126                return stream.str();
127        }
128};
129
130UIREGISTER(Bike);
131
132int main()
133{       
134        /////////////////////////////////// SAVING //////////////////////////
135        /*
136        Car audi( 1998, "audi", 25000);
137        Car liaz( 1992, "liaz", 1555000);
138        Bike author( 1996, "author", true );
139
140        UI_File root("testUI.cfg");     
141        UI::save( audi, root, "pepikovo");
142        UI::save( liaz, root, "jardovo");
143        UI::save( author, root, "ondrejovo");
144        root.save();
145
146        cout << "all the transport means were saved correctly" << endl;                         
147        getchar();
148        */
149       
150        //////////////////////////////////// LOADING ////////////////////////////////
151        UI_File root("testUI.cfg");     
152        root.load();
153        Transport *pepikovo = UI::build<Transport>( root, "pepikovo"); 
154        cout << "pepikovo: " << pepikovo->ToString() << endl;           
155        Transport *jardovo = UI::build<Transport>( root, "jardovo");   
156        cout << "jardovo: " << jardovo->ToString() << endl;             
157        Transport *ondrejovo = UI::build<Transport>( root, "ondrejovo");       
158        cout << "ondrejovo: " << ondrejovo->ToString() << endl;         
159        Transport *elisky = UI::build<Transport>( root, "elisky");     
160        cout << "elisky: " << elisky->ToString() << endl;               
161        Transport *kati = UI::build<Transport>( root, "kati"); 
162        cout << "kati: " << kati->ToString() << endl;           
163        getchar(); 
164        return 0;
165}
Note: See TracBrowser for help on using the browser.