root/tests/UI/UIbuilder_test.cpp @ 249

Revision 249, 1.4 kB (checked in by smidl, 15 years ago)

libconfig refactorization

Line 
1#include <uibuilder.h>
2
3using namespace libconfig;
4using namespace std;
5using namespace itpp;
6
7class cls {
8        public:
9                int a;
10                string S;
11                cls(int a0, string S0):a(a0),S(S0){};
12                virtual void print(){cout << a << " and "<< S << endl;}
13};
14class cls2: public cls{
15        public:
16        cls2(int a0, string S0):cls(a0,S0){};
17        void print(){cout << a << " or "<< S << endl;}
18};
19
20class UItest : public UIbuilder{
21        public:
22        UItest():UIbuilder("test"){}
23        void build(Setting &S, void** ret) const{
24                try{
25                        int a=S["a"];
26                        string St;
27                        S.lookupValue("S",St);
28                        cls* tmp = new cls(a,St);
29                        *ret=tmp;
30                }
31                catch (...){
32                        it_error(string(S.getPath()) + " is not a valid test UI");
33                }
34        }       
35};
36
37class UItest2 : public UIbuilder{
38        public:
39        UItest2():UIbuilder("test2"){}
40        void build(Setting &S, void** ret) const{
41                try{
42                        int a=S["a"];
43                        string St;
44                        S.lookupValue("S",St);
45                        cls* tmp = new cls2(a,St);
46                        *ret=tmp;
47                }
48                catch (...){
49                        it_error(string(S.getPath()) + " is not a valid test UI");
50                }
51        }       
52        int no(){return 2;}
53};
54
55UIREGISTER(UItest);
56UIREGISTER(UItest2);
57//UItest* UItest_instance = new UItest();
58//UItest2* UItest2_instance = new UItest2();
59
60int main(){
61
62UIFile UI("UIbuilder_test.cfg");
63
64cls* Cls;
65UIbuild(UI.lookup("test"),&Cls);
66cls* Cls2;
67UIbuild(UI.lookup("test2"),&Cls2);
68cls* Cls3;
69UIbuild(UI.lookup("test3"),&Cls3);
70
71Cls->print();
72Cls2->print();
73Cls3->print();
74return 0;
75}
Note: See TracBrowser for help on using the browser.