- Timestamp:
- 06/08/09 02:15:30 (15 years ago)
- Location:
- bdm
- Files:
-
- 2 added
- 15 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/CMakeLists.txt
r345 r357 7 7 8 8 # Normal BDM library 9 add_library (bdm STATIC itpp_ext.cpp itpp_ext.h osutils.cpp osutils.h ${BdmMath} ${BdmStat} ${BdmEstim} ${BdmUI})9 add_library (bdm STATIC bdmroot.cpp bdmroot.h itpp_ext.cpp itpp_ext.h osutils.cpp osutils.h ${BdmMath} ${BdmStat} ${BdmEstim} ${BdmUI}) -
bdm/estim/arx.cpp
r286 r357 1 1 #include "arx.h" 2 #include "..\user_info.h" 2 3 3 4 namespace bdm { … … 194 195 } 195 196 196 } 197 void ARX::from_setting( const Setting &root ) 198 { 199 RV *yrv = UI::build<RV>(root,"y"); 200 RV *rrv = UI::build<RV>(root,"rgr"); 201 int ylen = yrv->_dsize(); 202 int rgrlen = rrv->_dsize(); 203 204 //init 205 mat V0; 206 if( root.exists("dV0") ) 207 { 208 vec dV0; 209 UI::get( dV0, root, "dV0" ); 210 V0=diag ( dV0 ); 211 } 212 else 213 V0=concat ( 1e-3*ones ( ylen ), 1e-5*ones ( rgrlen ) ); 214 215 double nu0; 216 if ( !root.lookupValue( "nu0", nu0 ) ) 217 nu0 = rgrlen+ylen+2; 218 219 double frg; 220 if ( !root.lookupValue( "frg", frg ) ) 221 frg = 1.0; 222 223 set_parameters(frg); 224 set_statistics(ylen,V0, nu0); 225 set_drv(concat(*yrv,*rrv)); 226 227 //name results (for logging) 228 set_rv(RV("{theta r }", vec_2(ylen*rgrlen, ylen*ylen))); 229 230 delete yrv; 231 delete rrv; 232 } 233 234 /*void ARX::to_setting( Setting &root ) const 235 { 236 Transport::to_setting( root ); 237 238 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 239 kilometers_setting = kilometers; 240 241 UI::save( passengers, root, "passengers" ); 242 }*/ 243 244 245 } -
bdm/estim/arx.h
r286 r357 116 116 } 117 117 //!@} 118 119 // TODO dokumentace - aktualizovat 120 /*! UI for ARX estimator 121 122 The ARX is constructed from a structure with fields: 123 \code 124 estimator = { 125 type = "ARX"; 126 y = {type="rv", ...} // description of output variables 127 rgr = {type="rv", ...} // description of regressor variables 128 constant = true; // boolean switch if the constant term is modelled or not 129 130 //optional fields 131 dV0 = [1e-3, 1e-5, 1e-5, 1e-5]; 132 // default: 1e-3 for y, 1e-5 for rgr 133 nu0 = 6; // default: rgrlen + 2 134 frg = 1.0; // forgetting, default frg=1.0 135 }; 136 \endcode 137 138 The estimator will assign names of the posterior in the form ["theta_i" and "r_i"] 139 */ 140 void from_setting( const Setting &root ); 141 142 // TODO dodelat void to_setting( Setting &root ) const; 118 143 }; 144 145 UIREGISTER(ARX); 119 146 120 147 } -
bdm/estim/libKF.cpp
r348 r357 1 1 2 2 #include "libKF.h" 3 #include "..\user_info.h" 3 4 4 5 namespace bdm{ … … 250 251 } 251 252 252 } 253 void EKFCh::from_setting( const Setting &root ) 254 { 255 diffbifn* IM = UI::build<diffbifn>(root, "IM"); 256 diffbifn* OM = UI::build<diffbifn>(root, "OM"); 257 258 //statistics 259 int dim=IM->dimension(); 260 vec mu0; 261 if(root.exists("mu0")) 262 UI::get( mu0, root, "mu0"); 263 else 264 mu0=zeros(dim); 265 266 mat P0; 267 if(root.exists("dP0")) 268 { 269 vec dP0; 270 UI::get( dP0, root, "dP0"); 271 P0=diag(dP0); 272 } 273 else if ( root.exists( "P0" ) ) 274 UI::get(P0, root, "P0"); 275 else 276 P0=eye(dim); 277 278 set_statistics(mu0,P0); 279 280 //parameters 281 vec dQ, dR; 282 UI::get( dQ, root, "dQ"); 283 UI::get( dR, root, "dR"); 284 set_parameters(IM, OM, diag(dQ), diag(dR)); 285 286 //connect 287 RV* drv = UI::build<RV>(root, "drv"); 288 set_drv(*drv); 289 RV* rv = UI::build<RV>(root, "rv"); 290 set_rv(*rv); 291 292 string options; 293 if(root.lookupValue( "options", options )) 294 set_options(options); 295 } 296 297 /*void EKFCh::to_setting( Setting &root ) const 298 { 299 Transport::to_setting( root ); 300 301 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 302 kilometers_setting = kilometers; 303 304 UI::save( passengers, root, "passengers" ); 305 }*/ 306 307 void MultiModel::from_setting( const Setting &root ) 308 { 309 Array<EKFCh*> A; 310 UI::get( A, root, "models"); 311 312 set_parameters(A); 313 set_drv(A(0)->_drv()); 314 //set_rv(A(0)->_rv()); 315 316 string options; 317 if(root.lookupValue( "options", options )) 318 set_options(options); 319 } 320 321 /*void MultiModel::to_setting( Setting &root ) const 322 { 323 Transport::to_setting( root ); 324 325 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 326 kilometers_setting = kilometers; 327 328 UI::save( passengers, root, "passengers" ); 329 }*/ 330 331 332 } -
bdm/estim/libKF.h
r338 r357 258 258 //! Here dt = [yt;ut] of appropriate dimensions 259 259 void bayes ( const vec &dt ); 260 }; 260 261 void from_setting( const Setting &root ); 262 263 // TODO dodelat void to_setting( Setting &root ) const; 264 265 }; 266 267 UIREGISTER(EKFCh); 268 261 269 262 270 /*! … … 447 455 //all posterior densities are equal => return the first one 448 456 const enorm<chmat>& posterior() const {return est;} 449 }; 457 458 void from_setting( const Setting &root ); 459 460 // TODO dodelat void to_setting( Setting &root ) const; 461 462 }; 463 464 UIREGISTER(MultiModel); 465 450 466 451 467 -
bdm/stat/libBM.cpp
r280 r357 1 1 2 2 #include "libBM.h" 3 #include "../itpp_ext.h"4 3 5 4 //! Space of basic BDM structures … … 213 212 } 214 213 214 void RV::from_setting( const Setting &root ) 215 { 216 Array<string> A; 217 if( root.exists("names")) 218 UI::get( A, root, "names" ); 219 else 220 A.set_length(0); 221 222 ivec szs; 223 if( root.exists("sizes")) 224 UI::get(szs,root,"sizes"); 225 else 226 szs = ones_i(A.length()); 227 228 ivec tms; 229 if( root.exists( "times") ) 230 UI::get(tms,root,"times"); 231 else 232 tms = zeros_i(A.length()); 233 234 // TODO tady se bude plnit primo do jeho promennych, a pak se zavola validacnni metoda, takze cele prepsat, ano? 235 init( A, szs, tms ); 236 } 237 238 /*void RV::to_setting( Setting &root ) const 239 { 240 Transport::to_setting( root ); 241 242 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 243 kilometers_setting = kilometers; 244 245 UI::save( passengers, root, "passengers" ); 246 }*/ 247 248 249 215 250 RV concat ( const RV &rv1, const RV &rv2 ) { 216 251 RV pom = rv1; -
bdm/stat/libBM.h
r351 r357 17 17 18 18 #include "../itpp_ext.h" 19 #include "../libconfig/libconfig.h++" 19 #include "../bdmroot.h" 20 #include "../user_info.h" 20 21 21 22 22 23 using namespace libconfig; 23 24 24 using namespace itpp; 25 25 using namespace std; 26 26 27 27 namespace bdm { 28 29 //! Root class of BDM objects30 31 class bdmroot {32 public:33 //! make sure this is a virtual object34 virtual ~bdmroot()35 {36 }37 38 //! This method returns a basic info about the current instance39 virtual string ToString()40 {41 return "";42 }43 44 //! This method arrange instance properties according the data stored in the Setting structure45 virtual void from_setting( const Setting &root )46 {47 }48 49 //! This method save all the instance properties into the Setting structure50 virtual void to_setting( Setting &root ) const51 {52 }53 };54 28 55 29 typedef std::map<string, int> RVmap; … … 57 31 extern Array<string> RV_NAMES; 58 32 59 //! Structure of RV (used internally), i.e. expanded RVs 33 //! Structure of RV (used internally), i.e. expanded RVs - TODO tak proc je ve verejnem prostoru jmen? upravit 60 34 class str { 61 35 public: … … 189 163 //!@{ 190 164 191 //! generate \c str from rv, by expanding sizes 165 //! generate \c str from rv, by expanding sizes TODO to_string.. 192 166 str tostr() const; 193 167 //! when this rv is a part of bigger rv, this function returns indeces of self in the data vector of the bigger crv. … … 201 175 //!@} 202 176 203 }; 204 177 // TODO aktualizovat dle soucasneho UI 178 /*! \brief UI for class RV (description of data vectors) 179 180 \code 181 rv = { 182 type = "rv"; //identifier of the description 183 // UNIQUE IDENTIFIER same names = same variable 184 names = ["a", "b", "c", ...]; // which will be used e.g. in loggers 185 186 //optional arguments 187 sizes = [1, 2, 3, ...]; // (optional) default = ones() 188 times = [-1, -2, 0, ...]; // time shifts with respect to current time (optional) default = zeros() 189 } 190 \endcode 191 */ 192 void from_setting( const Setting &root ); 193 194 // TODO dodelat void to_setting( Setting &root ) const; 195 }; 196 197 UIREGISTER(RV); 205 198 206 199 //! Concat two random variables -
bdm/stat/libDS.cpp
r313 r357 1 1 2 2 #include "libDS.h" 3 #include "..\user_info.h" 4 3 5 using namespace bdm; 4 6 … … 53 55 } 54 56 57 void ArxDS::from_setting( const Setting &root ) 58 { 59 RV *yrv = UI::build<RV>( root, "y" ); 60 RV *urv = UI::build<RV>( root, "u" ); 61 RV *rrv = UI::build<RV>( root, "rgr" ); 62 63 mat Th; 64 UI::get( Th, root, "theta" ); 65 66 vec mu0; 67 if( root.exists( "offset" )) 68 UI::get( mu0, root, "offset" ); 69 else 70 mu0= zeros( yrv->_dsize() ); 71 72 mat sqR; 73 UI::get( sqR, root, "r" ); 74 set_parameters(Th,mu0,sqR); 75 set_drv(*yrv,*urv,*rrv); 76 77 if(root.exists("opt")) 78 set_options(root["opt"]); 79 } 80 81 /*void ArxDS::to_setting( Setting &root ) const 82 { 83 Transport::to_setting( root ); 84 85 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 86 kilometers_setting = kilometers; 87 88 UI::save( passengers, root, "passengers" ); 89 }*/ 90 91 55 92 CsvFileDS::CsvFileDS ( const string& fname, const string& orientation ) :FileDS() { 56 93 time = 0; … … 87 124 } 88 125 126 void ITppFileDS::from_setting( const Setting &root ) 127 { 128 RV* rvtmp = UI::build<RV>(root, "rv" ); 129 130 it_file it ( root["filename"] ); 131 it << Name ( root["varname"] ); 132 it >> Data; 133 time = 0; 134 //rowid and delays are ignored 135 136 set_drv(*rvtmp,RV()); 137 } 138 139 /*void ITppFileDS::to_setting( Setting &root ) const 140 { 141 Transport::to_setting( root ); 142 143 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 144 kilometers_setting = kilometers; 145 146 UI::save( passengers, root, "passengers" ); 147 }*/ 148 149 void stateDS::from_setting( const Setting &root ) 150 { 151 IM = UI::build<mpdf>(root, "IM"); 152 OM = UI::build<mpdf>(root, "OM"); 153 154 dt.set_length( OM->dimension() ); 155 xt.set_length( IM->dimension() ); 156 ut.set_length(0); 157 158 RV* rvtmp = UI::build<RV>(root["IM"], "rvu"); 159 //set_drv(rvtmp); 160 } 161 162 /*void stateDS::to_setting( Setting &root ) const 163 { 164 Transport::to_setting( root ); 165 166 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 167 kilometers_setting = kilometers; 168 169 UI::save( passengers, root, "passengers" ); 170 }*/ 171 172 -
bdm/stat/libDS.h
r342 r357 90 90 //rowid and delays are ignored 91 91 }; 92 }; 92 93 ITppFileDS () :FileDS() { 94 }; 95 96 void from_setting( const Setting &root ); 97 98 // TODO dodelat void to_setting( Setting &root ) const; 99 100 }; 101 102 UIREGISTER(ITppFileDS); 93 103 94 104 /*! … … 200 210 } 201 211 202 }; 212 // TODO dokumentace - aktualizovat 213 /*! UI for ArxDS using factorized description! 214 215 The ArxDS is constructed from a structure with fields: 216 \code 217 system = { 218 type = "ArxDS"; 219 // description of y variables 220 y = {type="rv"; names=["y", "u"];}; 221 // description of u variable 222 u = {type="rv"; names=[];} 223 // description of regressor 224 rgr = {type="rv"; 225 names = ["y","y","y","u"]; 226 times = [-1, -2, -3, -1]; 227 } 228 229 // theta 230 theta = [0.8, -0.3, 0.4, 1.0, 231 0.0, 0.0, 0.0, 0.0]; 232 // offset (optional) 233 offset = [0.0, 0.0]; 234 //variance 235 r = [0.1, 0.0, 236 0.0, 1.0]; 237 //options: L_theta = log value of theta, 238 opt = "L_theta"; 239 }; 240 \endcode 241 242 Result is ARX data source offering with full history as Drv. 243 */ 244 void from_setting( const Setting &root ); 245 246 // TODO dodelat void to_setting( Setting &root ) const; 247 }; 248 249 UIREGISTER( ArxDS ); 203 250 204 251 class stateDS : public DS { … … 222 269 stateDS ( mpdf* IM0, mpdf* OM0, int usize ) :DS ( ),IM ( IM0 ),OM ( OM0 ), 223 270 dt ( OM0->dimension() ), xt ( IM0->dimension() ), ut ( usize ) {} 271 272 stateDS(){} 273 224 274 ~stateDS() {delete IM; delete OM;} 225 275 virtual void step() { … … 237 287 } 238 288 239 }; 289 /*! UI for stateDS 290 291 The DS is constructed from a structure with fields: 292 \code 293 system = { 294 type = "stateDS"; 295 //Internal model 296 IM = { type = "mpdf"; //<-- valid offspring! e.g. "mlnorm" 297 rv = { //description of x_t 298 names=["name1",...]; 299 sizes=[2,1]; // optional default=[1,1...]; 300 times=[0,0]; // optional default=[0,0...]; 301 } 302 rvu= { //description of u_t 303 //optional default=empty 304 } 305 306 // remaining fields depending on the chosen type 307 }; 308 //Observation model 309 OM = { type = "mpdf-offspring"; 310 rv = {}; //description of d_t 311 rvu = {type="internal", path="system.IM.rvu"}; //description of u_t 312 313 //remaining fields 314 } 315 }; 316 \endcode 317 */ 318 void from_setting( const Setting &root ); 319 320 // TODO dodelat void to_setting( Setting &root ) const; 321 322 }; 323 324 UIREGISTER(stateDS); 240 325 241 326 }; //namespace -
bdm/stat/libEF.cpp
r330 r357 1 #include <math.h> 1 2 2 3 #include <itpp/base/bessel.h> 3 4 #include "libEF.h" 4 #include <math.h>5 #include "..\user_info.h" 5 6 6 7 namespace bdm{ … … 319 320 } 320 321 322 void migamma_ref::from_setting( const Setting &root ) 323 { 324 vec ref; 325 UI::get( ref, root, "ref" ); 326 set_parameters(root["k"],ref,root["l"]); 327 } 328 329 /*void migamma_ref::to_setting( Setting &root ) const 330 { 331 Transport::to_setting( root ); 332 333 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 334 kilometers_setting = kilometers; 335 336 UI::save( passengers, root, "passengers" ); 337 }*/ 338 339 340 void mlognorm::from_setting( const Setting &root ) 341 { 342 vec mu0; 343 UI::get( mu0, root, "mu0"); 344 set_parameters(mu0.length(),root["k"]); 345 condition(mu0); 346 } 347 348 /*void mlognorm::to_setting( Setting &root ) const 349 { 350 Transport::to_setting( root ); 351 352 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 353 kilometers_setting = kilometers; 354 355 UI::save( passengers, root, "passengers" ); 356 }*/ 357 358 321 359 }; -
bdm/stat/libEF.h
r330 r357 17 17 #include "libBM.h" 18 18 #include "../math/chmat.h" 19 //#include <std> 19 #include "../user_info.h" 20 20 21 21 namespace bdm … … 515 515 void set_parameters ( fnc* g0, const sq_T &R0 ) {g=g0; epdf.set_parameters ( zeros ( g->dimension() ), R0 );} 516 516 void condition ( const vec &cond ) {mu=g->eval ( cond );}; 517 }; 517 518 519 /*! UI for mgnorm 520 521 The mgnorm is constructed from a structure with fields: 522 \code 523 system = { 524 type = "mgnorm"; 525 // function for mean value evolution 526 g = {type="fnc"; ... } 527 528 // variance 529 R = [1, 0, 530 0, 1]; 531 // --OR -- 532 dR = [1, 1]; 533 534 // == OPTIONAL == 535 536 // description of y variables 537 y = {type="rv"; names=["y", "u"];}; 538 // description of u variable 539 u = {type="rv"; names=[];} 540 }; 541 \endcode 542 543 Result if 544 */ 545 546 void from_setting( const Setting &root ) 547 { 548 fnc* g = UI::build<fnc>( root, "g" ); 549 550 mat R; 551 if ( root.exists( "dR" ) ) 552 { 553 vec dR; 554 UI::get( dR, root, "dR" ); 555 R=diag(dR); 556 } 557 else 558 UI::get( R, root, "R"); 559 560 set_parameters(g,R); 561 } 562 563 /*void mgnorm::to_setting( Setting &root ) const 564 { 565 Transport::to_setting( root ); 566 567 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 568 kilometers_setting = kilometers; 569 570 UI::save( passengers, root, "passengers" ); 571 }*/ 572 573 }; 574 575 UIREGISTER(mgnorm<chmat>); 576 518 577 519 578 /*! (Approximate) Student t density with linear function of mean value … … 630 689 }; 631 690 691 632 692 /*! 633 693 \brief Gamma random walk around a fixed point … … 699 759 migamma::condition ( mean ); 700 760 }; 701 }; 761 762 /*! UI for migamma_ref 763 764 The migamma_ref is constructed from a structure with fields: 765 \code 766 system = { 767 type = "migamma_ref"; 768 ref = [1e-5; 1e-5; 1e-2 1e-3]; // reference vector 769 l = 0.999; // constant l 770 k = 0.1; // constant k 771 772 // == OPTIONAL == 773 // description of y variables 774 y = {type="rv"; names=["y", "u"];}; 775 // description of u variable 776 u = {type="rv"; names=[];} 777 }; 778 \endcode 779 780 Result if 781 */ 782 void from_setting( const Setting &root ); 783 784 // TODO dodelat void to_setting( Setting &root ) const; 785 }; 786 787 788 UIREGISTER(migamma_ref); 702 789 703 790 /*! Log-Normal probability density … … 753 840 mu=log ( val )-sig2;//elem_mult ( refl,pow ( val,l ) ); 754 841 }; 755 }; 842 843 /*! UI for mlognorm 844 845 The mlognorm is constructed from a structure with fields: 846 \code 847 system = { 848 type = "mlognorm"; 849 k = 0.1; // constant k 850 mu0 = [1., 1.]; 851 852 // == OPTIONAL == 853 // description of y variables 854 y = {type="rv"; names=["y", "u"];}; 855 // description of u variable 856 u = {type="rv"; names=[];} 857 }; 858 \endcode 859 860 */ 861 void from_setting( const Setting &root ); 862 863 // TODO dodelat void to_setting( Setting &root ) const; 864 865 }; 866 867 UIREGISTER(mlognorm); 756 868 757 869 /*! inverse Wishart density defined on Choleski decomposition -
bdm/stat/loggers.cpp
r347 r357 26 26 } 27 27 } 28 29 void memlog::from_setting( const Setting &root ) 30 { 31 // TODO tady se natvrdo ocekava existence stringu, nejsou zadne defaulty.. je to tak OK? 32 string itfilename = (string)root["filename"]; 33 maxlen = root["maxlen"]; 34 } 35 36 /*void memlog::to_setting( Setting &root ) const 37 { 38 Transport::to_setting( root ); 39 40 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 41 kilometers_setting = kilometers; 42 43 UI::save( passengers, root, "passengers" ); 44 }*/ 28 45 29 46 void dirfilelog::init() { … … 62 79 ii++; 63 80 } 64 } else { 65 ii++;} 81 } 82 else { 83 ii++;} 66 84 } 67 85 } … … 140 158 } 141 159 160 161 void dirfilelog::from_setting( const Setting &root ) 162 { 163 // TODO tady se natvrdo ocekava existence stringu, nejsou zadne defaulty.. je to tak OK? 164 dirname = (string)root["dirname"]; 165 maxlen = root["maxlen"]; 166 scalarnames.set_length(0); 142 167 } 168 169 /*void dirfilelog::to_setting( Setting &root ) const 170 { 171 Transport::to_setting( root ); 172 173 Setting &kilometers_setting = root.add("kilometers", Setting::TypeInt ); 174 kilometers_setting = kilometers; 175 176 UI::save( passengers, root, "passengers" ); 177 }*/ 178 179 180 181 } -
bdm/stat/loggers.h
r347 r357 15 15 16 16 #include "libBM.h" 17 #include "..\user_info.h" 17 18 18 19 namespace bdm{ … … 38 39 public: 39 40 //!Default constructor 40 memlog ( int maxlen0, string itf="" ) : logger(),maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ),itfilename(itf) {} 41 memlog ( int maxlen0, string itf="" ) : maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ),itfilename(itf) {} 42 43 memlog(): ind ( 0 ),vectors ( 0 ) {} 44 41 45 //! Initialize storage 42 46 void init() { … … 60 64 void finalize() {if (itfilename.length()>0) itsave(itfilename.c_str());}; 61 65 66 67 /*! \brief UI for memlog 68 69 TODO dat tam kam patri, a to celej blok 70 71 \code 72 logger = { 73 type = "itpplog"; 74 filename = "file_name.it"; // resulting filename with results in it format 75 maxlen = 100; // size of memory buffer 76 } 77 \endcode 78 */ 79 void from_setting( const Setting &root ); 80 81 // TODO dodelat void to_setting( Setting &root ) const; 62 82 }; 83 84 UIREGISTER(memlog); 63 85 64 86 /*! … … 69 91 * This format is used to store scalars, hence multivariate RVs must be separated. 70 92 */ 71 72 93 class dirfilelog : public memlog { 73 94 … … 81 102 @param dirname0 name of the directory in which to store the results 82 103 @param maxlen0 length of the memory buffers, when full the buffers will be dumped to HDD and returned to the beginning. */ 83 dirfilelog ( std::string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {} 104 dirfilelog ( string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {} 105 106 dirfilelog() {} 107 84 108 //! Initialize storage 85 109 void init(); … … 90 114 */ 91 115 void write_buffers ( int Len ); 116 117 // TODO dokumentace - aktualizovat 118 /*! \brief UI for dirfilelog (Kst file format) 119 \code 120 logger = { 121 type = "dirfilelog"; 122 dirmane = "directory_for_files"; // resulting files will be stored there 123 maxlen = 100; // size of memory buffer, when full results are written to disk 124 } 125 \endcode 126 */ 127 void from_setting( const Setting &root ); 128 129 // TODO dodelat void to_setting( Setting &root ) const; 92 130 }; 131 132 UIREGISTER(dirfilelog); 93 133 94 134 }; -
bdm/user_info.cpp
r351 r357 13 13 #include "user_info.h" 14 14 15 namespace bdm { 15 namespace bdm 16 { 16 17 17 18 … … 19 20 20 21 21 UI_File::UI_File ( const string &file_name ) : file_name( file_name)22 { 23 22 UI_File::UI_File () 23 { 24 setAutoConvert( true ); 24 25 } 25 26 26 27 //! loads root element from a file 27 void UI_File::load() 28 { 29 try 30 { 31 readFile( file_name.c_str() ); 32 } 33 catch ( FileIOException f ) 34 { 35 it_error ( "UI error: file " + file_name + " not found." ); 36 } 37 catch ( ParseException& P ) 38 { 39 stringstream msg; 40 msg << "UI error: parsing ui_error """ << P.getError() << """ in file " << file_name << " on line " << P.getLine() << "."; 41 it_error ( msg.str() ); 42 } 28 UI_File::UI_File ( const string &file_name ) 29 { 30 setAutoConvert( true ); 31 try 32 { 33 readFile( file_name.c_str() ); 34 } 35 catch ( FileIOException f ) 36 { 37 it_error ( "UI error: file " + file_name + " not found." ); 38 } 39 catch ( ParseException& P ) 40 { 41 stringstream msg; 42 msg << "UI error: parsing error """ << P.getError() << """ in file " << file_name << " on line " << P.getLine() << "."; 43 it_error ( msg.str() ); 44 } 43 45 } 44 46 45 47 46 48 //! save UserInfo to the file (typically with an XML extension) 47 void UI_File::save( )48 { 49 50 51 52 53 catch ( FileIOException f ) 54 55 56 } 57 } 49 void UI_File::save( const string &file_name ) 50 { 51 try 52 { 53 writeFile ( file_name.c_str() ); 54 } 55 catch ( FileIOException f ) 56 { 57 it_error( "UI error: file " + file_name + " is inacessible." ); 58 } 59 } 58 60 59 61 UI_File::operator Setting&() 60 62 { 61 63 return getRoot(); 62 64 } 63 65 ///////////////////////// INTERNAL MAPPED_UI ///////////////////////////////////////////// … … 65 67 UI::Mapped_UI::String_To_UI_Map& UI::Mapped_UI::mapped_strings() 66 68 { 67 68 69 static String_To_UI_Map var; 70 return var; 69 71 } 70 72 71 73 UI::Mapped_UI::Type_Info_To_String_Map& UI::Mapped_UI::mapped_type_infos() 72 74 { 73 74 75 static Type_Info_To_String_Map var; 76 return var; 75 77 } 76 78 77 79 void UI::Mapped_UI::add_class( const string &class_name, const type_info * const class_type_info, const UI* const ui ) 78 80 { 79 80 81 81 pair< const string, const UI* const > new_pair = make_pair( class_name, ui ); 82 mapped_strings().insert( new_pair ); 83 mapped_type_infos().insert( make_pair( class_type_info, new_pair.first ) ); 82 84 } 83 85 84 86 const UI& UI::Mapped_UI::retrieve_ui( const string &class_name ) 85 87 { 86 87 if( iter == mapped_strings().end()) 88 89 90 } 88 String_To_UI_Map::const_iterator iter = mapped_strings().find( class_name ); 89 if ( iter == mapped_strings().end()) 90 it_error ( "UI error: class " + class_name + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 91 return *iter->second; 92 } 91 93 92 94 const string& UI::Mapped_UI::retrieve_class_name( const type_info * const class_type_info ) 93 95 { 94 95 if( iter == mapped_type_infos().end()) 96 97 98 } 96 Type_Info_To_String_Map::const_iterator iter = mapped_type_infos().find( class_type_info ); 97 if ( iter == mapped_type_infos().end()) 98 it_error ( "UI error: class with RTTI name " + string(class_type_info->name()) + " was not properly registered. Use the macro ""UIREGISTER([class name]);"" within your code." ); 99 return iter->second; 100 } 99 101 100 102 ///////////////////////// INTERNAL LINK EXPANDER ///////////////////////////////////////////// … … 102 104 UI::Link_Expander::Link_Expander( const Setting &potential_link ) 103 105 { 104 file = NULL; 105 result = &potential_link; 106 107 if( potential_link.getType() != Setting::TypeString ) 108 return; 109 110 string link = (string) potential_link; 111 size_t aerobase = link.find('@'); 112 if( aerobase != string::npos ) 113 { 114 string file_name = link.substr( aerobase + 1, link.length() ); 115 file = new UI_File( file_name ); 116 file->load(); 117 result = &(Setting&)(*file); 118 link = link.substr( 0, aerobase ); 119 } 120 else 121 while ( !result->isRoot() ) 122 result = &result->getParent(); 123 124 if( !result->exists( link ) ) 125 ui_error( "linked Setting was not found", potential_link ); 126 127 result = &(*result)[link]; 106 file = NULL; 107 result = &potential_link; 108 109 if ( potential_link.getType() != Setting::TypeString ) 110 return; 111 112 string link = (string) potential_link; 113 size_t aerobase = link.find('@'); 114 if ( aerobase != string::npos ) 115 { 116 string file_name = link.substr( aerobase + 1, link.length() ); 117 file = new UI_File( file_name ); 118 result = &(Setting&)(*file); 119 link = link.substr( 0, aerobase ); 120 } 121 else 122 while ( !result->isRoot() ) 123 result = &result->getParent(); 124 125 if ( !result->exists( link ) ) 126 ui_error( "linked Setting was not found", potential_link ); 127 128 result = &(*result)[link]; 128 129 } 129 130 130 131 UI::Link_Expander::~Link_Expander() 131 132 { 132 if( file ) delete file;133 if ( file ) delete file; 133 134 } 134 135 135 136 const Setting& UI::Link_Expander::root() const 136 137 { 137 138 return *result; 138 139 } 139 140 140 141 ///////////////////////// UI ///////////////////////////////////////////// 141 142 142 143 144 //! This methods - kvuli ukladani pole stringu, dat jen privatne? 143 void UI::ui_error( string message, const Setting &element ) 144 { 145 stringstream error_message; 146 error_message << "UI error: " << message << "! Check path """ << element.getPath() << """, source line " << element.getSourceLine() << "."; 147 it_error ( error_message.str() ); 148 } 149 150 //! This methods - kvuli ukladani pole stringu, dat jen privatne? 145 151 void UI::save( const string &str, Setting &element ) 146 152 { 147 148 153 Setting &root = element.add( Setting::TypeString ); 154 root = str; 149 155 } 150 156 151 157 void UI::save( const mat &matrix, Setting &element, const string &name) 152 158 { 153 154 Setting &root = (name == "") ? element.add( Setting::TypeList ) 155 : element.add( name, Setting::TypeList ); 156 157 Setting &cols = root.add( Setting::TypeInt ); 158 cols = matrix.cols(); 159 160 Setting &rows = root.add( Setting::TypeInt ); 161 rows = matrix.rows(); 162 163 Setting &elements = root.add( Setting::TypeArray ); 164 165 // build matrix row-wise 166 for( int i=0; i<matrix.rows(); i++ ) 167 for( int j=0; j<matrix.cols(); j++) 168 { 169 Setting &new_field = elements.add(Setting::TypeFloat); 170 new_field = matrix(i,j); 171 } 172 } 173 174 175 //! This methods tries to save a double vec 176 void UI::save( const ivec &vec, Setting &element, const string &name) 177 { 178 179 Setting &root = (name == "") ? element.add( Setting::TypeArray ) 180 : element.add( name, Setting::TypeArray ); 181 for( int i=0; i<vec.length(); i++ ) 182 { 183 Setting &new_field = root.add(Setting::TypeInt); 184 new_field = vec(i); 185 } 186 } 187 188 189 //! This methods tries to build a new double matrix 159 160 Setting &root = (name == "") ? element.add( Setting::TypeList ) 161 : element.add( name, Setting::TypeList ); 162 163 Setting &cols = root.add( Setting::TypeInt ); 164 cols = matrix.cols(); 165 166 Setting &rows = root.add( Setting::TypeInt ); 167 rows = matrix.rows(); 168 169 Setting &elements = root.add( Setting::TypeArray ); 170 171 // build matrix row-wise 172 for ( int i=0; i<matrix.rows(); i++ ) 173 for ( int j=0; j<matrix.cols(); j++) 174 { 175 Setting &new_field = elements.add(Setting::TypeFloat); 176 new_field = matrix(i,j); 177 } 178 } 179 180 181 //! This methods tries to save a integer vector 182 void UI::save( const ivec &vector, Setting &element, const string &name) 183 { 184 185 Setting &root = (name == "") ? element.add( Setting::TypeArray ) 186 : element.add( name, Setting::TypeArray ); 187 for ( int i=0; i<vector.length(); i++ ) 188 { 189 Setting &new_field = root.add(Setting::TypeInt); 190 new_field = vector(i); 191 } 192 } 193 194 195 //! This methods tries to save a double vector 196 void UI::save( const vec &vector, Setting &element, const string &name) 197 { 198 199 Setting &root = (name == "") ? element.add( Setting::TypeArray ) 200 : element.add( name, Setting::TypeArray ); 201 for ( int i=0; i<vector.length(); i++ ) 202 { 203 Setting &new_field = root.add(Setting::TypeFloat); 204 new_field = vector(i); 205 } 206 } 207 208 209 //! This methods tries to build a new double matrix 190 210 191 211 void UI::from_setting( mat& matrix, const Setting &element ) 192 212 { 193 194 195 196 if( root.isNumber() )197 198 199 200 201 202 203 if( root.isList() )204 205 if( root.getLength() != 3 )206 207 208 Setting &cols_setting = root[0];209 Setting &rows_setting = root[1];210 211 212 213 214 215 216 217 218 219 if( cols < 0 | rows < 0 )220 221 222 if( elements.getLength() != cols * rows )223 224 225 226 227 if( cols == 0 || rows == 0 )228 229 230 if( !elements[0].isNumber() )231 232 233 234 235 for( int i=0;i<rows;i++ ) 236 for( int j=0; j<cols; j++)237 238 239 240 241 213 const Link_Expander link_expander( element ); 214 const Setting &root = link_expander.root(); 215 216 if ( root.isNumber() ) 217 { 218 matrix.set_size( 1, 1 ); 219 matrix(0,0) = root; 220 return; 221 } 222 223 if ( root.isList() ) 224 { 225 if ( root.getLength() != 3 ) 226 ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 227 228 Setting &rows_setting = root[0]; 229 Setting &cols_setting = root[1]; 230 Setting &elements = root[2]; 231 232 ASSERT_UITYPE(cols_setting,TypeInt); 233 ASSERT_UITYPE(rows_setting,TypeInt); 234 ASSERT_UITYPE(elements,TypeArray); 235 236 int cols = cols_setting; 237 int rows = rows_setting; 238 239 if ( cols < 0 | rows < 0 ) 240 ui_error( "the dimensions of a matrix has to be non-negative", root ); 241 242 if ( elements.getLength() != cols * rows ) 243 ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 244 245 matrix.set_size( rows, cols ); 246 247 if ( cols == 0 || rows == 0 ) 248 return; 249 250 if ( !elements[0].isNumber() ) 251 ui_error( "matrix elements have to be numbers", elements[0] ); 252 253 // build matrix row-wise 254 int k = 0; 255 for ( int i=0; i<rows; i++ ) 256 for ( int j=0; j<cols; j++) 257 matrix(i,j) = elements[k++]; 258 return; 259 } 260 261 ui_error( "only numeric types or TypeList are supported as matrix values", root ); 242 262 } 243 263 244 264 //! This methods tries to build a new integer vector 245 void UI::from_setting( ivec &vec, const Setting &element ) 246 { 247 const Link_Expander link_expander( element ); 248 const Setting &root = link_expander.root(); 249 250 if( root.isNumber() ) 251 { 252 ASSERT_UITYPE(root,TypeInt); 253 vec.set_length( 1 ); 254 vec(0) = root; 255 return; 256 } 257 258 if( root.isList() ) 259 { 260 if( root.getLength() != 3 ) 261 ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 262 263 Setting &cols_setting = root[0]; 264 Setting &rows_setting = root[1]; 265 Setting &elements = root[2]; 266 267 ASSERT_UITYPE(cols_setting,TypeInt); 268 ASSERT_UITYPE(rows_setting,TypeInt); 269 ASSERT_UITYPE(elements,TypeArray); 270 271 int cols = cols_setting; 272 int rows = rows_setting; 273 274 if( cols < 0 | rows < 0) 275 ui_error( "the dimensions of a matrix has to be non-negative", root ); 276 277 if( elements.getLength() != cols * rows ) 278 ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 279 280 if( cols != 1 & rows !=1) 281 ui_error( "the vector length is invalid, it seems to be rather a matrix", elements ); 282 283 int len = rows * cols; 284 vec.set_length ( len ); 285 if( len == 0 ) return; 286 287 ASSERT_UITYPE(elements[0],TypeInt); 288 for( int i=0; i<len; i++ ) 289 vec(i) = elements[i]; 290 return; 291 } 292 293 if( root.isArray() ) 294 { 295 int len = root.getLength(); 296 vec.set_length( len ); 297 if( len == 0 ) return; 298 299 ASSERT_UITYPE(root[0],TypeInt); 300 for( int i=0; i < len; i++ ) 301 vec(i) = root[i]; 302 return; 303 } 304 305 ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", root ); 265 void UI::from_setting( ivec &vector, const Setting &element ) 266 { 267 const Link_Expander link_expander( element ); 268 const Setting &root = link_expander.root(); 269 270 if ( root.isNumber() ) 271 { 272 ASSERT_UITYPE(root,TypeInt); 273 vector.set_length( 1 ); 274 vector(0) = root; 275 return; 276 } 277 278 if ( root.isList() ) 279 { 280 if ( root.getLength() != 3 ) 281 ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 282 283 Setting &cols_setting = root[0]; 284 Setting &rows_setting = root[1]; 285 Setting &elements = root[2]; 286 287 ASSERT_UITYPE(cols_setting,TypeInt); 288 ASSERT_UITYPE(rows_setting,TypeInt); 289 ASSERT_UITYPE(elements,TypeArray); 290 291 int cols = cols_setting; 292 int rows = rows_setting; 293 294 if ( cols < 0 | rows < 0) 295 ui_error( "the dimensions of a matrix has to be non-negative", root ); 296 297 if ( elements.getLength() != cols * rows ) 298 ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 299 300 if ( cols != 1 & rows !=1) 301 ui_error( "the vector length is invalid, it seems to be rather a matrix", elements ); 302 303 int len = rows * cols; 304 vector.set_length ( len ); 305 if ( len == 0 ) return; 306 307 ASSERT_UITYPE(elements[0],TypeInt); 308 for ( int i=0; i<len; i++ ) 309 vector(i) = elements[i]; 310 return; 311 } 312 313 if ( root.isArray() ) 314 { 315 int len = root.getLength(); 316 vector.set_length( len ); 317 if ( len == 0 ) return; 318 319 ASSERT_UITYPE(root[0],TypeInt); 320 for ( int i=0; i < len; i++ ) 321 vector(i) = root[i]; 322 return; 323 } 324 325 ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", root ); 326 } 327 328 //! This methods tries to build a new double vector 329 void UI::from_setting( vec &vector, const Setting &element ) 330 { 331 const Link_Expander link_expander( element ); 332 const Setting &root = link_expander.root(); 333 334 if ( root.isNumber() ) 335 { 336 vector.set_length( 1 ); 337 vector(0) = root; 338 return; 339 } 340 341 if ( root.isList() ) 342 { 343 if ( root.getLength() != 3 ) 344 ui_error( "the setting supposed to represent a matrix element has wrong syntax", root ); 345 346 Setting &cols_setting = root[0]; 347 Setting &rows_setting = root[1]; 348 Setting &elements = root[2]; 349 350 ASSERT_UITYPE(cols_setting,TypeInt); 351 ASSERT_UITYPE(rows_setting,TypeInt); 352 ASSERT_UITYPE(elements,TypeArray); 353 354 int cols = cols_setting; 355 int rows = rows_setting; 356 357 if ( cols < 0 | rows < 0) 358 ui_error( "the dimensions of a matrix has to be non-negative", root ); 359 360 if ( elements.getLength() != cols * rows ) 361 ui_error( "the count of the matrix elements is incompatible with matrix dimension", elements ); 362 363 if ( cols != 1 & rows !=1) 364 ui_error( "the vector length is invalid, it seems to be rather a matrix", elements ); 365 366 int len = rows * cols; 367 vector.set_length ( len ); 368 if ( len == 0 ) return; 369 370 if ( !elements[0].isNumber()) 371 ui_error("a vector element has to be a number", elements[0]); 372 373 for ( int i=0; i<len; i++ ) 374 vector(i) = elements[i]; 375 return; 376 } 377 378 if ( root.isArray() ) 379 { 380 int len = root.getLength(); 381 vector.set_length( len ); 382 if ( len == 0 ) return; 383 384 if ( !root[0].isNumber()) 385 ui_error("a vector element has to be a number", root[0]); 386 387 for ( int i=0; i < len; i++ ) 388 vector(i) = root[i]; 389 return; 390 } 391 392 ui_error( "only numeric types, TypeArray or TypeList are supported as vector values", root ); 306 393 } 307 394 … … 309 396 void UI::from_setting( string &str, const Setting &element ) 310 397 { 311 312 398 ASSERT_UITYPE(element,TypeString); 399 str = (string) element; 313 400 } 314 401 315 402 316 403 ///////////////////////// UI FILE ///////////////////////////////////////////// 317 //! This methods tries to save an instance of type T (or some of its descendant types) 318 //! and build DOM tree accordingly. Then, it creates a new DOMNode named according class_name 319 //! and connecti it to the passed Setting as a new child node. 320 const Setting* UI::pointer_to_child_setting( const Setting &element, const int index ) 321 { 322 if( !element.isList()) 323 return NULL; 324 325 if( element.getLength() <= index ) 326 return NULL; 327 328 return &element[index]; 329 } 330 331 const Setting* UI::pointer_to_child_setting( const Setting &element, const string &name ) 332 { 333 if( !element.isGroup() ) 334 return NULL; 335 336 if( !element.exists( name ) ) 337 return NULL; 338 339 return &element[name]; 340 } 341 342 const Setting& UI::reference_to_child_setting( const Setting &element, const int index ) 343 { 344 if( !element.isList()) 345 ui_error( "only TypeList elements could be indexed by integers", element ); 346 347 if( element.getLength() <= index ) 348 ui_error( "there is not any child with index " + index, element ); 349 350 return element[index]; 351 } 352 353 const Setting& UI::reference_to_child_setting( const Setting &element, const string &name ) 354 { 355 ASSERT_UITYPE(element,TypeGroup); 356 if( !element.exists( name ) ) 357 ui_error( "there is not any child named """ + name, element ); 358 return element[name]; 359 } 360 361 362 } 363 404 //! This methods tries to save an instance of type T (or some of its descendant types) 405 //! and build DOM tree accordingly. Then, it creates a new DOMNode named according class_name 406 //! and connecti it to the passed Setting as a new child node. 407 const Setting& UI::to_child_setting( const Setting &element, const int index ) 408 { 409 if ( !element.isList()) 410 ui_error( "only TypeList elements could be indexed by integers", element ); 411 412 if ( element.getLength() <= index ) 413 ui_error( "there is not any child with index " + index, element ); 414 415 return element[index]; 416 } 417 418 const Setting& UI::to_child_setting( const Setting &element, const string &name ) 419 { 420 ASSERT_UITYPE(element,TypeGroup); 421 if ( !element.exists( name ) ) 422 ui_error( "there is not any child named """ + name, element ); 423 return element[name]; 424 } 425 426 427 } 428 -
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