Changeset 357 for bdm/user_info.h
- Timestamp:
- 06/08/09 02:15:30 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/user_info.h
r351 r357 1 #ifndef UIBUILD 2 #define UIBUILD 3 4 5 #include <sstream> 6 #include <iostream> 1 #ifndef USER_INFO_H 2 #define USER_INFO_H 3 7 4 #include <stdio.h> 8 5 #include <string> 9 6 #include <typeinfo> 10 7 #include <map> 11 #include <utility>12 #include <vector>13 #include <iostream>14 8 15 9 #include "libconfig/libconfig.h++" 16 17 #include <itpp/itbase.h> 18 19 #include "stat/libBM.h" 10 #include "bdmroot.h" 11 #include "itpp/itbase.h" 12 20 13 21 14 using std::string; … … 35 28 36 29 public: 37 //! attach new RootElement instance to a file (typically with an XML extension) 30 //! create empty object prepared to store Settings 31 UI_File(); 32 33 //! creates object and fills it from a file 38 34 UI_File( const string &file_name ); 39 35 40 //! loads root element from a file 41 void load(); 42 43 //! save UserInfo to the file (typically with an XML extension) 44 void save(); 36 //! save UserInfo to the file 37 void save(const string &file_name); 45 38 46 39 operator Setting&(); … … 141 134 //! and build DOM tree accordingly. Then, it creates a new DOMNode named according class_name 142 135 //! and connecti it to the passed Setting as a new child node. 143 static const Setting* pointer_to_child_setting( const Setting &element, const int index ); 144 145 static const Setting* pointer_to_child_setting( const Setting &element, const string &name ); 146 147 static const Setting& reference_to_child_setting( const Setting &element, const int index ); 148 149 static const Setting& reference_to_child_setting( const Setting &element, const string &name ); 136 static const Setting& to_child_setting( const Setting &element, const int index ); 137 138 static const Setting& to_child_setting( const Setting &element, const string &name ); 150 139 151 140 … … 153 142 static void from_setting( mat& matrix, const Setting &element ); 154 143 //! This methods tries to build a new integer vector 155 static void from_setting( ivec &vec , const Setting &element );144 static void from_setting( ivec &vector, const Setting &element ); 156 145 // jednak kvuli pretypovani, apak taky proto, ze na string nefunguje link_expander.. 157 146 static void from_setting( string &str, const Setting &element ); 158 147 //! This methods tries to build a new templated array 148 149 static void from_setting( vec &vector, const Setting &element ); 159 150 160 151 template<class T> static void from_setting( T* &instance, const Setting &element ) … … 213 204 } 214 205 206 static void ui_error( string message, const Setting &element ); 207 215 208 protected: 216 209 //! default constructor … … 223 216 virtual ~UI(){}; 224 217 225 226 218 public: 227 static void ui_error( string message, const Setting &element )228 {229 stringstream error_message;230 error_message << "UI ui_error: " << message << "! Check path """ << element.getPath() << """, source line " << element.getSourceLine() << ".";231 it_error ( error_message.str() );232 }233 234 219 //! This methods tries to build a new instance of type T (or some of its descendant types) 235 220 //! according to a data stored in a DOMNode named class_name within a child nodes of the passed element. 236 //! If an ui_error occurs, it returns a NULL pointer.221 //! If an error occurs, it returns a NULL pointer. 237 222 238 223 //! Prototype of a UI builder. Return value is by the second argument since it type checking via \c dynamic_cast. … … 240 225 { 241 226 T* instance; 242 from_setting<T>( reference_to_child_setting( element, index ) );227 from_setting<T>( to_child_setting( element, index ) ); 243 228 return instance; 244 229 } … … 247 232 { 248 233 T* instance; 249 from_setting<T>( instance, reference_to_child_setting( element, name ) );234 from_setting<T>( instance, to_child_setting( element, name ) ); 250 235 return instance; 251 236 } 252 237 253 238 //! This methods tries to build a new double matrix 254 template<class T> static bool get( T &instance, const Setting &element, const string &name ) 255 { 256 const Setting *root = pointer_to_child_setting( element, name ); 257 if( !root ) return false; 258 from_setting( instance, *root ); 259 return true; 260 } 261 262 //! This methods tries to build a new double matrix 263 template<class T> static bool get( T &instance, const Setting &element, const int index ) 264 { 265 const Setting *root = pointer_to_child_setting( element, index ); 266 if( !root ) return false; 267 from_setting( instance, *root ); 268 return true; 269 } 270 271 //! This methods tries to build a new double matrix 272 template<class T> static bool get( Array<T> &array_to_load, const Setting &element, const string &name ) 273 { 274 const Setting *root = pointer_to_child_setting( element, name ); 275 if( !root ) return false; 276 from_setting( array_to_load, *root ); 277 return true; 278 } 279 280 //! This methods tries to build a new double matrix 281 template<class T> static bool get( Array<T> &array_to_load, const Setting &element, const int index ) 282 { 283 const Setting *root = pointer_to_child_setting( element, index ); 284 if( !root ) return false; 285 from_setting( array_to_load, *root ); 286 return true; 239 template<class T> static void get( T &instance, const Setting &element, const string &name ) 240 { 241 from_setting( instance, to_child_setting( element, name ) ); 242 } 243 244 //! This methods tries to build a new double matrix 245 template<class T> static void get( T &instance, const Setting &element, const int index ) 246 { 247 from_setting( instance, to_child_setting( element, index ) ); 248 } 249 250 //! This methods tries to build a new double matrix 251 template<class T> static void get( Array<T> &array_to_load, const Setting &element, const string &name ) 252 { 253 from_setting( array_to_load, to_child_setting( element, name ) ); 254 } 255 256 //! This methods tries to build a new double matrix 257 template<class T> static void get( Array<T> &array_to_load, const Setting &element, const int index ) 258 { 259 from_setting( array_to_load, to_child_setting( element, index ) ); 287 260 } 288 261 … … 325 298 static void save( const ivec &vec, Setting &element, const string &name = "" ); 326 299 300 static void save( const vec &vector, Setting &element, const string &name); 301 327 302 private: 328 303 //! This methods tries to save a double vec … … 385 360 */ 386 361 387 #endif // #ifndef U IBUILD362 #endif // #ifndef USER_INFO_H