Show
Ignore:
Timestamp:
04/19/10 12:44:57 (14 years ago)
Author:
mido
Message:

LOG LEVEL improved and hopefully finished

Files:
1 modified

Legend:

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

    r870 r907  
    304304        //! 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 log_level_template<T> variant and initialize options properly 
    308         template< class T> static void from_setting ( log_level_template<T> &log_level, const Setting &element ) 
    309         { 
    310                 string raw_log_level; 
    311                 UI::get( raw_log_level, element ); 
    312                 Array<string> loaded_log_level = log_level_template<T>::string2Array( raw_log_level ); 
    313                  
    314                 log_level.values.reset(); 
    315  
    316                 for( int i = 0; i < loaded_log_level.length(); i++ ) 
    317                         for( int j = 0; j < log_level.names().length(); j++ ){ 
    318                                 if( loaded_log_level(i) == log_level.names()(j)  )  
    319                                 { 
    320                                         log_level.values[j] = true; 
    321                                         break; 
    322                                 }  
    323                         } 
    324         } 
     306        //! This method converts a Setting into a log_level variant and initialize options properly 
     307        static void from_setting ( log_level_base &log_level, const Setting &element ); 
    325308 
    326309        //! This method converts a Setting into a class T descendant 
     
    374357 
    375358        //! This method converts a Setting into a descendant of class 
    376         //! T, wrapped in an instance of shared_ptr<T> . 
     359        //! T, wrapped in an instance of bdm::shared_ptr<T> . 
    377360        template<class T> 
    378         static void from_setting ( shared_ptr<T> &instance, const Setting &element ) { 
     361        static void from_setting ( bdm::shared_ptr<T> &instance, const Setting &element ) { 
    379362                T *tmp_inst = 0; 
    380363                from_setting ( tmp_inst, element ); 
     
    398381        } 
    399382 
    400  
    401383        //! This is dummy version of the from_setting method for other, unsupported types. It just throws an exception. 
    402384        //! 
    403385        //! At the moment, this is the only way how to compile the library without obtaining the compiler error c2665. 
    404386        //! The exception can help to find the place where the template is misused and also to correct it. 
    405         template<class T> static void from_setting ( T &variable_to_load, const Setting &element ) { 
    406                 std::string msg = "UIException: from_setting is not implemented for type "; 
     387//      template<class T> static void from_setting ( T &variable_to_load, const Setting &element ) { 
     388//              std::string msg = "UIException: from_setting is not implemented for type "; 
    407389//              try{ 
    408                         variable_to_load.from_setting(element); 
     390//                      variable_to_load.from_setting(element); 
    409391/*              } catch (...){ 
    410392                msg += typeid ( T ).name(); 
     
    412394                throw UISettingException ( msg, element ); 
    413395                }*/ 
    414         } 
     396//      } 
    415397 
    416398 
     
    432414        //! The new instance of type T* is constructed and initialized with values stored in the Setting element[name] 
    433415        //! 
    434         //! If there is not any sub-element named #name and settingPresence is #optional, an empty shared_ptr<T> is returned. When settingPresence is #compulsory, the returned shared_ptr<T> is never empty (an exception is thrown when the object isn't found). 
     416        //! If there is not any sub-element named #name and settingPresence is #optional, an empty bdm::shared_ptr<T> is returned. When settingPresence is #compulsory, the returned bdm::shared_ptr<T> is never empty (an exception is thrown when the object isn't found). 
    435417        template<class T> 
    436         static shared_ptr<T> build ( const Setting &element, const string &name, SettingPresence settingPresence = optional ) { 
     418        static bdm::shared_ptr<T> build ( const Setting &element, const string &name, SettingPresence settingPresence = optional ) { 
    437419                if ( !element.exists ( name ) ) { 
    438420                        if ( settingPresence == optional ) 
    439                                 return shared_ptr<T>(); 
     421                                return bdm::shared_ptr<T>(); 
    440422                        else 
    441423                                throw UISettingException ( "UIException: the compulsory Setting named \"" + name + "\" is missing.", element ); 
    442424                } 
    443425 
    444                 shared_ptr<T> instance; 
     426                bdm::shared_ptr<T> instance; 
    445427                from_setting<T> ( instance, to_child_setting ( element, name ) ); 
    446428                return instance; 
     
    449431        //! The new instance of type T* is constructed and initialized with values stored in the Setting element[index] 
    450432        //! 
    451         //! If there is not any sub-element indexed by #index, and settingPresence is #optional, an empty shared_ptr<T> is returned. When settingPresence is #compulsory, the returned shared_ptr<T> is never empty (an exception is thrown when the object isn't found). 
     433        //! If there is not any sub-element indexed by #index, and settingPresence is #optional, an empty bdm::shared_ptr<T> is returned. When settingPresence is #compulsory, the returned bdm::shared_ptr<T> is never empty (an exception is thrown when the object isn't found). 
    452434        template<class T> 
    453         static shared_ptr<T> build ( const Setting &element, const int index, SettingPresence settingPresence = optional ) { 
     435        static bdm::shared_ptr<T> build ( const Setting &element, const int index, SettingPresence settingPresence = optional ) { 
    454436                if ( element.getLength() <= index ) { 
    455437                        if ( settingPresence == optional ) 
    456                                 return shared_ptr<T>(); 
     438                                return bdm::shared_ptr<T>(); 
    457439                        else { 
    458440                                stringstream stream; 
     
    462444                } 
    463445 
    464                 shared_ptr<T> instance; 
     446                bdm::shared_ptr<T> instance; 
    465447                from_setting<T> ( instance, to_child_setting ( element, index ) ); 
    466448                return instance; 
     
    471453//! Handy in mex files. Use with care. 
    472454        template<class T> 
    473         static shared_ptr<T> build ( const Setting &element, SettingPresence settingPresence = optional ) { 
    474                 shared_ptr<T> instance; 
     455        static bdm::shared_ptr<T> build ( const Setting &element, SettingPresence settingPresence = optional ) { 
     456                bdm::shared_ptr<T> instance; 
    475457                from_setting<T> ( instance,  element ); 
    476458                return instance; 
     
    545527                if ( element.getLength() <= index ) { 
    546528                        if ( settingPresence == optional ) 
    547                                 return shared_ptr<T>(); 
     529                                return bdm::shared_ptr<T>(); 
    548530                        else { 
    549531                                stringstream stream; 
     
    590572        } 
    591573 
    592         template< class T> static void save ( const shared_ptr<T> &instance, Setting &element, const string &name = "" ) { 
     574        template< class T> static void save ( const bdm::shared_ptr<T> &instance, Setting &element, const string &name = "" ) { 
    593575                save<T> ( instance.get(), element, name ); 
    594576        } 
     
    603585        } 
    604586 
    605         // The only difference from classical UserInfo approach to log_level_template is the fact 
     587        //! A matrix(of type mat) is stored in the new child Setting appended to the passed element 
     588        static void save ( const mat &matrix, Setting &element, const string &name = "" ); 
     589 
     590        //! An integer vector (of type ivec) is stored in the new child Setting appended to the passed element 
     591        static void save ( const ivec &vec, Setting &element, const string &name = "" ); 
     592 
     593        //! A double vector (of type vec) is stored in the new child Setting appended to the passed element 
     594        static void save ( const vec &vector, Setting &element, const string &name = "" ); 
     595 
     596        //! A string is stored in the new child Setting appended to the passed element 
     597        static void save ( const string &str, Setting &element, const string &name = "" ); 
     598 
     599        //! An integer is stored in the new child Setting appended to the passed element 
     600        static void save ( const int &integer, Setting &element, const string &name = "" ); 
     601 
     602        //! A double is stored in the new child Setting appended to the passed element 
     603        static void save ( const double &real, Setting &element, const string &name = "" ); 
     604 
     605// The only difference from classical UserInfo approach to log_level_template is the fact 
    606606        // that the actual UI element related to log_level_template could possibly exists yet. In this case,  
    607607        // we do not want to throw an exception like in the case of any other type being loaded 
     
    609609        // possible that more instances of log_level_template class (templated with different classes) 
    610610        // can be stored in only one line in a configuration file 
    611         template< class T> static void save ( const log_level_template<T> &log_level, Setting &element, const string &name = "log_level"  ) { 
    612                 assert_type ( element, Setting::TypeGroup ); 
    613  
    614                 string string_to_write; 
    615  
    616                 Setting *list; 
    617                 if( element.exists( name ) )  
    618                 { 
    619                         list = &element[name]; 
    620                         assert_type ( *list, Setting::TypeString ); 
    621                         string_to_write = ( const char* ) *list; 
    622                 } 
    623                 else 
    624                         list = &element.add ( name, Setting::TypeString );  
    625  
    626                 for( unsigned int i = 0; i < log_level.values.size(); i++ ) 
    627                         if( log_level.values[i] ) // a jeste zkontrolovat zda to jmeno uz neni obsazeno?  
    628                         { 
    629                                 if( string_to_write.length() > 0 ) 
    630                                         string_to_write = string_to_write + ','; 
    631                                 string_to_write = string_to_write + log_level.names()(i); 
    632                         } 
    633                          
    634                 *list = string_to_write; 
    635         } 
    636  
    637  
    638         //! A matrix(of type mat) is stored in the new child Setting appended to the passed element 
    639         static void save ( const mat &matrix, Setting &element, const string &name = "" ); 
    640  
    641         //! An integer vector (of type ivec) is stored in the new child Setting appended to the passed element 
    642         static void save ( const ivec &vec, Setting &element, const string &name = "" ); 
    643  
    644         //! A double vector (of type vec) is stored in the new child Setting appended to the passed element 
    645         static void save ( const vec &vector, Setting &element, const string &name = "" ); 
    646  
    647         //! A string is stored in the new child Setting appended to the passed element 
    648         static void save ( const string &str, Setting &element, const string &name = "" ); 
    649  
    650         //! An integer is stored in the new child Setting appended to the passed element 
    651         static void save ( const int &integer, Setting &element, const string &name = "" ); 
    652  
    653         //! A double is stored in the new child Setting appended to the passed element 
    654         static void save ( const double &real, Setting &element, const string &name = "" ); 
     611        static void save ( const log_level_base &log_level, Setting &element, const string &name = "log_level"  ); 
     612 
    655613        //!@} 
    656614