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