[706] | 1 | |
---|
| 2 | /*! |
---|
| 3 | \file |
---|
| 4 | \brief Bayesian Models (bm) that use Bayes rule to learn from observations |
---|
| 5 | \author Vaclav Smidl. |
---|
| 6 | |
---|
| 7 | ----------------------------------- |
---|
| 8 | BDM++ - C++ library for Bayesian Decision Making under Uncertainty |
---|
| 9 | |
---|
| 10 | Using IT++ for numerical operations |
---|
| 11 | ----------------------------------- |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | #ifndef root_H |
---|
| 15 | #define root_H |
---|
| 16 | |
---|
| 17 | #include <string> |
---|
| 18 | |
---|
| 19 | #include "itpp_ext.h" |
---|
| 20 | #include "base/libconfig/lib/libconfig.h++" |
---|
| 21 | |
---|
| 22 | using namespace libconfig; |
---|
| 23 | using namespace itpp; |
---|
| 24 | using namespace std; |
---|
| 25 | |
---|
| 26 | namespace bdm { |
---|
[737] | 27 | |
---|
[706] | 28 | //forward declaration |
---|
| 29 | class logger; |
---|
[737] | 30 | |
---|
[706] | 31 | //! information about connection to a logger |
---|
| 32 | class log_record { |
---|
| 33 | public: |
---|
[737] | 34 | //!remember which logger is registered |
---|
[706] | 35 | logger &L; |
---|
| 36 | //! vector of log IDs - one element for each entry |
---|
| 37 | ivec ids; |
---|
[737] | 38 | |
---|
[706] | 39 | //!default constructor |
---|
[737] | 40 | log_record ( logger &L0 ) : L ( L0 ), ids ( 0 ) {} |
---|
[706] | 41 | }; |
---|
[737] | 42 | |
---|
[706] | 43 | //! Root class of BDM objects |
---|
| 44 | class root { |
---|
[737] | 45 | protected: |
---|
[706] | 46 | //! record of connections to the logger |
---|
| 47 | log_record* logrec; |
---|
| 48 | //! level of details that will be logged to a logger |
---|
| 49 | int log_level; |
---|
[737] | 50 | |
---|
[756] | 51 | //! It is necessary to allow calling of from_setting and to_setting within the user_info class |
---|
| 52 | friend class UI; |
---|
| 53 | |
---|
| 54 | //! Read instance properties according the data stored in the Setting structure |
---|
| 55 | //! |
---|
| 56 | //! It has to be called only through user_info class, therefore it is protected |
---|
| 57 | virtual void from_setting ( const Setting &set ) { |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | //! Save all the instance properties into the Setting structure |
---|
| 61 | //! |
---|
| 62 | //! It has to be called only through user_info class, therefore it is protected |
---|
| 63 | virtual void to_setting ( Setting &set ) const { |
---|
| 64 | } |
---|
| 65 | |
---|
[706] | 66 | public: |
---|
| 67 | //!default constructor |
---|
[737] | 68 | root() : logrec ( NULL ), log_level ( 0 ) {}; |
---|
| 69 | |
---|
[706] | 70 | //! make sure this is a virtual object |
---|
| 71 | virtual ~root() { |
---|
[737] | 72 | if ( logrec ) delete logrec; |
---|
[706] | 73 | } |
---|
| 74 | |
---|
| 75 | //! Returns a basic textual info about the current instance |
---|
| 76 | virtual string to_string() const { |
---|
| 77 | return ""; |
---|
| 78 | } |
---|
| 79 | //! Register itself in a logger, i.e. allocate space for data from this class |
---|
| 80 | //! The level of details (parameter \c level ) is individual for each class. |
---|
[737] | 81 | virtual void log_register ( logger &L, const string &prefix ) { |
---|
| 82 | logrec = new log_record ( L ); |
---|
[706] | 83 | } |
---|
[737] | 84 | |
---|
| 85 | //! Write current information into the given logger |
---|
[706] | 86 | virtual void log_write() const { |
---|
| 87 | } |
---|
| 88 | //! set level of details to be logged - needs to be called before log_register! |
---|
[737] | 89 | virtual void set_log_level ( int level ) { |
---|
| 90 | log_level = level; |
---|
| 91 | } |
---|
[706] | 92 | |
---|
| 93 | //! Check that all internal structures has been correctly set-up. Called at the end of from_setting. |
---|
| 94 | virtual void validate() { |
---|
| 95 | } |
---|
| 96 | //! access function |
---|
[737] | 97 | int _log_level() const { |
---|
| 98 | return log_level; |
---|
| 99 | } |
---|
| 100 | |
---|
[706] | 101 | }; |
---|
| 102 | |
---|
| 103 | }; //namespace |
---|
| 104 | #endif // root_H |
---|