Show
Ignore:
Timestamp:
05/14/10 12:16:00 (14 years ago)
Author:
mido
Message:

the functionality of user info was improved, it supports an initialization of root descendant via UI::get directly, however it is save only for static attributes, for dynamically allocated attributes UI::build should be called to handle with intahrence issues

Files:
1 modified

Legend:

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

    r927 r942  
    296296RV concat ( const RV &rv1, const RV &rv2 ); 
    297297 
    298  
    299 //! This class stores a details that will be logged to a logger 
    300 //! 
    301 //! This is only the first part of the whole declaration, which has to be however separated into 
    302 //! two different classes for allowing the compilation of source code. For more details 
    303 //! see logger::add_setting(...) method and mainly log_level_template<T>::template<class U> void store( const enum T::log_level_enums log_level_enum, const U data ) const 
    304 //! method. For the reason the second one is templated, it was necessary to declare this whole class.  
    305 template<class T> class log_level_intermediate : public log_level_base { 
    306 public: 
    307         //! this method adds new id to its proper position and return the name of this position 
    308         string store_id_and_give_name( enum T::log_level_enums const log_level_enum,  int enum_subindex, int id ) { 
    309 //              int ids_len = ids(log_level_enum).length(); <== compiler suggest to remove 
    310                 if( ids(log_level_enum).length() <= enum_subindex ) 
    311                         ids(log_level_enum).set_size( enum_subindex+1, true ); 
    312                 ids(log_level_enum)(enum_subindex) = id;  
    313  
    314                 // here we remove a "log" prefix from name, i.e., for instance it transforms "logevidence" to "evidence" 
    315                 ostringstream stream; 
    316                 string name_with_prefix = names()(log_level_enum); 
    317                 string possible_log_prefix = name_with_prefix.substr(0,3); 
    318                 if( possible_log_prefix == "log" ) 
    319                         stream << name_with_prefix.substr(3,name_with_prefix.length()-3); 
    320                 else  
    321                         stream << name_with_prefix; 
    322  
    323                 // add number to name only in the case there are more registered vectors with the same log_level_enum 
    324                 if( ids(log_level_enum).length() > 1 ) 
    325                         stream << "*" << enum_subindex; 
    326                  
    327                 return stream.str(); 
    328         } 
    329  
    330         log_level_intermediate( ) { 
    331                 int len = names().length(); 
    332                 ids.set_size( len ); 
    333                 for( int i = 0; i<len; i++ ) 
    334                 { 
    335                         ids(i).set_size ( 1 ); 
    336                         ids(i) = -1; 
    337                 } 
    338         } 
    339  
    340         //! string equivalents of the used enumerations which are filled with a help of #LOG_LEVEL macro within class T 
    341         const Array<string> &names() const 
    342         { 
    343                 return T::log_level_names(); 
    344         } 
    345  
    346         //! read only operator for testing individual fields of log_level 
    347         //! 
    348         //! it is necessary to acces it with a proper enumeration type, thus this approach is type-safe 
    349         bool operator [] (const enum T::log_level_enums &log_level_enum ) const 
    350         { 
    351                 return values[log_level_enum]; 
    352         } 
    353  
    354         //! operator for setting an individual field of log_level  
    355         //! 
    356         //! it is necessary to acces it with a proper enumeration type, thus this approach is type-safe 
    357         bitset<32>::reference operator [] (const enum T::log_level_enums &log_level_enum ) 
    358         { 
    359                 return values[log_level_enum]; 
    360         } 
    361 }; 
    362  
    363  
    364298/*! 
    365299@brief Class for storing results (and semi-results) of an experiment 
     
    417351        //!  
    418352        //! passing the last parameter \c enum_subindex one can store multiple vectors in the position of one enum 
    419         template<class T> void add_vector ( log_level_intermediate<T> &log_level, enum T::log_level_enums const log_level_enum, const RV &rv, const string &prefix, int enum_subindex = 0 ) 
     353        template<class T> void add_vector ( log_level_base<T> &log_level, enum T::log_level_enums const log_level_enum, const RV &rv, const string &prefix, int enum_subindex = 0 ) 
    420354        { 
    421355                if( !log_level.registered_logger ) 
     
    439373        //! It also sets a pointer to logger or justify it is correctly assigned from previous call to this procedure  
    440374        //! 
    441         //! To allow both arguments log_level and log_level_enum be templated, it was necessary to declare log_level_intermediate<T> class. 
     375        //! To allow both arguments log_level and log_level_enum be templated, it was necessary to declare log_level_base<T> class. 
    442376        //! This way we check compatibility of the passed log_level and log_level_enum, which would be impossible using just log_level_base class 
    443377        //! here.  
     
    445379        //! 
    446380        //! passing the last parameter \c enum_subindex one can store multiple settings in the position of one enum 
    447         template<class T> void add_setting ( log_level_intermediate<T> &log_level, enum T::log_level_enums const log_level_enum,  const string &prefix, int enum_subindex = 0 ) { 
     381        template<class T> void add_setting ( log_level_base<T> &log_level, enum T::log_level_enums const log_level_enum,  const string &prefix, int enum_subindex = 0 ) { 
    448382                if( !log_level.registered_logger ) 
    449383                        log_level.registered_logger = this; 
     
    471405 
    472406//! This class stores a details that will be logged to a logger 
    473 template<class T> class log_level_template : public log_level_intermediate<T> { 
     407template<class T> class log_level_template : public log_level_base<T> { 
    474408public: 
    475409        //! This method stores a vector to the proper place in registered logger  
     
    499433        //! If this method was not templated, we could store whole body of this class in cpp file without explicitly touching registered_logger->log_setting(...) here. 
    500434        //! (it would not be straightforward, though, still there are some enums which had to be converted into integers but it could be done without loosing type control) 
    501         //! This way, it would not be necessary to declare log_level_intermediate<T> class and we could declare log_level_template<T> 
     435        //! This way, it would not be necessary to declare log_level_base<T> class and we could declare log_level_template<T> 
    502436        //! before the logger class itself with a mere foroward declaration of logger. In our case, however, touching of registered_logger->log_setting 
    503         //! implies that friend declaration is not enough and we are lost in a circle. And just by cutting this circle we obtains log_level_intermediate<T> class.  
    504         //! Howg.) 
     437        //! implies that forward declaration is not enough and we are lost in a circle. And just by cutting this circle we obtains log_level_base<T> class.  
    505438        template<class U> void store( const enum T::log_level_enums log_level_enum, const U data, int enum_subindex = 0 ) const 
    506439        {                        
     
    526459  \ref ui 
    527460*/ 
    528 #define LOG_LEVEL(classname,...) public: enum log_level_enums { __VA_ARGS__ }; log_level_template<classname> log_level; private: friend class log_level_template<classname>; friend class log_level_intermediate<classname>; static const Array<string> &log_level_names() { static const Array<string> log_level_names = log_level_base::string2Array( #__VA_ARGS__ ); return log_level_names; } 
     461#define LOG_LEVEL(classname,...) public: enum log_level_enums { __VA_ARGS__ }; log_level_template<classname> log_level; private: friend class log_level_template<classname>; friend class log_level_base<classname>; static const Array<string> &log_level_names() { static const Array<string> log_level_names = log_level_base<classname>::string2Array( #__VA_ARGS__ ); return log_level_names; } 
    529462 
    530463