00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __EDG_WORKLOAD_LOGGING_CLIENT_COUNTREF_HPP__
00019 #define __EDG_WORKLOAD_LOGGING_CLIENT_COUNTREF_HPP__
00020
00024 #define EWL_BEGIN_NAMESPACE namespace glite { namespace lb {
00025
00029 #define EWL_END_NAMESPACE } }
00030
00031 EWL_BEGIN_NAMESPACE
00032
00042 template<typename T>
00043 class CountRef {
00044 public:
00045 CountRef(void *);
00046
00047
00048 void use(void);
00049 void release(void);
00050
00051 void *ptr;
00053 private:
00054 int count;
00055
00056 };
00057
00062 template <typename T>
00063 CountRef<T>::CountRef(void *p)
00064 {
00065 ptr = p;
00066 count = 1;
00067 }
00068
00075 template <typename T>
00076 void CountRef<T>::release(void)
00077 {
00078 if (--count == 0) {
00079 T::destroyFlesh(ptr);
00080 delete this;
00081 }
00082 }
00083
00089 template <typename T>
00090 void CountRef<T>::use(void)
00091 {
00092 count++;
00093 }
00094
00095 EWL_END_NAMESPACE
00096
00097 #endif