408 | | public: |
| 408 | protected: |
| 409 | //! boolean flags related indicating which details will be logged to a logger |
| 410 | bitset<32> values; |
| 411 | |
| 412 | public: |
| 413 | |
| 414 | //! read only operator for testing individual fields of log_level |
| 415 | //! |
| 416 | //! it is necessary to acces it with a proper enumeration type, thus this approach is type-safe |
| 417 | bool operator [] (const enum T::log_level_enums &log_level_enum ) const |
| 418 | { |
| 419 | return values[log_level_enum]; |
| 420 | } |
| 421 | |
| 422 | //! operator for setting an individual field of log_level |
| 423 | //! |
| 424 | //! it is necessary to acces it with a proper enumeration type, thus this approach is type-safe |
| 425 | bitset<32>::reference operator [] (const enum T::log_level_enums &log_level_enum ) |
| 426 | { |
| 427 | return values[log_level_enum]; |
| 428 | } |
| 429 | |
| 430 | //! Set log_levels according to the Setting element |
| 431 | void from_setting ( const Setting &element ) |
| 432 | { |
| 433 | string raw_log_level; |
| 434 | UI::get( raw_log_level, element ); |
| 435 | Array<string> loaded_log_level = string2Array( raw_log_level ); |
| 436 | |
| 437 | values.reset(); |
| 438 | |
| 439 | for( int i = 0; i < loaded_log_level.length(); i++ ) |
| 440 | for( int j = 0; j < names().length(); j++ ){ |
| 441 | if( loaded_log_level(i) == names()(j) ) |
| 442 | { |
| 443 | values[j] = true; |
| 444 | break; |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | //! Store log_levels into the Setting element |
| 450 | void to_setting ( Setting &element ) const |
| 451 | { |
| 452 | // HERE WE WANT NOT TO DELETE PREVIOUS DATA STORED BY OTHER LOG_LEVELS, SEE SPECIAL IMPLEMENTATION OF UI::GET(...) FOR THIS CLASS |
| 453 | string string_to_write = ( const char* ) element; |
| 454 | |
| 455 | for( unsigned int i = 0; i < values.size(); i++ ) |
| 456 | if( values[i] ) |
| 457 | { |
| 458 | if( string_to_write.length() > 0 ) |
| 459 | string_to_write = string_to_write + ','; |
| 460 | string_to_write = string_to_write + names()(i); |
| 461 | } |
| 462 | |
| 463 | element = string_to_write; |
| 464 | } |
| 465 | |
432 | | //! |
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. |
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) |
435 | | //! This way, it would not be necessary to declare log_level_base<T> class and we could declare log_level_template<T> |
436 | | //! before the logger class itself with a mere foroward declaration of logger. In our case, however, touching of registered_logger->log_setting |
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. |