Changeset 907 for library/bdm/bdmroot.h
- Timestamp:
- 04/19/10 12:44:57 (14 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/bdmroot.h
r870 r907 37 37 //! auxiliary function for debugging 38 38 void 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 41 class 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 47 class log_level_base 48 { 42 49 private: 43 50 // UserInfo class have to be able to read all the internal … … 45 52 friend class UI; 46 53 54 protected: 47 55 //! boolean flags related indicating which details will be logged to a logger 48 56 bitset<32> values; 57 58 public: 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 ); 49 62 50 63 //! 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; 89 65 }; 90 66 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 class94 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 through99 an array of strings, we are no more dependant on their precise ordering. What is more, we can add or remove any without harming100 any applications which are using this library.101 102 \todo Write a more detailed explanation including also examples103 104 \ref ui105 */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 declaration109 class logger;110 111 //! information about connection to a logger112 class log_record {113 public:114 //!remember which logger is registered115 logger &L;116 //! vector of log IDs - one element for each entry117 ivec ids;118 119 //!default constructor120 log_record ( logger &L0 ) : L ( L0 ), ids ( 0 ) {}121 };122 67 123 68 //! Root class of BDM objects … … 127 72 friend class UI; 128 73 129 //! This method is a dummy method closely related to to the #LOG_LEVEL macro, do not remove it130 static const string &log_level_names()131 {132 static const string log_level_names;133 return log_level_names;134 };135 136 74 protected: 137 //! record of connections to the logger138 log _record* logrec;75 //!remember which logger is registered 76 logger * registered_logger; 139 77 140 78 /*! … … 217 155 218 156 public: 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 224 158 //!default constructor 225 root() : logrec( NULL ) {};159 root() : registered_logger ( NULL ) {}; 226 160 227 161 //! make sure this is a virtual object 228 162 virtual ~root() { 229 if ( logrec ) delete logrec;230 163 } 231 164 … … 242 175 //! The level of details (parameter \c level ) is individual for each class. 243 176 virtual void log_register ( logger &L, const string &prefix ) { 244 logrec = new log_record ( L );177 registered_logger = &L; 245 178 } 246 179 247 180 //! Write current information into the given logger 248 181 virtual void log_write() const { 249 } 182 } 250 183 251 184 /*!