From 40c086725083465778bb85d8447a4fc69ee996c0 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Wed, 16 Feb 2011 16:57:47 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@174 ed2142bd-67ad-457f-ba7c-d818d4011675 --- pre_estimater/lin1d_estimater.hpp | 18 +++------ pre_estimater/pre_estimater.hpp | 78 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 16 deletions(-) diff --git a/pre_estimater/lin1d_estimater.hpp b/pre_estimater/lin1d_estimater.hpp index 1ec62cb..e36f2a7 100644 --- a/pre_estimater/lin1d_estimater.hpp +++ b/pre_estimater/lin1d_estimater.hpp @@ -2,33 +2,27 @@ #define LIN1D_ESTIMATER #include "pre_estimater.hpp" #include -#include - +#include +#include namespace opt_utilities { template class lin1d_estimater - :public pre_estimater,optvec,optvec,T,std::string> + :public pre_estimater,std::string> { - private: - const std::string model_id; private: lin1d_estimater() - :model_id(lin1d().get_type_name()) - {} + { + } lin1d_estimater do_clone()const { return new lin1d_estimater(*this); } - void do_estimate(fitter,optvec,optvec,T,std::string>& fit)const + void do_estimate(const data& d,model,std::string>& m)const { - if(model_id!=fit.get_model().get_type_name()) - { - return; - } } }; } diff --git a/pre_estimater/pre_estimater.hpp b/pre_estimater/pre_estimater.hpp index db21e94..9810683 100644 --- a/pre_estimater/pre_estimater.hpp +++ b/pre_estimater/pre_estimater.hpp @@ -6,23 +6,93 @@ namespace opt_utilities { - template + + + template class pre_estimater { private: - virtual void do_estimate(fitter& fit)const=0; + std::string model_id; + private: + virtual void do_estimate(const data_set& d,model& m)const=0; virtual pre_estimater* do_clone()const=0; + virtual void do_destroy() + { + delete this; + } public: - void estimate(fitter& fit)const + void estimate(const data_set& d,model& m)const { - do_estimate(fit); + do_estimate(d,m); } pre_estimater* clone()const { return this->do_clone(); } + + void destroy() + { + do_destroy(); + } + public: + std::string get_model_id()const + { + return model_id; + } + + void set_model_id(const std::string& s) + { + model_id=s; + } }; + + template + class pre_estimatable + { + private: + pre_estimater* ppe; + public: + pre_estimatable() + :ppe(0) + {} + + void set_pre_estimater(const pre_estimater& pe) + { + if(dynamic_cast&>(*this).get_type_name()!=pe.get_model_id()) + { + return; + } + if(ppe) + { + ppe->destroy(); + } + ppe=pe.clone(); + } + + virtual ~pre_estimatable() + { + if(ppe) + { + delete ppe; + } + } + + public: + void estimate(const data_set& d) + { + if(ppe) + { + ppe->estimate(d,dynamic_cast&>(*this)); + } + } + }; + + template + void pre_estimate(fitter& fit) + { + dynamic_cast&>(fit.get_model()).estimate(fit.get_data_set()); + } } -- cgit v1.2.2