Show
Ignore:
Timestamp:
05/17/10 17:54:44 (14 years ago)
Author:
mido
Message:

patch of UI and log_levels to obtain nicer and mainly compilable source code.)

Files:
1 modified

Legend:

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

    r944 r945  
    406406//! This class stores a details that will be logged to a logger 
    407407template<class T> class log_level_template : public log_level_base<T> { 
    408 public: 
     408protected: 
     409        //! boolean flags related indicating which details will be logged to a logger 
     410        bitset<32> values; 
     411 
     412public: 
     413 
     414        //! read only operator for testing individual fields of log_level 
     415        //! 
     416        //! it is necessary to acces it with a proper enumeration type, thus this approach is type-safe 
     417        bool operator [] (const enum T::log_level_enums &log_level_enum ) const 
     418        { 
     419                return values[log_level_enum]; 
     420        } 
     421 
     422        //! operator for setting an individual field of log_level  
     423        //! 
     424        //! it is necessary to acces it with a proper enumeration type, thus this approach is type-safe 
     425        bitset<32>::reference operator [] (const enum T::log_level_enums &log_level_enum ) 
     426        { 
     427                return values[log_level_enum]; 
     428        } 
     429 
     430        //! Set log_levels according to the Setting element 
     431        void from_setting ( const Setting &element ) 
     432        { 
     433                string raw_log_level; 
     434                UI::get( raw_log_level, element ); 
     435                Array<string> loaded_log_level = string2Array( raw_log_level ); 
     436         
     437                values.reset(); 
     438 
     439                for( int i = 0; i < loaded_log_level.length(); i++ ) 
     440                        for( int j = 0; j < names().length(); j++ ){ 
     441                                if( loaded_log_level(i) == names()(j)  )  
     442                                { 
     443                                        values[j] = true; 
     444                                        break; 
     445                                }  
     446                        } 
     447        } 
     448 
     449        //! Store log_levels into the Setting element 
     450        void to_setting ( Setting &element ) const  
     451        { 
     452                // HERE WE WANT NOT TO DELETE PREVIOUS DATA STORED BY OTHER LOG_LEVELS, SEE SPECIAL IMPLEMENTATION OF UI::GET(...) FOR THIS CLASS 
     453                string string_to_write =  ( const char* ) element; 
     454 
     455                for( unsigned int i = 0; i < values.size(); i++ ) 
     456                        if( values[i] )  
     457                        { 
     458                                if( string_to_write.length() > 0 ) 
     459                                        string_to_write = string_to_write + ','; 
     460                                string_to_write = string_to_write + names()(i); 
     461                        } 
     462                         
     463                element = string_to_write; 
     464        } 
     465 
    409466        //! This method stores a vector to the proper place in registered logger  
    410467        //! 
     
    430487        //! 
    431488        //! parameter \c enum_subindex identifies the precise position of setting in the case there is more settings registered to with this enum 
    432         //! 
    433         //! 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. 
    434         //! (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) 
    435         //! This way, it would not be necessary to declare log_level_base<T> class and we could declare log_level_template<T> 
    436         //! before the logger class itself with a mere foroward declaration of logger. In our case, however, touching of registered_logger->log_setting 
    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.  
    438489        template<class U> void store( const enum T::log_level_enums log_level_enum, const U data, int enum_subindex = 0 ) const 
    439490        {                        
     
    443494        } 
    444495}; 
     496//UIREGISTER IS FORBIDDEN FOR THIS CLASS,  AS IT SHOULD BE LOADED ONLY THROUGH THE SPECIALIZED UI::GET(...) METHOD 
     497 
    445498 
    446499/*! 
     
    459512  \ref ui 
    460513*/ 
    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; } 
     514#define LOG_LEVEL(classname,...) public: enum log_level_enums { __VA_ARGS__ }; log_level_template<classname> log_level; private: friend class log_level_base<classname>; static const Array<string> &log_level_names() { static const Array<string> log_level_names = log_level_template<classname>::string2Array( #__VA_ARGS__ ); return log_level_names; } 
    462515 
    463516