Module: Threads Package: Smart Pointer
RWTCountingPointer<Body,Counter=RWSafeCounter> RWTPointer<Body>
#include <rw/pointer/RWTCountingPointer.h>
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 one of two typedefs provided by the Smart Pointer package. RWSafeCounter, the default, is a typedef for RWTCounter<RWMutexLock> and provides thread-safe reference counting. RWUnsafeCounter is a typedef for RWTCounter<RWNullMutexLock> and can be used for greater efficiency in situations where thread-safety is not required.
RWTCountingPointer<int> pointer = new int(10);
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(RWStaticCtor);
Special constructor that performs no initialization.
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();
Decrements the reference counter and deletes the body instance, if there are no other references.
Body* operator->() 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.
Body& operator*() const;
Dereferences the handle to get a reference to the body. Throws exception RWTHRInvalidPointer. if pointer invalid.
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.
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.
RWTCounter, RWSafeCounter, RWUnsafeCounter
© 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.