| 1 | // |
| 2 | // C++ Implementation: itpp_ext |
| 3 | // |
| 4 | // Description: |
| 5 | // |
| 6 | // |
| 7 | // Author: smidl <smidl@utia.cas.cz>, (C) 2008 |
| 8 | // |
| 9 | // Copyright: See COPYING file that comes with this distribution |
| 10 | // |
| 11 | // |
| 12 | |
| 13 | #include "uibuilder.h" |
| 14 | |
| 15 | namespace bdm { |
| 16 | |
| 17 | UI::StringToUIMap::MappedString2UI& UI::StringToUIMap::privateMap() |
| 18 | { |
| 19 | static MappedString2UI var; |
| 20 | return var; |
| 21 | } |
| 22 | |
| 23 | void UI::StringToUIMap::Add( const string &className, pUI pInstance ) |
| 24 | { |
| 25 | privateMap().insert( make_pair( className, pInstance ) ); |
| 26 | } |
| 27 | |
| 28 | UI::pUI UI::StringToUIMap::Retrieve( const string &className ) |
| 29 | { |
| 30 | MappedString2UI::const_iterator iter = privateMap().find( className ); |
| 31 | if( iter == privateMap().end()) return NULL; |
| 32 | else return iter->second; |
| 33 | } |
| 34 | |
| 35 | ////////////////////////////////////////////////////////////////////// |
| 36 | |
| 37 | |
| 38 | UIFile::UIFile ( const string &file_name ) : fileName( file_name ) |
| 39 | { |
| 40 | Config::setAutoConvert( true ); |
| 41 | } |
| 42 | |
| 43 | //! loads root element from a file |
| 44 | void UIFile::Load() |
| 45 | { |
| 46 | try |
| 47 | { |
| 48 | Config::readFile( fileName.c_str() ); |
| 49 | } |
| 50 | catch ( FileIOException f ) |
| 51 | { |
| 52 | it_error ( "UI: file " + fileName + " not found." ); |
| 53 | } |
| 54 | catch ( ParseException& P ) |
| 55 | { |
| 56 | stringstream msg; |
| 57 | msg << "UI: parsing error """ << P.getError() << """ in file " << fileName << " on line " << P.getLine() << "."; |
| 58 | it_error ( msg.str() ); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | |
| 63 | //! Save UserInfo to the file (typically with an XML extension) |
| 64 | void UIFile::Save() |
| 65 | { |
| 66 | try |
| 67 | { |
| 68 | Config::writeFile ( fileName.c_str() ); |
| 69 | } |
| 70 | catch ( FileIOException f ) |
| 71 | { |
| 72 | it_error( "UI: file " + fileName + " is inacessible." ); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | UIFile::operator Setting&() |
| 77 | { |
| 78 | return getRoot(); |
| 79 | } |
| 80 | |
| 81 | } |
| 82 | /* |