| 3 | ////////////////////////////////////////////////////////////////////////////////////////////// |
| 4 | ////////////////////////////////////////// BASIC VALUED USER INFOS /////////////////////////// |
| 5 | ////////////////////////////////////////////////////////////////////////////////////////////// |
| 6 | |
| 7 | class BoolUI: public ValuedUserInfo<bool> |
| 8 | { |
| 9 | private: |
| 10 | |
| 11 | bool* AssemblyInstance() |
| 12 | { |
| 13 | if( value == "true" ) |
| 14 | return new bool( true ); |
| 15 | else |
| 16 | return new bool( false ); |
| 17 | } |
| 18 | |
| 19 | bool DisassemblyInstance(bool &instance) |
| 20 | { |
| 21 | if( instance ) |
| 22 | value = "true"; |
| 23 | else |
| 24 | value = "false"; |
| 25 | return true; |
| 26 | } |
| 27 | |
| 28 | public: |
| 29 | |
| 30 | BoolUI() |
| 31 | : ValuedUserInfo<bool>("bool") |
| 32 | { |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | const TypedUserInfo<bool>& TypedUserInfo<bool>::instance = BoolUI(); |
| 37 | |
| 38 | |
32 | | |
33 | | void Build(string* &pInstance) |
34 | | { |
35 | | pInstance = new string( value ); |
36 | | } |
37 | | |
38 | | void Absorb(string* &pInstance) |
39 | | { |
40 | | value = *pInstance; |
41 | | } |
42 | | }; |
43 | | |
44 | | const TypedUserInfo<string>* TypedUserInfo<string>::pInstance = new StringUI(); |
45 | | |
46 | | class Car |
47 | | { |
48 | | public: |
49 | | int age; |
50 | | string brand; |
51 | | |
52 | | Car( int age, string brand) |
53 | | : age( age), brand( brand) |
54 | | { |
55 | | } |
56 | | }; |
| 109 | }; |
| 110 | |
| 111 | const TypedUserInfo<string>& TypedUserInfo<string>::instance = StringUI(); |
| 112 | |
| 113 | ////////////////////////////////////////////////////////////////////////////////////////////// |
| 114 | ////////////////////////////////////////// EXAMPLE CLASSES DEFINITION //////////////////////// |
| 115 | ////////////////////////////////////////////////////////////////////////////////////////////// |
| 116 | class Transport |
| 117 | { |
| 118 | public: |
| 119 | const int year; |
| 120 | const string manufacturer; |
| 121 | |
| 122 | Transport( int year, string manufacturer ) |
| 123 | : year( year ), manufacturer( manufacturer ) |
| 124 | { |
| 125 | } |
| 126 | |
| 127 | virtual public void ToString() = 0; |
| 128 | }; |
| 129 | |
| 130 | class Car : public Transport |
| 131 | { |
| 132 | public: |
| 133 | const int kilometers; |
| 134 | |
| 135 | Car( int year, string manufacturer, int kilometers ) |
| 136 | : Transport( year, manufacturer ), kilometers( kilometers ) |
| 137 | { |
| 138 | } |
| 139 | |
| 140 | void ToString() |
| 141 | { |
| 142 | cout << "a car made in " << year << " by " << manufacturer << ", having " << kilometers << " kilometers on the clock." << endl; |
| 143 | } |
| 144 | }; |
| 145 | |
| 146 | class Bike : public Transport |
| 147 | { |
| 148 | public: |
| 149 | const bool electricLights; |
| 150 | |
| 151 | Bike( int age, string manufacturer, bool electricLights ) |
| 152 | : Transport( age, manufacturer ), electricLights( electricLights ) |
| 153 | { |
| 154 | } |
| 155 | |
| 156 | void ToString() |
| 157 | { |
| 158 | cout << "a bike made in " << year << " by " << manufacturer; |
| 159 | if( electricLights ) cout << " with electric lights included"; |
| 160 | cout << endl; |
| 161 | } |
| 162 | }; |
| 163 | |
| 164 | ////////////////////////////////////////////////////////////////////////////////////////////// |
| 165 | ////////////////////////////////////////// AND RELATED USER INFOS //////////////////////////// |
| 166 | ////////////////////////////////////////////////////////////////////////////////////////////// |
| 167 | |
66 | | age( this, "age" ), |
67 | | brand( this, "brand") |
68 | | { |
69 | | } |
70 | | |
71 | | void Build(Car* &pInstance) |
72 | | { |
73 | | if( age.pInstance == NULL ) age.pInstance = new int (0); |
74 | | if( brand.pInstance == NULL ) brand.pInstance = new string("noname"); |
75 | | pInstance = new Car( *age.pInstance, *brand.pInstance ); |
76 | | } |
77 | | |
78 | | void Absorb(Car* &pInstance) |
79 | | { |
80 | | age.pInstance = &pInstance->age; |
81 | | brand.pInstance = &pInstance->brand; |
82 | | } |
83 | | }; |
84 | | |
85 | | const TypedUserInfo<Car>* TypedUserInfo<Car>::pInstance = new CarUI( ); |
| 178 | year( this, "year", 0 ), |
| 179 | kilometers( this, "kilometers", 0 ), |
| 180 | manufacturer( this, "manufacturer", "unknown") |
| 181 | { |
| 182 | } |
| 183 | private: |
| 184 | |
| 185 | Car* AssemblyInstance() |
| 186 | { |
| 187 | // assembly new instance |
| 188 | return new Car( year.value, manufacturer.value, kilometers.value ); |
| 189 | } |
| 190 | |
| 191 | bool DisassemblyInstance(Car& instance) |
| 192 | { |
| 193 | year.value = instance.year; |
| 194 | manufacturer.value = instance.manufacturer; |
| 195 | kilometers.value = instance.kilometers; |
| 196 | return true; |
| 197 | } |
| 198 | }; |
| 199 | |
| 200 | const TypedUserInfo<Car>& TypedUserInfo<Car>::instance = CarUI( ); |
| 201 | |
| 202 | |
| 203 | class BikeUI: public CompoundUserInfo<Bike> |
| 204 | { |
| 205 | private: |
| 206 | BindedElement<int> year; |
| 207 | BindedElement<bool> lights; |
| 208 | BindedElement<string> manufacturer; |
| 209 | public: |
| 210 | BikeUI() |
| 211 | :CompoundUserInfo<Bike>("bike"), |
| 212 | year( this, "year", 0 ), |
| 213 | lights( this, "electric_lights", false ), // jen jedno slovo! |
| 214 | manufacturer( this, "manufacturer", "unknown") |
| 215 | { |
| 216 | } |
| 217 | private: |
| 218 | |
| 219 | Bike* AssemblyInstance() |
| 220 | { |
| 221 | // assembly new instance |
| 222 | return new Bike( year.value, manufacturer.value, lights.value ); |
| 223 | } |
| 224 | |
| 225 | bool DisassemblyInstance(Bike& instance) |
| 226 | { |
| 227 | year.value = instance.year; |
| 228 | manufacturer.value = instance.manufacturer; |
| 229 | lights.value = instance.electricLights; |
| 230 | return true; |
| 231 | } |
| 232 | }; |
| 233 | |
| 234 | const TypedUserInfo<Bike>& TypedUserInfo<Bike>::instance = BikeUI( ); |
91 | | Car newCar( 20, "audina" ); |
92 | | |
93 | | RootElement root("car.xml"); |
94 | | // NESLO BY TAM MISTO POINTERU PRIMO REFERENCI, |
95 | | // NEBO TAK NECO?!?! ASI JO..! |
96 | | if( !UserInfo::Disassembly( &newCar,root,"kara") ) |
| 244 | |
| 245 | RootElement root("transport.xml"); |
| 246 | |
| 247 | if( !UserInfo::Disassembly( audi, root, "pepikovo") |
| 248 | || !UserInfo::Disassembly( liaz, root, "jardovo") |
| 249 | || !UserInfo::Disassembly( author, root, "ondrejovo") ) |