Changeset 345 for bdm/user_info.h

Show
Ignore:
Timestamp:
05/20/09 23:15:05 (15 years ago)
Author:
mido
Message:

dodelano user_info, castecne predelano podle stabni kultury, zbyva otestovat a udelat dokumentaci

Files:
1 moved

Legend:

Unmodified
Added
Removed
  • bdm/user_info.h

    r344 r345  
    2020using namespace libconfig; 
    2121 
    22 #define UIREGISTER(className) template<> ParticularUI<className>& ParticularUI<className>::ui = ParticularUI<className>(#className) 
     22#define UIREGISTER(class_name) template<> Particular_UI<class_name>& Particular_UI<class_name>::ui = Particular_UI<class_name>(#class_name) 
    2323 
    2424#define ASSERT_UITYPE(S,Type) it_assert_debug(S.getType()==Setting::Type, string("Wrong setting type, see input path \"")+string(S.getPath())+string("\"")) 
     
    3737        CAudi audi; 
    3838        RootElement root("cars.xml"); 
    39         UserInfo::Save( audi, root, "TT"); 
    40         root.Save(); 
     39        UserInfo::save( audi, root, "TT"); 
     40        root.save(); 
    4141\endcode 
    4242 
     
    4444\code 
    4545        RootElement root("cars.xml"); 
    46         root.Load(); 
    47         UserInfo::Build<T>(root,"TT"); 
     46        root.load(); 
     47        UserInfo::build<T>(root,"TT"); 
    4848\endcode 
    4949*/ 
    5050 
    51 class UIFile : public Config 
     51class UI_File : public Config 
    5252{ 
    5353private: 
    54         const string fileName; 
     54        const string file_name; 
    5555 
    5656public: 
    5757        //! attach new RootElement instance to a file (typically with an XML extension) 
    58         UIFile( const string &file_name ); 
     58        UI_File( const string &file_name ); 
    5959 
    6060        //! loads root element from a file 
    61         void Load(); 
    62  
    63         //! Save UserInfo to the file (typically with an XML extension) 
    64         void Save (); 
     61        void load(); 
     62 
     63        //! save UserInfo to the file (typically with an XML extension) 
     64        void save(); 
    6565 
    6666        operator Setting&(); 
     
    6969 
    7070/*! 
    71 @brief UserInfo is an abstract is for internal purposes only. Use CompoundUserInfo<T> or ParticularUI<T> instead. 
     71@brief UserInfo is an abstract is for internal purposes only. Use CompoundUserInfo<T> or Particular_UI<T> instead. 
    7272The raison d'etre of this class is to allow pointers to its templated descendants.  
    7373 
    7474Also, the main functions of the whole UserInfo library are included within this class, see 
    75 static methods 'Build' and 'Save'. 
     75static methods 'build' and 'save'. 
    7676 
    7777 
     
    8585{ 
    8686private: 
    87         //! just a typedef shortuct for a constant pointer to UI 
    88         typedef UI* pUI; 
    89  
    9087        //! static class encalupsating map of names to related UserInfos 
    9188        //!  
    9289        //! The key property of this class is that it initilaized the internal map immediately 
    9390        //! when it is used for a first time. 
    94         class StringToUIMap 
     91        class Class_To_UI 
    9592        { 
    9693        private: 
    9794                //! Type definition of mapping which transforms type names to the related user infors 
    98                 typedef map< const string, pUI > MappedString2UI; 
    99  
    100                 //! immediately initialized instance of type MappedString2UI 
    101                 static MappedString2UI& privateMap(); 
     95                typedef map< const string, UI* > Class_To_UI_Map; 
     96 
     97                //! immediately initialized instance of type Class_To_UI_Map 
     98                static Class_To_UI_Map& private_map(); 
    10299 
    103100        public: 
    104101                //! add a pair key-userinfo into the internal map 
    105                 static void Add( const string &className, pUI pInstance ); 
     102                static void add_class( const string &class_name, UI* ui ); 
    106103 
    107104                //! search for an userinfo related to the passed key within the internal map 
    108                 static pUI Retrieve( const string &className ); 
     105                static UI* retrieve_ui( const string &class_name ); 
    109106        }; 
    110107                                 
    111108        //! internal method assembling a typeless instance from components obtained by the 'AssemblyComponentsFromSetting()' method 
    112         virtual bdmroot* New() = 0; 
     109        virtual bdmroot* new_instance() = 0; 
    113110         
    114111        //! type name defined by user 
    115         const string className; 
    116  
    117 protected: 
    118  
    119         //! default constructor  
    120         UI( const string& className ) : className ( className ) 
    121         {        
    122                 StringToUIMap::Add( className, this ); 
    123         } 
    124  
    125         //! Virtual destructor for future use; 
    126         virtual ~UI(){}; 
    127  
    128 private: 
     112        const string class_name; 
    129113 
    130114        //! This methods tries to save an instance of type T (or some of its descendant types) 
    131         //! and build DOM tree accordingly. Then, it creates a new DOMNode named according className 
     115        //! and build DOM tree accordingly. Then, it creates a new DOMNode named according class_name 
    132116        //! and connecti it to the passed Setting as a new child node. 
    133         template<class T> static void ToSetting( T &instance, Setting &element ) 
    134         { 
    135                 string &className = ParticularUI<T>::ui.className; 
     117        template<class T> static void to_setting( const T &instance, Setting &root ) 
     118        { 
     119                const string &class_name = Particular_UI<T>::ui.class_name; 
    136120                         
    137121                // add attribute "class"  
    138122                Setting &type = root.add( "class", Setting::TypeString ); 
    139                 type = className; 
     123                type = class_name; 
    140124         
    141125                try 
    142126                { 
    143127                        // instance disassembling  
    144                         instance.ToSetting( root ); 
     128                        instance.to_setting( root ); 
    145129                } 
    146130                catch(SettingException xcptn) 
    147131                { 
    148                         it_error ( "UI: the method " + className + ".ToSetting(Setting&) has thrown an exception when filling the setting " + xcptn.getPath() + ". Try to correct this method." ); 
     132                        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." ); 
    149133                }        
    150134        } 
    151135 
    152         template<class T> static T* FromSetting( const Setting &element ) 
     136        template<class T> static T* from_setting( const Setting &element ) 
    153137        {                        
    154                 RevealIfLinked revealed_link( element ); 
    155                 const Setting &root = revealed_link.root(); 
     138                const Link_Expander link_expander( element ); 
     139                const Setting &root = link_expander.root(); 
    156140 
    157141                ASSERT_UITYPE(root,TypeGroup); 
    158142 
    159143                // we get a velue stored in the "class" attribute  
    160                 string className; 
    161                 if( !root.lookupValue( "class", className ) ) 
    162                 { 
    163                         stringstream msg; 
    164                         msg << "UI: the class identifier is missing within the setting """ << root.getPath() <<  """. Check line "  
    165                                 << root.getSourceLine() << "."; 
    166                         it_error ( msg.str() ); 
    167                 } 
    168  
     144                string class_name; 
     145                if( !root.lookupValue( "class", class_name ) ) 
     146                        ui_error( "the obligatory ""class"" identifier is missing", root ); 
    169147         
    170148                // and finally we find a UserInfo related to this type 
    171                 pUI pRelatedUI = StringToUIMap::Retrieve( className ); 
    172                 if( !pRelatedUI) 
    173                         it_error ( "UI: class " + className + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 
     149                UI* related_UI = Class_To_UI::retrieve_ui( class_name ); 
     150                if( !related_UI) 
     151                        it_error ( "UI error: class " + class_name + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 
    174152                 
    175                 bdmroot* pTypelessInstance = pRelatedUI->New(); 
    176  
    177                 T* pInstance = NULL; 
     153                bdmroot* typeless_instance = related_UI->new_instance(); 
     154 
     155                T* ui = NULL; 
    178156                try 
    179157                { 
    180                         pInstance = (T*) pTypelessInstance ; 
     158                        ui = (T*) typeless_instance ; 
    181159                } 
    182160                catch(...) 
    183161                { 
    184                         it_error ( "UI: class " + className + " is not a descendant of the desired output class. Try to call the UI::Build function with a different type parameter." ); 
     162                        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." ); 
    185163                } 
    186164                 
     
    188166                { 
    189167                        // instance assembling  
    190                         pInstance->FromSetting( root ); 
     168                        ui->from_setting( root ); 
    191169                } 
    192170                catch(SettingException xcptn) 
    193171                { 
    194                         string msg = "UI: the method " + className + ".FromSetting(Setting&) has thrown an exception when parsing the setting " + xcptn.getPath() + ". Try to correct this method."; 
    195                         it_error ( msg ); 
    196                 } 
    197                 return pInstance; 
     172                        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." ); 
     173                } 
     174                return ui; 
    198175        }        
    199176 
    200  
    201  
    202 public: 
    203177 
    204178        // vraci true, kdyz to byl platny link, jinak false.. v pripade chyby konci it_errorem.. 
    205179        // do elementu vrati setting prislusny po rozbaleni linku, jinak ponecha beze zmeny 
    206         class RevealIfLinked     
     180        class Link_Expander      
    207181        { 
    208182        private: 
    209                 UIFile *file; 
    210                 const Setting * result; 
     183                UI_File *file; 
     184                const Setting *result; 
    211185 
    212186        public: 
    213187 
    214                 RevealIfLinked( const Setting &element ) 
     188                Link_Expander( const Setting &potential_link ) 
    215189                { 
    216190                        file = NULL; 
    217                         result = &element; 
    218  
    219                         if( element.getType() !=  Setting::TypeString ) 
     191                        result = &potential_link; 
     192 
     193                        if( potential_link.getType() !=  Setting::TypeString ) 
    220194                                return; 
    221195 
    222                         string link = (string) element; 
     196                        string link = (string) potential_link; 
    223197                        size_t aerobase = link.find('@'); 
    224198                        if( aerobase != string::npos ) 
    225199                        { 
    226200                                string file_name = link.substr( aerobase + 1, link.length() ); 
    227                                 file = new UIFile( file_name ); 
    228                                 file->Load(); 
    229                                 // TODO OSETRIT FALSE, vyhodit iterr 
    230  
     201                                file = new UI_File( file_name ); 
     202                                file->load(); 
    231203                                result = &(Setting&)(*file); 
    232  
    233204                                link = link.substr( 0, aerobase ); 
    234205                        } 
     
    238209 
    239210                        if( !result->exists( link ) ) 
    240                         { 
    241                                 // vyhodi chybu v pripade chyby 
    242                                 printf(""); 
    243                         } 
     211                                ui_error( "linked Setting was not found", potential_link ); 
     212 
    244213                        result = &(*result)[link]; 
    245                         return; 
    246                 } 
    247  
    248                 ~RevealIfLinked() 
     214                } 
     215 
     216                ~Link_Expander() 
    249217                { 
    250218                        if( file ) delete file; 
    251219                } 
    252  
    253220                 
    254                 const Setting& root() 
     221                const Setting& root() const 
    255222                { 
    256223                        return *result; 
     
    258225        }; 
    259226 
    260         private: 
    261                 static const Setting* ToChildSetting( const Setting &element, const int index ) 
     227                static const Setting* to_child_setting( const Setting &element, const int index ) 
    262228                { 
    263229                        if( !element.isAggregate()) 
     
    270236                } 
    271237 
    272                 static const Setting* ToChildSetting( const Setting &element, const string &name ) 
     238                static const Setting* to_child_setting( const Setting &element, const string &name ) 
    273239                { 
    274240                        if( !element.isGroup() ) 
     
    281247                } 
    282248 
    283                 static Setting& ToChildSetting( Setting &element, const int index ) 
     249                static Setting& to_child_setting( Setting &element, const int index ) 
    284250                { 
    285251                        if( !element.isAggregate()) 
    286                         { 
    287                                 // TODO CO ZA TYP? ASI NE GROUP, COZ.. 
    288                         } 
     252                                ui_error( "it is not possible to index non-agregate element by integers", element ); 
     253 
    289254                        if( element.getLength() <= index ) 
    290                         { 
    291                                 stringstream msg; 
    292                                 msg << "UI: there is not any child with index " << index << " in the parsed setting "  
    293                                         << element.getPath() <<  ", check line " << element.getSourceLine() << "."; 
    294  
    295                                 it_error ( msg.str() ); 
    296                         } 
     255                                ui_error( "there is not any child with index " + index, element ); 
     256 
    297257                        return element[index]; 
    298258                } 
    299259 
    300                 static Setting& ToChildSetting( Setting &element, const string &name ) 
     260                static Setting& to_child_setting( Setting &element, const string &name ) 
    301261                { 
    302262                        ASSERT_UITYPE(element,TypeGroup); 
    303263                        if( !element.exists( name ) ) 
    304                         { 
    305                                 stringstream msg; 
    306                                 msg << "UI: there is not any child named """ << name << """ in the parsed setting "  
    307                                         << element.getPath() <<  ", check line " << element.getSourceLine() << "."; 
    308  
    309                                 it_error ( msg.str() ); 
    310                         } 
     264                                ui_error( "there is not any child named """ + name, element ); 
    311265                        return element[name]; 
    312266                } 
    313267 
    314268        //! This methods tries to build a new double matrix  
    315         static bool FromSetting( mat& matrix, const Setting &root ) 
    316         { 
    317                 ASSERT_UITYPE(root,TypeList); 
    318                 if( root.getLength() != 3 ) 
    319                 { 
    320                         stringstream msg; 
    321                         msg << "UI: the setting " << root.getPath() <<  """ supposed to represent a matrix element has wrong syntax"". Check line "  
    322                                 << root.getSourceLine() << "."; 
    323                         it_error ( msg.str() ); 
    324                 } 
    325  
    326                 Setting &cols_setting = root[0]; 
    327                 Setting &rows_setting = root[1]; 
    328                 Setting &values = root[2]; 
    329  
    330                 ASSERT_UITYPE(cols_setting,TypeInt); 
    331                 ASSERT_UITYPE(rows_setting,TypeInt); 
    332                 ASSERT_UITYPE(values,TypeArray); 
    333  
    334                 int cols = cols_setting; 
    335                 int rows = rows_setting; 
    336                  
    337                 if( values.getLength() != cols * rows ) 
    338                 { 
    339                         stringstream msg; 
    340                         msg << "UI: the lenght of array containing matrix values within setting " << root.getPath() <<  """ is improper, check line "  
    341                                 << root.getSourceLine() << "."; 
    342                         it_error ( msg.str() ); 
    343                 } 
    344  
    345                 matrix.set_size( rows, cols ); 
    346  
    347                 if( cols == 0 || rows == 0 ) 
    348                         return true; 
    349  
    350                 if( !values[0].isNumber() ) 
    351                 { 
    352                         stringstream msg; 
    353                         msg << "UI: the array containing matrix values within setting " << root.getPath() <<  """ has to contain numeric values only! Check line "  
    354                                 << root.getSourceLine() << "."; 
    355                         it_error ( msg.str() ); 
    356                 } 
    357  
    358                 // Build matrix row-wise 
    359                 int k = 0; 
    360                 for( int i=0;i<rows;i++ )  
    361                         for( int j=0; j<cols; j++) 
    362                                 matrix(i,j) = values[k++]; 
    363  
    364                 return true; 
     269        static void from_setting( mat& matrix, const Setting &element ) 
     270        { 
     271                const Link_Expander link_expander( element ); 
     272                const Setting &root = link_expander.root(); 
     273 
     274                if( root.isNumber() ) 
     275                { 
     276                        matrix.set_size( 1, 1 ); 
     277                        matrix(0,0) = root; 
     278                        return; 
     279                } 
     280 
     281                if( root.isList() ) 
     282                { 
     283                        if( root.getLength() != 3 ) 
     284                                ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
     285 
     286                        Setting &cols_setting = root[0]; 
     287                        Setting &rows_setting = root[1]; 
     288                        Setting &elements = root[2]; 
     289 
     290                        ASSERT_UITYPE(cols_setting,TypeInt); 
     291                        ASSERT_UITYPE(rows_setting,TypeInt); 
     292                        ASSERT_UITYPE(elements,TypeArray); 
     293 
     294                        int cols = cols_setting; 
     295                        int rows = rows_setting; 
     296                                                 
     297                        if( cols < 0 | rows < 0 ) 
     298                                ui_error( "the dimensions of a matrix has to be non-negative", root ); 
     299 
     300                        if( elements.getLength() != cols * rows ) 
     301                                ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
     302 
     303                        matrix.set_size( rows, cols ); 
     304 
     305                        if( cols == 0 || rows == 0 ) 
     306                                return; 
     307 
     308                        if( !elements[0].isNumber() ) 
     309                                ui_error( "matrix elements have to be numbers", elements[0] ); 
     310 
     311                        // build matrix row-wise 
     312                        int k = 0; 
     313                        for( int i=0;i<rows;i++ )  
     314                                for( int j=0; j<cols; j++) 
     315                                        matrix(i,j) = elements[k++]; 
     316                        return; 
     317                } 
     318 
     319                ui_error( "only numeric types or TypeList are supported as matrix values", root ); 
    365320        } 
    366321 
    367322        //! This methods tries to save a double matrix  
    368         static void ToSetting( mat &matrix, Setting &root ) 
     323        static void to_setting( const mat &matrix, Setting &root ) 
    369324        { 
    370325                Setting &cols = root.add( Setting::TypeInt ); 
     
    374329                rows = matrix.rows(); 
    375330 
    376                 Setting &values = root.add( Setting::TypeArray ); 
    377  
    378                 // Build matrix row-wise 
     331                Setting &elements = root.add( Setting::TypeArray ); 
     332 
     333                // build matrix row-wise 
    379334                for( int i=0; i<matrix.rows(); i++ )  
    380335                        for( int j=0; j<matrix.cols(); j++) 
    381336                        { 
    382                                 Setting &newField = values.add(Setting::TypeFloat); 
     337                                Setting &newField = elements.add(Setting::TypeFloat); 
    383338                                newField = matrix(i,j); 
    384339                        } 
     
    386341 
    387342        //! This methods tries to build a new integer vector 
    388         static bool FromSetting( ivec &vec, const Setting &root ) 
    389         { 
    390                 ASSERT_UITYPE(root,TypeArray); 
    391  
    392                 int len = root.getLength(); 
    393                 vec.set_length( len ); 
    394                 if( len == 0 ) return true; 
    395                 ASSERT_UITYPE(root[0],TypeInt); 
    396  
    397                 for( int i=0; i < len; i++ )  
    398                         vec(i) = root[i]; 
    399                  
    400                 return true; 
     343        static void from_setting( ivec &vec, const Setting &element ) 
     344        { 
     345                const Link_Expander link_expander( element ); 
     346                const Setting &root = link_expander.root(); 
     347 
     348                if( root.isNumber() ) 
     349                { 
     350                        ASSERT_UITYPE(root,TypeInt); 
     351                        vec.set_length( 1 ); 
     352                        vec(0) = root; 
     353                        return; 
     354                } 
     355 
     356                if( root.isList() ) 
     357                { 
     358                        if( root.getLength() != 3 ) 
     359                                ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
     360 
     361                        Setting &cols_setting = root[0]; 
     362                        Setting &rows_setting = root[1]; 
     363                        Setting &elements = root[2]; 
     364 
     365                        ASSERT_UITYPE(cols_setting,TypeInt); 
     366                        ASSERT_UITYPE(rows_setting,TypeInt); 
     367                        ASSERT_UITYPE(elements,TypeArray); 
     368 
     369                        int cols = cols_setting; 
     370                        int rows = rows_setting; 
     371                         
     372                        if( cols < 0 | rows < 0) 
     373                                ui_error( "the dimensions of a matrix has to be non-negative", root ); 
     374 
     375                        if( elements.getLength() != cols * rows ) 
     376                                ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
     377 
     378                        if( cols != 1 & rows !=1) 
     379                                ui_error( "the vector length is invalid, it seems to be rather a matrix", elements ); 
     380                         
     381                        int len = rows * cols; 
     382                        vec.set_length ( len ); 
     383                        if( len == 0 ) return; 
     384 
     385                        ASSERT_UITYPE(elements[0],TypeInt); 
     386                        for( int i=0; i<len; i++ )  
     387                                vec(i) = elements[i]; 
     388                        return; 
     389                } 
     390 
     391                if( root.isArray() ) 
     392                {        
     393                        int len = root.getLength(); 
     394                        vec.set_length( len ); 
     395                        if( len == 0 ) return; 
     396 
     397                        ASSERT_UITYPE(root[0],TypeInt); 
     398                        for( int i=0; i < len; i++ )  
     399                                vec(i) = root[i]; 
     400                        return; 
     401                } 
     402 
     403                ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", root ); 
    401404        } 
    402405 
    403406        //! This methods tries to save an integer vector 
    404         static void ToSetting( ivec &vec, Setting &root ) 
     407        static void to_setting( const ivec &vec, Setting &root ) 
    405408        { 
    406409                for( int i=0; i<vec.length(); i++ )  
     
    412415 
    413416        //! This methods tries to build a new array of strings  
    414         static bool FromSetting( Array<string> &string_array, const Setting &root) 
    415         { 
    416                 ASSERT_UITYPE(root,TypeArray); 
    417  
    418                 int len = root.getLength(); 
    419                 string_array.set_length( len ); 
    420                 if( len == 0 ) return true; 
    421                 ASSERT_UITYPE(root[0],TypeString); 
    422  
    423                 for( int i=0; i < len; i++ )  
    424                         string_array(i) = (string)root[i]; 
    425  
    426                 return true; 
     417        static void from_setting( Array<string> &string_array, const Setting &element ) 
     418        { 
     419                const Link_Expander link_expander( element ); 
     420                const Setting &root = link_expander.root(); 
     421 
     422                if( root.getType() == Setting::TypeString ) 
     423                { 
     424                        string_array.set_length( 1 ); 
     425                        string_array(0) = (string)root; 
     426                        return; 
     427                } 
     428 
     429                if( root.isArray() ) 
     430                { 
     431                        int len = root.getLength(); 
     432                        string_array.set_length( len ); 
     433                        if( len == 0 ) return; 
     434 
     435                        ASSERT_UITYPE(root[0],TypeString); 
     436                        for( int i=0; i < len; i++ )  
     437                                string_array(i) = (string)root[i]; 
     438                        return; 
     439                } 
     440 
     441                ui_error( "only TypeString or TypeArray are supported as vector of string values", root ); 
    427442        } 
    428443 
    429444        //! This methods tries to save an array of strings 
    430         static void ToSetting( Array<string> &string_array, Setting &root ) 
     445        static void to_setting( const Array<string> &string_array, Setting &root ) 
    431446        { 
    432447                for( int i=0; i<string_array.length(); i++ )  
     
    437452        } 
    438453 
     454protected: 
     455 
     456        //! default constructor  
     457        UI( const string& class_name ) : class_name ( class_name ) 
     458        {        
     459                Class_To_UI::add_class( class_name, this ); 
     460        } 
     461 
     462        //! Virtual destructor for future use; 
     463        virtual ~UI(){}; 
     464 
    439465public:  
    440466 
     467        static void ui_error( string message, const Setting &element ) 
     468        { 
     469                stringstream error_message; 
     470                error_message << "UI ui_error: " << message << "! Check path """ << element.getPath() << """, source line " << element.getSourceLine() << "."; 
     471                it_error ( error_message.str() ); 
     472        } 
     473 
    441474        //! This methods tries to build a new instance of type T (or some of its descendant types) 
    442         //! according to a data stored in a DOMNode named className within a child nodes of the passed element. 
    443         //! If an error occurs, it returns a NULL pointer. 
     475        //! according to a data stored in a DOMNode named class_name within a child nodes of the passed element. 
     476        //! If an ui_error occurs, it returns a NULL pointer. 
    444477 
    445478        //! Prototype of a UI builder. Return value is by the second argument since it type checking via \c dynamic_cast. 
    446         template<class T> static T* Build( Setting &element, const int index ) 
    447         { 
    448                 return FromSetting<T>( ToChildSetting( element, index ) ); 
    449         } 
    450  
    451         template<class T> static T* Build( Setting &element, const string &name ) 
     479        template<class T> static T* build( Setting &element, const int index ) 
     480        { 
     481                return from_setting<T>( to_child_setting( element, index ) ); 
     482        } 
     483 
     484        template<class T> static T* build( Setting &element, const string &name ) 
    452485        {                        
    453                 return FromSetting<T>( ToChildSetting( element, name ) ); 
     486                return from_setting<T>( to_child_setting( element, name ) ); 
    454487        } 
    455488 
    456489        //! This methods tries to save an instance of type T (or some of its descendant types) 
    457         //! and build DOM tree accordingly. Then, it creates a new DOMNode named according className 
     490        //! and build DOM tree accordingly. Then, it creates a new DOMNode named according class_name 
    458491        //! and connecti it to the passed Setting as a new child node. 
    459         template<class T> static void Save( T &instance, Setting &element ) 
    460         { 
    461                 Setting &root = element.add( Setting::TypeGroup );               
    462                 ToSetting( instance, root ); 
    463         } 
    464  
    465         //! This methods tries to save an instance of type T (or some of its descendant types) 
    466         //! and build DOM tree accordingly. Then, it creates a new DOMNode named according className 
    467         //! and connecti it to the passed Setting as a new child node. 
    468         template<class T> static void Save( T &instance, Setting &element, const string &name ) 
    469         { 
    470                 Setting &root = element.add( name, Setting::TypeGroup );                 
    471                 ToSetting( instance, root ); 
     492        template<class T> static void save( T &instance, Setting &element, const string &name = "") 
     493        { 
     494                Setting &root = (name == "") ? element.add( Setting::TypeGroup )                                                         
     495                                                                         : element.add( name, Setting::TypeGroup );              
     496                to_setting( instance, root ); 
    472497        } 
    473498 
    474499        //! This methods tries to build a new double matrix  
    475         static bool Get( mat& matrix, const Setting &element, const string &name ) 
    476         { 
    477                 const Setting *root = ToChildSetting( element, name ); 
     500        static bool get( mat& matrix, const Setting &element, const string &name ) 
     501        { 
     502                const Setting *root = to_child_setting( element, name ); 
    478503                if( !root ) return false;                                
    479                 return FromSetting( matrix, *root ); 
     504                from_setting( matrix, *root ); 
     505                return true; 
    480506        } 
    481507 
    482508        //! This methods tries to build a new double matrix  
    483         static bool Get( mat& matrix, const Setting &element, const int index ) 
    484         { 
    485                 const Setting *root = ToChildSetting( element, index ); 
     509        static bool get( mat& matrix, const Setting &element, const int index ) 
     510        { 
     511                const Setting *root = to_child_setting( element, index ); 
    486512                if( !root ) return false;                                
    487                 return FromSetting( matrix, *root ); 
     513                from_setting( matrix, *root ); 
     514                return true; 
    488515        } 
    489516 
    490517        //! This methods tries to save a double matrix  
    491         static void Save( mat &matrix, Setting &element, const string &name ) 
    492         { 
    493                 Setting &root = element.add( name, Setting::TypeList );          
    494                 ToSetting( matrix, root ); 
    495         } 
    496  
    497         //! This methods tries to save a double matrix  
    498         static void Save( mat &matrix, Setting &element ) 
    499         { 
    500                 Setting &root = element.add( Setting::TypeList );                
    501                 ToSetting( matrix, root ); 
    502         } 
    503  
     518        static void save( mat &matrix, Setting &element, const string &name = "" ) 
     519        { 
     520                Setting &root = (name == "") ? element.add( Setting::TypeList )                                                  
     521                                                                         : element.add( name, Setting::TypeList );               
     522                to_setting( matrix, root ); 
     523        } 
    504524 
    505525        //! This methods tries to build a new double vec  
    506         static bool Get( ivec& vec, const Setting &element, const string &name ) 
    507         { 
    508                 const Setting *root = ToChildSetting( element, name ); 
     526        static bool get( ivec& vec, const Setting &element, const string &name ) 
     527        { 
     528                const Setting *root = to_child_setting( element, name ); 
    509529                if( !root ) return false;                                
    510                 return FromSetting( vec, *root ); 
     530                from_setting( vec, *root ); 
     531                return true; 
    511532        } 
    512533 
    513534        //! This methods tries to build a new double vec  
    514         static bool Get( ivec& vec, const Setting &element, const int index ) 
    515         { 
    516                 const Setting *root = ToChildSetting( element, index ); 
     535        static bool get( ivec& vec, const Setting &element, const int index ) 
     536        { 
     537                const Setting *root = to_child_setting( element, index ); 
    517538                if( !root ) return false;                                
    518                 return FromSetting( vec, *root ); 
     539                from_setting( vec, *root ); 
     540                return true; 
    519541        } 
    520542 
    521543        //! This methods tries to save a double vec  
    522         static void Save( ivec &vec, Setting &element, const string &name ) 
    523         { 
    524                 Setting &root = element.add( name, Setting::TypeArray );                 
    525                 ToSetting( vec, root ); 
    526         } 
    527  
    528         //! This methods tries to save a double vec  
    529         static void Save( ivec &vec, Setting &element) 
    530         { 
    531                 Setting &root = element.add( Setting::TypeArray );               
    532                 ToSetting( vec, root ); 
    533         } 
    534  
     544        static void save( ivec &vec, Setting &element, const string &name = "" ) 
     545        { 
     546                Setting &root = (name == "") ? element.add( Setting::TypeArray )                                                         
     547                                                                         : element.add( name, Setting::TypeArray );              
     548                to_setting( vec, root ); 
     549        } 
    535550 
    536551        //! This methods tries to build a new double string_array  
    537         static bool Get( Array<string> &string_array, const Setting &element, const string &name ) 
    538         { 
    539                 const Setting *root = ToChildSetting( element, name ); 
     552        static bool get( Array<string> &string_array, const Setting &element, const string &name ) 
     553        { 
     554                const Setting *root = to_child_setting( element, name ); 
    540555                if( !root ) return false;                                
    541                 return FromSetting( string_array, *root ); 
     556                from_setting( string_array, *root ); 
     557                return true; 
    542558        } 
    543559 
    544560        //! This methods tries to build a new double string_array  
    545         static bool Get( Array<string> &string_array, const Setting &element, const int index ) 
    546         { 
    547                 const Setting *root = ToChildSetting( element, index ); 
     561        static bool get( Array<string> &string_array, const Setting &element, const int index ) 
     562        { 
     563                const Setting *root = to_child_setting( element, index ); 
    548564                if( !root ) return false;                                
    549                 return FromSetting( string_array, *root ); 
     565                from_setting( string_array, *root ); 
     566                return true; 
    550567        } 
    551568 
    552569        //! This methods tries to save a double string_array  
    553         static void Save( Array<string> &string_array, Setting &element, const string &name ) 
    554         { 
    555                 Setting &root = element.add( name, Setting::TypeArray );                 
    556                 ToSetting( string_array, root ); 
    557         } 
    558  
    559         //! This methods tries to save a double string_array  
    560         static void Save( Array<string> &string_array, Setting &element ) 
    561         { 
    562                 Setting &root = element.add( Setting::TypeArray );               
    563                 ToSetting( string_array, root ); 
    564         } 
    565  
    566  
     570        static void save( Array<string> &string_array, Setting &element, const string &name = "" ) 
     571        { 
     572                Setting &root = (name == "") ? element.add( Setting::TypeArray )                                                         
     573                                                                         : element.add( name, Setting::TypeArray );              
     574                to_setting( string_array, root ); 
     575        } 
    567576}; 
    568577 
     
    573582own userinfo class prepared). 
    574583*/ 
    575 template<typename T> class ParticularUI : private UI 
     584template<typename T> class Particular_UI : private UI 
    576585{ 
    577         // to permit acces to the ParticularUI<T>::ui to the UI class 
     586        // to permit acces to the Particular_UI<T>::ui to the UI class 
    578587        friend UI; 
    579588 
    580589        //! default constructor, which is intentionally declared as private 
    581         ParticularUI<T>( const string &className) : UI( className )  
     590        Particular_UI<T>( const string &class_name) : UI( class_name )  
    582591        {        
    583592        }; 
     
    585594        //! the only instance of this class (each type T has its own instance) 
    586595        //! which is used as a factory for processing related UI 
    587         static ParticularUI<T>& ui;      
    588  
    589         bdmroot* New() 
     596        static Particular_UI<T>& ui;     
     597 
     598        bdmroot* new_instance() 
    590599        { 
    591600                return new T(); 
     
    617626/ 
    618627 
    619  
    620 //! [Debugging] Print values in current S to cout 
    621 void UI_DBG ( Setting &S, const string &spc ); 
    622  
    623  
    624 /* 
    625 //! Auxiliary function allowing recursivity in S (too complex, remove?) 
    626 template<class T> 
    627 void UIcall ( Setting &S, void ( *func ) ( Setting&, T ), T Tmp ) { 
    628         ASSERT_UITYPE ( S,TypeGroup ); 
    629         // Check if field "class" is present, if not it is not a valid UI 
    630         it_assert_debug ( S.exists ( "class" ), string ( S.getPath() ) +" is not a valid UI!" ); 
    631  
    632         const string typ=S["class"]; 
    633         if ( typ=="internal" ) { 
    634                 try { 
    635                         Setting* Stmp = &S; 
    636                         do {Stmp=& ( Stmp->getParent() );} 
    637                         while ( !Stmp->isRoot() ); 
    638                         Setting& intS=Stmp->lookup ( ( const char* ) S["path"] ); 
    639                         func ( intS, Tmp ); // <======== calling func 
    640                         return; 
    641                 } 
    642                 catch ( ... ) { 
    643                         it_error ( "Internal field " + string ( S.getPath() ) + " not valid" ); 
    644                 } 
    645         } 
    646         if ( typ=="external" ) { 
    647                 UIFile C ( S["filename"] ); 
    648                 try { 
    649                         func ( C.lookup ( ( const char* ) S["path"] ), Tmp ); 
    650                 } 
    651                 catch ( ... ) { 
    652                         it_error ( "External field " + string ( S.getPath() ) + " not valid" ); 
    653                 } 
    654                 return; 
    655         } 
    656  
    657         // v======================= calling final func 
    658         func ( S, Tmp ); 
    659 }; 
    660  
    661 } 
    662  
    663628*/ 
    664629