00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef REFERENCECOUNT_H
00020 #define REFERENCECOUNT_H
00021
00022 #include <pandabase.h>
00023
00024 #include "typedObject.h"
00025 #include "memoryUsage.h"
00026 #include "config_express.h"
00027 #include "atomicAdjust.h"
00028
00029 #include <stdlib.h>
00030
00031 #ifdef HAVE_RTTI
00032 #include <typeinfo>
00033 #endif
00034
00035
00036
00037
00038
00039
00040
00041
00042 class EXPCL_PANDAEXPRESS ReferenceCount {
00043 protected:
00044 INLINE ReferenceCount();
00045 INLINE ReferenceCount(const ReferenceCount &);
00046 INLINE void operator = (const ReferenceCount &);
00047 INLINE ~ReferenceCount();
00048
00049 PUBLISHED:
00050 INLINE int get_ref_count() const;
00051 INLINE int ref() const;
00052 INLINE int unref() const;
00053
00054 INLINE void test_ref_count_integrity() const;
00055
00056 public:
00057 static TypeHandle get_class_type() {
00058 return _type_handle;
00059 }
00060 static void init_type() {
00061 register_type(_type_handle, "ReferenceCount");
00062 }
00063
00064 private:
00065 int _ref_count;
00066 static TypeHandle _type_handle;
00067 };
00068
00069 template<class RefCountType>
00070 INLINE void unref_delete(RefCountType *ptr);
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 template<class Base>
00088 class RefCountProxy : public ReferenceCount {
00089 public:
00090 INLINE RefCountProxy();
00091 INLINE RefCountProxy(const Base ©);
00092
00093 INLINE operator Base &();
00094 INLINE operator const Base &() const;
00095
00096 static TypeHandle get_class_type() {
00097 return _type_handle;
00098 }
00099 static void init_type();
00100
00101 private:
00102 Base _base;
00103 static TypeHandle _type_handle;
00104 };
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 template<class Base>
00116 class RefCountObj : public ReferenceCount, public Base {
00117 public:
00118 INLINE RefCountObj();
00119 INLINE RefCountObj(const Base ©);
00120
00121 static TypeHandle get_class_type() {
00122 return _type_handle;
00123 }
00124 static void init_type();
00125
00126 private:
00127 static TypeHandle _type_handle;
00128 };
00129
00130
00131
00132 #include "referenceCount.I"
00133
00134 #endif