1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include "tjhandler.h"
#include "tjlog.h"
#include "tjlog_code.h"
const char* HandlerComponent::get_compName() {return "Handler";}
LOGGROUNDWORK(HandlerComponent)
////////////////////////////////////////////////////////////////////////
void SingletonBase::set_singleton_map_external(SingletonMap* extmap) {
// Log uses SingletonHandler -> do not use Log in here
singleton_map_external=extmap;
// in order to cache ptr properly, no singletons should be allocated at this point
if(singleton_map && singleton_map->size()) {
STD_cerr << "ERROR: SingletonBase::set_singleton_map_external: There are already singletons allocated:" << STD_endl;
for(SingletonMap::iterator it=singleton_map->begin(); it!=singleton_map->end(); ++it) {
STD_cerr << it->first << "/" << (void*)it->second << STD_endl;
}
}
}
SingletonBase::SingletonBase() {
if(!singleton_map) singleton_map=new SingletonMap;
}
SingletonMap* SingletonBase::get_singleton_map() {
// NOTE: Debug uses SingletonHandler -> do not use Debug in here
if(!singleton_map) singleton_map=new SingletonMap;
return singleton_map;
}
STD_string SingletonBase::get_singleton_label(SingletonBase* sing_ptr) {
Log<HandlerComponent> odinlog("SingletonBase","get_singleton_label");
STD_string result;
if(!(singleton_map || singleton_map_external)) {
ODINLOG(odinlog,normalDebug) << "neither singleton_map nor singleton_map_external available" << STD_endl;
return result;
}
SingletonMap::iterator mapbegin=singleton_map->begin();
SingletonMap::iterator mapend =singleton_map->end();
if(singleton_map_external) {
mapbegin=singleton_map_external->begin();
mapend =singleton_map_external->end();
}
for(SingletonMap::iterator it=mapbegin; it!=mapend; ++it) {
if(it->second==sing_ptr) result=it->first;
}
ODINLOG(odinlog,normalDebug) << "result(" << (void*)sing_ptr << ")=" << result << STD_endl;
return result;
}
void* SingletonBase::get_external_map_ptr(const STD_string& sing_label) {
// NOTE: Log uses SingletonHandler -> do not use Log in here
if(singleton_map_external) {
if(singleton_map_external->find(sing_label)==singleton_map_external->end()) {
STD_cerr << "ERROR: SingletonBase::get_external_map_ptr: singleton >" << sing_label << "< not found in singleton_map_external" << STD_endl;
return 0;
}
return (*singleton_map_external)[sing_label]->get_ptr();
}
return 0;
}
SingletonMap* SingletonBase::singleton_map=0;
SingletonMap* SingletonBase::singleton_map_external=0;
////////////////////////////////////////////////////////////////////////
|