Show
Ignore:
Timestamp:
03/04/10 16:41:30 (14 years ago)
Author:
smidl
Message:

changes in Loggers!

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/base/user_info.h

    r821 r850  
    302302        //! This method converts a Setting into a integer scalar 
    303303        static void from_setting ( int &integer, const Setting &element ); 
    304         //! This method converts a Setting into a real scalar 
     304        //! This method converts a Setting into a real scalar    
    305305        static void from_setting ( double &real, const Setting &element ); 
     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        } 
    306321 
    307322        //! This method converts a Setting into a class T descendant 
     
    379394        } 
    380395 
     396 
    381397        //! This is dummy version of the from_setting method for other, unsupported types. It just throws an exception. 
    382398        //! 
     
    583599        } 
    584600 
     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 
    585629        //! A matrix(of type mat) is stored in the new child Setting appended to the passed element 
    586630        static void save ( const mat &matrix, Setting &element, const string &name = "" );