00001 #ifndef VARIABLERECORDER_H_
00002 #define VARIABLERECORDER_H_
00003
00004 #include "EvSimObject.h"
00005 #include "SimException.h"
00006 #include "EvSimObjectTypeUtils.h"
00007
00008 #include <vector>
00009 using std::vector;
00010
00011 #include <boost/shared_ptr.hpp>
00012 #include <boost/format.hpp>
00013
00014 #ifndef SWIG
00015
00016 #include <typeinfo>
00017 using std::type_info;
00018
00019 #endif
00020
00021
00022 #include "evesim_hash.h"
00023
00024 class VariableRecorder : public EvSimObject {
00025 public:
00026
00027 virtual ~VariableRecorder();
00028
00029 virtual void eventHit(SimContext & sim_info, Time time, port_id_t port) { };
00030
00031 virtual void setRecordedSimObject(EvSimObject *obj, const string &var_name) { };
00032
00033 };
00034
00035
00036 template <typename T>
00037 class VariableRecorderImpl : public VariableRecorder {
00038
00039 public:
00040 typedef vector<T> ValuesVector;
00041
00042 VariableRecorderImpl() {};
00043
00044 virtual ~VariableRecorderImpl() {};
00045
00046 virtual void eventHit(SimContext & sim_info, Time time, port_id_t port) {
00047 rec_values.push_back(*rec_var_ptr);
00048 }
00049
00050 virtual void setRecordedSimObject(EvSimObject *obj, const string &var_name) {
00051 rec_var_ptr = (T *)obj->getVariablePtr(var_name);
00052 }
00053
00054
00055 const std::vector<T> & getRecordedValues() const {
00056 return rec_values;
00057 }
00058
00059 protected:
00060 T *rec_var_ptr;
00061 vector<T> rec_values;
00062
00063 };
00064
00065
00066 #endif