Changeset 396 for library/bdm

Show
Ignore:
Timestamp:
06/24/09 13:38:47 (15 years ago)
Author:
mido
Message:

UI documentation almost finished; UIException redesigned and used instead of UI::ui_error function

Location:
library/bdm/base
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/base/user_info.cpp

    r394 r396  
    11// 
    2 // C++ Implementation: itpp_ext 
    3 // 
    4 // Description: 
    5 // 
    6 // 
    7 // Author: smidl <smidl@utia.cas.cz>, (C) 2008 
     2// C++ Implementation: user_info.cpp 
     3// 
     4// Description: UI (user info) class for loading/saving objects from/to configuration files. 
     5// 
     6// 
     7// Author: smidl <smidl@utia.cas.cz>, (C) 2009 
    88// 
    99// Copyright: See COPYING file that comes with this distribution 
     
    120120} 
    121121 
    122 ///////////////////////////// Class UI::SettingResolver ///////////////////////////////////////////// 
    123  
    124 UI::SettingResolver::SettingResolver( const Setting &potential_link ) 
     122///////////////////////////// Class SettingResolver ///////////////////////////////////////////// 
     123 
     124SettingResolver::SettingResolver( const Setting &potential_link ) 
    125125        : result( initialize_reference( file, potential_link ) ) 
    126126{ 
    127127} 
    128128 
    129 const Setting& UI::SettingResolver::initialize_reference(UIFile *&file, const Setting &potential_link) 
     129const Setting& SettingResolver::initialize_reference(UIFile *&file, const Setting &potential_link) 
    130130{ 
    131131        file = NULL; 
     
    153153 
    154154    if ( !result->exists( link ) ) 
    155         ui_error( "linked setting was not found", potential_link ); 
     155        throw UIException( "linked setting was not found", potential_link ); 
    156156 
    157157    return (*result)[link]; 
    158158} 
    159159 
    160 UI::SettingResolver::~SettingResolver() 
     160SettingResolver::~SettingResolver() 
    161161{ 
    162162    if ( file ) delete file; 
     
    165165///////////////////////////// Class UI ///////////////////////////////////////////// 
    166166 
    167 void UI::ui_error( string message, const Setting &element ) 
    168 { 
    169     stringstream error_message; 
    170     error_message << "UI error: " << message << "! Check path """ << element.getPath() << """, source line " << element.getSourceLine() << "."; 
    171     it_error ( error_message.str() ); 
     167void UI::assert_type( const Setting &element, Setting::Type type ) 
     168{ 
     169        if( element.getType()!=type) 
     170                throw UIException("wrong setting type", element); 
    172171} 
    173172 
     
    175174{ 
    176175    if ( !element.isList()) 
    177         ui_error( "only TypeList elements could be indexed by integers", element ); 
     176        throw UIException( "only TypeList elements could be indexed by integers", element ); 
    178177 
    179178    if ( element.getLength() <= index ) 
    180         ui_error( "there is not any child with index " + index, element ); 
     179        throw UIException( "there is not any child with index " + index, element ); 
    181180 
    182181    return element[index]; 
     
    186185{ 
    187186    if ( !element.isGroup()) 
    188         ui_error( "only TypeGroup elements could be indexed by strings", element ); 
     187        throw UIException( "only TypeGroup elements could be indexed by strings", element ); 
    189188 
    190189    if ( !element.exists( name ) ) 
    191         ui_error( "there is not any child named """ + name, element ); 
     190        throw UIException( "there is not any child named """ + name, element ); 
    192191 
    193192    return element[name]; 
     
    278277                else if ( link.result.getLength() == 4 ) 
    279278                { 
    280                 ASSERT_UITYPE(link.result[0],TypeString); 
     279                assert_type(link.result[0],Setting::TypeString); 
    281280                        const char* elem1=(const char*)link.result[0]; 
    282281                        if( (strcmp(elem1, "matrix") )) 
    283                                 ui_error( "the setting supposed to represent a matrix element has wrong syntax", link.result ); 
     282                                throw UIException( "the setting supposed to represent a matrix element has wrong syntax", link.result ); 
    284283 
    285284                        data_offset = 1; 
    286285                } 
    287286                else 
    288                         ui_error( "the setting supposed to represent a matrix element has wrong syntax", link.result ); 
     287                        throw UIException( "the setting supposed to represent a matrix element has wrong syntax", link.result ); 
    289288 
    290289        Setting &rows_setting = link.result[0 + data_offset]; 
     
    292291        Setting &elements = link.result[2 + data_offset]; 
    293292 
    294         ASSERT_UITYPE(cols_setting,TypeInt); 
    295         ASSERT_UITYPE(rows_setting,TypeInt); 
    296         ASSERT_UITYPE(elements,TypeArray); 
     293        assert_type(cols_setting,Setting::TypeInt); 
     294        assert_type(rows_setting,Setting::TypeInt); 
     295        assert_type(elements,Setting::TypeArray); 
    297296 
    298297        int cols = cols_setting; 
     
    300299 
    301300        if ( cols < 0 | rows < 0 ) 
    302             ui_error( "the dimensions of a matrix has to be non-negative", link.result ); 
     301            throw UIException( "the dimensions of a matrix has to be non-negative", link.result ); 
    303302 
    304303        if ( elements.getLength() != cols * rows ) 
    305             ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
     304            throw UIException( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
    306305 
    307306        matrix.set_size( rows, cols ); 
     
    311310 
    312311        if ( !elements[0].isNumber() ) 
    313             ui_error( "matrix elements have to be numbers", elements[0] ); 
     312            throw UIException( "matrix elements have to be numbers", elements[0] ); 
    314313 
    315314        // build matrix row-wise 
     
    321320    } 
    322321 
    323     ui_error( "only numeric types or TypeList are supported as matrix values", link.result ); 
    324 } 
    325  
    326 void UI::from_setting( ivec &vector, const Setting &element ) 
     322    throw UIException( "only numeric types or TypeList are supported as matrix values", link.result ); 
     323} 
     324 
     325void UI::from_setting( vec &vector, const Setting &element ) 
    327326{ 
    328327    const SettingResolver link( element ); 
     
    330329    if ( link.result.isNumber() ) 
    331330    { 
    332   //      ASSERT_UITYPE(link.result,TypeInt); 
    333331        vector.set_length( 1 ); 
    334332        vector(0) = link.result; 
     
    342340 
    343341        if ( matrix.cols() != 1 & matrix.rows() !=1) 
    344                         ui_error( "the vector length is invalid, it seems to be rather a matrix", link.result ); 
     342                        throw UIException( "the vector length is invalid, it seems to be rather a matrix", link.result ); 
    345343 
    346344        int len = matrix.rows() * matrix.cols(); 
    347345        vector.set_length ( len ); 
    348346        if ( len == 0 ) return; 
    349  
    350                 Setting &elements = link.result[2]; 
    351         // ASSERT_UITYPE(elements[0],TypeInt); -- spolehame an autoconvert 
    352347 
    353348        if ( matrix.cols() == 1 ) 
     
    358353                                vector(i) = matrix(0,i); 
    359354        return; 
    360  
    361355    } 
    362356 
     
    367361        if ( len == 0 ) return; 
    368362 
    369         ASSERT_UITYPE(link.result[0],TypeInt); 
    370         for ( int i=0; i < len; i++ ) 
    371             vector(i) = link.result[i]; 
    372         return; 
    373     } 
    374  
    375     ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", link.result ); 
    376 } 
    377  
    378 void UI::from_setting( vec &vector, const Setting &element ) 
    379 { 
    380     const SettingResolver link( element ); 
    381  
    382     if ( link.result.isNumber() ) 
    383     { 
    384         vector.set_length( 1 ); 
    385         vector(0) = link.result; 
    386         return; 
    387     } 
    388  
    389     if ( link.result.isList() ) 
    390     { 
    391                 mat matrix; 
    392                 from_setting( matrix, link.result ); 
    393  
    394         if ( matrix.cols() != 1 & matrix.rows() !=1) 
    395                         ui_error( "the vector length is invalid, it seems to be rather a matrix", link.result ); 
    396  
    397         int len = matrix.rows() * matrix.cols(); 
    398         vector.set_length ( len ); 
    399         if ( len == 0 ) return; 
    400  
    401         if ( matrix.cols() == 1 ) 
    402                         for ( int i=0; i<len; i++ ) 
    403                                 vector(i) = matrix(i,0); 
    404                 else 
    405                         for ( int i=0; i<len; i++ ) 
    406                                 vector(i) = matrix(0,i); 
    407         return; 
    408     } 
    409  
    410     if ( link.result.isArray() ) 
    411     { 
    412         int len = link.result.getLength(); 
    413         vector.set_length( len ); 
    414         if ( len == 0 ) return; 
    415  
    416363        if ( !link.result[0].isNumber()) 
    417             ui_error("a vector element has to be a number", link.result[0]); 
     364            throw UIException("a vector element has to be a number", link.result[0]); 
    418365 
    419366        for ( int i=0; i < len; i++ )  
     
    423370    } 
    424371 
    425     ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", link.result ); 
     372    throw UIException( "only numeric types, TypeArray or TypeList are supported as vector values", link.result ); 
     373} 
     374 
     375void UI::from_setting( ivec &vector, const Setting &element ) 
     376{ 
     377        vec double_vector; 
     378        from_setting( double_vector, element );  
     379    int len = double_vector.length(); 
     380    vector.set_length ( len ); 
     381        for( int i = 0; i< len; i++ ) 
     382                vector(i) = (int) double_vector(i); 
    426383} 
    427384 
    428385void UI::from_setting( string &str, const Setting &element ) 
    429386{ 
    430     ASSERT_UITYPE(element,TypeString); 
     387    assert_type(element,Setting::TypeString); 
    431388    str = (const char*) element; 
    432389} 
     
    434391void UI::from_setting( int &integer, const Setting &element ) 
    435392{ 
    436     ASSERT_UITYPE(element,TypeInt); 
     393    assert_type(element,Setting::TypeInt); 
    437394    integer = element; 
    438395} 
     
    440397void UI::from_setting( double &real, const Setting &element ) 
    441398{ 
    442     ASSERT_UITYPE(element,TypeFloat); 
     399    assert_type(element,Setting::TypeFloat); 
    443400    real = element; 
    444401} 
  • library/bdm/base/user_info.h

    r394 r396  
     1/*! 
     2  \file 
     3  \brief UI (user info) class for loading/saving objects from/to configuration files.   
     4  It is designed over with an use of 'libconfig � C/C++ Configuration File Library' 
     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 
    114#ifndef USER_INFO_H 
    215#define USER_INFO_H 
     
    619#include <typeinfo> 
    720#include <map> 
     21#include <stdexcept> 
    822 
    923#include "libconfig/libconfig.h++" 
     
    1125#include "itpp/itbase.h" 
    1226 
    13 #include <stdexcept> 
    1427 
    1528using std::string; 
     
    2235/*! 
    2336  \def UIREGISTER(class_name) 
    24   Macro for registration of class into map of UserInfos -- registered class is scriptable  
    25  
    26   TODO napsat i to, ze UIREG musi byt v hacku.. 
     37  \brief Macro for registration of class into map of user-infos, registered class is scriptable using UI static methods 
     38   
     39  Argument \a class_name has to be a descendant of root class and also, it has to have parameterless constructor prepared. 
     40  This macro should be used in header file, immediately after a class declaration. 
     41   
     42  \sa TODO MODUL   
    2743*/ 
    2844#ifndef BDMLIB  
    29 #define UIREGISTER(class_name) template<> const ParticularUI<class_name>& ParticularUI<class_name>::ui = ParticularUI<class_name>(#class_name)  
     45        #define UIREGISTER(class_name) template<> const ParticularUI<class_name>& ParticularUI<class_name>::factory = ParticularUI<class_name>(#class_name)  
    3046#else 
    31 #define UIREGISTER(class_name) 
     47        #define UIREGISTER(class_name) 
    3248#endif 
    3349 
    34 //!  macro assertting that the setting SET is of the SettingType TYPE 
    35 #define ASSERT_UITYPE(SET,TYPE) it_assert_debug(SET.getType()==Setting::TYPE, string("Wrong setting type, see input path \"")+string(SET.getPath())+string("\"")) 
    36  
    37 //! exception used in UI::build if it fails it can be caught and handled - see merger_mex.h 
    38 class UIbuildException : public std::invalid_argument { 
    39         public: 
    40                 UIbuildException() : std::invalid_argument("class name") { } 
     50//! Exception prepared for reporting user-info errors which are always related to some concrete Setting path 
     51class UIException : public std::exception 
     52{ 
     53private: 
     54        //! Error message 
     55        const string message; 
     56 
     57public: 
     58        //! Use this constructor when you can pass the problematical Setting as a parameter 
     59        UIException( const string &message, const Setting &element  )  
     60                : message( "UI error: " + message + ". Check path \"" + string(element.getPath()) + "\"." ) 
     61        { 
     62        } 
     63 
     64        //! This constructor is for other occasions, when only path of problematical Setting is known 
     65        UIException( const string &message, const string &path  )  
     66                : message( "UI error: " + message + "! Check path \"" + path + "\"." ) 
     67        { 
     68        } 
     69 
     70        //! Overriden method for reporting an error message 
     71        virtual const char* what() const throw() 
     72        { 
     73                return message.c_str(); 
     74        } 
    4175}; 
     76 
    4277 
    4378/*! 
     
    66101{ 
    67102public: 
    68         //! create empty file instance prepared to store Settings 
     103        //! Create empty file instance prepared to store Settings 
    69104        UIFile(); 
    70105 
    71         //! creates instance and fills it from the configuration file file_name 
     106        //! Creates instance and fills it from the configuration file file_name 
    72107        UIFile( const string &file_name ); 
    73108 
    74         //! save all the stored Settings into the configuration file file_name 
     109        //! Save all the stored Settings into the configuration file file_name 
    75110        void save(const string &file_name); 
    76111 
    77         //! this operator allows the ability of substituting Setting parameter by UIFile instance 
     112        //! This operator allows the ability of substituting Setting parameter by UIFile instance 
    78113        operator Setting&(); 
    79114}; 
    80115 
    81  
     116/*! 
     117@brief This class serves to expand links used within configuration files.  
     118 
     119Value of any type but string can be linked to some other value of the same type 
     120defined elsewhere in the current configuration file or even in some different 
     121configuration file.  
     122 
     123Link have three parts, \<name\> : \<path\> \<\@filename\>. Field \<name\> contains the  
     124name of the new setting, \<path\> is the relative path to the referenced setting, which 
     125has to be taken from the %root Setting element. The last part \<\@filename\> is optional,  
     126it contains filename in the case the link should refer to a variable stored in a different 
     127file. From the previous part \<path\>, it has to be separated by '@'. 
     128 
     129\code 
     130    ... 
     131        jardovo :  
     132        { 
     133          class = "Car"; 
     134          year = 1992; 
     135          manufacturer = "liaz"; 
     136          kilometers = 1555000; 
     137        }; 
     138        ondrejovo :  
     139        { 
     140          class = "Bike"; 
     141          year = 1996; 
     142          manufacturer = "author"; 
     143          electricLights = true; 
     144          matr = ( 2, 2, [ 1.0, 0.0, 0.0, 1.0 ] ); 
     145        }; 
     146         
     147        #this is the example of local link to another mean of transport  
     148        elisky = "jardovo"; 
     149 
     150        ... 
     151 
     152        # and this link is external link pointing to file "other_cars.cfg" stored in the 
     153        # same directory, in that file, it refers to the local Setting "magic_cars.skubankovo" 
     154        kati = "magic_cars.skubankovo@other_cars.cfg"; 
     155 
     156    ... 
     157\endcode 
     158 
     159When you want to expand a possible linked setting "element" within your code, it has to be treated this way: 
     160 
     161\code 
     162        ... 
     163 
     164        const SettingResolver link( element ); 
     165 
     166        ... 
     167 
     168        int len = link.result.getLength(); 
     169 
     170        ... 
     171\endcode 
     172 
     173The whole point is that a resolved link (class member #result, i.e., "link.result" in the previous example) could point  
     174into a different configuration file. In that case there has to be an UIFile instance managing reading from this 
     175file. As the libconfig::Config deletes all its Settings when dealocated, UIFile must not be dealocated until all  
     176the necessary operation on the linked Setting are finished (otherwise, the link #result would be invalid just after  
     177the UIFile dealocation). And that is exactly the mechanism implemented within SettingResolver class. It assures,  
     178that the #result Setting reference is valid within the scope of SettingResolver instance. 
     179 */ 
     180class SettingResolver : root 
     181{ 
     182private: 
     183        //! If necessary, this pointer stores an addres of an opened UIFile, else it equals NULL 
     184        UIFile *file; 
     185 
     186        //! This method initialize #result reference, i.e., it executes the main code of SettingResolver class 
     187        //! 
     188        //! This code could be also located directly in constructor. The only reason why we made this  
     189        //! method is the keyword 'const' within the declaration of #result reference . Such a reference 
     190        //! have to be intialized before any other constructor command, exactly in the way it is implemented now. 
     191        const Setting &initialize_reference( UIFile* &file, const Setting &potential_link); 
     192 
     193public: 
     194        //! Reference to a resolved link or to the original Setting in the case it does not contain a link 
     195        const Setting &result; 
     196 
     197        //! If potential_link contains a link to some other setting, it is resolved here. Anyway, the Setting reference #result is prepared for use. 
     198        SettingResolver( const Setting &potential_link ); 
     199         
     200        //! An opened UIFile file is closed here if necessary. 
     201        ~SettingResolver();              
     202}; 
    82203 
    83204/*! 
     
    94215        //!  
    95216        //! The key property of this class is that it initilaize the internal map immediately 
    96         //! when it is used for a first time. Therefore, we do not have to care about the  
    97         //! order of calls to UIREGISTER macro, which operates with both these mappings. 
     217        //! when it is used for a first time. Therefore, we do not have to care about initialization  
     218        //! during a call of UIREGISTER macro operating with both these mappings. 
    98219        class MappedUI 
    99220        { 
     
    105226                typedef map< const type_info * const, const string > TypeInfoToStringMap; 
    106227 
    107                 //! immediately initialized instance of type StringToUIMap 
     228                //! Immediately initialized instance of type StringToUIMap 
    108229                static StringToUIMap& mapped_strings(); 
    109230 
    110                 //! immediately initialized instance of type TypeInfoToStringMap 
     231                //! Immediately initialized instance of type TypeInfoToStringMap 
    111232                static TypeInfoToStringMap& mapped_type_infos(); 
    112233 
    113                 //! method for reporting a error when an attempt to operate with an unregistered class occures 
     234                //! Method for reporting a error when an attempt to operate with an unregistered class occures 
    114235                static void unregistered_class_error( const string &unregistered_class_name ); 
    115236 
    116237        public: 
    117                 //! add a pair key-userinfo into the internal map 
     238                //! Add a pair key-userinfo into the internal map 
    118239                static void add_class( const string &class_name, const type_info * const class_type_info, const UI* const ui ); 
    119240 
    120                 //! search for an userinfo related to the passed class name within the internal map 
     241                //! Search for an userinfo related to the passed class name within the internal map 
    121242                static const UI& retrieve_ui( const string &class_name ); 
    122243 
    123                 //! search for an class name related to the passed type_info within the internal map 
     244                //! Search for an class name related to the passed type_info within the internal map 
    124245                static const string& retrieve_class_name( const type_info* const class_type_info ); 
    125246        }; 
    126247 
     248        //! Function assertting that the setting element is of the SettingType type 
     249        static void assert_type( const Setting &element, Setting::Type type); 
     250 
    127251        //! Method assembling a typeless instance, it is implemented in descendant class ParticularUI<T> 
    128252        virtual root* new_instance() const = 0; 
     
    134258        static const Setting& to_child_setting( const Setting &element, const string &name ); 
    135259 
    136         //! This methods converts a Setting into a matrix  
     260        //! This method converts a Setting into a matrix  
    137261        static void from_setting( mat& matrix, const Setting &element );         
    138         //! This methods converts a Setting into an integer vector 
     262        //! This method converts a Setting into an integer vector 
    139263        static void from_setting( ivec &vector, const Setting &element ); 
    140         //! This methods converts a Setting into a string 
     264        //! This method converts a Setting into a string 
    141265        static void from_setting( string &str, const Setting &element ); 
    142         //! This methods converts a Setting into a real vector 
     266        //! This method converts a Setting into a real vector 
    143267        static void from_setting( vec &vector, const Setting &element ); 
    144         //! This methods converts a Setting into a integer scalar  
     268        //! This method converts a Setting into a integer scalar  
    145269        static void from_setting( int &integer, const Setting &element ); 
    146         //! This methods converts a Setting into a real scalar  
     270        //! This method converts a Setting into a real scalar  
    147271        static void from_setting( double &real, const Setting &element ); 
    148         //! This methods converts a Setting into a class T descendant 
     272        //! This method converts a Setting into a class T descendant 
    149273        template<class T> static void from_setting( T* &instance, const Setting &element ) 
    150274        {                        
    151275                const SettingResolver link( element ); 
    152  
    153                 ASSERT_UITYPE(link.result,TypeGroup); 
    154  
    155                 // we get a velue stored in the "class" attribute  
     276                assert_type(link.result,Setting::TypeGroup); 
     277 
     278                // we get a value stored in the "class" attribute  
    156279                string class_name; 
    157280                if( !link.result.lookupValue( "class", class_name ) ) 
    158                         ui_error( "the obligatory ""class"" identifier is missing", link.result ); 
     281                        throw UIException( "the obligatory \"class\" identifier is missing", link.result ); 
    159282         
    160283                // then we find a user-info related to this type 
     
    163286                root* typeless_instance = related_UI.new_instance(); 
    164287 
    165                 instance = NULL; 
    166                 //try catch does not work!!! 
    167288                instance = dynamic_cast<T*>(typeless_instance); 
    168                 if (!instance){ 
    169                         throw UIbuildException(); 
    170                 } 
    171 //              catch(...) 
    172 //              { 
    173                         // TODO pouzit ui_error?  
    174 //                      it_error ( "UI error: class " + class_name + " is not a descendant of the desired output class. Try to call the UI::build function with a different type parameter." ); 
    175 //              } 
    176 //               
     289                if (!instance) 
     290                        throw UIException( "class " + class_name + " is not a descendant of the desired output class. Try to call the UI::build<T> function with a different type parameter.", link.result ); 
     291                 
    177292                try 
    178293                { 
     
    181296                catch(SettingException xcptn) 
    182297                { 
    183                         // TODO pouzit ui_error?  
    184                         it_error ( "UI error: the method " + class_name + ".from_setting(Setting&) has thrown an exception when parsing the setting " + xcptn.getPath() + ". Try to correct this method." ); 
     298                        throw UIException( "the method " + class_name + ".from_setting(Setting&) has thrown an SettingException. Try to correct this method", xcptn.getPath()); 
    185299                } 
    186300        }        
    187301 
    188         //! This methods converts a Setting into a new templated array ,  
    189         // TODO efektivne jen pro vect, mat a string, pro dalsi je nutne pridat from_setting metodu.. ale to asi necceme 
     302        //! This methods converts a Setting into a new templated array of type Array<T> 
    190303        template<class T> static void from_setting( Array<T> &array_to_load, const Setting &element ) 
    191304        { 
    192305                const SettingResolver link( element ); 
    193306 
    194                 ASSERT_UITYPE(link.result,TypeList); 
     307                assert_type(link.result,Setting::TypeList); 
    195308 
    196309                int len = link.result.getLength(); 
     
    202315        } 
    203316 
    204         //! Method for reporting user-info errors related to some concrete Setting 
    205         static void ui_error( string message, const Setting &element ); 
    206  
    207317protected: 
    208318        //! Default constructor for internal use only, see \sa ParticularUI<T> 
     
    214324public:  
    215325 
    216         /*! 
    217         @brief This class serves to expand links used in configuration file.  
    218  
    219         TODO - napsat co dela, a hlavne proc je to takhle implementovany.. otevreny soubor! 
    220  
    221         ABSOLUTE PATH..  
    222  
    223         Firstly, save some user-infos into the new UIFile instance. Then,  
    224         call the save method with a filename as its only argument: 
    225  
    226         \code 
    227                 CAudi audi; 
    228                 UIFile file; 
    229                 UI::save( audi, file, "TT"); 
    230                 file.save("cars.cfg"); 
    231         \endcode 
    232  
    233         */ 
    234         class SettingResolver    
    235         { 
    236         private: 
    237                 //! If necessary, this pointer stores an addres of an opened UIFile, else it equals NULL 
    238                 UIFile *file; 
    239  
    240                 //! This method initialize result reference, i.e., it executes the main code of SettingResolver class 
    241                 //! 
    242                 //! This code could be also located directly in constructor. The only reason why we made this  
    243                 //! method is the keyword 'const' within the declaration of result reference (TODO funguje odkaz?). Such a reference 
    244                 //! have to be intialized before any other constructor command, exactly in the way it is implemented now. 
    245                 const Setting &initialize_reference( UIFile* &file, const Setting &potential_link); 
    246  
    247         public: 
    248                 //! Reference to a resolved link or to the original Setting in the case it does not contain a link 
    249                 const Setting &result; 
    250  
    251                 //! If potential_link contains a link to some other setting, it is resolved here. Anyway, the Setting reference result is prepared for use. 
    252                 SettingResolver( const Setting &potential_link ); 
    253                  
    254                 //! An opened UIFile file is closed here if necessary. 
    255                 ~SettingResolver();              
    256         }; 
    257  
    258         //TODO 
    259         //! \name Initialization of bdm::root descendant classes according the values stored in a Setting variable 
     326        //! \name Initialization of classes  
    260327        //!@{ 
    261         //! Return value is by the second argument since it type checking via \c dynamic_cast. 
    262         template<class T> static T* build( const Setting &element, const int index ) 
    263         { 
    264                 T* instance; 
    265                 from_setting<T>( instance, to_child_setting( element, index ) ); 
    266                 return instance; 
    267         } 
    268         //! VS: addition for root elements 
    269         template<class T> static T* build( const Setting &element ) 
    270         { 
    271                 T* instance; 
    272                 from_setting<T>( instance,  element ); 
    273                 return instance; 
    274         } 
    275  
     328        //! The type T has to be a root descendant class 
     329 
     330        //! The new instance of type T* is constructed and initialized with values stored in the Setting element[name] 
    276331        template<class T> static T* build( const Setting &element, const string &name ) 
    277332        {                        
     
    280335                return instance; 
    281336        } 
     337        //! The new instance of type T* is constructed and initialized with values stored in the Setting element[index] 
     338        template<class T> static T* build( const Setting &element, const int index ) 
     339        { 
     340                T* instance; 
     341                from_setting<T>( instance, to_child_setting( element, index ) ); 
     342                return instance; 
     343        } 
     344        //! The new instance of type T* is constructed and initialized with values stored in the Setting element 
     345        template<class T> static T* build( const Setting &element ) 
     346        { 
     347                T* instance; 
     348                from_setting<T>( instance,  element ); 
     349                return instance; 
     350        } 
    282351        //!@} 
    283352 
    284         //! \name Initialization of structures according the values stored in a Setting variable - TODO VYCET?! 
     353        //! \name Initialization of structures  
    285354        //!@{ 
    286         //! This methods tries to build a new double matrix  
     355        //! The type T has to be int, double, string, vec, ivec or mat. 
     356 
     357        //! The existing instance of type T is initialized with values stored in the Setting element[name] 
    287358        template<class T> static void get( T &instance, const Setting &element, const string &name ) 
    288359        { 
     
    290361        } 
    291362 
    292         //! This methods tries to build a new double matrix  
     363        //! The existing instance of type T is initialized with values stored in the Setting element[index]  
    293364        template<class T> static void get( T &instance, const Setting &element, const int index ) 
    294365        { 
     
    296367        } 
    297368 
    298         //! This methods tries to build a new double matrix  
     369        //! The existing instance of type T is initialized with values stored in the Setting element directly 
    299370        template<class T> static void get( T &instance, const Setting &element  ) 
    300371        { 
    301372                from_setting( instance, element ); 
    302373        } 
    303  
    304         //! This methods tries to build a new double matrix  
     374        //!@} 
     375 
     376        //! \name Initialization of arrays Array<T> 
     377        //!@{ 
     378        //! The type T has to be int, double, string, vec, ivec or mat, or pointer to any root descendant. 
     379 
     380        //! The existing array of type T is initialized with values stored in the Setting element[name] 
    305381        template<class T> static void get( Array<T> &array_to_load, const Setting &element, const string &name ) 
    306382        { 
     
    308384        } 
    309385 
    310         //! This methods tries to build a new double matrix  
     386        //! The existing array of type T is initialized with values stored in the Setting element[index] 
    311387        template<class T> static void get( Array<T> &array_to_load, const Setting &element, const int index ) 
    312388        { 
     
    314390        } 
    315391 
    316         //! This methods tries to build a new double matrix  
     392        //! The existing array of type T is initialized with values stored in the Setting element 
    317393        template<class T> static void get( Array<T> &array_to_load, const Setting &element  ) 
    318394        { 
     
    321397        //!@} 
    322398 
     399        //! \name Serialization of objects and structures into a new Setting  
     400        //!@{ 
     401        //! The new child Setting can be accessed either by its name - if some name is passed as a parameter - 
     402        //! or by its integer index. In that case, the new element is added at the very end of the current list of child Settings. 
     403 
     404        //! A root descendant instance is stored in the new child Setting appended to the passed element 
    323405        template< class T> static void save( const T * const instance, Setting &element, const string &name = "") 
    324406        { 
     
    338420                catch(SettingException xcptn) 
    339421                { 
    340                         it_error ( "UI error: the method " + class_name + ".to_setting(Setting&) has thrown an exception when filling the setting " + xcptn.getPath() + ". Try to correct this method." ); 
     422                        throw UIException( "the method " + class_name + ".to_setting(Setting&) has thrown an SettingException. Try to correct this method", xcptn.getPath()); 
    341423                }        
    342424        } 
    343425 
    344         //! This methods tries to save a double vec  
     426        //! An Array<T> instance is stored in the new child Setting appended to the passed element 
    345427        template<class T> static void save( const Array<T> &array_to_save, Setting &element, const string &name = "" ) 
    346428        { 
    347                 ASSERT_UITYPE(element,TypeGroup); 
     429                assert_type(element,Setting::TypeGroup); 
    348430                Setting &list = (name == "") ? element.add( Setting::TypeList )                                                  
    349431                                                                         : element.add( name, Setting::TypeList );               
     
    352434        } 
    353435 
    354  
    355         //! This methods tries to save a double matrix  
     436        //! A matrix(of type mat) is stored in the new child Setting appended to the passed element 
    356437        static void save( const mat &matrix, Setting &element, const string &name = "" ); 
    357438 
    358         //! This methods tries to save a double vec  
     439        //! An integer vector (of type ivec) is stored in the new child Setting appended to the passed element 
    359440        static void save( const ivec &vec, Setting &element, const string &name = "" ); 
    360441         
     442        //! A double vector (of type vec) is stored in the new child Setting appended to the passed element 
    361443        static void save( const vec &vector, Setting &element, const string &name = "" ); 
    362         //! This methods tries to save a double vec  
     444 
     445        //! A string is stored in the new child Setting appended to the passed element 
    363446        static void save( const string &str, Setting &element, const string &name = "" ); 
    364447 
     448        //! An integer is stored in the new child Setting appended to the passed element 
    365449        static void save( const int &integer, Setting &element, const string &name = "" ); 
    366450 
     451        //! A double is stored in the new child Setting appended to the passed element 
    367452        static void save( const double &real, Setting &element, const string &name = "" );       
     453        //!@} 
    368454 
    369455}; 
    370456 
    371457 
    372 /*! 
    373 @brief The main userinfo template class. You should derive this class whenever you need  
    374 a new userinfo of a class which is compound from smaller elements (all having its 
    375 own userinfo class prepared). 
    376 */ 
     458//! The only UI descendant class which is not intended for direct use. It should be accessed within the ::UIREGISTER macro only. 
    377459template<typename T> class ParticularUI : private UI 
    378460{ 
    379         public: 
    380  
    381         //! default constructor, which is intentionally declared as private 
     461private: 
     462        //! Default constructor, which is intentionally declared as private 
    382463        ParticularUI<T>( const string &class_name) : UI( class_name, &typeid(T) )  
    383         {       cout << class_name << endl; 
    384         }; 
    385  
    386         //! the only instance of this class (each type T has its own instance) 
    387         //! which is used as a factory for processing related UI 
    388         static const ParticularUI<T>& ui;        
    389  
     464        {}; 
     465 
     466public: 
     467        //! The only instance of this class (each type T has its own instance) which is used as a factory for processing related UI 
     468        static const ParticularUI<T>& factory;   
     469 
     470        //! A method returning a brand new instance of class T, this method is the reason why there have to be a parameterless construcotor in class T 
    390471        root* new_instance() const 
    391472        { 
     
    394475}; 
    395476 
    396  
    397  
    398  
    399477} 
    400478 
    401 /*! Recursive build of objects defined in the same file 
    402  
    403 \code  
    404 {type="internal"; 
    405 path="system.profile.[0]";    // Path from the root  
    406 }; 
    407 \endcode 
    408  */ 
    409  
    410  
    411  
    412 /*! Recursive build of objects defined in external file 
    413  
    414 \code  
    415 {type="external"; 
    416 filename="my_file.cfg";       // name of file from which to read 
    417 path="system.profile.[0]";    // Path in the external file 
    418 }; 
    419 \endcode 
    420 / 
    421  
    422 */ 
    423  
    424479#endif // #ifndef USER_INFO_H