root/library/bdm/bdmroot.h @ 1154

Revision 1064, 6.1 kB (checked in by mido, 14 years ago)

astyle applied all over the library

  • Property svn:eol-style set to native
Line 
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#include <bitset>
19
20#include "itpp_ext.h"
21#include "bdmerror.h"
22
23#ifdef MEX
24#include "base/libconfig/lib/libconfig.h++"
25// TODO DODELAT A NAHRADIT #include "base/libconfig_mex.h"
26#else
27#include "base/libconfig/lib/libconfig.h++"
28#endif
29
30
31using namespace libconfig;
32using namespace itpp;
33using namespace std;
34
35namespace bdm {
36
37//! auxiliary function for debugging
38void UI_DBG (const Setting &S, const string &spc, ostream &out );
39
40
41//! Forward class declaration
42class logger;
43
44//! Root class of BDM objects
45class root {
46private:
47    //! It is necessary to allow calling of from_setting and to_setting within the UI class ++ i log_options
48    friend class UI;
49
50protected:
51
52    /*!
53    \brief Read instance properties according the data stored in the Setting structure.
54    It has to be called only through UI class, therefore it is protected
55
56    At the begining of this method, it is obligatory to call
57    the corresponding base::from_setting method. Sometimes, there can be
58    an exception from this rule. If so, the programmer is encouraged
59    to describe the reasons for this exception in the documentation in detail.
60
61    Then, all the configuration components should be read through the UI mechanism.
62    Those with UI::SettingPresence set to optional shoud have their defaults fulfilled
63    within the body of this method.
64
65    For instance, declaring a class \c trunk derived from our #root class,
66    the implementation of the from_setting method should look like this
67
68    \code
69
70    public trunk : public root {
71
72        anytype xxx, yyy;
73
74        virtual void from_setting ( const Setting &set ) {
75                root::from_setting( set );
76
77                UI::get ( xxx, set, "xxx", UI::compulsory );
78
79                if ( !UI::get ( yyy, set, "yyy", UI::optional ) ) {
80                        ... // here, it is necessary to set the default of attribute yyy
81                }
82
83                ... // another stuff related to trunk class
84        }
85
86        ... // other members of this class
87    };
88
89    \endcode
90    */
91    virtual void from_setting ( const Setting &set ) {
92    }
93
94    /*!
95    \brief      Save all the instance properties into the Setting structure.
96    It has to be called only through UI class, therefore it is protected
97
98    The only obligatory rule concerning the body of this method is to call
99    the corresponding base::to_setting method first.    Sometimes, there can
100    be an exception from this rule. If so, the programmer is encouraged
101    to describe the reasons for this exception in the documentation in detail.
102
103    For instance, declaring
104    a class \c trunk derived from our #root class, the implementation of
105    the to_setting method should look like this
106
107    \code
108    public trunk : public root {
109
110        anytype xxx;
111
112        virtual void to_setting ( const Setting &set ) {
113                root::to_setting( set );
114
115                UI::save ( xxx, set, "xxx" );
116
117                ... // another stuff related directly to trunk class
118
119        }
120
121        ... // other members of this class
122
123    };
124
125    \endcode
126    */
127    virtual void to_setting ( Setting &set ) const {
128    }
129
130public:
131
132    //!default constructor
133    root() {};
134
135    //! make sure this is a virtual object
136    virtual ~root() {
137    }
138
139    //! Returns basic textual info about the current instance
140    virtual string to_string() const {
141        Config C;
142        Setting &set=C.getRoot();
143        this->to_setting(set);
144        ostringstream os;
145        UI_DBG(set, "", os);
146        return os.str();
147    }
148    //! Register log levels of each inheritance layer to a logger, i.e. allocate space for data from this class
149    virtual void log_register ( logger &L, const string &prefix ) {
150    }
151
152    //! Write current information into the given logger
153    virtual void log_write() const {
154    }
155
156    /*!
157    \brief      This method checks that all internal structures has been set up correctly.
158
159    It is called automatically after the call of the #from_setting method by the mechanism of the UI class.
160    However, it can be called in any other situation to assure the correctness of an instance.
161
162    The only obligatory rule concerning the body of this method is to call
163    the corresponding base::validate method first. Sometimes, there can be
164    an exception from this rule. If so, the programmer is encouraged
165    to describe the reasons for this exception in the documentation in detail.
166
167    Then, only those checks which are not implemented in the base method
168    are implemented here. For instance, declaring a class \c trunk derived from our
169    #root class, the implementation of the method validate should
170    look like this
171
172    \code
173    public trunk : public root {
174
175        virtual void validate ( ) {
176                root::validate( );
177
178                ... // checks related directly to trunk class
179        }
180
181        ... // other members of this class
182
183    };
184
185    \endcode
186
187    */
188    virtual void validate() {
189    }
190
191    //! Virtual method providing deep copy of instances
192    virtual root* _copy() const NOT_IMPLEMENTED(NULL);
193
194};
195
196//! base class for all log_levels
197//!
198//! the existence of this class is forced by the necessity of passing log_levels to user_info methods, however, the main functionality
199//! is located in \c log_level_template class
200class log_level_base : public root {
201private:
202    //! this is necessary to allow logger to set ids vector appropriately and also to set registered_logger
203    friend class logger;
204
205protected:
206    //! internal pointer to the logger to which this log_level is registered
207    //!
208    //! it is set to NULL at the beginning
209    logger * registered_logger;
210
211    //! vector of vectors of log IDs - one element for each entry and multiple entries can be stored on the position of one enum
212    Vec<ivec> ids;
213
214
215    //! default constructor�which is intentionaly declared as protected
216    log_level_base( ) {
217        registered_logger = NULL;
218    }
219};
220//UIREGISTER IS FORBIDDEN FOR THIS CLASS,  AS IT SHOULD BE LOADED ONLY THROUGH THE SPECIALIZED UI::GET(...) METHOD
221
222}; //namespace
223#endif // root_H
Note: See TracBrowser for help on using the browser.