Show
Ignore:
Timestamp:
08/05/09 00:01:58 (15 years ago)
Author:
mido
Message:

1) ad UserInfo?: UI::get a UI::build predelany tak, ze vraci fals / NULL v pripade neexistence pozadovaneho Settingu, pridana enumericky typ UI::SettingPresence?, predelany stavajici UI implementace, dodelana UI dokumentace
2) dokoncena konfigurace ASTYLERU, brzy bude aplikovan
3) doxygen nastaven tak, ze vytvari soubor doxy_warnings.txt

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/doc/tutorial/ui.dox

    r272 r471  
    11/*! 
    2 \page ui User Infos and their use  
     2\page ui_page User Infos and their use 
     3  
     4\sa #bdm::UI 
    35 
    4 For easier interaction with users, experiments can be configured via structures called User Info. These structures contain information about details of the experiment that is to be performed. Since experiments involve the use of basic BDM classes and their compositions, the experiment description is also hierarchical with specific user info for each object or class. 
     6\sa #UIREGISTER 
    57 
    6  The User Infos are designed using customized version of the libconfig library (link!). It is specialized for BDM so as to recognize basic mathematical objects, such as vectors and matrices, see ... for details. 
     8\sa #bdm::UIFile 
     9 
     10\sa <a href="http://www.hyperrealm.com/libconfig/">The web page of the libconfig library.</a> 
     11 
     12\section ui_intro Introduction 
     13 
     14For easier interaction with users, experiments can be configured via structures called <b>User Info</b>. These structures contain information about details of the experiment that is to be performed. Since experiments involve the use of basic BDM classes and their compositions, the experiment description is also hierarchical with specific user info for each object or class. 
     15 
     16The User Infos are designed using customized version of the libconfig library (www.hyperrealm.com/libconfig). It is specialized for BDM so as to recognize basic mathematical objects, such as vectors and matrices, see details below. 
    717  
    8  (Technically it can be made compatible with matlab structures!) 
     18Technically it can be made compatible with matlab structures (TODO) 
     19 
     20\section ui_example Example 
    921  
    10  For example a simple experiment can be configures in a following way:  
     22For example, a simple experiment can be configures in the following way:  
    1123\code 
    1224ndat = 100;                //number of data points 
    13 prior = {type="enorm"; 
     25prior = { class="enorm"; 
    1426        mu = [1, 2, 3]; 
    1527        R = [1, 0, 0, 
     
    1830}; 
    1931\endcode 
    20  Exact meaning of root fields in this structure (i.e. ndat and prior) is defined by the application (or mex file) that is using this configuration file. It will look for expected fields and it will ignore any other structures. When it does not find what it is looking for, it terminates with an appropriate error message. 
     32The exact meaning of the root fields in this structure (i.e. \c ndat and \c prior) is defined by the application (or mex file) that is using this configuration file. It will look for expected fields and it will ignore any other structures. When it does not find what it is looking for, it terminates with an appropriate error message. 
    2133  
    22  A structure with field \c type="identifier" is special. Such a structure will be parsed by an appropriate class bdm::UIbuilder which will construct the desired object, in this instance of an object of the class bdm::enorm. 
    23  For a detailed example how this mechanism works in practice see \ref arx_ui. 
    24  */ 
     34A structure with field \c class="identifier" is special. Such a structure will be parsed by an appropriate #bdm::UI::build method which will construct the desired object, in this instance of an object of the class bdm::enorm. 
     35  
     36For a detailed example how this mechanism works in practice see \ref arx_ui. To learn about the possinility of making <b> internal or external links</b> in configuration files, see the documentation of #bdm::SettingResolver. 
     37 
     38\section ui_implementation Implementation of user info in a custom class 
     39  
     40In accordance with the previous example of the configuration file, consider the class defined as follows: 
     41 
     42\code 
     43 
     44class newbee : public bdm::root {   
     45  ... 
     46     
     47  bdm::enorm prior; 
     48  int ndat; 
     49   
     50  ...    
     51} 
     52 
     53\endcode 
     54   
     55There are few obligatory steps to implement user info mechanism in this class.  At first, the class has to be \b inherited (directly or indirectly) from #bdm::root, as you can see in our example. What is hidden behind the scene is the use of a <b>parameterless constructor.</b> Each class using User infos has to have one.  
     56 
     57Next, <b>two virtual methods</b> #bdm::root::from_setting and #bdm::root::to_setting defined in the #bdm::root class <b>should be overriden </b> in accordance with the content of the current class. In fact, you can override just method #bdm::root::from_setting in the case you are interested only in loading from configuration files, which is quite common. It is valid also in the other way round, i.e., in the case you are interested just in saving, override only #bdm::root::to_setting. 
     58 
     59How should look the bodies of these methods? It is important not to forget to call their <b>implementation in the base class</b> (in our case, it is the #bdm::root class). Then, they should contain loading of all the necessary class attributes in the case of #bdm::root::from_setting method and saving of them in the other case. To implement these operation, you are encouraged to use static methods of #bdm::UI class, namely #bdm::UI::get, #bdm::UI::build and #bdm::UI::save.  
     60 
     61It can look like this: 
     62 
     63\code  
     64  
     65class newbee : public bdm::root {   
     66  ... 
     67     
     68  bdm::enorm prior; 
     69  int ndat; 
     70   
     71  ... 
     72 
     73  virtual void from_setting(const Setting &set) { 
     74    root::from_setting(set); 
     75    if( !UI::get( ndat, set, "ndat" ) ) 
     76       ndat = 1;           
     77    prior = UI::build<enorm>( set, "prior", compulsory ); 
     78  } 
     79 
     80  virtual void to_setting(Setting &set) const { 
     81    root::to_setting(set); 
     82    UI::save(ndat, set, "ndat"); 
     83    UI::save(prior, set, "prior"); 
     84  } 
     85 
     86  ... 
     87} 
     88 
     89\endcode 
     90 
     91As you can see, the presence of a concrete Setting in the configuration file can be tested by the return value of these methods and the code initializing the 
     92default values can follow immediately. Imagine, for example, that the first attribute \c ndat is optional. Thereore, the default value is filled in the case that there is not any other in the configuration file (and so #bdm::UI::get method returs \c false). The second atribute, \c prior, is intended to be compulsory. This fact is specified by the last parameter of the templated #bdm::UI::build method. In this case, the method throws an exception if there is not proper data in the configuration file.  
     93 
     94The only difference between #bdm::UI::build and #bdm::UI::get method is in the types of variables they are prepared to. The #bdm::UI::build<T> method is used to initialize instances of classes derived from #bdm::root. It allocates them dynamically and return just an pointer to the new instance. This way it is possible even to load instances of inherited classes without aneven knowing about it. Oppositely, all scalar values of types int, double, string, vec, ivec or mat are loaded by the #bdm::UI::get method with a static memory management. It is also capable to load arrays of templated type #itpp::Array<T>.  
     95 
     96Saving is much more easier. For all the variable types, use the #bdm::UI::save method. 
     97*/