13#ifndef __smartpointer__
14#define __smartpointer__
34 unsigned refs()
const {
return refCount; }
42 smartable(
const smartable&): refCount(0) {}
67 SMARTP(T* rawptr) : fSmartPtr(rawptr) {
if (fSmartPtr) fSmartPtr->addReference(); }
70 SMARTP(
const SMARTP<T2>& ptr) : fSmartPtr((T*)ptr) {
if (fSmartPtr) fSmartPtr->addReference(); }
72 SMARTP(
const SMARTP& ptr) : fSmartPtr((T*)ptr) {
if (fSmartPtr) fSmartPtr->addReference(); }
75 ~SMARTP() {
if (fSmartPtr) fSmartPtr->removeReference(); }
78 operator T*()
const {
return fSmartPtr; }
83 assert (fSmartPtr != 0);
90 assert (fSmartPtr != 0);
101 if (fSmartPtr != p_) {
103 if (p_ != 0) p_->addReference();
105 if (fSmartPtr != 0) fSmartPtr->removeReference();
SMARTP(const SMARTP &ptr)
build a smart pointer from another smart pointer reference
Definition smartpointer.h:72
T & operator*() const
'*' operator to access the actual class pointer
Definition smartpointer.h:81
SMARTP & operator=(const SMARTP< T > &p_)
operator = to support inherited class reference
Definition smartpointer.h:112
SMARTP & operator=(T2 p1_)
operator = that moves the actual class pointer
Definition smartpointer.h:96
bool operator<(const SMARTP< T > &p_) const
operator < (require by VC6 for maps)
Definition smartpointer.h:118
SMARTP(T *rawptr)
build a smart pointer from a class pointer
Definition smartpointer.h:67
SMARTP(const SMARTP< T2 > &ptr)
build a smart pointer from an convertible class reference
Definition smartpointer.h:70
T * operator->() const
operator -> overloading to access the actual class pointer
Definition smartpointer.h:88
SMARTP & cast(const SMARTP< T2 > &p_)
dynamic cast support
Definition smartpointer.h:116
SMARTP & operator=(T *p_)
operator = that moves the actual class pointer
Definition smartpointer.h:99
SMARTP()
an empty constructor - points to null
Definition smartpointer.h:65
SMARTP & cast(T2 *p_)
dynamic cast support
Definition smartpointer.h:114
~SMARTP()
the smart pointer destructor: simply removes one reference count
Definition smartpointer.h:75
the base class for smart pointers implementation
Definition smartpointer.h:29
void addReference()
addReference increments the ref count and checks for refCount overflow
Definition smartpointer.h:36
virtual ~smartable()
destructor checks for non-zero refCount
Definition smartpointer.h:44
unsigned refs() const
gives the reference count of the object
Definition smartpointer.h:34
void removeReference()
removeReference delete the object when refCount is zero
Definition smartpointer.h:38