| 306 | |
| 307 | //! This method converts a Setting into a specific logged_options<T> variant and initialize options properly |
| 308 | template< class T> static void from_setting ( logged_options<T> &options, const Setting &element ) |
| 309 | { |
| 310 | options.values.reset(); |
| 311 | Array<string> true_options; |
| 312 | UI::get( true_options, element ); |
| 313 | for( int i = 0; i < true_options.length(); i++ ) |
| 314 | for( int j = 0; j < options.names().length(); j++ ) |
| 315 | if( true_options(i) == options.names()(j) ) |
| 316 | { |
| 317 | options.values[j] = true; |
| 318 | break; |
| 319 | } |
| 320 | } |
| 601 | // The only difference from classical UserInfo approach to logged_options is the fact |
| 602 | // that the actual element related to logged_options could possibly exists yet. In this case, |
| 603 | // we do not want to throw an exception like in the case of any other type being loaded |
| 604 | // from Setting. Here, we rather add our options into this existig element. This way, it is |
| 605 | // possible that more instances of logged_options class (all contained in one wrapping instance of |
| 606 | // a particular class!) can be stored in only one line in a configuration file |
| 607 | template< class T> static void save ( const logged_options<T> &options, Setting &element, const string &name = "options" ) { |
| 608 | assert_type ( element, Setting::TypeGroup ); |
| 609 | |
| 610 | Setting *list; |
| 611 | if( element.exists( name ) ) |
| 612 | { |
| 613 | list = &element[name]; |
| 614 | assert_type ( *list, Setting::TypeList ); |
| 615 | } |
| 616 | else |
| 617 | list = &element.add ( name, Setting::TypeList ); |
| 618 | |
| 619 | Array<string> true_options; |
| 620 | int true_options_count = 0; |
| 621 | true_options.set_length( options.values.size() ); |
| 622 | for( unsigned int i = 0; i < options.values.size(); i++ ) |
| 623 | if( options.values[i] ) |
| 624 | true_options( true_options_count++ ) = options.names()(i); |
| 625 | save( true_options, *list, name ); |
| 626 | } |
| 627 | |
| 628 | |