31 static const int k_REFCOUNT_DEBUG = 0x20000000;
33 static const int k_REFCOUNT_STATIC = 0x40000000;
34 static const int k_REFCOUNT_DESTRUCT = 0x80000000;
35 static const int k_REFCOUNT_MASK = 0xE0000000;
38 mutable cInterlockedInt m_nRefCount;
41 void _InternalAddRef() noexcept
46 const int iRefCount = get_RefCount();
49 ASSERT(iRefCount != 123123);
51 ASSERT(iRefCount < (~k_REFCOUNT_MASK));
55 void _InternalRelease()
60 const int iRefCount2 = get_RefCount();
63 ASSERT(iRefCount2 != 123123);
66 const int iRefCount = m_nRefCount.Dec();
80 : m_nRefCount(iRefCount)
86 ASSERT(get_RefCount() == 0);
91 return m_nRefCount.get_Value() & ~k_REFCOUNT_MASK;
101 return get_HashCode();
121 #if defined(_DEBUG) && ! defined(__GNUC__)
133 return (ULONG)get_RefCount();
138 int iRefCount = get_RefCount();
140 return (ULONG)(iRefCount - 1);
142 STDMETHOD(QueryInterface)(
const IID& riid,
void __RPC_FAR* __RPC_FAR* ppvObject)
override
151 *ppvObject =
nullptr;
152 return E_NOINTERFACE;
178 return(m_nRefCount.get_Value() & k_REFCOUNT_STATIC) ? true :
false;
183 ASSERT(m_nRefCount.get_Value() == 0);
184 m_nRefCount.AddX(k_REFCOUNT_STATIC);
190 ASSERT(isStaticConstruct());
191 m_nRefCount.put_Value(0);
196 return(m_nRefCount.get_Value() & k_REFCOUNT_DESTRUCT) ? true :
false;
203 ASSERT(get_RefCount() == 0);
204 m_nRefCount.put_Value(k_REFCOUNT_DESTRUCT);
208 bool isSmartDebug()
const
210 return(m_nRefCount.get_Value() & k_REFCOUNT_DEBUG) ? true :
false;
217 m_nRefCount.AddX(k_REFCOUNT_DEBUG);
222 template<
class TYPE = cRefBase >
240 if (this->
m_p !=
nullptr)
294 return this->
m_p !=
nullptr;
300 if (this->
m_p ==
nullptr)
336 if (this->
m_p ==
nullptr)
359 this->
m_p = ref.m_p; ref.m_p =
nullptr;
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define IS_TYPE_OF(t, p)
Definition: PtrCast.h:23
#define DYNPTR_CAST(t, p)
Definition: PtrCast.h:22
#define TYPE
Definition: StrT.cpp:38
#define UNREFERENCED_PARAMETER(P)
< _WIN32 type thing. get rid of stupid warning.
Definition: SysTypes.h:299
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define DEBUG_CHECK(exp)
Definition: cDebugAssert.h:90
Definition: cPtrFacade.h:19
cRefBase * m_p
Pointer to some object of TYPE.
Definition: cPtrFacade.h:28
void AttachPtr(cRefBase *p) noexcept
Definition: cPtrFacade.h:71
cRefBase * get_Ptr() const noexcept
Definition: cPtrFacade.h:53
void SetDestructing()
Definition: cRefPtr.h:198
virtual ~cRefBase()
Definition: cRefPtr.h:83
void StaticConstruct()
Definition: cRefPtr.h:180
bool isStaticConstruct() const noexcept
Definition: cRefPtr.h:175
void IncRefCount()
Definition: cRefPtr.h:165
int get_RefCount() const noexcept
Definition: cRefPtr.h:89
void DecRefCount()
Definition: cRefPtr.h:169
STDMETHOD_(ULONG, Release)(void) override
Definition: cRefPtr.h:135
STDMETHOD_(HASHCODE_t, get_HashCodeX)() const noexcept
Definition: cRefPtr.h:98
virtual void onFinalRelease()
Definition: cRefPtr.h:105
cRefBase(int iRefCount=0) noexcept
Definition: cRefPtr.h:79
bool isValidObj() const noexcept
Definition: cRefPtr.h:115
void StaticDestruct()
Definition: cRefPtr.h:186
bool isDestructing() noexcept
Definition: cRefPtr.h:194
HASHCODE_t get_HashCode() const noexcept
Definition: cRefPtr.h:93
STDMETHOD_(ULONG, AddRef)(void) override
Definition: cRefPtr.h:129
Definition: cRefPtr.h:225
THIS_t & operator=(const TYPE *p2)
Definition: cRefPtr.h:342
bool isValidPtr() const
Definition: cRefPtr.h:288
void IncRefFirst()
Definition: cRefPtr.h:237
void ReleasePtr()
Definition: cRefPtr.h:320
cRefPtr(const TYPE *p2, TIMESYSD_t dwWaitMS)
Definition: cRefPtr.h:275
cRefPtr() noexcept
Definition: cRefPtr.h:251
bool isCorruptPtr() const
Definition: cRefPtr.h:296
~cRefPtr()
Definition: cRefPtr.h:283
int get_RefCount() const
Definition: cRefPtr.h:333
cRefPtr(const THIS_t &ref)
Definition: cRefPtr.h:260
void put_Ptr(TYPE *p)
Definition: cRefPtr.h:310
cRefPtr(const TYPE *p2)
Definition: cRefPtr.h:254
Definition: IUnknown.h:68
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
INT32 TIMESYSD_t
Time delta. signed milli-Seconds Span. cTimeSys::k_DMAX, cTimeSys::k_INF = MAILSLOT_WAIT_FOREVER.
Definition: cTimeSys.h:28
__DECL_IMPORT cRefPtr cRefBasePtr
Definition: cRefPtr.h:376
UINT_PTR HASHCODE_t
could hold a pointer converted to a number? maybe 64 or 32 bit ? same as size_t.
Definition: GrayCore.h:116
static bool __stdcall IsValid(const void *pData, size_t nSize=1, bool bWriteAccess=false) noexcept
Definition: cMem.cpp:33
static COMPARE_t Compare(const void *p1, const void *p2, size_t nSizeBlock) noexcept
Definition: cMem.h:78
Definition: IUnknown.h:34