00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "TmTimerManager.h"
00021
00022 using namespace std;
00023 using namespace Marsyas;
00024
00039 #define TimerCreateWrapper(_NAME) \
00040 struct Make##_NAME : public MakeTimer { \
00041 Make##_NAME() {}; ~Make##_NAME() {}; \
00042 TmTimer* make(std::string ident) { return new _NAME (ident); }; \
00043 }
00044 #define registerTimer(_NAME) registry_[#_NAME] = new Make##_NAME();
00045
00046 # include "TmRealTime.h"
00047 # include "TmVirtualTime.h"
00048
00049 TimerCreateWrapper(TmRealTime);
00050 TimerCreateWrapper(TmVirtualTime);
00051
00052 TmTimerManager* TmTimerManager::instance_ = NULL;
00053
00054 TmTimerManager::TmTimerManager()
00055 {
00056 addTimers();
00057 }
00058
00059 TmTimerManager::~TmTimerManager()
00060 {
00061 delete instance_;
00062 instance_=NULL;
00063 }
00064
00065 void TmTimerManager::addTimers()
00066 {
00067
00068 registerTimer(TmRealTime);
00069 registerTimer(TmVirtualTime);
00070 }
00071
00072 TmTimerManager*
00073 TmTimerManager::getInstance()
00074 {
00075 if (instance_==NULL) {
00076 instance_=new TmTimerManager();
00077 }
00078 return instance_;
00079 }
00080
00081 TmTimer*
00082 TmTimerManager::make(std::string class_name, std::string identifier)
00083 {
00084 MakeTimer* m = registry_[class_name];
00085 if (m==NULL) {
00086 MRSWARN("TmTimerManager::make(string,string) name '"+class_name+"' does not name a timer");
00087 return NULL;
00088 }
00089 return m->make(identifier);
00090 }
00091
00092 TmTimer*
00093 TmTimerManager::make(std::string class_name, std::string identifier, std::vector<TmParam> params)
00094 {
00095 TmTimer* tmr = make(class_name,identifier);
00096 if(tmr!=NULL) {
00097 tmr->updtimer(params);
00098 }
00099 return tmr;
00100 }
00101