Changeset 907 for library/bdm/bdmroot.h

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/bdmroot.h

    r870 r907  
    3737//! auxiliary function for debugging 
    3838void UI_DBG (const Setting &S, const string &spc, ostream &out ); 
    39          
    40 //! This class stores a details that will be logged to a logger 
    41 template<class T> class log_level_template { 
     39 
     40//forward declaration 
     41class logger; 
     42 
     43//! base class for all log_levels 
     44//! 
     45//! the existence of this class is forced by the necessity of passing log_levels to user_info methods, however, the main functionality 
     46//! is located in \c log_level_template class 
     47class log_level_base 
     48{ 
    4249private: 
    4350        // UserInfo class have to be able to read all the internal  
     
    4552        friend class UI; 
    4653 
     54protected: 
    4755        //! boolean flags related indicating which details will be logged to a logger 
    4856        bitset<32> values; 
     57         
     58public: 
     59 
     60        //! a general utility transforming a comma-separated sequence of strings into an instance of Array<strings> 
     61        static Array<string> string2Array( const string &input ); 
    4962 
    5063        //! string equivalents of the used enumerations which are filled with a help of #LOG_LEVEL macro within class T 
    51         const Array<string> &names() const 
    52         { 
    53                 return T::log_level_names(); 
    54         } 
    55  
    56 public: 
    57          
    58         //! a general utility transforming a comma-separated sequence of strings into an instance of Array<strings> 
    59         static Array<string> string2Array( const string &input ) 
    60         { 
    61                 string result = input; 
    62                 string::size_type loc; 
    63                 while( loc = result.find( ',' ), loc != string::npos ) 
    64                         result[loc] = ' '; 
    65                 return Array<string>("{ " + result + " }" ); 
    66         } 
    67  
    68         //! is any field of log_level active? 
    69         bool any() const 
    70         { 
    71                 return values.any(); 
    72         } 
    73  
    74         //! read only operator for testing  individual fields of log_level 
    75         //! 
    76         //! it is necessary to acces it with a proper enumeration type, thus this approach is type-safe 
    77         bool operator [] (const enum T::log_level_enums &log_level ) const 
    78         { 
    79                 return values[log_level]; 
    80         } 
    81  
    82         //! operator for setting an individual field of log_level  
    83         //! 
    84         //! it is necessary to acces it with a proper enumeration type, thus this approach is type-safe 
    85         bitset<32>::reference operator [] (const enum T::log_level_enums &log_level ) 
    86         { 
    87                 return values[log_level]; 
    88         } 
     64        virtual const Array<string> &names() const = 0; 
    8965}; 
    9066 
    91 /*! 
    92   \def LOG_LEVEL(classname,...) 
    93   \brief Macro for defining a log_level attribute with a specific set of enumerations related to a specific class  
    94  
    95   This macro has to be called within a class declaration. Its argument \a classname has to correspond to that wrapping class. 
    96   This macro defines a log_level instance which can be modified either directly or by the means of #UI class. 
    97  
    98   One of the main purposes of this macro is to allow variability in using enumerations. By relating them to their names through 
    99   an array of strings, we are no more dependant on their precise ordering. What is more, we can add or remove any without harming  
    100   any applications which are using this library. 
    101  
    102   \todo Write a more detailed explanation including also examples 
    103  
    104   \ref ui 
    105 */ 
    106 #define LOG_LEVEL(classname,...) public: enum log_level_enums { __VA_ARGS__ }; log_level_template<classname> log_level; private: friend class log_level_template<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; } 
    107  
    108 //forward declaration 
    109 class logger; 
    110  
    111 //! information about connection to a logger 
    112 class log_record { 
    113 public: 
    114         //!remember which logger is registered 
    115         logger &L; 
    116         //! vector of log IDs - one element for each entry 
    117         ivec ids; 
    118  
    119         //!default constructor 
    120         log_record ( logger &L0 ) : L ( L0 ), ids ( 0 ) {} 
    121 }; 
    12267 
    12368//! Root class of BDM objects 
     
    12772        friend class UI; 
    12873 
    129         //! This method is a dummy method closely related to to the #LOG_LEVEL macro, do not remove it 
    130         static const string &log_level_names()  
    131         {  
    132                 static const string log_level_names;  
    133                 return log_level_names;  
    134         };  
    135  
    13674protected: 
    137         //! record of connections to the logger 
    138         log_record* logrec; 
     75        //!remember which logger is registered 
     76        logger * registered_logger; 
    13977 
    14078        /*!      
     
    217155 
    218156public: 
    219         //! This enumeration defines all possible options specifing the level of details logged by a logger about this specific class  
    220         //!  
    221         //! It has to be reimplemented in descendant classes using the #LOG_LEVEL macro 
    222         enum log_level_enums { }; 
    223  
     157         
    224158        //!default constructor 
    225         root() : logrec ( NULL ) {}; 
     159        root() : registered_logger ( NULL ) {}; 
    226160 
    227161        //! make sure this is a virtual object 
    228162        virtual ~root() { 
    229                 if ( logrec ) delete logrec; 
    230163        } 
    231164 
     
    242175        //! The level of details (parameter \c level ) is individual for each class. 
    243176        virtual void log_register ( logger &L, const string &prefix ) { 
    244                 logrec = new log_record ( L ); 
     177                registered_logger = &L; 
    245178        } 
    246179 
    247180        //! Write current information into the given logger 
    248181        virtual void log_write() const { 
    249         } 
     182        }  
    250183 
    251184        /*!