2#ifndef __OBJ_REF_IMPL_HPP
3#define __OBJ_REF_IMPL_HPP
7#include <interface/obj-ref-i.h>
29 STDMETHOD_(
long,
AddRef)(THIS)
override
31 return InterlockedIncrement(&
m_cRef);
38 long lRet = InterlockedDecrement(&
m_cRef);
60template<
class T,
class T2>
67 delete static_cast<T2*
>(
this);
89 if (
p != NULL && bAddRef)
267#define CAutoRefPtr SAutoRefPtr
~SAutoRefPtr()
Destructor that releases the object.
SAutoRefPtr()
Default constructor that initializes the pointer to NULL.
HRESULT CopyTo(T **ppT)
Copies the pointer to another location and adds a reference.
void Release()
Releases the object and sets the pointer to NULL.
bool operator!=(T *pT) const
Overloaded not-equal operator.
T * operator=(T *lp)
Overloaded assignment operator from a raw pointer.
T * operator=(const SAutoRefPtr< T > &lp)
Overloaded assignment operator from another SAutoRefPtr.
bool operator<(T *pT) const
Overloaded less-than operator.
T * p
Pointer to the managed object.
T * Detach()
Detaches the object without releasing it.
T * operator->() const
Overloaded operator-> to access members of the object.
SAutoRefPtr(const SAutoRefPtr &src)
Copy constructor that adds a reference to the object.
bool operator!() const
Overloaded not operator to check if the pointer is NULL.
SAutoRefPtr(T *lp, BOOL bAddRef=TRUE)
Constructor that takes a pointer and optionally adds a reference.
T & operator*() const
Overloaded dereference operator.
bool operator==(T *pT) const
Overloaded equal operator.
void Attach(T *p2)
Attaches to an existing object without adding a reference.
T ** operator&()
Overloaded address-of operator.
Template class extending TObjRefImpl with a specific final release behavior.
void OnFinalRelease() override
Deletes the object as the derived type T2.
void OnFinalRelease() override
Deletes the object.
virtual ~TObjRefImpl()
Virtual destructor.
LONG m_cRef
Reference count.
long AddRef() override
Increments the reference count.
TObjRefImpl()
Constructor that initializes the reference count to 1.
long Release() override
Decrements the reference count and deletes the object if the count reaches zero.