73 _objPtr(NULL), _refCount(NULL), _bOwner(true) {
79 _objPtr(obj), _bOwner(bOwner) {
80 _refCount = (_objPtr == NULL) ? NULL :
new unsigned(1);
85 _objPtr(p._objPtr), _refCount(p._refCount), _bOwner(p._bOwner) {
86 if (_refCount != NULL) {
92 if ((_refCount != NULL) && (--*_refCount == 0)) {
108 if ((_refCount != NULL) && (--*_refCount == 0)) {
132 return (_objPtr == o);
136 return (_objPtr != o);
147 inline operator const T*()
const {
return _objPtr; }
153 template <
typename T>
drwnSmartPointer< T > & operator=(const drwnSmartPointer< T > &p)
assignment operator
Definition: drwnSmartPointer.h:103
drwnSmartPointer(T *obj, bool bOwner=true)
create a smart pointer of type T to obj
Definition: drwnSmartPointer.h:78
T * _objPtr
pointer to the shared object
Definition: drwnSmartPointer.h:66
T * operator->()
de-reference the smart pointer
Definition: drwnSmartPointer.h:140
drwnSmartPointer()
default constructor (NULL smart pointer)
Definition: drwnSmartPointer.h:72
unsigned * _refCount
number of drwnSmartPointer objects that share _objPtr
Definition: drwnSmartPointer.h:67
comparison operator for objects held in a drwnSmartPointer
Definition: drwnSmartPointer.h:154
bool operator==(const T *o)
compare smart pointers with object pointer for equality
Definition: drwnSmartPointer.h:131
bool operator==(const drwnSmartPointer< T > &p)
compare two smart pointers for equality
Definition: drwnSmartPointer.h:123
bool operator!=(const drwnSmartPointer< T > &p)
compare two smart pointers for inequality
Definition: drwnSmartPointer.h:127
bool _bOwner
true if drwnSmartPointer is responsible for destroying _objPtr
Definition: drwnSmartPointer.h:68
bool operator!=(const T *o)
compare smart pointers with object pointer for inequality
Definition: drwnSmartPointer.h:135
Implements a shared pointer interface to avoid the need to deep copy constant (shared) objects...
Definition: drwnSmartPointer.h:64
const T * operator->() const
de-reference the smart pointer
Definition: drwnSmartPointer.h:142
drwnSmartPointer(const drwnSmartPointer< T > &p)
copy constructor
Definition: drwnSmartPointer.h:84