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 | | } |
| 45 | int number; |
| 46 | Array<string> software; |
| 47 | |
| 48 | Robot() : software() { |
| 49 | number = -1; |
| 50 | } |
| 51 | |
| 52 | virtual void from_setting(const Setting &root) { |
| 53 | root.lookupValue("number", number); |
| 54 | if( root.exists( "software" ) ) |
| 55 | UI::get(software, root, "software"); |
| 56 | } |
| 57 | |
| 58 | virtual void to_setting(Setting &root) const { |
| 59 | Setting &number_setting = root.add("number", Setting::TypeInt); |
| 60 | number_setting = number; |
| 61 | |
| 62 | UI::save(software, root, "software"); |
| 63 | } |
| 64 | |
| 65 | string to_string() { |
| 66 | stringstream stream; |
| 67 | stream << number; |
| 68 | for (int i = 0; i < software.length(); i++) |
| 69 | stream << "_" + software(i); |
| 70 | return stream.str(); |
| 71 | } |
89 | | int year; |
90 | | string manufacturer; |
91 | | |
92 | | Transport() |
93 | | { |
94 | | year = 1900; |
95 | | manufacturer = "unknown"; |
96 | | } |
97 | | |
98 | | Transport( int year, string manufacturer ) |
99 | | : year( year ), manufacturer( manufacturer ) |
100 | | { |
101 | | } |
102 | | |
103 | | virtual void from_setting( const Setting &root ) |
104 | | { |
105 | | root.lookupValue( "year", year ); |
106 | | root.lookupValue( "manufacturer", manufacturer ); |
107 | | } |
108 | | |
109 | | virtual void to_setting( Setting &root ) const |
110 | | { |
111 | | Setting &year_setting = root.add("year", Setting::TypeInt ); |
112 | | year_setting = year; |
113 | | |
114 | | Setting &manufacturer_setting = root.add("manufacturer", Setting::TypeString ); |
115 | | manufacturer_setting = manufacturer; |
116 | | } |
| 79 | int year; |
| 80 | string manufacturer; |
| 81 | |
| 82 | Transport() { |
| 83 | year = 1900; |
| 84 | manufacturer = "unknown"; |
| 85 | } |
| 86 | |
| 87 | Transport(int year, string manufacturer) |
| 88 | : year(year), manufacturer(manufacturer) { |
| 89 | } |
| 90 | |
| 91 | virtual void from_setting(const Setting &root) { |
| 92 | root.lookupValue("year", year); |
| 93 | root.lookupValue("manufacturer", manufacturer); |
| 94 | } |
| 95 | |
| 96 | virtual void to_setting(Setting &root) const { |
| 97 | Setting &year_setting = root.add("year", Setting::TypeInt); |
| 98 | year_setting = year; |
| 99 | |
| 100 | Setting &manufacturer_setting = root.add("manufacturer", Setting::TypeString); |
| 101 | manufacturer_setting = manufacturer; |
| 102 | } |
122 | | int kilometers; |
123 | | Array<Passenger*> passengers; |
124 | | |
125 | | Car() : Transport() |
126 | | { |
127 | | kilometers = 0; |
128 | | } |
129 | | |
130 | | |
131 | | Car( int year, string manufacturer, int kilometers ) |
132 | | : Transport( year, manufacturer ), kilometers( kilometers ) |
133 | | { |
134 | | } |
135 | | |
136 | | virtual void from_setting( const Setting &root ) |
137 | | { |
138 | | Transport::from_setting( root ); |
139 | | |
140 | | root.lookupValue( "kilometers", kilometers ); |
141 | | |
142 | | UI::get( passengers, root, "passengers" ); |
143 | | } |
144 | | |
145 | | virtual void to_setting( Setting &root ) const |
146 | | { |
147 | | Transport::to_setting( root ); |
148 | | |
149 | | Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); |
150 | | kilometers_setting = kilometers; |
151 | | |
152 | | UI::save( passengers, root, "passengers" ); |
153 | | } |
154 | | |
155 | | string ToString() |
156 | | { |
157 | | stringstream stream; |
158 | | stream << "A car made in " << year << " by " << manufacturer << ", having " << kilometers << " kilometers on the clock."; |
159 | | if( passengers.length() ) |
160 | | { |
161 | | stream << "The names of passengers are as follows: "; |
162 | | for( int i=0; i<passengers.length(); i++) |
163 | | stream << passengers(i)->ToString() << " "; |
164 | | } |
165 | | return stream.str(); |
166 | | } |
| 108 | int kilometers; |
| 109 | Array<Passenger*> passengers; |
| 110 | |
| 111 | Car() : Transport() { |
| 112 | kilometers = 0; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | Car(int year, string manufacturer, int kilometers) |
| 117 | : Transport(year, manufacturer), kilometers(kilometers) { |
| 118 | } |
| 119 | |
| 120 | virtual void from_setting(const Setting &root) { |
| 121 | Transport::from_setting(root); |
| 122 | |
| 123 | root.lookupValue("kilometers", kilometers); |
| 124 | |
| 125 | if( root.exists( "passengers" ) ) |
| 126 | UI::get(passengers, root, "passengers"); |
| 127 | } |
| 128 | |
| 129 | virtual void to_setting(Setting &root) const { |
| 130 | Transport::to_setting(root); |
| 131 | |
| 132 | Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt); |
| 133 | kilometers_setting = kilometers; |
| 134 | |
| 135 | UI::save(passengers, root, "passengers"); |
| 136 | } |
| 137 | |
| 138 | string to_string() { |
| 139 | stringstream stream; |
| 140 | stream << "A car made in " << year << " by " << manufacturer << ", having " << kilometers << " kilometers on the clock."; |
| 141 | if (passengers.length()) { |
| 142 | stream << "The names of passengers are as follows: "; |
| 143 | for (int i = 0; i < passengers.length(); i++) |
| 144 | stream << passengers(i)->to_string() << " "; |
| 145 | } |
| 146 | return stream.str(); |
| 147 | } |
174 | | bool electricLights; |
175 | | mat matr; |
176 | | |
177 | | Bike() : Transport(), matr("2,2;3,4") |
178 | | { |
179 | | electricLights = false; |
180 | | } |
181 | | |
182 | | Bike( int year, string manufacturer, bool electricLights ) |
183 | | : Transport( year, manufacturer ), electricLights( electricLights ) |
184 | | { |
185 | | } |
186 | | |
187 | | ~Bike() |
188 | | { |
189 | | } |
190 | | |
191 | | void from_setting( const Setting &root ) |
192 | | { |
193 | | Transport::from_setting( root ); |
194 | | |
195 | | root.lookupValue( "electricLights", electricLights ); |
196 | | |
197 | | UI::get( matr, root, "matr" ); |
198 | | } |
199 | | |
200 | | void to_setting( Setting &root ) const |
201 | | { |
202 | | Transport::to_setting( root ); |
203 | | |
204 | | Setting &electricLights_setting = root.add("electricLights", Setting::TypeBoolean ); |
205 | | electricLights_setting = electricLights; |
206 | | |
207 | | UI::save( matr, root, "matr" ); |
208 | | } |
209 | | |
210 | | string ToString() |
211 | | { |
212 | | stringstream stream; |
213 | | stream << "a bike made in " << year << " by " << manufacturer; |
214 | | if( electricLights ) stream << " with electric lights included"; |
215 | | return stream.str(); |
216 | | } |
| 155 | bool electricLights; |
| 156 | mat matr; |
| 157 | |
| 158 | Bike() : Transport(), matr("2,2;3,4") { |
| 159 | electricLights = false; |
| 160 | } |
| 161 | |
| 162 | Bike(int year, string manufacturer, bool electricLights) |
| 163 | : Transport(year, manufacturer), electricLights(electricLights) { |
| 164 | } |
| 165 | |
| 166 | ~Bike() { |
| 167 | } |
| 168 | |
| 169 | void from_setting(const Setting &root) { |
| 170 | Transport::from_setting(root); |
| 171 | |
| 172 | root.lookupValue("electricLights", electricLights); |
| 173 | |
| 174 | UI::get(matr, root, "matr"); |
| 175 | } |
| 176 | |
| 177 | void to_setting(Setting &root) const { |
| 178 | Transport::to_setting(root); |
| 179 | |
| 180 | Setting &electricLights_setting = root.add("electricLights", Setting::TypeBoolean); |
| 181 | electricLights_setting = electricLights; |
| 182 | |
| 183 | UI::save(matr, root, "matr"); |
| 184 | } |
| 185 | |
| 186 | string to_string() { |
| 187 | stringstream stream; |
| 188 | stream << "a bike made in " << year << " by " << manufacturer; |
| 189 | if (electricLights) stream << " with electric lights included"; |
| 190 | return stream.str(); |
| 191 | } |
222 | | { |
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 | | |
238 | | /////////////////////////////////// SAVING ////////////////////////// |
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(); |
250 | | |
251 | | cout << "all the transport means were saved correctly" << endl; |
252 | | getchar(); |
253 | | return 0; |
| 197 | { |
| 198 | //////////////////////////////////// LOADING //////////////////////////////// |
| 199 | UI_File in("testUI_in.cfg"); |
| 200 | Transport *pepikovo = UI::build<Transport>(in, "pepikovo"); |
| 201 | cout << "pepikovo: " << pepikovo->to_string() << endl; |
| 202 | Transport *jardovo = UI::build<Transport>(in, "jardovo"); |
| 203 | cout << "jardovo: " << jardovo->to_string() << endl; |
| 204 | Transport *ondrejovo = UI::build<Transport>(in, "ondrejovo"); |
| 205 | cout << "ondrejovo: " << ondrejovo->to_string() << endl; |
| 206 | Transport *elisky = UI::build<Transport>(in, "elisky"); |
| 207 | cout << "elisky: " << elisky->to_string() << endl; |
| 208 | Transport *kati = UI::build<Transport>(in, "kati"); |
| 209 | cout << "kati: " << kati->to_string() << endl; |
| 210 | getchar(); |
| 211 | |
| 212 | /////////////////////////////////// SAVING ////////////////////////// |
| 213 | |
| 214 | Car audi(1968, "zyl", 200); |
| 215 | Car liaz(1989, "skoda", 1000); |
| 216 | Bike author(2001, "noname", false); |
| 217 | UI_File out; |
| 218 | |
| 219 | UI::save(&audi, out, "marty"); |
| 220 | UI::save(&liaz, out, "bohousovo"); |
| 221 | UI::save(&author, out, "karlovo"); |
| 222 | UI::save(pepikovo, out, "pepikovo"); |
| 223 | out.save("testUI_out.cfg"); |
| 224 | |
| 225 | cout << "all the transport means were saved correctly" << endl; |
| 226 | getchar(); |
| 227 | return 0; |