// // C++ Implementation: itpp_ext // // Description: // // // Author: smidl , (C) 2008 // // Copyright: See COPYING file that comes with this distribution // // #include "user_info.h" namespace bdm { ///////////////////////// UI FILE ///////////////////////////////////////////// UI_File::UI_File () { setAutoConvert( true ); } //! loads root element from a file UI_File::UI_File ( const string &file_name ) { try { readFile( file_name.c_str() ); setAutoConvert( true ); } catch ( FileIOException f ) { it_error ( "UI error: file " + file_name + " not found." ); } catch ( ParseException& P ) { stringstream msg; msg << "UI error: parsing error """ << P.getError() << """ in file " << file_name << " on line " << P.getLine() << "."; it_error ( msg.str() ); } } //! save UserInfo to the file (typically with an XML extension) void UI_File::save( const string &file_name ) { try { writeFile ( file_name.c_str() ); } catch ( FileIOException f ) { it_error( "UI error: file " + file_name + " is inacessible." ); } } UI_File::operator Setting&() { return getRoot(); } ///////////////////////// INTERNAL MAPPED_UI ///////////////////////////////////////////// UI::Mapped_UI::String_To_UI_Map& UI::Mapped_UI::mapped_strings() { static String_To_UI_Map var; return var; } UI::Mapped_UI::Type_Info_To_String_Map& UI::Mapped_UI::mapped_type_infos() { static Type_Info_To_String_Map var; return var; } void UI::Mapped_UI::add_class( const string &class_name, const type_info * const class_type_info, const UI* const ui ) { pair< const string, const UI* const > new_pair = make_pair( class_name, ui ); mapped_strings().insert( new_pair ); mapped_type_infos().insert( make_pair( class_type_info, new_pair.first ) ); } const UI& UI::Mapped_UI::retrieve_ui( const string &class_name ) { String_To_UI_Map::const_iterator iter = mapped_strings().find( class_name ); if ( iter == mapped_strings().end()) it_error ( "UI error: class " + class_name + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); return *iter->second; } const string& UI::Mapped_UI::retrieve_class_name( const type_info * const class_type_info ) { Type_Info_To_String_Map::const_iterator iter = mapped_type_infos().find( class_type_info ); if ( iter == mapped_type_infos().end()) 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." ); return iter->second; } ///////////////////////// INTERNAL LINK EXPANDER ///////////////////////////////////////////// UI::SettingsResolver::SettingsResolver( const Setting &potential_link ) { file = NULL; result = &potential_link; if ( potential_link.getType() != Setting::TypeString ) return; string link = (const char*) potential_link; size_t aerobase = link.find('@'); if ( aerobase != string::npos ) { string file_name = link.substr( aerobase + 1, link.length() ); file = new UI_File( file_name ); result = &(Setting&)(*file); link = link.substr( 0, aerobase ); } else while ( !result->isRoot() ) result = &result->getParent(); if ( !result->exists( link ) ) ui_error( "linked Setting was not found", potential_link ); result = &(*result)[link]; } UI::SettingsResolver::~SettingsResolver() { if ( file ) delete file; } const Setting& UI::SettingsResolver::root() const { return *result; } ///////////////////////// UI ///////////////////////////////////////////// void UI::ui_error( string message, const Setting &element ) { stringstream error_message; error_message << "UI error: " << message << "! Check path """ << element.getPath() << """, source line " << element.getSourceLine() << "."; it_error ( error_message.str() ); } //! This methods - kvuli ukladani pole stringu, dat jen privatne? void UI::save( const string &str, Setting &element ) { Setting &root = element.add( Setting::TypeString ); root = str; } void UI::save( const mat &matrix, Setting &element, const string &name) { Setting &root = (name == "") ? element.add( Setting::TypeList ) : element.add( name, Setting::TypeList ); Setting &cols = root.add( Setting::TypeInt ); cols = matrix.cols(); Setting &rows = root.add( Setting::TypeInt ); rows = matrix.rows(); Setting &elements = root.add( Setting::TypeArray ); // build matrix row-wise for ( int i=0; i