Revision 257, 1.4 kB
(checked in by smidl, 16 years ago)
|
All objects have a virtual predecessor. This allows type checking in UI, see
|
Line | |
---|
1 | #include <uibuilder.h> |
---|
2 | |
---|
3 | using namespace libconfig; |
---|
4 | using namespace std; |
---|
5 | using namespace bdm; |
---|
6 | |
---|
7 | class cls :public bdmroot{ |
---|
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 | }; |
---|
14 | class cls2: public cls{ |
---|
15 | public: |
---|
16 | cls2(int a0, string S0):cls(a0,S0){}; |
---|
17 | void print(){cout << a << " or "<< S << endl;} |
---|
18 | }; |
---|
19 | |
---|
20 | class UItest : public UIbuilder{ |
---|
21 | public: |
---|
22 | UItest():UIbuilder("test"){} |
---|
23 | bdmroot* build(Setting &S) const{ |
---|
24 | try{ |
---|
25 | int a=S["a"]; |
---|
26 | string St; |
---|
27 | S.lookupValue("S",St); |
---|
28 | cls* tmp = new cls(a,St); |
---|
29 | return tmp; |
---|
30 | } |
---|
31 | catch (...){ |
---|
32 | it_error(string(S.getPath()) + " is not a valid test UI"); |
---|
33 | } |
---|
34 | } |
---|
35 | }; |
---|
36 | |
---|
37 | class UItest2 : public UIbuilder{ |
---|
38 | public: |
---|
39 | UItest2():UIbuilder("test2"){} |
---|
40 | bdmroot* build(Setting &S) const{ |
---|
41 | try{ |
---|
42 | int a=S["a"]; |
---|
43 | string St; |
---|
44 | S.lookupValue("S",St); |
---|
45 | return new cls2(a,St); |
---|
46 | } |
---|
47 | catch (...){ |
---|
48 | it_error(string(S.getPath()) + " is not a valid test UI"); |
---|
49 | } |
---|
50 | } |
---|
51 | int no(){return 2;} |
---|
52 | }; |
---|
53 | |
---|
54 | UIREGISTER(UItest); |
---|
55 | UIREGISTER(UItest2); |
---|
56 | //UItest* UItest_instance = new UItest(); |
---|
57 | //UItest2* UItest2_instance = new UItest2(); |
---|
58 | |
---|
59 | int main(){ |
---|
60 | UIFile UI("UIbuilder_test.cfg"); |
---|
61 | |
---|
62 | cls* Cls; |
---|
63 | UIbuild(UI.lookup("test"),Cls); |
---|
64 | cls* Cls2; |
---|
65 | UIbuild(UI.lookup("test2"),Cls2); |
---|
66 | cls* Cls3; |
---|
67 | UIbuild(UI.lookup("test3"),Cls3); |
---|
68 | |
---|
69 | Cls->print(); |
---|
70 | Cls2->print(); |
---|
71 | Cls3->print(); |
---|
72 | |
---|
73 | delete Cls; |
---|
74 | delete Cls2; |
---|
75 | delete Cls3; |
---|
76 | } |
---|