[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++" |
---|
[766] | 21 | #include "bdmerror.h" |
---|
[706] | 22 | |
---|
| 23 | using namespace libconfig; |
---|
| 24 | using namespace itpp; |
---|
| 25 | using namespace std; |
---|
| 26 | |
---|
| 27 | namespace bdm { |
---|
[737] | 28 | |
---|
[769] | 29 | |
---|
| 30 | //! auxiliary function for debugging |
---|
| 31 | void UI_DBG (const Setting &S, const string &spc, ostream &out ); |
---|
| 32 | |
---|
[706] | 33 | //forward declaration |
---|
| 34 | class logger; |
---|
[737] | 35 | |
---|
[706] | 36 | //! information about connection to a logger |
---|
| 37 | class log_record { |
---|
| 38 | public: |
---|
[737] | 39 | //!remember which logger is registered |
---|
[706] | 40 | logger &L; |
---|
| 41 | //! vector of log IDs - one element for each entry |
---|
| 42 | ivec ids; |
---|
[737] | 43 | |
---|
[706] | 44 | //!default constructor |
---|
[737] | 45 | log_record ( logger &L0 ) : L ( L0 ), ids ( 0 ) {} |
---|
[706] | 46 | }; |
---|
[737] | 47 | |
---|
[706] | 48 | //! Root class of BDM objects |
---|
| 49 | class root { |
---|
[737] | 50 | protected: |
---|
[706] | 51 | //! record of connections to the logger |
---|
| 52 | log_record* logrec; |
---|
| 53 | //! level of details that will be logged to a logger |
---|
| 54 | int log_level; |
---|
[737] | 55 | |
---|
[756] | 56 | //! It is necessary to allow calling of from_setting and to_setting within the user_info class |
---|
| 57 | friend class UI; |
---|
| 58 | |
---|
| 59 | //! Read instance properties according the data stored in the Setting structure |
---|
| 60 | //! |
---|
| 61 | //! It has to be called only through user_info class, therefore it is protected |
---|
| 62 | virtual void from_setting ( const Setting &set ) { |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | //! Save all the instance properties into the Setting structure |
---|
| 66 | //! |
---|
| 67 | //! It has to be called only through user_info class, therefore it is protected |
---|
| 68 | virtual void to_setting ( Setting &set ) const { |
---|
| 69 | } |
---|
| 70 | |
---|
[706] | 71 | public: |
---|
| 72 | //!default constructor |
---|
[737] | 73 | root() : logrec ( NULL ), log_level ( 0 ) {}; |
---|
| 74 | |
---|
[706] | 75 | //! make sure this is a virtual object |
---|
| 76 | virtual ~root() { |
---|
[737] | 77 | if ( logrec ) delete logrec; |
---|
[706] | 78 | } |
---|
| 79 | |
---|
[769] | 80 | //! Returns basic textual info about the current instance |
---|
[706] | 81 | virtual string to_string() const { |
---|
[769] | 82 | Config C; |
---|
| 83 | Setting &set=C.getRoot(); |
---|
| 84 | this->to_setting(set); |
---|
| 85 | ostringstream os; |
---|
| 86 | UI_DBG(set, "", os); |
---|
| 87 | return os.str(); |
---|
[706] | 88 | } |
---|
| 89 | //! Register itself in a logger, i.e. allocate space for data from this class |
---|
| 90 | //! The level of details (parameter \c level ) is individual for each class. |
---|
[737] | 91 | virtual void log_register ( logger &L, const string &prefix ) { |
---|
| 92 | logrec = new log_record ( L ); |
---|
[706] | 93 | } |
---|
[737] | 94 | |
---|
| 95 | //! Write current information into the given logger |
---|
[706] | 96 | virtual void log_write() const { |
---|
| 97 | } |
---|
| 98 | //! set level of details to be logged - needs to be called before log_register! |
---|
[737] | 99 | virtual void set_log_level ( int level ) { |
---|
| 100 | log_level = level; |
---|
| 101 | } |
---|
[706] | 102 | |
---|
| 103 | //! Check that all internal structures has been correctly set-up. Called at the end of from_setting. |
---|
| 104 | virtual void validate() { |
---|
| 105 | } |
---|
[766] | 106 | |
---|
| 107 | //! Virtual method providing deep copy of instances |
---|
| 108 | virtual root* _copy() const NOT_IMPLEMENTED(NULL); |
---|
| 109 | |
---|
| 110 | |
---|
[706] | 111 | //! access function |
---|
[737] | 112 | int _log_level() const { |
---|
| 113 | return log_level; |
---|
| 114 | } |
---|
| 115 | |
---|
[706] | 116 | }; |
---|
| 117 | |
---|
| 118 | }; //namespace |
---|
| 119 | #endif // root_H |
---|