Changeset 942 for library/bdm/base/bdmbase.h
- Timestamp:
- 05/14/10 12:16:00 (14 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.h
r927 r942 296 296 RV concat ( const RV &rv1, const RV &rv2 ); 297 297 298 299 //! This class stores a details that will be logged to a logger300 //!301 //! This is only the first part of the whole declaration, which has to be however separated into302 //! two different classes for allowing the compilation of source code. For more details303 //! 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 ) const304 //! method. For the reason the second one is templated, it was necessary to declare this whole class.305 template<class T> class log_level_intermediate : public log_level_base {306 public:307 //! this method adds new id to its proper position and return the name of this position308 string store_id_and_give_name( enum T::log_level_enums const log_level_enum, int enum_subindex, int id ) {309 // int ids_len = ids(log_level_enum).length(); <== compiler suggest to remove310 if( ids(log_level_enum).length() <= enum_subindex )311 ids(log_level_enum).set_size( enum_subindex+1, true );312 ids(log_level_enum)(enum_subindex) = id;313 314 // here we remove a "log" prefix from name, i.e., for instance it transforms "logevidence" to "evidence"315 ostringstream stream;316 string name_with_prefix = names()(log_level_enum);317 string possible_log_prefix = name_with_prefix.substr(0,3);318 if( possible_log_prefix == "log" )319 stream << name_with_prefix.substr(3,name_with_prefix.length()-3);320 else321 stream << name_with_prefix;322 323 // add number to name only in the case there are more registered vectors with the same log_level_enum324 if( ids(log_level_enum).length() > 1 )325 stream << "*" << enum_subindex;326 327 return stream.str();328 }329 330 log_level_intermediate( ) {331 int len = names().length();332 ids.set_size( len );333 for( int i = 0; i<len; i++ )334 {335 ids(i).set_size ( 1 );336 ids(i) = -1;337 }338 }339 340 //! string equivalents of the used enumerations which are filled with a help of #LOG_LEVEL macro within class T341 const Array<string> &names() const342 {343 return T::log_level_names();344 }345 346 //! read only operator for testing individual fields of log_level347 //!348 //! it is necessary to acces it with a proper enumeration type, thus this approach is type-safe349 bool operator [] (const enum T::log_level_enums &log_level_enum ) const350 {351 return values[log_level_enum];352 }353 354 //! operator for setting an individual field of log_level355 //!356 //! it is necessary to acces it with a proper enumeration type, thus this approach is type-safe357 bitset<32>::reference operator [] (const enum T::log_level_enums &log_level_enum )358 {359 return values[log_level_enum];360 }361 };362 363 364 298 /*! 365 299 @brief Class for storing results (and semi-results) of an experiment … … 417 351 //! 418 352 //! passing the last parameter \c enum_subindex one can store multiple vectors in the position of one enum 419 template<class T> void add_vector ( log_level_ intermediate<T> &log_level, enum T::log_level_enums const log_level_enum, const RV &rv, const string &prefix, int enum_subindex = 0 )353 template<class T> void add_vector ( log_level_base<T> &log_level, enum T::log_level_enums const log_level_enum, const RV &rv, const string &prefix, int enum_subindex = 0 ) 420 354 { 421 355 if( !log_level.registered_logger ) … … 439 373 //! It also sets a pointer to logger or justify it is correctly assigned from previous call to this procedure 440 374 //! 441 //! To allow both arguments log_level and log_level_enum be templated, it was necessary to declare log_level_ intermediate<T> class.375 //! To allow both arguments log_level and log_level_enum be templated, it was necessary to declare log_level_base<T> class. 442 376 //! This way we check compatibility of the passed log_level and log_level_enum, which would be impossible using just log_level_base class 443 377 //! here. … … 445 379 //! 446 380 //! passing the last parameter \c enum_subindex one can store multiple settings in the position of one enum 447 template<class T> void add_setting ( log_level_ intermediate<T> &log_level, enum T::log_level_enums const log_level_enum, const string &prefix, int enum_subindex = 0 ) {381 template<class T> void add_setting ( log_level_base<T> &log_level, enum T::log_level_enums const log_level_enum, const string &prefix, int enum_subindex = 0 ) { 448 382 if( !log_level.registered_logger ) 449 383 log_level.registered_logger = this; … … 471 405 472 406 //! This class stores a details that will be logged to a logger 473 template<class T> class log_level_template : public log_level_ intermediate<T> {407 template<class T> class log_level_template : public log_level_base<T> { 474 408 public: 475 409 //! This method stores a vector to the proper place in registered logger … … 499 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. 500 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) 501 //! This way, it would not be necessary to declare log_level_ intermediate<T> class and we could declare log_level_template<T>435 //! This way, it would not be necessary to declare log_level_base<T> class and we could declare log_level_template<T> 502 436 //! before the logger class itself with a mere foroward declaration of logger. In our case, however, touching of registered_logger->log_setting 503 //! implies that friend declaration is not enough and we are lost in a circle. And just by cutting this circle we obtains log_level_intermediate<T> class. 504 //! Howg.) 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. 505 438 template<class U> void store( const enum T::log_level_enums log_level_enum, const U data, int enum_subindex = 0 ) const 506 439 { … … 526 459 \ref ui 527 460 */ 528 #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_ intermediate<classname>; static const Array<string> &log_level_names() { static const Array<string> log_level_names = log_level_base::string2Array( #__VA_ARGS__ ); return log_level_names; }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; } 529 462 530 463