1 #include <tjutils/tjhandler.h>
2 #include <tjutils/tjlog.h>
8 Handled<I>::Handled() {}
11 Handled<I>::~Handled() {
13 for(
typename STD_list<
const Handler<I>* >::const_iterator it=handlers.begin(); it!=handlers.end(); ++it) {
14 (*it)->handled_remove(
this);
20 const Handled<I>& Handled<I>::set_handler(
const Handler<I>& handler)
const {
21 handlers.push_back(&handler);
26 const Handled<I>& Handled<I>::erase_handler(
const Handler<I>& handler)
const {
27 handlers.remove(&handler);
36 Handler<I>::Handler() {
41 Handler<I>::Handler(
const Handler& handler) {
42 Handler<I>::operator = (handler);
46 Handler<I>& Handler<I>::operator = (
const Handler& handler) {
48 I hd=handler.get_handled();
49 if(hd) set_handled(hd);
55 Handler<I>::~Handler() {
61 const Handler<I>& Handler<I>::clear_handledobj()
const {
63 ODINLOG(odinlog,normalDebug) <<
"handledobj=" << (
void*)handledobj << STD_endl;
64 if(handledobj) handledobj->Handled<I>::erase_handler(*
this);
70 const Handler<I>& Handler<I>::set_handled(I handled)
const {
72 ODINLOG(odinlog,normalDebug) <<
"handled=" << (
void*)handled << STD_endl;
74 handled->Handled<I>::set_handler(*
this);
82 I Handler<I>::get_handled()
const {
88 const Handler<I>& Handler<I>::handled_remove(Handled<I>* handled)
const {
90 I handledtype=
static_cast<I
>(handled);
91 ODINLOG(odinlog,normalDebug) <<
"handledtype=" << (
void*)handledtype << STD_endl;
92 if(handledtype) handledobj=0;
93 else ODINLOG(odinlog,errorLog) <<
"Unable to remove handled!" << STD_endl;
103 template<
class T,
bool thread_safe>
106 singleton_label=
new STD_string;
108 if(thread_safe) mutex=
new Mutex();
109 (*singleton_label)=unique_label;
110 if(!get_external_map_ptr(unique_label)) {
112 ptr->set_label(unique_label);
113 (*get_singleton_map())[unique_label]=
this;
119 template<
class T,
bool thread_safe>
121 if(ptr) {
delete ptr; ptr=0;}
122 delete singleton_label;
123 if(mutex)
delete mutex;
126 template<
class T,
bool thread_safe>
129 if(p) destination=(*p);
133 template<
class T,
bool thread_safe>
136 if(singleton_map_external) {
137 T* ext_ptr=(T*)get_external_map_ptr(*singleton_label);
138 if(ext_ptr) ptr=ext_ptr;
void init(const char *unique_label)
void copy(T &destination) const