Smart pointer class used for handling reference counted objects (that derive from Object). More...
Public Types | |
typedef T *PtrRef::* | unspecified_bool_type |
Helper type to implement the safe-bool idiom. More... | |
Public Member Functions | |
PtrRef (T *object=NULL) | |
Constructs an object from naked pointer. More... | |
PtrRef (const PtrRef &other) | |
Construct and object as a copy of other. More... | |
template<typename T2 > | |
PtrRef (const PtrRef< T2 > &other) | |
Constructs from related. More... | |
PtrRef & | operator= (T *rhs) |
Assigns from raw pointer. More... | |
PtrRef & | operator= (PtrRef rhs) |
Assigns from rhs. More... | |
template<typename T2 > | |
PtrRef & | operator= (const PtrRef< T2 > &rhs) |
Assigns from related. More... | |
T * | operator-> () |
Returns the naked pointer this object is associated with. More... | |
const T * | operator-> () const |
Returns naked const pointer this object is associated with. More... | |
T & | operator* () |
Dereference operator returning a modifiable reference to the associated object. More... | |
const T & | operator* () const |
Dereference operator returning a const reference to the associated object. More... | |
bool | operator< (const PtrRef &rhs) const |
Does less than comparison of two PtrRef objects. More... | |
const T * | get () const |
Returns naked const pointer. More... | |
T * | get () |
Returns the naked pointer. More... | |
void | swap (PtrRef &other) |
Exchanges the contents of the two smart pointers. More... | |
T * | detach () |
Detach the PtrRef from the internal object WITHOUT calling release on the object. More... | |
operator unspecified_bool_type () const | |
Operator for supporting tests if the objects internal pointer is NULL or not. More... | |
template<typename T2 > | |
PtrRef< T > & | operator= (const PtrRef< T2 > &rhs) |
Smart pointer class used for handling reference counted objects (that derive from Object).
The PtrRef<T> class encapsulates reference counting by calling Object::addRef() and Object::release() on the internally stored object pointer.
typedef T* PtrRef::* cee::PtrRef< T >::unspecified_bool_type |
Helper type to implement the safe-bool idiom.
cee::PtrRef< T >::PtrRef | ( | T * | object = NULL | ) |
Constructs an object from naked pointer.
Will call addRef() on the passed object.
cee::PtrRef< T >::PtrRef | ( | const PtrRef< T > & | other | ) |
Construct and object as a copy of other.
Copies the internal pointer from the passed PtrRef object and calls addRef() on the object.
Constructs from related.
Copies the internal pointer from the passed PtrRef object and calls addRef() on the object.
T * cee::PtrRef< T >::detach | ( | ) |
Detach the PtrRef from the internal object WITHOUT calling release on the object.
After calling, *this == NULL and associated object will have the same refCount as before the call.
|
inline |
Returns naked const pointer.
|
inline |
Returns the naked pointer.
cee::PtrRef< T >::operator unspecified_bool_type | ( | ) | const |
Operator for supporting tests if the objects internal pointer is NULL or not.
Using the safe bool idiom, PtrRef allows for code like
without defining the operator bool(), which have many potential side effects.
|
inline |
Dereference operator returning a modifiable reference to the associated object.
Added to be able to write the same code for smart pointers as for normal naked pointers.
|
inline |
Dereference operator returning a const reference to the associated object.
|
inline |
Returns the naked pointer this object is associated with.
Added to be able to write the same code for smart pointers as for normal naked pointers.
|
inline |
Returns naked const pointer this object is associated with.
bool cee::PtrRef< T >::operator< | ( | const PtrRef< T > & | rhs | ) | const |
Does less than comparison of two PtrRef objects.
Returns true if this object's internal pointer is less than the internal pointer of rhs.
The comparison is done by comparing the internal pointer values ( this.p() < rhs.p() ) This operator is used in several STL collections (e.g. std::set) as well as in many STL algorithms (e.g. std::sort() ).
PtrRef< T > & cee::PtrRef< T >::operator= | ( | T * | rhs | ) |
Assigns from raw pointer.
PtrRef< T > & cee::PtrRef< T >::operator= | ( | PtrRef< T > | rhs | ) |
Assigns from rhs.
Copies the internal pointer from rhs and calls addRef(). If we're already storing an internal pointer, this pointer will be release()'ed.
Assigns from related.
Copies the internal pointer from rhs and calls addRef(). If we're already storing an internal pointer, this pointer will be release()'ed.
void cee::PtrRef< T >::swap | ( | PtrRef< T > & | other | ) |
Exchanges the contents of the two smart pointers.
other is a modifiable reference to the PtrRef object that should have its contents swapped.
Swap the associated pointer in this and the passed PtrRef object. Will not modify the reference count of any of the associated objects.