00001 #ifndef RECORDERSELECTOR_H_
00002 #define RECORDERSELECTOR_H_
00003
00004 #include "VariableRecorder.h"
00005 #include "VariableRecorderTypes.h"
00006
00007 class RecorderSelector {
00008 public:
00009
00010 RecorderSelector();
00011
00012 virtual ~RecorderSelector();
00013
00014 void registerRecorder(const string & type, VariableRecorder * const rec);
00015
00016 VariableRecorder & selectAppropriateRecorder(const type_info & type) const;
00017
00018 protected:
00019 typedef hash_map<string, VariableRecorder *, evesim::hash<string> > RecorderRegistryType;
00020 RecorderRegistryType recorder_registry;
00021 };
00022
00023
00024 inline RecorderSelector::RecorderSelector()
00025 {
00026 recorder_registry.insert(make_pair(string(typeid(int).name()), (VariableRecorder *)(new IntVariableRecorder())));
00027 recorder_registry.insert(make_pair(string(typeid(short).name()), (VariableRecorder *)(new ShortIntVariableRecorder())));
00028 recorder_registry.insert(make_pair(string(typeid(double).name()), (VariableRecorder *)(new DoubleVariableRecorder())));
00029 recorder_registry.insert(make_pair(string(typeid(float).name()), (VariableRecorder *)(new FloatVariableRecorder())));
00030 recorder_registry.insert(make_pair(string(typeid(unsigned).name()), (VariableRecorder *)(new UnsignedVariableRecorder())));
00031 recorder_registry.insert(make_pair(string(typeid(bool).name()), (VariableRecorder *)(new BoolVariableRecorder())));
00032 }
00033
00034
00035 inline void RecorderSelector::registerRecorder(const string & type, VariableRecorder * const rec)
00036 {
00037 recorder_registry.insert(make_pair(type, rec));
00038 }
00039
00040
00041 inline VariableRecorder & RecorderSelector::selectAppropriateRecorder(const type_info & type) const
00042 {
00043 RecorderRegistryType::const_iterator it = recorder_registry.find(string(type.name()));
00044 if (it == recorder_registry.end()) {
00045 throw ( evesim::ConstructionException("RecorderSelector::getAppropriateRecorder",
00046 boost::str( boost::format("Can not find an appropriate recorder for a variable of type %s") % type.name()) ) );
00047 }
00048 return *it->second;
00049 }
00050
00051 extern RecorderSelector recorderSelector;
00052
00053 #endif