A smart pointer handle to a reference-counting body. More...
#include <rw/pointer/RWTCountedPointer.h>
Public Types | |
typedef Body | BodyType |
Public Types inherited from RWTPointer< Body > | |
typedef Body | BodyType |
Public Member Functions | |
RWTCountedPointer (RWStaticCtor) | |
RWTCountedPointer (Body *bodyP=rwnil) | |
RWTCountedPointer (const RWTCountedPointer< Body > &second) | |
~RWTCountedPointer (void) | |
Body & | operator* (void) const |
Body * | operator-> (void) const |
RWTCountedPointer< Body > & | operator= (const RWTCountedPointer< Body > &second) |
RWTCountedPointer< Body > & | operator= (Body *ptr) |
void | orphan (void) |
Public Member Functions inherited from RWTPointer< Body > | |
~RWTPointer (void) | |
bool | isValid (void) const |
bool | operator!= (const RWTPointer< Body > &second) const |
bool | operator!= (const Body *ptr) const |
bool | operator== (const RWTPointer< Body > &second) const |
bool | operator== (const Body *ptr) const |
void | swapWith (RWTPointer< Body > &second) |
void | validate (void) const |
Protected Member Functions | |
void | transfer (Body *bodyP=rwnil) |
Protected Member Functions inherited from RWTPointer< Body > | |
RWTPointer (void) | |
RWTPointer (RWStaticCtor) | |
RWTPointer (Body *bodyP) | |
RWTPointer (const RWTPointer< Body > &second) | |
Body * | get (void) const |
RWTPointer< Body > & | operator= (Body *ptr) |
RWTCountedPointer is a smart pointer class 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 tracking when it is safe to delete a body instance.
Any class used for the template parameter Body
must derive from class RWTCountingBody or provide the following interface:
typedef Body RWTCountedPointer< Body >::BodyType |
The type of the Body
.
RWTCountedPointer< Body >::RWTCountedPointer | ( | RWStaticCtor | ) |
Special constructor that performs no initialization. Throws no exceptions.
RWTCountedPointer< Body >::RWTCountedPointer | ( | Body * | bodyP = rwnil | ) |
Attaches to and increments the reference count on a body.
RWTCountedPointer< Body >::RWTCountedPointer | ( | const RWTCountedPointer< Body > & | second | ) |
Attaches to and increments the reference count on the body of second.
RWTCountedPointer< Body >::~RWTCountedPointer | ( | void | ) |
Decrements the body's reference count, and deletes it if there are no other references.
Body& RWTCountedPointer< Body >::operator* | ( | void | ) | const |
Dereferences the handle to get a reference to the body. Throws an RWTHRInvalidPointer exception.
Body* RWTCountedPointer< Body >::operator-> | ( | void | ) | const |
Dereferences the handle. Always use this operator to dereference the handle, since it validates the pointer. Throws an RWTHRInvalidPointer exception if invalid.
RWTCountedPointer<Body>& RWTCountedPointer< Body >::operator= | ( | const RWTCountedPointer< Body > & | second | ) |
Detaches from the current body (if any), decrements its reference count, and deletes it if there are no other references. It then attaches to the body of second, and increments its reference count.
RWTCountedPointer<Body>& RWTCountedPointer< Body >::operator= | ( | Body * | ptr | ) |
Detaches from the current body (if any), decrements its reference count, and deletes it if there are no other references. It then attaches to pointer body ptr, and increments its reference count.
|
inline |
Detaches from the current body (if any), decrements its reference count, and deletes it if there are no other references.
|
inlineprotected |
Detaches from the current body (if any), decrements its reference count, and deletes it if there are no other references. Then it attaches to the new body, incrementing its reference count.
Copyright © 2021 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |