Changeset 915
- Timestamp:
- 04/23/10 16:46:05 (15 years ago)
- Location:
- library/bdm
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.cpp
r910 r915 432 432 } 433 433 434 435 string logger::remove_log_prefix_if_possible( string name_with_prefix )436 {437 string possible_log_prefix = name_with_prefix.substr(0,3);438 if( possible_log_prefix == "log" )439 return name_with_prefix.substr(3,name_with_prefix.length()-3);440 else return name_with_prefix;441 }442 443 434 void epdf::log_register ( logger &L, const string &prefix ) { 444 435 root::log_register ( L, prefix ); -
library/bdm/base/bdmbase.h
r914 r915 305 305 template<class T> class log_level_intermediate : public log_level_base { 306 306 public: 307 //! this method adds new id to its proper position and return the name of this position 308 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(); 310 if( ids(log_level_enum).length() < enum_subindex ) 311 ids(log_level_enum).set_size( enum_subindex ); 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 else 321 stream << name_with_prefix; 322 323 // add number to name only in the case there are more registered vectors with the same log_level_enum 324 if( ids_len > 0 ) 325 stream << "[" << enum_subindex << "]"; 326 327 return stream.str(); 328 } 329 307 330 log_level_intermediate( ) { 308 ids.set_size( names().length() ); 309 ids = -1; 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 } 310 338 } 311 339 … … 340 368 */ 341 369 class logger : public root { 342 private:343 //! this method removes a "log" prefix from a string, i.e., it transforms "logevidence" to "evidence"344 //!345 //! for other cases, it keeps string unchanged346 static string remove_log_prefix_if_possible( string name_with_prefix );347 370 protected: 348 371 //! RVs of all logged variables. … … 392 415 //! It also sets a pointer to logger or justify it is correctly assigned from previous call to this procedure 393 416 //! Entries with empty RV will be ignored 394 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 ) 417 //! 418 //! 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 ) 395 420 { 396 421 if( !log_level.registered_logger ) … … 403 428 404 429 int id = entries.length(); 405 string adjusted_name = remove_log_prefix_if_possible( log_level.names()(log_level_enum) ); 430 string adjusted_name = log_level.store_id_and_give_name( log_level_enum, enum_subindex, id ); 431 406 432 names = concat ( names, prefix + separator + adjusted_name ); // diff 407 433 entries.set_length ( id + 1, true ); 408 434 entries ( id ) = rv; 409 log_level.ids(log_level_enum) = id;410 435 } 411 436 … … 417 442 //! This way we check compatibility of the passed log_level and log_level_enum, which would be impossible using just log_level_base class 418 443 //! here. 419 template<class T> void add_setting ( log_level_intermediate<T> &log_level, enum T::log_level_enums const log_level_enum, const string &prefix ) { 444 //! 445 //! 446 //! 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 ) { 420 448 if( !log_level.registered_logger ) 421 449 log_level.registered_logger = this; … … 424 452 425 453 Setting &root = setting_conf.getRoot(); 426 int id = root.getLength(); //root must be group!! 454 int id = root.getLength(); //root must be group!! 455 string adjusted_name = log_level.store_id_and_give_name( log_level_enum, enum_subindex, id ); 427 456 settings.set_length ( id + 1, true ); 428 string adjusted_name = remove_log_prefix_if_possible( log_level.names()(log_level_enum) );429 457 settings ( id ) = &root.add ( prefix + separator + adjusted_name, Setting::TypeList ); 430 log_level.ids(log_level_enum) = id;431 458 } 432 459 … … 447 474 public: 448 475 //! This method stores a vector to the proper place in registered logger 449 void store( const enum T::log_level_enums log_level_enum, const vec &vect ) const 476 //! 477 //! parameter \c enum_subindex identifies the precise position of vector in the case there is more vectors registered to with this enum 478 void store( const enum T::log_level_enums log_level_enum, const vec &vect, int enum_subindex = 0 ) const 450 479 { 451 480 bdm_assert_debug( this->registered_logger != NULL, "You have to register instance to a logger first! Use root::log_register(...) method."); 452 bdm_assert_debug( ids( log_level_enum ) >= 0, "This particular vector was not added to logger! Use logger::add_vector(...) method.");453 this->registered_logger->log_vector( ids( log_level_enum ) , vect );481 bdm_assert_debug( ids( log_level_enum )( enum_subindex ) >= 0, "This particular vector was not added to logger! Use logger::add_vector(...) method."); 482 this->registered_logger->log_vector( ids( log_level_enum )( enum_subindex ), vect ); 454 483 } 455 484 456 485 //! This method stores a double to the proper place in registered logger 457 void store( const enum T::log_level_enums log_level_enum, const double &dbl ) const 486 //! 487 //! parameter \c enum_subindex identifies the precise position of double in the case there is more doubles registered to with this enum 488 void store( const enum T::log_level_enums log_level_enum, const double &dbl, int enum_subindex = 0 ) const 458 489 { 459 490 bdm_assert_debug( this->registered_logger != NULL, "You have to register instance to a logger first! See root::log_register(...) method."); 460 bdm_assert_debug( ids( log_level_enum ) >= 0, "This particular double was not added to logger! Use logger::add_vector(...) method.");461 this->registered_logger->log_double( ids( log_level_enum ) , dbl );491 bdm_assert_debug( ids( log_level_enum )( enum_subindex ) >= 0, "This particular double was not added to logger! Use logger::add_vector(...) method."); 492 this->registered_logger->log_double( ids( log_level_enum )( enum_subindex ), dbl ); 462 493 } 463 494 464 495 //! This method stores a Setting obtained by call of UI::save( data, .. ) to the proper place in registered logger 496 //! 497 //! parameter \c enum_subindex identifies the precise position of setting in the case there is more settings registered to with this enum 465 498 //! 466 499 //! 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. … … 470 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. 471 504 //! Howg.) 472 template<class U> void store( const enum T::log_level_enums log_level_enum, const U data ) const505 template<class U> void store( const enum T::log_level_enums log_level_enum, const U data, int enum_subindex = 0 ) const 473 506 { 474 507 bdm_assert_debug( this->registered_logger != NULL, "You have to register instance to a logger first! See root::log_register(...) method."); 475 bdm_assert_debug( ids( log_level_enum ) >= 0, "This particular vector was not added to logger! Use logger::add_setting(...) method.");476 this->registered_logger->log_setting( ids( log_level_enum ) , data);508 bdm_assert_debug( ids( log_level_enum )(enum_subindex ) >= 0, "This particular vector was not added to logger! Use logger::add_setting(...) method."); 509 this->registered_logger->log_setting( ids( log_level_enum )( enum_subindex ), data); 477 510 } 478 511 }; -
library/bdm/bdmroot.h
r910 r915 59 59 bitset<32> values; 60 60 61 //! vector of log IDs - one element for each entry62 ivecids;61 //! vector of vectors of log IDs - one element for each entry and multiple entries can be stored on the position of one enum 62 Vec<ivec> ids; 63 63 64 64 //! internal pointer to the logger to which this log_level is registered