Changeset 527 for library/bdm/base
- Timestamp:
- 08/13/09 15:58:32 (15 years ago)
- Location:
- library/bdm/base
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.cpp
r507 r527 169 169 170 170 void mpdf::from_setting ( const Setting &set ) { 171 RV *r = UI::build<RV> ( set, "rv");171 shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional ); 172 172 if ( r ) { 173 173 set_rv ( *r ); 174 delete r; 175 } 176 177 r = UI::build<RV> ( set, "rvc" ); 174 } 175 176 r = UI::build<RV> ( set, "rvc", UI::optional ); 178 177 if ( r ) { 179 178 set_rvc ( *r ); 180 delete r;181 179 } 182 180 } -
library/bdm/base/bdmbase.h
r513 r527 379 379 //!@} 380 380 void from_setting (const Setting &set) { 381 RV* r = UI::build<RV> (set, "rv");381 shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional ); 382 382 if (r) { 383 383 set_rv (*r); 384 delete r;385 384 } 386 385 } … … 455 454 return rvc; 456 455 } 457 int dimension() { 456 457 int dimension() const { 458 458 return ep->dimension(); 459 459 } -
library/bdm/base/datasources.cpp
r477 r527 57 57 58 58 void ArxDS::from_setting ( const Setting &set ) { 59 RV *yrv = UI::build<RV> ( set, "y" , UI::compulsory );60 RV *urv = UI::build<RV> ( set, "u" , UI::compulsory );61 RV *rrv = UI::build<RV> ( set, "rgr" , UI::compulsory );59 shared_ptr<RV> yrv = UI::build<RV> ( set, "y" , UI::compulsory ); 60 shared_ptr<RV> urv = UI::build<RV> ( set, "u" , UI::compulsory ); 61 shared_ptr<RV> rrv = UI::build<RV> ( set, "rgr" , UI::compulsory ); 62 62 63 63 mat Th; … … 112 112 113 113 void ITppFileDS::from_setting ( const Setting &set ) { 114 RV*rvtmp = UI::build<RV> ( set, "rv" , UI::compulsory );114 shared_ptr<RV> rvtmp = UI::build<RV> ( set, "rv" , UI::compulsory ); 115 115 116 116 it_file it ( set["filename"] ); … … 131 131 ut.set_length ( 0 ); 132 132 133 #if 0 133 134 RV* rvtmp = UI::build<RV> ( set["IM"], "rvu", UI::compulsory ); 134 135 //set_drv(rvtmp); 136 #endif 135 137 } -
library/bdm/base/datasources.h
r477 r527 173 173 }; 174 174 //! Set 175 void set_drv ( RV &yrv, RV &urv,RV &rrv ) {175 void set_drv ( const RV &yrv, const RV &urv, const RV &rrv ) { 176 176 Rrv = rrv; 177 177 Urv = urv; … … 265 265 266 266 class stateDS : public DS { 267 private: 268 //!conditional pdf of the state evolution \f$ f(x_t|x_{t-1}) \f$ 269 shared_ptr<mpdf> IM; 270 271 //!conditional pdf of the observations \f$ f(d_t|x_t) \f$ 272 shared_ptr<mpdf> OM; 273 267 274 protected: 268 //!conditional pdf of the state evolution \f$ f(x_t|x_{t-1}) \f$269 mpdf* IM;270 //!conditional pdf of the observations \f$ f(d_t|x_t) \f$271 mpdf* OM;272 275 //! result storage 273 276 vec dt; … … 278 281 //! Logger 279 282 int L_xt; 283 280 284 public: 281 285 void getdata ( vec &dt0 ) { … … 286 290 } 287 291 288 stateDS ( mpdf* IM0, mpdf* OM0, int usize ) : DS ( ), IM ( IM0 ), OM ( OM0 ), 289 dt ( OM0->dimension() ), xt ( IM0->dimension() ), ut ( usize ) {} 290 291 stateDS() {} 292 293 ~stateDS() { 294 delete IM; 295 delete OM; 296 } 292 stateDS ( const shared_ptr<mpdf> &IM0, const shared_ptr<mpdf> &OM0, int usize ) : IM ( IM0 ), OM ( OM0 ), 293 dt ( OM0->dimension() ), xt ( IM0->dimension() ), 294 ut ( usize ), L_xt(0) { } 295 296 stateDS() : L_xt(0) { } 297 297 298 virtual void step() { 298 299 xt = IM->samplecond ( concat ( xt, ut ) ); 299 300 dt = OM->samplecond ( concat ( xt, ut ) ); 300 } ;301 } 301 302 302 303 virtual void log_add ( logger &L ) { -
library/bdm/base/user_info.h
r494 r527 24 24 #include "libconfig/libconfig.h++" 25 25 #include "../bdmroot.h" 26 #include "../shared_ptr.h" 26 27 #include "itpp/itbase.h" 27 28 … … 253 254 static void assert_type ( const Setting &element, Setting::Type type ); 254 255 255 //! Method assembling a typeless instance, it is implemented in descendant class ParticularUI<T> 256 /*! 257 \brief Method constructing a configured instance 258 259 The returned pointer must be allocated using operator new 260 (it's deleted at the end of its life cycle). The method is 261 implemented in descendant class ParticularUI<T>, which knows 262 the correct type T. 263 */ 256 264 virtual root* new_instance() const = 0; 257 265 … … 274 282 //! This method converts a Setting into a real scalar 275 283 static void from_setting ( double &real, const Setting &element ); 284 276 285 //! This method converts a Setting into a class T descendant 277 286 template<class T> static void from_setting ( T* &instance, const Setting &element ) { … … 287 296 const UI& related_UI = MappedUI::retrieve_ui ( class_name ); 288 297 289 root* typeless_instance = related_UI.new_instance(); 298 root *typeless_instance = related_UI.new_instance(); 299 it_assert_debug ( typeless_instance, "UI::new_instance failed" ); 290 300 291 301 instance = dynamic_cast<T*> ( typeless_instance ); 292 if ( !instance ) 302 if ( !instance ) { 303 delete typeless_instance; 293 304 throw UIException ( "class " + class_name + " is not a descendant of the desired output class. Try to call the UI::build<T> function with a different type parameter.", link.result ); 305 } 294 306 295 307 try { … … 301 313 } 302 314 315 //! This method converts a Setting into a descendant of class 316 //! T, wrapped in an instance of shared_ptr<T> . 317 template<class T> 318 static void from_setting ( shared_ptr<T> &instance, const Setting &element ) { 319 T *tmp_inst = 0; 320 from_setting ( tmp_inst, element ); 321 it_assert_debug ( tmp_inst, "UI::from_setting failed" ); 322 instance = tmp_inst; 323 } 324 303 325 //! This methods converts a Setting into a new templated array of type Array<T> 304 326 template<class T> static void from_setting ( Array<T> &array_to_load, const Setting &element ) { … … 320 342 //! The exception can help to find the place where the template is misused and also to correct it. 321 343 template<class T> static void from_setting ( T &variable_to_load, const Setting &element ) { 322 throw UIException ( "from_setting is not implemented for this type", element ); 344 std::string msg = "from_setting is not implemented for type "; 345 msg += typeid(T).name(); 346 throw UIException ( msg, element ); 323 347 } 324 348 … … 341 365 //! The new instance of type T* is constructed and initialized with values stored in the Setting element[name] 342 366 //! 343 //! If there is not any sub-element named #name, the null pointer is returned. 344 template<class T> static T* build ( const Setting &element, const string &name, SettingPresence settingPresence = optional ) { 367 //! If there is not any sub-element named #name and settingPresence is #optional, an empty shared_ptr<T> is returned. When settingPresence is #compulsory, the returned shared_ptr<T> is never empty (an exception is thrown when the object isn't found). 368 template<class T> 369 static shared_ptr<T> build ( const Setting &element, const string &name, SettingPresence settingPresence = optional ) { 345 370 if ( !element.exists ( name ) ) { 346 371 if ( settingPresence == optional ) 347 return NULL;372 return shared_ptr<T>(); 348 373 else 349 374 throw UIException ( "the compulsory Setting named \"" + name + "\" is missing", element ); 350 375 } 351 376 352 T*instance;377 shared_ptr<T> instance; 353 378 from_setting<T> ( instance, to_child_setting ( element, name ) ); 354 379 return instance; … … 483 508 } 484 509 510 template< class T> static void save ( const shared_ptr<T> &instance, Setting &element, const string &name = "" ) { 511 save<T> ( instance.get(), element, name ); 512 } 513 485 514 //! An Array<T> instance is stored in the new child Setting appended to the passed element 486 515 template<class T> static void save ( const Array<T> &array_to_save, Setting &element, const string &name = "" ) {