00001 #ifndef _EDG_WORKLOAD_LOGGING_COUNTREF_H_
00002 #define _EDG_WORKLOAD_LOGGING_COUNTREF_H_
00003
00004 #define EWL_BEGIN_NAMESPACE namespace edg { namespace workload { namespace logging { namespace client {
00005 #define EWL_END_NAMESPACE } } } }
00006
00007 EWL_BEGIN_NAMESPACE;
00008
00009 template<typename T>
00010 class CountRef {
00011 public:
00012 CountRef(void *);
00013
00014
00015 void use(void);
00016 void release(void);
00017
00018 void *ptr;
00019 private:
00020 int count;
00021
00022 };
00023
00024 template <typename T>
00025 CountRef<T>::CountRef(void *p)
00026 {
00027 ptr = p;
00028 count = 1;
00029 }
00030
00031 template <typename T>
00032 void CountRef<T>::release(void)
00033 {
00034 if (--count == 0) {
00035 T::destroyFlesh(ptr);
00036 delete this;
00037 }
00038 }
00039
00040 template <typename T>
00041 void CountRef<T>::use(void)
00042 {
00043 count++;
00044 }
00045
00046 EWL_END_NAMESPACE;
00047
00048 #endif