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 "user_info.h" |
---|
14 | |
---|
15 | namespace bdm { |
---|
16 | |
---|
17 | UI::Class_To_UI::Class_To_UI_Map& UI::Class_To_UI::private_map() |
---|
18 | { |
---|
19 | static Class_To_UI_Map var; |
---|
20 | return var; |
---|
21 | } |
---|
22 | |
---|
23 | void UI::Class_To_UI::add_class( const string &class_name, UI* ui ) |
---|
24 | { |
---|
25 | private_map().insert( make_pair( class_name, ui ) ); |
---|
26 | } |
---|
27 | |
---|
28 | UI* UI::Class_To_UI::retrieve_ui( const string &class_name ) |
---|
29 | { |
---|
30 | Class_To_UI_Map::const_iterator iter = private_map().find( class_name ); |
---|
31 | if( iter == private_map().end()) return NULL; |
---|
32 | else return iter->second; |
---|
33 | } |
---|
34 | |
---|
35 | ////////////////////////////////////////////////////////////////////// |
---|
36 | |
---|
37 | |
---|
38 | UI_File::UI_File ( const string &file_name ) : file_name( file_name ) |
---|
39 | { |
---|
40 | setAutoConvert( true ); |
---|
41 | } |
---|
42 | |
---|
43 | //! loads root element from a file |
---|
44 | void UI_File::load() |
---|
45 | { |
---|
46 | try |
---|
47 | { |
---|
48 | readFile( file_name.c_str() ); |
---|
49 | } |
---|
50 | catch ( FileIOException f ) |
---|
51 | { |
---|
52 | it_error ( "UI error: file " + file_name + " not found." ); |
---|
53 | } |
---|
54 | catch ( ParseException& P ) |
---|
55 | { |
---|
56 | stringstream msg; |
---|
57 | msg << "UI error: parsing ui_error """ << P.getError() << """ in file " << file_name << " 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 UI_File::save() |
---|
65 | { |
---|
66 | try |
---|
67 | { |
---|
68 | writeFile ( file_name.c_str() ); |
---|
69 | } |
---|
70 | catch ( FileIOException f ) |
---|
71 | { |
---|
72 | it_error( "UI error: file " + file_name + " is inacessible." ); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | UI_File::operator Setting&() |
---|
77 | { |
---|
78 | return getRoot(); |
---|
79 | } |
---|
80 | |
---|
81 | } |
---|