| 178 | void UI::call_to_setting( const root &instance, Setting &set, string class_name ) { |
| 179 | try { |
| 180 | instance.to_setting ( set ); |
| 181 | } catch ( SettingException &sttng_xcptn ) { |
| 182 | string msg = "UIException: method "; |
| 183 | msg += class_name; |
| 184 | msg += ".to_setting(Setting&) has thrown a SettingException."; |
| 185 | throw UISettingException ( msg, sttng_xcptn.getPath() ); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | void UI::save ( const root &instance, Setting &element, const string &name ) { |
| 190 | Setting &set = ( name == "" ) ? (element.getType()==Setting::TypeArray || element.getType()==Setting::TypeList) ? element.add ( Setting::TypeGroup ) : element |
| 191 | : element.add ( name, Setting::TypeGroup ); |
| 192 | |
| 193 | call_to_setting( instance, set ); |
| 194 | } |
| 195 | |
| 196 | void UI::save ( const root * const instance, Setting &element, const string &name ) { |
| 197 | Setting &set = ( name == "" ) ? (element.getType()==Setting::TypeArray || element.getType()==Setting::TypeList) ? element.add ( Setting::TypeGroup ) : element |
| 198 | : element.add ( name, Setting::TypeGroup ); |
| 199 | |
| 200 | // add attribute "class" |
| 201 | const string &class_name = MappedUI::retrieve_class_name ( &typeid ( *instance ) ); |
| 202 | Setting &type = set.add ( "class", Setting::TypeString ); |
| 203 | type = class_name; |
| 204 | |
| 205 | call_to_setting( *instance, set, class_name ); |
| 206 | } |
| 207 | |
237 | | void UI::save ( const log_level_base &log_level, Setting &element, const string &name ) { |
238 | | assert_type ( element, Setting::TypeGroup ); |
239 | | |
240 | | string string_to_write; |
241 | | |
242 | | Setting *list; |
243 | | if( element.exists( name ) ) |
244 | | { |
245 | | list = &element[name]; |
246 | | assert_type ( *list, Setting::TypeString ); |
247 | | string_to_write = ( const char* ) *list; |
248 | | } |
249 | | else |
250 | | list = &element.add ( name, Setting::TypeString ); |
251 | | |
252 | | for( unsigned int i = 0; i < log_level.values.size(); i++ ) |
253 | | if( log_level.values[i] ) // a jeste zkontrolovat zda to jmeno uz neni obsazeno? |
254 | | { |
255 | | if( string_to_write.length() > 0 ) |
256 | | string_to_write = string_to_write + ','; |
257 | | string_to_write = string_to_write + log_level.names()(i); |
258 | | } |
259 | | |
260 | | *list = string_to_write; |
| 267 | |
| 268 | void UI::call_from_setting( root &instance, const Setting &set, string class_name) { |
| 269 | try { |
| 270 | instance.from_setting ( set ); |
| 271 | } catch ( SettingException &sttng_xcptn ) { |
| 272 | string msg = "UIException: method "; |
| 273 | msg += class_name; |
| 274 | msg += ".from_setting(Setting&) has thrown a SettingException."; |
| 275 | throw UISettingException ( msg, sttng_xcptn.getPath() ); |
| 276 | } catch ( std::runtime_error &e ) { |
| 277 | string msg = "UIException: method "; |
| 278 | msg += class_name; |
| 279 | msg += " says: "; |
| 280 | msg += e.what(); |
| 281 | throw UISettingException ( msg, set ); |
| 282 | } |
| 283 | |
| 284 | // validate the new instance |
| 285 | instance.validate(); |
| 286 | } |
| 287 | |
| 288 | void UI::from_setting ( root &instance, const Setting &element ) { |
| 289 | const SettingResolver link ( element ); |
| 290 | assert_type( link.result, Setting::TypeGroup ); |
| 291 | call_from_setting( instance, link.result ); |
395 | | void UI::from_setting ( log_level_base &log_level, const Setting &element ) |
396 | | { |
397 | | string raw_log_level; |
398 | | UI::get( raw_log_level, element ); |
399 | | Array<string> loaded_log_level = log_level_base::string2Array( raw_log_level ); |
400 | | |
401 | | log_level.values.reset(); |
402 | | |
403 | | for( int i = 0; i < loaded_log_level.length(); i++ ) |
404 | | for( int j = 0; j < log_level.names().length(); j++ ){ |
405 | | if( loaded_log_level(i) == log_level.names()(j) ) |
406 | | { |
407 | | log_level.values[j] = true; |
408 | | break; |
409 | | } |
410 | | } |
411 | | } |
412 | | |