Does not inherit
isValid() operator *() operator typename RefCountingPointer() |
operator->() operator=() PointerType |
RefCountingPointer() ReferenceType ~RefCountingPointer() |
#include rwsf/core/RefCountingPointer.h
A smart pointer class that is intended for use as a handle to a reference-counting body. Each time an instance of this class is bound to a body instance, it increments the reference count maintained by that body. Each time it detaches from a body instance, it decrements the body's reference count; and if the reference count reaches zero, it deletes the body instance. The reference counting relieves clients of the burden of having to keep track of when it is safe to delete a body instance.
The class T specified as a template parameter must provide member functions for incrementing and decrementing the reference count, are responsible for deleting the instance of T when the count reaches 0.
void addRef(); void releaseRef();
The class rwsf::RefCountingObject can be used as a base class in order to provide this functionality in user-defined types.
Note
For classes that do not implement the addRef() and releaseRef() methods above, see rwsf::CountingPointer for a non-intrusive smart-pointer solution.
rwsf::CountingPointer, rwsf::RefCountingObject
T * PointerType;
Typedef to the underlying raw pointer type.
T & ReferenceType;
Typdef to the underlying reference type.
RefCountingPointer(PointerType pointer = 0);
Attaches to and increments the reference-count on a body.
RefCountingPointer(const RefCountingPointer< T > & second);
Attaches to and increments the reference-count on second's body.
RefCountingPointer(const RefCountingPointer< O > & second);
Attaches to and increments the reference-count on second's body.
The automatic dynamic_cast associated with this method may be removed in a future release, and should not be relied upon in user code. Users can define the macro RWSF_CORE_DISABLE_DEPRECATED before including this header file in order to check their code for conversions that should use an explicit cast.
Note
This method performs a dynamic_cast on O in order to convert it to a type T. This may be an expensive operation if a dynamic_cast is not needed for the conversion. It is recommended that users use the explicit cast methods associated with this class in order to convert between different RefCountingPointer types.
~RefCountingPointer(void);
Decrements the body's reference-count and deletes it if there are no other references.
bool isValid(void) const;
Returns true if the underlying pointer is non-zero, false otherwise.
Deprecated. Use conversion to unspecified bool type instead.
ReferenceType operator *(void) const;
Verifies that the underlying is not null, dereferences, and returns the underlying body.
Exceptions
NullPointerException |
If the underlying pointer is null. |
RefCountingPointer< T > & operator=(const RefCountingPointer< T > & second);
Attaches to second's body, and increments it's reference-count. If there was already a body associated with this, it's count is decremented, and the body is deleted if there are no other references.
RefCountingPointer< T > & operator=(const RefCountingPointer< O > & second);
Attaches to second's body, and increments it's reference-count. If there was already a body associated with this, it's count is decremented, and the body is deleted if there are no other references.
The automatic dynamic_cast associated with this method may be removed in a future release, and should not be relied upon in user code. Users can define the macro RWSF_CORE_DISABLE_DEPRECATED before including this header file in order to check their code for conversions that should use an explicit cast.
Note
This method performs a dynamic_cast on O in order to convert it to a type T. This may be an expensive operation if a dynamic_cast is not needed for the conversion. It is recommended that users use the explicit cast methods associated with this class in order to convert between different RefCountingPointer types.
RefCountingPointer< T > & operator=(PointerType second);
Attaches to second's body, and increments it's reference-count. If there was already a body associated with this, it's count is decremented, and the body is deleted if there are no other references.
PointerType operator->(void) const;
Verifies that the underlying body is not null, and returns an instance of the underlying body.
Exceptions
NullPointerException |
If the underlying pointer is null. |
operator typename RefCountingPointer() const;
Returns an unspecified boolean type to allow for testing if the associated pointer is null. The boolean type is not specified in order to avoid unintended implicit conversions.
© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.