Changeset 870 for library/bdm/bdmroot.h

Show
Ignore:
Timestamp:
03/18/10 19:13:02 (14 years ago)
Author:
mido
Message:

LOG_LEVEL final cut (or rather semifinal? I hope to improve work with ids soon)
and also it rests to adapt applications, work is in progress

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/bdmroot.h

    r865 r870  
    3838void UI_DBG (const Setting &S, const string &spc, ostream &out ); 
    3939         
    40 //! level of details that will be logged to a logger 
    41 // DULEZITE TODO - zde musi respektovat aktualne ulozene hodnoty, tj. nacist je, pak pridat 
    42 // ty co se maji v tomto kroku ulozit a pak vse ulozit.. protoze to delame kompozici a ne dedenim  DODELAT 
    43 // ALE HOUBY, TAKHLE TO NEJDE, musime nechat jako samostatny objekt, kazda uroven tedy zvlast,  
    44 // jednoznacne jmeno atd..  
    45 // 
    46 //! information about connection to a logger 
    47 template<class T> class logged_options { 
     40//! This class stores a details that will be logged to a logger 
     41template<class T> class log_level_template { 
    4842private: 
     43        // UserInfo class have to be able to read all the internal  
     44        // attributes to be able to write/read log_level to/from a Setting structure 
    4945        friend class UI; 
    5046 
     
    5248        bitset<32> values; 
    5349 
     50        //! string equivalents of the used enumerations which are filled with a help of #LOG_LEVEL macro within class T 
    5451        const Array<string> &names() const 
    5552        { 
    56                 return T::option_names(); 
     53                return T::log_level_names(); 
    5754        } 
    5855 
    5956public: 
    6057         
     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? 
    6169        bool any() const 
    6270        { 
     
    6472        } 
    6573 
    66         bool operator [] (const enum T::possible_options &option ) const 
    67         { 
    68                 return values[option]; 
    69         } 
    70  
    71         bitset<32>::reference operator [] (const enum T::possible_options &option ) 
    72         { 
    73                 return values[option]; 
     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]; 
    7488        } 
    7589}; 
    7690 
    77 // MUZEME INTERNE POUZIVAT ENUMY, A KLIDNE MENIT JEJICH PORADI, DIKY TOMUHLE MAKRU SE VZDY NAMAPUJI NA TY SPRAVNE STRINGY  
    78 #define LOG_LEVEL(CLASSNAME,...) private: friend class logged_options<CLASSNAME>; static const Array<string> &option_names() { static const Array<string> option_names( "{"#__VA_ARGS__" }" ); return option_names; }; public: enum possible_options { __VA_ARGS__ }; logged_options<CLASSNAME> log_level; 
     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; } 
    79107 
    80108//forward declaration 
     
    99127        friend class UI; 
    100128 
    101         // TODO okomentovat 
    102         static const Array<string> &option_names()  
     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()  
    103131        {  
    104                 static const Array<string> option_names;  
    105                 return option_names;  
     132                static const string log_level_names;  
     133                return log_level_names;  
    106134        };  
    107135 
     
    189217 
    190218public: 
    191         // TODO okomentovat 
    192         enum possible_options { }; 
     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 { }; 
    193223 
    194224        //!default constructor