00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TJSTATIC_H
00019 #define TJSTATIC_H
00020
00021
00022 #include <tjutils/tjutils.h>
00023 #include <tjutils/tjthread.h>
00024
00031
00032
00033 class Static {
00034
00035 public:
00036
00037 Static() {}
00038 virtual ~Static() {}
00039
00040
00041 static void destroy_all();
00042
00043 static void append_to_destructor_list(Static* sp);
00044
00045 protected:
00046
00047 static STD_list<Static*>* destructor_list;
00048 };
00049
00051
00052
00053 template<class T>
00054 struct StaticAlloc : public virtual Static {
00055
00056 StaticAlloc() {
00057 }
00058
00059 ~StaticAlloc() {
00060 T::destroy_static();
00061 }
00062 };
00063
00064
00066
00094 template<class T>
00095 class StaticHandler {
00096
00097 public:
00098 StaticHandler() {
00099 if(!staticdone) {
00100 staticdone=true;
00101 Static* sp=new StaticAlloc<T>;
00102 Static::append_to_destructor_list(sp);
00103 T::init_static();
00104 }
00105 }
00106
00107
00108 private:
00109 static bool staticdone;
00110
00111 };
00112
00115 #endif