root/tests/UI/UIbuilder_test.cpp @ 256

Revision 256, 1.4 kB (checked in by smidl, 16 years ago)

uibuilder works (again)

RevLine 
[249]1#include <uibuilder.h>
[244]2
3using namespace libconfig;
4using namespace std;
[254]5using namespace bdm;
[244]6
[256]7class cls :public bdmroot{
[244]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"){}
[256]23        void build(Setting &S, bdmroot* &ret) const{
[244]24                try{
25                        int a=S["a"];
26                        string St;
27                        S.lookupValue("S",St);
28                        cls* tmp = new cls(a,St);
[256]29                        ret=tmp;
[244]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"){}
[256]40        void build(Setting &S, bdmroot* &ret) const{
[244]41                try{
42                        int a=S["a"];
43                        string St;
44                        S.lookupValue("S",St);
45                        cls* tmp = new cls2(a,St);
[256]46                        ret=tmp;
[244]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(){
[246]61UIFile UI("UIbuilder_test.cfg");
[244]62
63cls* Cls;
[256]64UIbuild(UI.lookup("test"),Cls);
[244]65cls* Cls2;
[256]66UIbuild(UI.lookup("test2"),Cls2);
[246]67cls* Cls3;
[256]68UIbuild(UI.lookup("test3"),Cls3);
[244]69
70Cls->print();
71Cls2->print();
[256]72Cls3->print(); 
73
74delete Cls;
75delete Cls2;
76delete Cls3;
[244]77}
Note: See TracBrowser for help on using the browser.