Changeset 357 for bdm/user_info.cpp

Show
Ignore:
Timestamp:
06/08/09 02:15:30 (15 years ago)
Author:
mido
Message:

mnoho zmen:
1) presun FindXXX modulu do \system
2) zalozeni dokumentace \doc\local\library_structure.dox
3) presun obsahu \tests\UI primo do \tests
4) namisto \INSTALL zalozen \install.html, je to vhodnejsi pro uzivatele WINDOWS, a snad i obecne
5) snaha o predelani veskerych UI podle nove koncepce, soubory pmsm_ui.h, arx_ui.h, KF_ui.h, libDS_ui.h, libEF_ui.h a loggers_ui.h ponechavam
jen zdokumentacnich duvodu, nic by na nich jiz nemelo zaviset, a po zkontrolovani spravnosti provedenych uprav by mely byt smazany
6) predelani estimatoru tak, aby fungoval s novym UI konceptem
7) vytazeni tridy bdmroot do samostatneho souboru \bdm\bdmroot.h
8) pridana dokumentace pro zacleneni programu ASTYLE do Visual studia, ASTYLE pridan do instalacniho balicku pro Windows

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bdm/user_info.cpp

    r351 r357  
    1313#include "user_info.h" 
    1414 
    15 namespace bdm { 
     15namespace bdm 
     16{ 
    1617 
    1718 
     
    1920 
    2021 
    21 UI_File::UI_File ( const string &file_name ) : file_name( file_name ) 
    22 { 
    23         setAutoConvert( true ); 
     22UI_File::UI_File () 
     23{ 
     24    setAutoConvert( true ); 
    2425} 
    2526 
    2627//! loads root element from a file 
    27 void UI_File::load()  
    28 { 
    29         try 
    30         { 
    31                 readFile( file_name.c_str()  ); 
    32         } 
    33         catch ( FileIOException f )  
    34         { 
    35                 it_error ( "UI error: file " + file_name + " not found." ); 
    36         } 
    37         catch ( ParseException& P )  
    38         { 
    39                 stringstream msg; 
    40                 msg << "UI error: parsing ui_error """ << P.getError() << """ in file " << file_name << " on line " <<  P.getLine() << "."; 
    41                 it_error ( msg.str() ); 
    42         }        
     28UI_File::UI_File ( const string &file_name ) 
     29{ 
     30    setAutoConvert( true ); 
     31    try 
     32    { 
     33        readFile( file_name.c_str()  ); 
     34    } 
     35    catch ( FileIOException f ) 
     36    { 
     37        it_error ( "UI error: file " + file_name + " not found." ); 
     38    } 
     39    catch ( ParseException& P ) 
     40    { 
     41        stringstream msg; 
     42        msg << "UI error: parsing error """ << P.getError() << """ in file " << file_name << " on line " <<  P.getLine() << "."; 
     43        it_error ( msg.str() ); 
     44    } 
    4345} 
    4446 
    4547 
    4648//! save UserInfo to the file (typically with an XML extension) 
    47 void UI_File::save() 
    48 { 
    49         try 
    50         { 
    51                 writeFile ( file_name.c_str()  ); 
    52         } 
    53         catch ( FileIOException f )  
    54         { 
    55                 it_error( "UI error: file " + file_name + " is inacessible." ); 
    56         }                
    57 }        
     49void UI_File::save(  const string &file_name ) 
     50{ 
     51    try 
     52    { 
     53        writeFile ( file_name.c_str()  ); 
     54    } 
     55    catch ( FileIOException f ) 
     56    { 
     57        it_error( "UI error: file " + file_name + " is inacessible." ); 
     58    } 
     59} 
    5860 
    5961UI_File::operator Setting&() 
    6062{ 
    61         return getRoot(); 
     63    return getRoot(); 
    6264} 
    6365///////////////////////// INTERNAL MAPPED_UI ///////////////////////////////////////////// 
     
    6567UI::Mapped_UI::String_To_UI_Map& UI::Mapped_UI::mapped_strings() 
    6668{ 
    67         static String_To_UI_Map var; 
    68         return var; 
     69    static String_To_UI_Map var; 
     70    return var; 
    6971} 
    7072 
    7173UI::Mapped_UI::Type_Info_To_String_Map& UI::Mapped_UI::mapped_type_infos() 
    7274{ 
    73         static Type_Info_To_String_Map var; 
    74         return var; 
     75    static Type_Info_To_String_Map var; 
     76    return var; 
    7577} 
    7678 
    7779void UI::Mapped_UI::add_class( const string &class_name, const type_info * const class_type_info, const UI* const ui ) 
    7880{ 
    79         pair< const string, const UI* const > new_pair = make_pair( class_name, ui ); 
    80         mapped_strings().insert( new_pair ); 
    81         mapped_type_infos().insert( make_pair( class_type_info, new_pair.first ) ); 
     81    pair< const string, const UI* const > new_pair = make_pair( class_name, ui ); 
     82    mapped_strings().insert( new_pair ); 
     83    mapped_type_infos().insert( make_pair( class_type_info, new_pair.first ) ); 
    8284} 
    8385 
    8486const UI& UI::Mapped_UI::retrieve_ui( const string &class_name ) 
    8587{ 
    86         String_To_UI_Map::const_iterator iter = mapped_strings().find( class_name ); 
    87         if( iter == mapped_strings().end())  
    88                 it_error ( "UI error: class " + class_name + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 
    89         return *iter->second; 
    90 }        
     88    String_To_UI_Map::const_iterator iter = mapped_strings().find( class_name ); 
     89    if ( iter == mapped_strings().end()) 
     90        it_error ( "UI error: class " + class_name + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 
     91    return *iter->second; 
     92} 
    9193 
    9294const string& UI::Mapped_UI::retrieve_class_name( const type_info * const class_type_info ) 
    9395{ 
    94         Type_Info_To_String_Map::const_iterator iter = mapped_type_infos().find( class_type_info ); 
    95         if( iter == mapped_type_infos().end())  
    96                 it_error ( "UI error: class with RTTI name " + string(class_type_info->name()) + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 
    97         return iter->second; 
    98 }        
     96    Type_Info_To_String_Map::const_iterator iter = mapped_type_infos().find( class_type_info ); 
     97    if ( iter == mapped_type_infos().end()) 
     98        it_error ( "UI error: class with RTTI name " + string(class_type_info->name()) + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 
     99    return iter->second; 
     100} 
    99101 
    100102///////////////////////// INTERNAL LINK EXPANDER ///////////////////////////////////////////// 
     
    102104UI::Link_Expander::Link_Expander( const Setting &potential_link ) 
    103105{ 
    104         file = NULL; 
    105         result = &potential_link; 
    106  
    107         if( potential_link.getType() !=  Setting::TypeString ) 
    108                 return; 
    109  
    110         string link = (string) potential_link; 
    111         size_t aerobase = link.find('@'); 
    112         if( aerobase != string::npos ) 
    113         { 
    114                 string file_name = link.substr( aerobase + 1, link.length() ); 
    115                 file = new UI_File( file_name ); 
    116                 file->load(); 
    117                 result = &(Setting&)(*file); 
    118                 link = link.substr( 0, aerobase ); 
    119         } 
    120         else 
    121                 while ( !result->isRoot() )  
    122                         result = &result->getParent(); 
    123  
    124         if( !result->exists( link ) ) 
    125                 ui_error( "linked Setting was not found", potential_link ); 
    126  
    127         result = &(*result)[link]; 
     106    file = NULL; 
     107    result = &potential_link; 
     108 
     109    if ( potential_link.getType() !=  Setting::TypeString ) 
     110        return; 
     111 
     112    string link = (string) potential_link; 
     113    size_t aerobase = link.find('@'); 
     114    if ( aerobase != string::npos ) 
     115    { 
     116        string file_name = link.substr( aerobase + 1, link.length() ); 
     117        file = new UI_File( file_name ); 
     118        result = &(Setting&)(*file); 
     119        link = link.substr( 0, aerobase ); 
     120    } 
     121    else 
     122        while ( !result->isRoot() ) 
     123            result = &result->getParent(); 
     124 
     125    if ( !result->exists( link ) ) 
     126        ui_error( "linked Setting was not found", potential_link ); 
     127 
     128    result = &(*result)[link]; 
    128129} 
    129130 
    130131UI::Link_Expander::~Link_Expander() 
    131132{ 
    132         if( file ) delete file; 
     133    if ( file ) delete file; 
    133134} 
    134135 
    135136const Setting& UI::Link_Expander::root() const 
    136137{ 
    137         return *result; 
     138    return *result; 
    138139} 
    139140 
    140141///////////////////////// UI ///////////////////////////////////////////// 
    141142 
    142  
    143  
    144 //! This methods   - kvuli ukladani pole stringu, dat jen privatne? 
     143void UI::ui_error( string message, const Setting &element ) 
     144{ 
     145    stringstream error_message; 
     146    error_message << "UI error: " << message << "! Check path """ << element.getPath() << """, source line " << element.getSourceLine() << "."; 
     147    it_error ( error_message.str() ); 
     148} 
     149 
     150//! This methods - kvuli ukladani pole stringu, dat jen privatne? 
    145151void UI::save( const string &str, Setting &element ) 
    146152{ 
    147         Setting &root = element.add( Setting::TypeString ); 
    148         root = str; 
     153    Setting &root = element.add( Setting::TypeString ); 
     154    root = str; 
    149155} 
    150156 
    151157void UI::save( const mat &matrix, Setting &element, const string &name) 
    152158{ 
    153          
    154         Setting &root = (name == "") ? element.add( Setting::TypeList )                                                  
    155                                                                  : element.add( name, Setting::TypeList );               
    156  
    157         Setting &cols = root.add( Setting::TypeInt ); 
    158         cols = matrix.cols(); 
    159  
    160         Setting &rows = root.add( Setting::TypeInt ); 
    161         rows = matrix.rows(); 
    162  
    163         Setting &elements = root.add( Setting::TypeArray ); 
    164  
    165         // build matrix row-wise 
    166         for( int i=0; i<matrix.rows(); i++ )  
    167                 for( int j=0; j<matrix.cols(); j++) 
    168                 { 
    169                         Setting &new_field = elements.add(Setting::TypeFloat); 
    170                         new_field = matrix(i,j); 
    171                 } 
    172 } 
    173  
    174  
    175         //! This methods tries to save a double vec  
    176 void UI::save( const ivec &vec, Setting &element, const string &name) 
    177 { 
    178          
    179         Setting &root = (name == "") ? element.add( Setting::TypeArray )                                                         
    180                                                                  : element.add( name, Setting::TypeArray );              
    181         for( int i=0; i<vec.length(); i++ )  
    182         { 
    183                 Setting &new_field = root.add(Setting::TypeInt); 
    184                 new_field = vec(i); 
    185         } 
    186 } 
    187  
    188  
    189 //! This methods tries to build a new double matrix  
     159 
     160    Setting &root = (name == "") ? element.add( Setting::TypeList ) 
     161                    : element.add( name, Setting::TypeList ); 
     162 
     163    Setting &cols = root.add( Setting::TypeInt ); 
     164    cols = matrix.cols(); 
     165 
     166    Setting &rows = root.add( Setting::TypeInt ); 
     167    rows = matrix.rows(); 
     168 
     169    Setting &elements = root.add( Setting::TypeArray ); 
     170 
     171    // build matrix row-wise 
     172    for ( int i=0; i<matrix.rows(); i++ ) 
     173        for ( int j=0; j<matrix.cols(); j++) 
     174        { 
     175            Setting &new_field = elements.add(Setting::TypeFloat); 
     176            new_field = matrix(i,j); 
     177        } 
     178} 
     179 
     180 
     181//! This methods tries to save a integer vector 
     182void UI::save( const ivec &vector, Setting &element, const string &name) 
     183{ 
     184 
     185    Setting &root = (name == "") ? element.add( Setting::TypeArray ) 
     186                    : element.add( name, Setting::TypeArray ); 
     187    for ( int i=0; i<vector.length(); i++ ) 
     188    { 
     189        Setting &new_field = root.add(Setting::TypeInt); 
     190        new_field = vector(i); 
     191    } 
     192} 
     193 
     194 
     195//! This methods tries to save a double vector 
     196void UI::save( const vec &vector, Setting &element, const string &name) 
     197{ 
     198 
     199    Setting &root = (name == "") ? element.add( Setting::TypeArray ) 
     200                    : element.add( name, Setting::TypeArray ); 
     201    for ( int i=0; i<vector.length(); i++ ) 
     202    { 
     203                Setting &new_field = root.add(Setting::TypeFloat); 
     204        new_field = vector(i); 
     205    } 
     206} 
     207 
     208 
     209//! This methods tries to build a new double matrix 
    190210 
    191211void UI::from_setting( mat& matrix, const Setting &element ) 
    192212{ 
    193         const Link_Expander link_expander( element ); 
    194         const Setting &root = link_expander.root(); 
    195  
    196         if( root.isNumber() ) 
    197         { 
    198                 matrix.set_size( 1, 1 ); 
    199                 matrix(0,0) = root; 
    200                 return; 
    201         } 
    202  
    203         if( root.isList() ) 
    204         { 
    205                 if( root.getLength() != 3 ) 
    206                         ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
    207  
    208                 Setting &cols_setting = root[0]; 
    209                 Setting &rows_setting = root[1]; 
    210                 Setting &elements = root[2]; 
    211  
    212                 ASSERT_UITYPE(cols_setting,TypeInt); 
    213                 ASSERT_UITYPE(rows_setting,TypeInt); 
    214                 ASSERT_UITYPE(elements,TypeArray); 
    215  
    216                 int cols = cols_setting; 
    217                 int rows = rows_setting; 
    218                                          
    219                 if( cols < 0 | rows < 0 ) 
    220                         ui_error( "the dimensions of a matrix has to be non-negative", root ); 
    221  
    222                 if( elements.getLength() != cols * rows ) 
    223                         ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
    224  
    225                 matrix.set_size( rows, cols ); 
    226  
    227                 if( cols == 0 || rows == 0 ) 
    228                         return; 
    229  
    230                 if( !elements[0].isNumber() ) 
    231                         ui_error( "matrix elements have to be numbers", elements[0] ); 
    232  
    233                 // build matrix row-wise 
    234                 int k = 0; 
    235                 for( int i=0;i<rows;i++ )  
    236                         for( int j=0; j<cols; j++) 
    237                                 matrix(i,j) = elements[k++]; 
    238                 return; 
    239         } 
    240  
    241         ui_error( "only numeric types or TypeList are supported as matrix values", root ); 
     213    const Link_Expander link_expander( element ); 
     214    const Setting &root = link_expander.root(); 
     215 
     216    if ( root.isNumber() ) 
     217    { 
     218        matrix.set_size( 1, 1 ); 
     219        matrix(0,0) = root; 
     220        return; 
     221    } 
     222 
     223    if ( root.isList() ) 
     224    { 
     225        if ( root.getLength() != 3 ) 
     226            ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
     227 
     228        Setting &rows_setting = root[0]; 
     229        Setting &cols_setting = root[1]; 
     230        Setting &elements = root[2]; 
     231 
     232        ASSERT_UITYPE(cols_setting,TypeInt); 
     233        ASSERT_UITYPE(rows_setting,TypeInt); 
     234        ASSERT_UITYPE(elements,TypeArray); 
     235 
     236        int cols = cols_setting; 
     237        int rows = rows_setting; 
     238 
     239        if ( cols < 0 | rows < 0 ) 
     240            ui_error( "the dimensions of a matrix has to be non-negative", root ); 
     241 
     242        if ( elements.getLength() != cols * rows ) 
     243            ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
     244 
     245        matrix.set_size( rows, cols ); 
     246 
     247        if ( cols == 0 || rows == 0 ) 
     248            return; 
     249 
     250        if ( !elements[0].isNumber() ) 
     251            ui_error( "matrix elements have to be numbers", elements[0] ); 
     252 
     253        // build matrix row-wise 
     254        int k = 0; 
     255        for ( int i=0; i<rows; i++ ) 
     256            for ( int j=0; j<cols; j++) 
     257                matrix(i,j) = elements[k++]; 
     258        return; 
     259    } 
     260 
     261    ui_error( "only numeric types or TypeList are supported as matrix values", root ); 
    242262} 
    243263 
    244264//! This methods tries to build a new integer vector 
    245 void UI::from_setting( ivec &vec, const Setting &element ) 
    246 { 
    247         const Link_Expander link_expander( element ); 
    248         const Setting &root = link_expander.root(); 
    249  
    250         if( root.isNumber() ) 
    251         { 
    252                 ASSERT_UITYPE(root,TypeInt); 
    253                 vec.set_length( 1 ); 
    254                 vec(0) = root; 
    255                 return; 
    256         } 
    257  
    258         if( root.isList() ) 
    259         { 
    260                 if( root.getLength() != 3 ) 
    261                         ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
    262  
    263                 Setting &cols_setting = root[0]; 
    264                 Setting &rows_setting = root[1]; 
    265                 Setting &elements = root[2]; 
    266  
    267                 ASSERT_UITYPE(cols_setting,TypeInt); 
    268                 ASSERT_UITYPE(rows_setting,TypeInt); 
    269                 ASSERT_UITYPE(elements,TypeArray); 
    270  
    271                 int cols = cols_setting; 
    272                 int rows = rows_setting; 
    273                  
    274                 if( cols < 0 | rows < 0) 
    275                         ui_error( "the dimensions of a matrix has to be non-negative", root ); 
    276  
    277                 if( elements.getLength() != cols * rows ) 
    278                         ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
    279  
    280                 if( cols != 1 & rows !=1) 
    281                         ui_error( "the vector length is invalid, it seems to be rather a matrix", elements ); 
    282                  
    283                 int len = rows * cols; 
    284                 vec.set_length ( len ); 
    285                 if( len == 0 ) return; 
    286  
    287                 ASSERT_UITYPE(elements[0],TypeInt); 
    288                 for( int i=0; i<len; i++ )  
    289                         vec(i) = elements[i]; 
    290                 return; 
    291         } 
    292  
    293         if( root.isArray() ) 
    294         {        
    295                 int len = root.getLength(); 
    296                 vec.set_length( len ); 
    297                 if( len == 0 ) return; 
    298  
    299                 ASSERT_UITYPE(root[0],TypeInt); 
    300                 for( int i=0; i < len; i++ )  
    301                         vec(i) = root[i]; 
    302                 return; 
    303         } 
    304  
    305         ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", root ); 
     265void UI::from_setting( ivec &vector, const Setting &element ) 
     266{ 
     267    const Link_Expander link_expander( element ); 
     268    const Setting &root = link_expander.root(); 
     269 
     270    if ( root.isNumber() ) 
     271    { 
     272        ASSERT_UITYPE(root,TypeInt); 
     273        vector.set_length( 1 ); 
     274        vector(0) = root; 
     275        return; 
     276    } 
     277 
     278    if ( root.isList() ) 
     279    { 
     280        if ( root.getLength() != 3 ) 
     281            ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
     282 
     283        Setting &cols_setting = root[0]; 
     284        Setting &rows_setting = root[1]; 
     285        Setting &elements = root[2]; 
     286 
     287        ASSERT_UITYPE(cols_setting,TypeInt); 
     288        ASSERT_UITYPE(rows_setting,TypeInt); 
     289        ASSERT_UITYPE(elements,TypeArray); 
     290 
     291        int cols = cols_setting; 
     292        int rows = rows_setting; 
     293 
     294        if ( cols < 0 | rows < 0) 
     295            ui_error( "the dimensions of a matrix has to be non-negative", root ); 
     296 
     297        if ( elements.getLength() != cols * rows ) 
     298            ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
     299 
     300        if ( cols != 1 & rows !=1) 
     301            ui_error( "the vector length is invalid, it seems to be rather a matrix", elements ); 
     302 
     303        int len = rows * cols; 
     304        vector.set_length ( len ); 
     305        if ( len == 0 ) return; 
     306 
     307        ASSERT_UITYPE(elements[0],TypeInt); 
     308        for ( int i=0; i<len; i++ ) 
     309            vector(i) = elements[i]; 
     310        return; 
     311    } 
     312 
     313    if ( root.isArray() ) 
     314    { 
     315        int len = root.getLength(); 
     316        vector.set_length( len ); 
     317        if ( len == 0 ) return; 
     318 
     319        ASSERT_UITYPE(root[0],TypeInt); 
     320        for ( int i=0; i < len; i++ ) 
     321            vector(i) = root[i]; 
     322        return; 
     323    } 
     324 
     325    ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", root ); 
     326} 
     327 
     328//! This methods tries to build a new double vector 
     329void UI::from_setting( vec &vector, const Setting &element ) 
     330{ 
     331    const Link_Expander link_expander( element ); 
     332    const Setting &root = link_expander.root(); 
     333 
     334    if ( root.isNumber() ) 
     335    { 
     336        vector.set_length( 1 ); 
     337        vector(0) = root; 
     338        return; 
     339    } 
     340 
     341    if ( root.isList() ) 
     342    { 
     343        if ( root.getLength() != 3 ) 
     344            ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 
     345 
     346        Setting &cols_setting = root[0]; 
     347        Setting &rows_setting = root[1]; 
     348        Setting &elements = root[2]; 
     349 
     350        ASSERT_UITYPE(cols_setting,TypeInt); 
     351        ASSERT_UITYPE(rows_setting,TypeInt); 
     352        ASSERT_UITYPE(elements,TypeArray); 
     353 
     354        int cols = cols_setting; 
     355        int rows = rows_setting; 
     356 
     357        if ( cols < 0 | rows < 0) 
     358            ui_error( "the dimensions of a matrix has to be non-negative", root ); 
     359 
     360        if ( elements.getLength() != cols * rows ) 
     361            ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 
     362 
     363        if ( cols != 1 & rows !=1) 
     364            ui_error( "the vector length is invalid, it seems to be rather a matrix", elements ); 
     365 
     366        int len = rows * cols; 
     367        vector.set_length ( len ); 
     368        if ( len == 0 ) return; 
     369 
     370        if ( !elements[0].isNumber()) 
     371            ui_error("a vector element has to be a number", elements[0]); 
     372 
     373        for ( int i=0; i<len; i++ ) 
     374            vector(i) = elements[i]; 
     375        return; 
     376    } 
     377 
     378    if ( root.isArray() ) 
     379    { 
     380        int len = root.getLength(); 
     381        vector.set_length( len ); 
     382        if ( len == 0 ) return; 
     383 
     384        if ( !root[0].isNumber()) 
     385            ui_error("a vector element has to be a number", root[0]); 
     386 
     387        for ( int i=0; i < len; i++ ) 
     388            vector(i) = root[i]; 
     389        return; 
     390    } 
     391 
     392    ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", root ); 
    306393} 
    307394 
     
    309396void UI::from_setting( string &str, const Setting &element ) 
    310397{ 
    311         ASSERT_UITYPE(element,TypeString); 
    312         str = (string) element; 
     398    ASSERT_UITYPE(element,TypeString); 
     399    str = (string) element; 
    313400} 
    314401 
    315402 
    316403///////////////////////// UI FILE ///////////////////////////////////////////// 
    317         //! This methods tries to save an instance of type T (or some of its descendant types) 
    318         //! and build DOM tree accordingly. Then, it creates a new DOMNode named according class_name 
    319         //! and connecti it to the passed Setting as a new child node. 
    320 const Setting* UI::pointer_to_child_setting( const Setting &element, const int index ) 
    321 { 
    322         if( !element.isList()) 
    323                 return NULL; 
    324  
    325         if( element.getLength() <= index ) 
    326                 return NULL; 
    327  
    328         return &element[index]; 
    329 } 
    330  
    331 const Setting* UI::pointer_to_child_setting( const Setting &element, const string &name ) 
    332 { 
    333         if( !element.isGroup() ) 
    334                 return NULL; 
    335  
    336         if( !element.exists( name ) ) 
    337                 return NULL; 
    338  
    339         return &element[name]; 
    340 } 
    341  
    342 const Setting& UI::reference_to_child_setting( const Setting &element, const int index ) 
    343 { 
    344         if( !element.isList()) 
    345                 ui_error( "only TypeList elements could be indexed by integers", element ); 
    346  
    347         if( element.getLength() <= index ) 
    348                 ui_error( "there is not any child with index " + index, element ); 
    349  
    350         return element[index]; 
    351 } 
    352  
    353 const Setting& UI::reference_to_child_setting( const Setting &element, const string &name ) 
    354 { 
    355         ASSERT_UITYPE(element,TypeGroup); 
    356         if( !element.exists( name ) ) 
    357                 ui_error( "there is not any child named """ + name, element ); 
    358         return element[name]; 
    359 } 
    360  
    361  
    362 } 
    363  
     404//! This methods tries to save an instance of type T (or some of its descendant types) 
     405//! and build DOM tree accordingly. Then, it creates a new DOMNode named according class_name 
     406//! and connecti it to the passed Setting as a new child node. 
     407const Setting& UI::to_child_setting( const Setting &element, const int index ) 
     408{ 
     409    if ( !element.isList()) 
     410        ui_error( "only TypeList elements could be indexed by integers", element ); 
     411 
     412    if ( element.getLength() <= index ) 
     413        ui_error( "there is not any child with index " + index, element ); 
     414 
     415    return element[index]; 
     416} 
     417 
     418const Setting& UI::to_child_setting( const Setting &element, const string &name ) 
     419{ 
     420    ASSERT_UITYPE(element,TypeGroup); 
     421    if ( !element.exists( name ) ) 
     422        ui_error( "there is not any child named """ + name, element ); 
     423    return element[name]; 
     424} 
     425 
     426 
     427} 
     428