SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Defines a reference-counted pointer that provides reference counting semantics for types that do not directly support reference counting. More...
#include <rw/pointer/RWTCountingPointer.h>
Public Types | |
typedef Body | BodyType |
Public Member Functions | |
RWTCountingPointer (RWStaticCtor) | |
RWTCountingPointer (Body *bodyP=rwnil) | |
RWTCountingPointer (const RWTCountingPointer< Body, Counter > &second) | |
~RWTCountingPointer (void) | |
RWTCountingPointer< Body, Counter > & | operator= (const RWTCountingPointer< Body, Counter > &second) |
RWTCountingPointer< Body, Counter > & | operator= (Body *bodyP) |
Body * | operator-> (void) const |
Body & | operator* (void) const |
Defines a reference-counted pointer that provides reference counting semantics for types that do not directly support reference counting. Body
, the first template parameter, can be any type. For the second template parameter, Counter
, you will generally use RWAtomicCounter.
A user-defined counter class must provide the following interface:
class Counter { public: // Constructs a counter instance with an initial count of x. Counter(int x); // Increments the reference count by one. void addReference(); // Decrements the reference count by one. // Must return 0 after the last reference count is removed, // indicating that it is safe to deallocate the body instance. int removeReference(); };
#include <rw/pointer/RWTCountingPointer.h> int main() { RWTCountingPointer<int> pointer = new int(10); return 0; }
typedef Body RWTCountingPointer< Body, Counter >::BodyType |
The type of the body.
Reimplemented from RWTPointer< Body >.
RWTCountingPointer< Body, Counter >::RWTCountingPointer | ( | RWStaticCtor | ) |
Special constructor that performs no initialization.
RWTCountingPointer< Body, Counter >::RWTCountingPointer | ( | Body * | bodyP = rwnil |
) |
Constructs a pointer instance that manages references for the specified Body
instance. Parameter bodyP is the Body
instance to be managed by this pointer.
RWTCountingPointer< Body, Counter >::RWTCountingPointer | ( | const RWTCountingPointer< Body, Counter > & | second | ) |
Constructs a pointer instance that can access the body instance associated with another pointer instance, incrementing the underlying reference count for that instance by one.
RWTCountingPointer< Body, Counter >::~RWTCountingPointer | ( | void | ) |
Decrements the reference counter and deletes the body instance, if there are no other references.
Body& RWTCountingPointer< Body, Counter >::operator* | ( | void | ) | const |
Dereferences the handle to get a reference to the body. Throws exception RWTHRInvalidPointer if pointer is invalid.
Body* RWTCountingPointer< Body, Counter >::operator-> | ( | void | ) | const |
Dereferencing operator. This operator should always be used to dereference the handle as it will validate the pointer, throwing an exception if it is not valid. Returns a pointer to the body instance attached to this handle. Throws exception RWTHRInvalidPointer if no body instance has been attached to this handle instance.
RWTCountingPointer<Body,Counter>& RWTCountingPointer< Body, Counter >::operator= | ( | Body * | bodyP | ) |
Detaches from the current body (if any), decrements its associated reference count, and deletes it if there are no other associated references. It then attaches to the pointer bodyP, and increments its associated reference count. The new attached pointer must point to the dynamically allocated object. Throws no exceptions.
Reimplemented from RWTPointer< Body >.
RWTCountingPointer<Body,Counter>& RWTCountingPointer< Body, Counter >::operator= | ( | const RWTCountingPointer< Body, Counter > & | second | ) |
Detaches from the current body (if any), decrements its associated reference count, and deletes it if there are no other associated references. It then attaches to second 's body, and increments its associated reference count.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.