Changeset 945 for library/bdm/bdmroot.h

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

    r942 r945  
    194194}; 
    195195 
     196//! This class stores the details which will be logged to a logger 
     197//! 
     198//! This is only the first part of the whole declaration, which has to be however separated into 
     199//! two different classes for allowing the compilation of source code. For more details 
     200//! 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 
     201//! method. For the reason the second one is templated, it was necessary to declare this whole class.  
     202template<class T> class log_level_base : public root { 
     203private: 
     204        //! this is necessary to allow logger to set ids vector appropriately and also to set registered_logger 
     205        friend class logger;  
     206 
     207 
     208        //! this method adds new id to its proper position and return the name of this position 
     209        string store_id_and_give_name( enum T::log_level_enums const log_level_enum,  int enum_subindex, int id ) { 
     210                if( ids(log_level_enum).length() <= enum_subindex ) 
     211                        ids(log_level_enum).set_size( enum_subindex+1, true ); 
     212                ids(log_level_enum)(enum_subindex) = id;  
     213 
     214                // here we remove a "log" prefix from name, i.e., for instance it transforms "logevidence" to "evidence" 
     215                ostringstream stream; 
     216                string name_with_prefix = names()(log_level_enum); 
     217                string possible_log_prefix = name_with_prefix.substr(0,3); 
     218                if( possible_log_prefix == "log" ) 
     219                        stream << name_with_prefix.substr(3,name_with_prefix.length()-3); 
     220                else  
     221                        stream << name_with_prefix; 
     222 
     223                // add number to name only in the case there are more registered vectors with the same log_level_enum 
     224                if( ids(log_level_enum).length() > 1 ) 
     225                        stream << "*" << enum_subindex; 
     226                 
     227                return stream.str(); 
     228        } 
     229 
     230protected: 
     231        //! internal pointer to the logger to which this log_level is registered 
     232        //!  
     233        //! it is set to NULL at the beginning 
     234        logger * registered_logger; 
     235                 
     236        //! vector of vectors of log IDs - one element for each entry and multiple entries can be stored on the position of one enum 
     237        Vec<ivec> ids; 
     238 
     239        //! string equivalents of the used enumerations which are filled with a help of #LOG_LEVEL macro within class T 
     240        const Array<string> &names() const 
     241        { 
     242                return T::log_level_names(); 
     243        } 
     244 
     245        //! default constructor�which is intentionaly declared as protected 
     246        log_level_base( ) { 
     247                registered_logger = NULL; 
     248                int len = names().length(); 
     249                ids.set_size( len ); 
     250                for( int i = 0; i<len; i++ ) 
     251                { 
     252                        ids(i).set_size ( 1 ); 
     253                        ids(i) = -1; 
     254                } 
     255        } 
     256         
     257public:  
     258        //! a general utility transforming a comma-separated sequence of strings into an instance of Array<strings> 
     259        static Array<string> string2Array( const string &input ) 
     260        { 
     261                string result = input; 
     262                string::size_type loc; 
     263                while( loc = result.find( ',' ), loc != string::npos ) 
     264                        result[loc] = ' '; 
     265                return Array<string>("{ " + result + " }" ); 
     266        } 
     267}; 
     268//UIREGISTER IS FORBIDDEN FOR THIS CLASS,  AS IT SHOULD BE LOADED ONLY THROUGH THE SPECIALIZED UI::GET(...) METHOD 
     269 
    196270}; //namespace 
    197271#endif // root_H