- Timestamp:
- 08/20/08 17:08:16 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
tests/testUI.cpp
r142 r146 4 4 { 5 5 public: 6 IntUI():ValuedUserInfo<int>("int") 7 { 8 } 6 9 7 10 void Build(int* &pInstance) 8 11 { 9 // KDO SE POSTARA O DEALOKACI TOHOTO? NADRAZENE UI? ASI..10 // PAK TO CHCE ALE OBDOBNE UDELAT I STRING NIZE, ZKOPIROVAT atd11 12 pInstance = new int( atoi( value.c_str()) ); 12 13 } 13 14 15 void Absorb(int* &pInstance) 16 { 17 char buff[30]; 18 sprintf(buff, "%d", *pInstance ); 19 value = buff; 20 } 14 21 }; 15 22 … … 20 27 { 21 28 public: 29 StringUI():ValuedUserInfo<string>("string") 30 { 31 } 32 22 33 void Build(string* &pInstance) 23 34 { 24 pInstance = &value; 35 pInstance = new string( value ); 36 } 37 38 void Absorb(string* &pInstance) 39 { 40 value = *pInstance; 25 41 } 26 42 }; 27 43 28 const TypedUserInfo<string>& StringUI::instance = StringUI(); 44 const TypedUserInfo<string>& StringUI::instance = StringUI( ); 45 46 class Car 47 { 48 public: 49 int age; 50 string brand; 51 52 Car( int age, string brand) 53 : age( age), brand( brand) 54 { 55 } 56 }; 57 58 class CarUI: public CompoundUserInfo<Car> 59 { 60 public: 61 BindedType<int> age; 62 BindedType<string> brand; 63 64 CarUI() 65 :CompoundUserInfo<Car>("car"), 66 age( this, "age" ), 67 brand( this, "brand") 68 { 69 } 70 71 void Build(Car* &pInstance) 72 { 73 if( age.pInstance == NULL ) age.pInstance = new int (0); 74 if( brand.pInstance == NULL ) brand.pInstance = new string("noname"); 75 pInstance = new Car( *age.pInstance, *brand.pInstance ); 76 } 77 78 void Absorb(Car* &pInstance) 79 { 80 age.pInstance = &pInstance->age; 81 brand.pInstance = &pInstance->brand; 82 } 83 }; 84 85 const TypedUserInfo<Car>& CarUI::instance = CarUI( ); 29 86 30 87 31 88 int main() 32 89 { 33 int i = 9, *pi = &i; 90 /////////////////////////////////// SAVING /////////////////////////// 91 Car newCar( 20, "audina" ); 34 92 35 93 RootElement root("car.xml"); 94 // NESLO BY TAM MISTO POINTERU PRIMO REFERENCI, 95 // NEBO TAK NECO?!?! ASI JO..! 96 if( !UserInfo::Disassembly( &newCar,root,"kara") ) 97 { 98 cout << "there was some error!" << endl; 99 getchar(); 100 return 0; 101 } 102 103 root.Save(); 104 cout << "the new car was saved correctly!" << endl; 105 getchar(); 106 107 //////////////////////////////////// LOADING //////////////////////////////// 108 109 110 Car *loadedCar; 36 111 root.Load(); 37 38 UserInfo::Assembly("clovek",root,pi); 112 UserInfo::Assembly(loadedCar,root,"kara"); 39 113 40 //root.Save(); 41 42 cout << "press any key to quit, pi=" << *pi << endl; 114 if( loadedCar ) 115 cout << "loaded car: age=" << loadedCar->age << ", brand=" << loadedCar->brand << endl; 116 else 117 cout << "there was some error during car loading!" << endl; 118 43 119 getchar(); 44 120 return 0;