Changeset 345 for bdm/user_info.cpp
- Timestamp:
- 05/20/09 23:15:05 (15 years ago)
- Files:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
bdm/user_info.cpp
r344 r345 11 11 // 12 12 13 #include "u ibuilder.h"13 #include "user_info.h" 14 14 15 15 namespace bdm { 16 16 17 UI:: StringToUIMap::MappedString2UI& UI::StringToUIMap::privateMap()17 UI::Class_To_UI::Class_To_UI_Map& UI::Class_To_UI::private_map() 18 18 { 19 static MappedString2UIvar;19 static Class_To_UI_Map var; 20 20 return var; 21 21 } 22 22 23 void UI:: StringToUIMap::Add( const string &className, pUI pInstance)23 void UI::Class_To_UI::add_class( const string &class_name, UI* ui ) 24 24 { 25 private Map().insert( make_pair( className, pInstance) );25 private_map().insert( make_pair( class_name, ui ) ); 26 26 } 27 27 28 UI ::pUI UI::StringToUIMap::Retrieve( const string &className )28 UI* UI::Class_To_UI::retrieve_ui( const string &class_name ) 29 29 { 30 MappedString2UI::const_iterator iter = privateMap().find( className );31 if( iter == private Map().end()) return NULL;30 Class_To_UI_Map::const_iterator iter = private_map().find( class_name ); 31 if( iter == private_map().end()) return NULL; 32 32 else return iter->second; 33 33 } … … 36 36 37 37 38 UI File::UIFile ( const string &file_name ) : fileName( file_name )38 UI_File::UI_File ( const string &file_name ) : file_name( file_name ) 39 39 { 40 Config::setAutoConvert( true );40 setAutoConvert( true ); 41 41 } 42 42 43 43 //! loads root element from a file 44 void UI File::Load()44 void UI_File::load() 45 45 { 46 46 try 47 47 { 48 Config::readFile( fileName.c_str() );48 readFile( file_name.c_str() ); 49 49 } 50 50 catch ( FileIOException f ) 51 51 { 52 it_error ( "UI : file " + fileName + " not found." );52 it_error ( "UI error: file " + file_name + " not found." ); 53 53 } 54 54 catch ( ParseException& P ) 55 55 { 56 56 stringstream msg; 57 msg << "UI : parsing error """ << P.getError() << """ in file " << fileName << " on line " << P.getLine() << ".";57 msg << "UI error: parsing ui_error """ << P.getError() << """ in file " << file_name << " on line " << P.getLine() << "."; 58 58 it_error ( msg.str() ); 59 59 } … … 61 61 62 62 63 //! Save UserInfo to the file (typically with an XML extension)64 void UI File::Save()63 //! save UserInfo to the file (typically with an XML extension) 64 void UI_File::save() 65 65 { 66 66 try 67 67 { 68 Config::writeFile ( fileName.c_str() );68 writeFile ( file_name.c_str() ); 69 69 } 70 70 catch ( FileIOException f ) 71 71 { 72 it_error( "UI : file " + fileName + " is inacessible." );72 it_error( "UI error: file " + file_name + " is inacessible." ); 73 73 } 74 74 } 75 75 76 UI File::operator Setting&()76 UI_File::operator Setting&() 77 77 { 78 78 return getRoot(); … … 80 80 81 81 } 82 /*83 #include "uibuilder.h"84 82 85 namespace bdm {86 87 //! global map of UIbulder names to instances of UIbuilders. Created by UIREGISTER macro88 UIbuilder::UImap UIbuilder::__uimap__;89 90 bdmroot* UIexternal::build ( Setting &S ) const {91 Config C;92 bdmroot* tmp;93 try {94 C.readFile ( ( const char* ) S["filename"] );95 }96 catch ( ... ) {97 it_error ( "File " + string ( ( const char* ) S["filename"] ) + " not found or broken" );98 }99 try {100 Setting& remS=C.lookup ( ( const char* ) S["path"] );101 UIbuilder::build( remS,tmp );102 }103 catch ( ... ) {104 it_error ( "External field " + string ( S.getPath() ) + " not valid" );105 }106 return tmp;107 };108 UIREGISTER ( UIexternal );109 110 bdmroot* UIinternal::build ( Setting &S ) const {111 bdmroot* tmp;112 try {113 Setting* Stmp = &S;114 do {Stmp=& ( Stmp->getParent() );}115 while ( !Stmp->isRoot() );116 Setting& intS=Stmp->lookup ( ( const char* ) S["path"] );117 UIbuilder::build( intS,tmp );118 }119 catch ( ... ) {120 it_error ( "Internal field " + string ( S.getPath() ) + " not valid" );121 }122 return tmp;123 };124 UIREGISTER ( UIinternal );125 126 void UI_DBG ( Setting &S, const string &spc ) {127 const char *Name=S.getName();128 if ( Name!=NULL ) {cout << spc << std::string ( Name );};129 Setting::Type T=S.getType();130 switch ( T ) {131 case Setting::TypeArray:132 cout << endl;133 for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );};134 break;135 case Setting::TypeList:136 cout << endl;137 for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );};138 break;139 case Setting::TypeGroup:140 cout << endl;141 for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );}142 break;143 case Setting::TypeInt:144 cout << " = ";145 cout << int ( S ) <<endl;146 break;147 case Setting::TypeFloat:148 cout << " = ";149 cout << double ( S ) <<endl;150 break;151 case Setting::TypeString:152 cout << " = ";153 cout << ( const char* ) ( S ) <<endl;154 break;155 case Setting::TypeBoolean:156 cout << " = ";157 cout << bool ( S ) <<endl;158 break;159 default: {cout << "?";};160 }161 }162 163 }164 //UIexternal* UIexternal_instance =new UIexternal();165 */