root/bdm/uibuilder.cpp @ 344

Revision 344, 3.5 kB (checked in by mido, 15 years ago)

funkcni verze noveho UI, zbyva jeste ucesat

  • Property svn:eol-style set to native
Line 
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
15namespace bdm {
16
17UI::StringToUIMap::MappedString2UI& UI::StringToUIMap::privateMap()
18{
19        static MappedString2UI var;
20        return var;
21}
22
23void UI::StringToUIMap::Add( const string &className, pUI pInstance )
24{
25        privateMap().insert( make_pair( className, pInstance ) );
26}
27
28UI::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
38UIFile::UIFile ( const string &file_name ) : fileName( file_name )
39{
40        Config::setAutoConvert( true );
41}
42
43//! loads root element from a file
44void 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)
64void 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
76UIFile::operator Setting&()
77{
78        return getRoot();
79}
80
81}
82/*
83#include "uibuilder.h"
84
85namespace bdm {
86
87//! global map of UIbulder names to instances of UIbuilders. Created by UIREGISTER macro
88UIbuilder::UImap UIbuilder::__uimap__;
89
90bdmroot* 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};
108UIREGISTER ( UIexternal );
109
110bdmroot* 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};
124UIREGISTER ( UIinternal );
125
126void 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*/
Note: See TracBrowser for help on using the browser.