|
Nemo
2.2.0
|
00001 00030 #ifndef STATHANDLER_H 00031 #define STATHANDLER_H 00032 00033 #include <list> 00034 #include <string> 00035 #include "handler.h" 00036 #include "statservices.h" 00037 00038 class Metapop; 00039 00040 class StatRecBase; 00047 class StatHandlerBase : public Handler { 00048 00049 private: 00051 std::list<StatRecBase*> _stats; 00053 unsigned int _nrows, _ncols; 00055 StatServices* _service; 00057 unsigned int _GenerationOccurrence; 00059 unsigned int _current_replicate; 00061 unsigned int _current_generation; 00063 age_t _current_age; 00064 00065 typedef std::list< StatRecBase* >::iterator STAT_IT; 00066 00067 protected: 00069 Metapop* _pop; 00070 00071 public: 00072 00073 StatHandlerBase ( ) 00074 : _nrows(0), _ncols(0), _service(0), _GenerationOccurrence(0), _current_replicate(0), 00075 _current_generation(0), _current_age(0) 00076 { } 00077 00078 virtual ~StatHandlerBase ( ) { } 00081 Metapop* get_pop_ptr ( ) {return _service->get_pop_ptr();} 00082 00083 void set_service (StatServices* srv) {_service = srv;} 00084 00085 StatServices* get_service ( ) {return _service;} 00086 00087 unsigned int getOccurrence ( ) {return _service->getOccurrence();} 00088 00089 unsigned int getNbRecorders ( ) {return _stats.size();} 00090 00091 unsigned int get_nrows ( ) {return _nrows;} 00092 00093 unsigned int get_ncols ( ) {return _ncols;} 00094 00095 std::list<StatRecBase*>& getStats ( ) {return _stats;} 00096 00097 virtual void add (StatRecBase* rec) {_stats.push_back(rec);} 00099 00100 virtual void reset ( ); 00101 00104 unsigned int getStatRecIndex (unsigned int i); 00105 00106 void setAverage ( ); 00107 00108 void print_headers (std::ofstream& FH, unsigned int order); 00109 00110 void print_value (std::ofstream& FH, unsigned int i, unsigned int j); 00111 00112 void print_average (std::ofstream& FH, unsigned int i); 00116 virtual void init ( ); 00117 virtual void update ( ); 00121 virtual void execute ( ) = 0; 00122 00123 virtual bool setStatRecorders (std::string& token) = 0; 00124 00125 virtual void clear ( ) = 0; 00127 }; 00128 00132 template <class SH> class StatHandler: public StatHandlerBase { 00133 00134 protected: 00136 std::list<StatRecorder<SH>*> _recorders; 00137 00138 typedef typename std::list< StatRecorder<SH>* >::iterator REC_IT; 00139 00140 public: 00141 00142 StatHandler( ) { } 00143 00144 virtual ~StatHandler ( ) { } 00146 virtual void clear ( ) {_recorders.clear();} 00148 virtual void execute ( ); 00166 virtual StatRecorder<SH>* add (std::string Title, std::string Name, age_t AGE, unsigned int ARG1, unsigned int ARG2, 00167 double(SH::* getStatNoArg)(void), double(SH::* getStatOneArg)(unsigned int), 00168 double(SH::* getStatTwoArg)(unsigned int, unsigned int), void(SH::* setStat)(void)) 00169 { 00170 StatRecorder<SH>* new_rec = new StatRecorder<SH>(this->get_nrows(),this->get_ncols()); 00171 00172 new_rec->set(Title,Name,AGE,ARG1,ARG2,getStatNoArg,getStatOneArg,getStatTwoArg,setStat); 00173 00174 _recorders.push_back(new_rec); 00175 00176 StatHandlerBase::add(new_rec); 00177 00178 return new_rec; 00179 } 00180 }; 00181 00182 // TraitStatHandler 00183 // 00187 template <class TP, class SH> class TraitStatHandler : public StatHandler<SH> { 00188 protected: 00190 TP* _SHLinkedTrait; 00192 int _SHLinkedTraitIndex; 00193 public: 00194 TraitStatHandler (TP* trait_proto); 00195 virtual ~TraitStatHandler () { } 00196 }; 00197 00198 template<class TP, class SH> TraitStatHandler<TP,SH>::TraitStatHandler(TP* trait_proto) 00199 { 00200 _SHLinkedTrait = trait_proto; 00201 _SHLinkedTraitIndex = trait_proto->get_index(); 00202 } 00203 00204 // EventStatHandler 00205 // 00208 template <class LCE, class SH> class EventStatHandler : public StatHandler<SH> { 00209 protected: 00211 LCE* _SHLinkedEvent; 00212 public: 00213 EventStatHandler (LCE* lce); 00214 virtual ~EventStatHandler () { } 00215 }; 00216 00217 template<class LCE, class SH> EventStatHandler<LCE,SH>::EventStatHandler(LCE* lce) 00218 { 00219 _SHLinkedEvent = lce; 00220 } 00221 00222 00223 #endif
1.7.5.1 -- Nemo is hosted by