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 | #include "bdmerror.h" |
---|
22 | |
---|
23 | using namespace libconfig; |
---|
24 | using namespace itpp; |
---|
25 | using namespace std; |
---|
26 | |
---|
27 | namespace bdm { |
---|
28 | |
---|
29 | |
---|
30 | //! auxiliary function for debugging |
---|
31 | void UI_DBG (const Setting &S, const string &spc, ostream &out ); |
---|
32 | |
---|
33 | //forward declaration |
---|
34 | class logger; |
---|
35 | |
---|
36 | //! information about connection to a logger |
---|
37 | class log_record { |
---|
38 | public: |
---|
39 | //!remember which logger is registered |
---|
40 | logger &L; |
---|
41 | //! vector of log IDs - one element for each entry |
---|
42 | ivec ids; |
---|
43 | |
---|
44 | //!default constructor |
---|
45 | log_record ( logger &L0 ) : L ( L0 ), ids ( 0 ) {} |
---|
46 | }; |
---|
47 | |
---|
48 | //! Root class of BDM objects |
---|
49 | class root { |
---|
50 | protected: |
---|
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; |
---|
55 | |
---|
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 | |
---|
71 | public: |
---|
72 | //!default constructor |
---|
73 | root() : logrec ( NULL ), log_level ( 0 ) {}; |
---|
74 | |
---|
75 | //! make sure this is a virtual object |
---|
76 | virtual ~root() { |
---|
77 | if ( logrec ) delete logrec; |
---|
78 | } |
---|
79 | |
---|
80 | //! Returns basic textual info about the current instance |
---|
81 | virtual string to_string() const { |
---|
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(); |
---|
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. |
---|
91 | virtual void log_register ( logger &L, const string &prefix ) { |
---|
92 | logrec = new log_record ( L ); |
---|
93 | } |
---|
94 | |
---|
95 | //! Write current information into the given logger |
---|
96 | virtual void log_write() const { |
---|
97 | } |
---|
98 | //! set level of details to be logged - needs to be called before log_register! |
---|
99 | virtual void set_log_level ( int level ) { |
---|
100 | log_level = level; |
---|
101 | } |
---|
102 | |
---|
103 | //! Check that all internal structures has been correctly set-up. Called at the end of from_setting. |
---|
104 | virtual void validate() { |
---|
105 | } |
---|
106 | |
---|
107 | //! Virtual method providing deep copy of instances |
---|
108 | virtual root* _copy() const NOT_IMPLEMENTED(NULL); |
---|
109 | |
---|
110 | |
---|
111 | //! access function |
---|
112 | int _log_level() const { |
---|
113 | return log_level; |
---|
114 | } |
---|
115 | |
---|
116 | }; |
---|
117 | |
---|
118 | }; //namespace |
---|
119 | #endif // root_H |
---|