Revision 249, 1.4 kB
(checked in by smidl, 16 years ago)
|
libconfig refactorization
|
Rev | Line | |
---|
[249] | 1 | #include <uibuilder.h> |
---|
[244] | 2 | |
---|
| 3 | using namespace libconfig; |
---|
| 4 | using namespace std; |
---|
| 5 | using namespace itpp; |
---|
| 6 | |
---|
| 7 | class 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 | }; |
---|
| 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 | 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 | |
---|
| 37 | class 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 | |
---|
| 55 | UIREGISTER(UItest); |
---|
| 56 | UIREGISTER(UItest2); |
---|
| 57 | //UItest* UItest_instance = new UItest(); |
---|
| 58 | //UItest2* UItest2_instance = new UItest2(); |
---|
| 59 | |
---|
| 60 | int main(){ |
---|
| 61 | |
---|
[246] | 62 | UIFile UI("UIbuilder_test.cfg"); |
---|
[244] | 63 | |
---|
| 64 | cls* Cls; |
---|
[246] | 65 | UIbuild(UI.lookup("test"),&Cls); |
---|
[244] | 66 | cls* Cls2; |
---|
[246] | 67 | UIbuild(UI.lookup("test2"),&Cls2); |
---|
| 68 | cls* Cls3; |
---|
| 69 | UIbuild(UI.lookup("test3"),&Cls3); |
---|
[244] | 70 | |
---|
| 71 | Cls->print(); |
---|
| 72 | Cls2->print(); |
---|
[246] | 73 | Cls3->print(); |
---|
[244] | 74 | return 0; |
---|
| 75 | } |
---|