- Timestamp:
- 04/20/10 21:16:56 (16 years ago)
- Location:
- library/bdm
- Files:
-
- 6 modified
-
base/bdmbase.cpp (modified) (3 diffs)
-
base/bdmbase.h (modified) (7 diffs)
-
base/datasources.cpp (modified) (3 diffs)
-
base/datasources.h (modified) (2 diffs)
-
bdmroot.h (modified) (7 diffs)
-
stat/exp_family.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified library/bdm/base/bdmbase.cpp ¶
r907 r910 453 453 if ( log_level[logfull] ) { 454 454 // log full data 455 registered_logger->add_setting ( log_level, logfull, prefix );455 L.add_setting ( log_level, logfull, prefix ); 456 456 } else { 457 457 // log only 458 458 459 459 if ( log_level[logmean] ) 460 registered_logger->add_vector ( log_level, logmean, r, prefix );460 L.add_vector ( log_level, logmean, r, prefix ); 461 461 if ( log_level[loglbound] ) 462 registered_logger->add_vector ( log_level, loglbound, r, prefix );462 L.add_vector ( log_level, loglbound, r, prefix ); 463 463 if ( log_level[logubound] ) 464 registered_logger->add_vector ( log_level, logubound, r, prefix );464 L.add_vector ( log_level, logubound, r, prefix ); 465 465 } 466 466 } … … 528 528 529 529 if ( log_level[logdt] ) 530 registered_logger->add_vector ( log_level, logdt, Drv, prefix );530 L.add_vector ( log_level, logdt, Drv, prefix ); 531 531 if ( log_level[logut] ) 532 registered_logger->add_vector ( log_level, logut, Urv, prefix );532 L.add_vector ( log_level, logut, Urv, prefix ); 533 533 } 534 534 … … 568 568 569 569 if ( log_level[logevidence] ) 570 registered_logger->add_vector ( log_level, logevidence, RV ( 1 ), prefix );570 L.add_vector ( log_level, logevidence, RV ( 1 ), prefix ); 571 571 572 572 if (log_level[logbounds]){ -
TabularUnified library/bdm/base/bdmbase.h ¶
r907 r910 298 298 299 299 //! This class stores a details that will be logged to a logger 300 template<class T> class log_level_template : public log_level_base { 301 //! this is necessary to allow logger to set ids vector appropriately and also to set registered_logger 302 friend class logger; 303 304 //! vector of log IDs - one element for each entry 305 ivec ids; 306 307 //! internal pointer to the logger to which this log_level is registered 308 //! 309 //! it is set to NULL at the beginning 310 logger * registered_logger; 311 312 public: 313 //! default constructor 314 log_level_template() { 315 registered_logger = NULL; 316 ids.set_size( T::log_level_names().length() ); 300 //! 301 //! This is only the first part of the whole declaration, which has to be however separated into 302 //! two different classes for allowing the compilation of source code. For more details 303 //! 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 304 //! 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 log_level_intermediate( ) { 308 ids.set_size( names().length() ); 317 309 ids = -1; 318 310 } 319 320 //! This method stores a vector to the proper place in registered logger321 void store( const enum T::log_level_enums log_level_enum, const vec &vect ) const322 {323 bdm_assert_debug( registered_logger != NULL, "You have to register instance to a logger first! Use root::log_register(...) method.");324 bdm_assert_debug( ids( log_level_enum ) >= 0, "This particular vector was not added to logger! Use logger::add_vector(...) method.");325 registered_logger->log_vector( ids( log_level_enum ), vect );326 }327 328 //! This method stores a double to the proper place in registered logger329 void store( const enum T::log_level_enums log_level_enum, const double &dbl ) const330 {331 bdm_assert_debug( registered_logger != NULL, "You have to register instance to a logger first! See root::log_register(...) method.");332 bdm_assert_debug( ids( log_level_enum ) >= 0, "This particular double was not added to logger! Use logger::add_vector(...) method.");333 registered_logger->log_double( ids( log_level_enum ), dbl );334 }335 336 //! This method stores a Setting obtained by call of UI::save( data, .. ) to the proper place in registered logger337 template<class U> void store( const enum T::log_level_enums log_level_enum, const U data ) const338 {339 bdm_assert_debug( registered_logger != NULL, "You have to register instance to a logger first! See root::log_register(...) method.");340 bdm_assert_debug( ids( log_level_enum ) >= 0, "This particular vector was not added to logger! Use logger::add_setting(...) method.");341 registered_logger->log_setting( ids( log_level_enum ), data);342 }343 344 311 345 312 //! string equivalents of the used enumerations which are filled with a help of #LOG_LEVEL macro within class T … … 349 316 } 350 317 351 //! read only operator for testing individual fields of log_level318 //! read only operator for testing individual fields of log_level 352 319 //! 353 320 //! it is necessary to acces it with a proper enumeration type, thus this approach is type-safe … … 365 332 } 366 333 }; 367 368 /*!369 \def LOG_LEVEL(classname,...)370 \brief Macro for defining a log_level attribute with a specific set of enumerations related to a specific class371 372 This macro has to be called within a class declaration. Its argument \a classname has to correspond to that wrapping class.373 This macro defines a log_level instance which can be modified either directly or by the means of #UI class.374 375 One of the main purposes of this macro is to allow variability in using enumerations. By relating them to their names through376 an array of strings, we are no more dependant on their precise ordering. What is more, we can add or remove any without harming377 any applications which are using this library.378 379 \todo Write a more detailed explanation including also examples380 381 \ref ui382 */383 #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_base::string2Array( #__VA_ARGS__ ); return log_level_names; }384 334 385 335 … … 442 392 //! It also sets a pointer to logger or justify it is correctly assigned from previous call to this procedure 443 393 //! Entries with empty RV will be ignored 444 template<class T> void add_vector ( log_level_ template<T> &log_level, enum T::log_level_enums const log_level_enum, const RV &rv, const string &prefix )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 ) 445 395 { 446 396 if( !log_level.registered_logger ) … … 448 398 else 449 399 bdm_assert_debug ( log_level.registered_logger == this, "This log_level is already registered to another logger!"); 450 451 400 452 401 if ( rv._dsize() == 0 ) … … 464 413 //! 465 414 //! It also sets a pointer to logger or justify it is correctly assigned from previous call to this procedure 466 template<class T> void add_setting ( log_level_template<T> &log_level, enum T::log_level_enums const log_level_enum, const string &prefix ) { 415 //! 416 //! To allow both arguments log_level and log_level_enum be templated, it was necessary to declare log_level_intermediate<T> class. 417 //! 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 //! 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 ) { 467 420 if( !log_level.registered_logger ) 468 421 log_level.registered_logger = this; … … 489 442 virtual void init() {}; 490 443 }; 444 445 //! This class stores a details that will be logged to a logger 446 template<class T> class log_level_template : public log_level_intermediate<T> { 447 public: 448 //! 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 450 { 451 bdm_assert_debug( 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 registered_logger->log_vector( ids( log_level_enum ), vect ); 454 } 455 456 //! 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 458 { 459 bdm_assert_debug( 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 registered_logger->log_double( ids( log_level_enum ), dbl ); 462 } 463 464 //! This method stores a Setting obtained by call of UI::save( data, .. ) to the proper place in registered logger 465 //! 466 //! 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. 467 //! (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) 468 //! This way, it would not be necessary to declare log_level_intermediate<T> class and we could declare log_level_template<T> 469 //! before the log_level class itself with a mere foroward declaration of log_level. In our case, however, touching of registered_logger->log_setting 470 //! 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 //! Howg.) 472 template<class U> void store( const enum T::log_level_enums log_level_enum, const U data ) const 473 { 474 bdm_assert_debug( 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 registered_logger->log_setting( ids( log_level_enum ), data); 477 } 478 }; 479 480 /*! 481 \def LOG_LEVEL(classname,...) 482 \brief Macro for defining a log_level attribute with a specific set of enumerations related to a specific class 483 484 This macro has to be called within a class declaration. Its argument \a classname has to correspond to that wrapping class. 485 This macro defines a log_level instance which can be modified either directly or by the means of #UI class. 486 487 One of the main purposes of this macro is to allow variability in using enumerations. By relating them to their names through 488 an array of strings, we are no more dependant on their precise ordering. What is more, we can add or remove any without harming 489 any applications which are using this library. 490 491 \todo Write a more detailed explanation including also examples 492 493 \ref ui 494 */ 495 #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; } 496 491 497 492 498 //! Class representing function \f$f(x)\f$ of variable \f$x\f$ represented by \c rv -
TabularUnified library/bdm/base/datasources.cpp ¶
r907 r910 42 42 dtsize = Data.rows(); 43 43 utsize = 0; 44 // DS::validate() has to be called after the dtsize attribute is set to proper value 44 45 DS::validate(); 45 46 } 46 47 47 48 48 void FileDS::from_setting ( const Setting & set ) { … … 76 76 } 77 77 78 void CsvFileDS::validate() {79 // TODO NASTASVIT DSIZE, OKOMENTOVAT PRO VOLAM DS::VALIDATE AZ PAK80 }81 82 78 void ITppFileDS::from_setting ( const Setting & set ) { 83 79 FileDS::from_setting ( set ); … … 89 85 it << Name ( varname ); 90 86 it >> Data; 91 }92 93 void ITppFileDS::validate() {94 // TODO NASTASVIT DSIZE, OKOMENTOVAT PRO VOLAM DS::VALIDATE AZ PAK95 87 } 96 88 -
TabularUnified library/bdm/base/datasources.h ¶
r907 r910 128 128 129 129 // TODO dodelat void to_setting( Setting &set ) const; 130 131 void validate(); 132 }; 133 130 }; 134 131 UIREGISTER ( ITppFileDS ); 135 132 SHAREDPTR ( ITppFileDS ); … … 145 142 public: 146 143 void from_setting ( const Setting & set ); 147 148 void validate();149 144 }; 150 145 -
TabularUnified library/bdm/bdmroot.h ¶
r907 r910 38 38 void UI_DBG (const Setting &S, const string &spc, ostream &out ); 39 39 40 //forward declaration 40 41 //! Forward class declaration 41 42 class logger; 42 43 … … 45 46 //! the existence of this class is forced by the necessity of passing log_levels to user_info methods, however, the main functionality 46 47 //! is located in \c log_level_template class 47 class log_level_base 48 { 48 class log_level_base { 49 49 private: 50 50 // UserInfo class have to be able to read all the internal … … 52 52 friend class UI; 53 53 54 //! this is necessary to allow logger to set ids vector appropriately and also to set registered_logger 55 friend class logger; 56 54 57 protected: 55 58 //! boolean flags related indicating which details will be logged to a logger 56 59 bitset<32> values; 57 60 61 //! vector of log IDs - one element for each entry 62 ivec ids; 63 64 //! internal pointer to the logger to which this log_level is registered 65 //! 66 //! it is set to NULL at the beginning 67 logger * registered_logger; 68 58 69 public: 70 //! default constructor 71 log_level_base() { 72 registered_logger = NULL; 73 } 74 59 75 60 76 //! a general utility transforming a comma-separated sequence of strings into an instance of Array<strings> … … 64 80 virtual const Array<string> &names() const = 0; 65 81 }; 66 67 82 68 83 //! Root class of BDM objects … … 73 88 74 89 protected: 75 //!remember which logger is registered76 logger * registered_logger;77 90 78 91 /*! … … 157 170 158 171 //!default constructor 159 root() : registered_logger ( NULL ){};172 root() {}; 160 173 161 174 //! make sure this is a virtual object … … 172 185 return os.str(); 173 186 } 174 //! Register itself in a logger, i.e. allocate space for data from this class 175 //! The level of details (parameter \c level ) is individual for each class. 187 //! Register log levels of each inheritance layer to a logger, i.e. allocate space for data from this class 176 188 virtual void log_register ( logger &L, const string &prefix ) { 177 registered_logger = &L;178 189 } 179 190 -
TabularUnified library/bdm/stat/exp_family.cpp ¶
r907 r910 303 303 304 304 if ( log_level[logmean] ) 305 registered_logger->add_vector( log_level, logmean, RV ( th_dim ), prefix );305 L.add_vector( log_level, logmean, RV ( th_dim ), prefix ); 306 306 if ( log_level[logvariance] ) 307 registered_logger->add_vector( log_level, logvariance, RV ( th_dim * th_dim ), prefix );307 L.add_vector( log_level, logvariance, RV ( th_dim * th_dim ), prefix ); 308 308 } else { 309 309 epdf::log_register ( L, prefix );
