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