7 | | class cls :public bdmroot{ |
8 | | public: |
9 | | int a; |
10 | | string S; |
11 | | cls(int a0, string S0):a(a0),S(S0){}; |
12 | | virtual void print(){cout << a << " and "<< S << endl;} |
13 | | }; |
14 | | class cls2: public cls{ |
15 | | public: |
16 | | cls2(int a0, string S0):cls(a0,S0){}; |
17 | | void print(){cout << a << " or "<< S << endl;} |
| 8 | class Transport : public bdmroot |
| 9 | { |
| 10 | public: |
| 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 FromSetting( const Setting &root ) |
| 26 | { |
| 27 | root.lookupValue( "year", year ); |
| 28 | root.lookupValue( "manufacturer", manufacturer ); |
| 29 | } |
| 30 | |
| 31 | virtual void ToSetting( 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 | } |
20 | | class UItest : public UIbuilder{ |
21 | | public: |
22 | | UItest():UIbuilder("test"){} |
23 | | bdmroot* build(Setting &S) const{ |
24 | | int a=S["a"]; |
25 | | string St; |
26 | | S.lookupValue("S",St); |
27 | | cls* tmp = new cls(a,St); |
28 | | return tmp; |
29 | | } |
| 41 | class Car : public Transport |
| 42 | { |
| 43 | public: |
| 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 FromSetting( const Setting &root ) |
| 58 | { |
| 59 | Transport::FromSetting( root ); |
| 60 | |
| 61 | root.lookupValue( "kilometers", kilometers ); |
| 62 | } |
| 63 | |
| 64 | virtual void ToSetting( Setting &root ) |
| 65 | { |
| 66 | Transport::ToSetting( 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 | } |
32 | | class UItest2 : public UIbuilder{ |
33 | | public: |
34 | | UItest2():UIbuilder("test2"){} |
35 | | bdmroot* build(Setting &S) const{ |
36 | | int a=S["a"]; |
37 | | string St; |
38 | | S.lookupValue("S",St); |
39 | | return new cls2(a,St); |
40 | | } |
41 | | int no(){return 2;} |
| 80 | UIREGISTER(Car); |
| 81 | |
| 82 | class Bike : public Transport |
| 83 | { |
| 84 | public: |
| 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 FromSetting( const Setting &root ) |
| 103 | { |
| 104 | Transport::FromSetting( root ); |
| 105 | |
| 106 | root.lookupValue( "electricLights", electricLights ); |
| 107 | |
| 108 | UI::Get( matr, root, "matr" ); |
| 109 | } |
| 110 | |
| 111 | void ToSetting( Setting &root ) |
| 112 | { |
| 113 | Transport::ToSetting( 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 | } |
52 | | cls* Cls; |
53 | | UIbuild(UI.lookup("test"),Cls); |
54 | | cls* Cls2; |
55 | | UIbuild(UI.lookup("test2"),Cls2); |
56 | | cls* Cls3; |
57 | | UIbuild(UI.lookup("test3"),Cls3); |
| 140 | UIFile root("UIbuilder_test.cfg"); |
| 141 | UI::Save( audi, root, "pepikovo"); |
| 142 | UI::Save( liaz, root, "jardovo"); |
| 143 | UI::Save( author, root, "ondrejovo"); |
| 144 | root.Save(); |
59 | | Cls->print(); |
60 | | Cls2->print(); |
61 | | Cls3->print(); |
62 | | |
63 | | delete Cls; |
64 | | delete Cls2; |
65 | | delete Cls3; |
| 146 | cout << "all the transport means were saved correctly" << endl; |
| 147 | getchar(); |
| 148 | */ |
| 149 | |
| 150 | //////////////////////////////////// LOADING //////////////////////////////// |
| 151 | UIFile root("UIbuilder_test.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; |