| 10 | class Passenger : public bdmroot |
| 11 | { |
| 12 | public: |
| 13 | |
| 14 | Passenger() |
| 15 | { |
| 16 | } |
| 17 | }; |
| 18 | |
| 19 | class Human : public Passenger |
| 20 | { |
| 21 | public: |
| 22 | string name; |
| 23 | |
| 24 | Human() |
| 25 | { |
| 26 | name = "none"; |
| 27 | } |
| 28 | |
| 29 | virtual void from_setting( const Setting &root ) |
| 30 | { |
| 31 | root.lookupValue( "name", name ); |
| 32 | } |
| 33 | |
| 34 | virtual void to_setting( Setting &root ) const |
| 35 | { |
| 36 | Setting &name_setting = root.add("name", Setting::TypeString ); |
| 37 | name_setting = name; |
| 38 | } |
| 39 | |
| 40 | string ToString() |
| 41 | { |
| 42 | return name; |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | UIREGISTER(Human); |
| 47 | |
| 48 | class Robot : public Passenger |
| 49 | { |
| 50 | public: |
| 51 | int number; |
| 52 | Array<string> software; |
| 53 | |
| 54 | Robot() : software() |
| 55 | { |
| 56 | number = -1; |
| 57 | } |
| 58 | |
| 59 | virtual void from_setting( const Setting &root ) |
| 60 | { |
| 61 | root.lookupValue( "number", number ); |
| 62 | |
| 63 | UI::get( software, root, "software" ); |
| 64 | } |
| 65 | |
| 66 | virtual void to_setting( Setting &root ) const |
| 67 | { |
| 68 | Setting &number_setting = root.add("number", Setting::TypeInt ); |
| 69 | number_setting = number; |
| 70 | |
| 71 | UI::save( software, root, "software" ); |
| 72 | } |
| 73 | |
| 74 | string ToString() |
| 75 | { |
| 76 | stringstream stream; |
| 77 | stream << number; |
| 78 | for( int i = 0; i<software.length(); i++) |
| 79 | stream << "_" + software(i); |
| 80 | return stream.str(); |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | UIREGISTER(Robot); |
| 85 | |
| 223 | //////////////////////////////////// LOADING //////////////////////////////// |
| 224 | UI_File in("testUI_in.cfg"); |
| 225 | in.load(); |
| 226 | Transport *pepikovo = UI::build<Transport>( in, "pepikovo"); |
| 227 | cout << "pepikovo: " << pepikovo->ToString() << endl; |
| 228 | Transport *jardovo = UI::build<Transport>( in, "jardovo"); |
| 229 | cout << "jardovo: " << jardovo->ToString() << endl; |
| 230 | Transport *ondrejovo = UI::build<Transport>( in, "ondrejovo"); |
| 231 | cout << "ondrejovo: " << ondrejovo->ToString() << endl; |
| 232 | Transport *elisky = UI::build<Transport>( in, "elisky"); |
| 233 | cout << "elisky: " << elisky->ToString() << endl; |
| 234 | Transport *kati = UI::build<Transport>( in, "kati"); |
| 235 | cout << "kati: " << kati->ToString() << endl; |
| 236 | getchar(); |
| 237 | |
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(); |
| 239 | |
| 240 | Car audi( 1968, "zyl", 200); |
| 241 | Car liaz( 1989, "skoda", 1000); |
| 242 | Bike author( 2001, "noname", false ); |
| 243 | UI_File out("testUI_out.cfg"); |
| 244 | |
| 245 | UI::save( &audi, out, "marty"); |
| 246 | UI::save( &liaz, out, "bohousovo"); |
| 247 | UI::save( &author, out, "karlovo"); |
| 248 | UI::save( pepikovo, out, "pepikovo"); |
| 249 | out.save(); |
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(); |