SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Simplifies the use of pointers that refer to objects on the heap, automatically destroying the object when the pointer object is itself destroyed. More...
#include <rw/pointer/RWTOnlyPointer.h>
Public Types | |
typedef Body | BodyType |
Public Member Functions | |
RWTOnlyPointer (RWStaticCtor) | |
RWTOnlyPointer (Body *bodyP=rwnil) | |
RWTOnlyPointer (const RWTOnlyPointer< Body > &second) | |
~RWTOnlyPointer (void) | |
RWTOnlyPointer< Body > & | operator= (const RWTOnlyPointer< Body > &second) |
RWTOnlyPointer< Body > & | operator= (Body *ptr) |
Body * | operator-> (void) const |
Body & | operator* (void) const |
operator Body * (void) | |
Protected Member Functions | |
Body * | orphan (void) |
void | transfer (Body *bodyP=rwnil) |
RWTOnlyPointer<Body> is an abstraction that simplifies the use of pointers referring to objects (that is, bodies) on the heap. It doesn't do reference counting on the body; rather, it is based on the idea of strict ownership semantics. Strict ownership means that if the assignment operator or the copy constructor is called, then the right-hand instance is invalidated (its body pointer is set to rwnil), and the left-hand instance assumes responsibility for deleting the body.
This class is useful for ensuring the recovery of dynamically allocated memory, especially in the presence of exceptions. This class provides functionality equivalent to that provided by the C++ Standard Library class std::auto_ptr.
#include <rw/pointer/RWTOnlyPointer.h> class A { }; class B { public: // The instance of A allocated here is automatically // deleted if an exception occurs in the initialize() // function. B() { p_ = new A; initialize(); } private: RWTOnlyPointer<A> p_; void initialize(void); };
typedef Body RWTOnlyPointer< Body >::BodyType |
The type of the body.
Reimplemented from RWTPointer< Body >.
RWTOnlyPointer< Body >::RWTOnlyPointer | ( | RWStaticCtor | ) | [inline] |
Special constructor that performs no initialization. Throws no exceptions.
RWTOnlyPointer< Body >::RWTOnlyPointer | ( | Body * | bodyP = rwnil |
) | [inline] |
Assumes responsibility for a new body. This pointer manages an instance parameter bodyP. Throws no exceptions.
RWTOnlyPointer< Body >::RWTOnlyPointer | ( | const RWTOnlyPointer< Body > & | second | ) | [inline] |
Assumes responsibility for another handle's body.
RWTOnlyPointer< Body >::~RWTOnlyPointer | ( | void | ) | [inline] |
Deletes the current body.
RWTOnlyPointer< Body >::operator Body * | ( | void | ) | [inline] |
Body pointer conversion operator for the handle (required for handle conversions). Gives up responsibility for deleting the body.
Body & RWTOnlyPointer< Body >::operator* | ( | void | ) | const [inline] |
Pointer dereference operator. Dereferences the handle to get a reference to the body. Throws the exception RWTHRInvalidPointer if the pointer is not valid.
Body * RWTOnlyPointer< Body >::operator-> | ( | void | ) | const [inline] |
Pointer dereference operator. This operator should always be used to dereference the handle as it first validates the pointer. If the pointer is not valid, throws an RWTHRInvalidPointer exception.
RWTOnlyPointer< Body > & RWTOnlyPointer< Body >::operator= | ( | Body * | ptr | ) | [inline] |
Assigns a new pointer value to the handle (required for handle conversions). Throws no exceptions.
Reimplemented from RWTPointer< Body >.
RWTOnlyPointer< Body > & RWTOnlyPointer< Body >::operator= | ( | const RWTOnlyPointer< Body > & | second | ) | [inline] |
Assumes responsibility for another handle's body.
Body * RWTOnlyPointer< Body >::orphan | ( | void | ) | [inline, protected] |
Relinquishes control over the current body (if any).
void RWTOnlyPointer< Body >::transfer | ( | Body * | bodyP = rwnil |
) | [inline, protected] |
Deletes the current body (if any), and assumes control of another body (if any).
© 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.