RWTOnlyPointer<Body> RWTPointer<Body>
#include <rw/pointer/RWTOnlyPointer.h>
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, specially in the presence of exceptions. This class provides functionality equivalent to that provided by the Standard C++ Library auto_ptr<> class.
#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(); } ~B() {} private: RWTOnlyPointer<A> p_; void initialize(void); };
RWTOnlyPointer(Body* bodyP=rwnil);
Assumes responsibility for a new body. This pointer manages an instance parameter bodyP. Throws no exceptions.
RWTOnlyPointer(RWStaticCtor);
Special constructor that performs no initialization. Throws no exceptions.
RWTOnlyPointer(RWTOnlyPointer<Body>& second);
Assumes responsibility for another handle's body.
~RWTOnlyPointer(void);
Deletes the current body.
typedef Body BodyType;
The type of the body.
RWTOnlyPointer<Body>& operator=(Body* ptr);
Assigns a new pointer value to the handle (required for handle conversions). Throws no exceptions.
RWTOnlyPointer<Body>& operator=(RWTOnlyPointer<Body>& second);
Assumes responsibility for another handle's body.
operator Body*(void);
Body pointer conversion operator for the handle (required for handle conversions). Gives up responsibility for deleting body.
Body& operator*(void) const;
Pointer dereference operator. Dereferences the handle to get a reference to the body. Throws the exception RWTHRInvalidPointer if it is not valid.
Body* operator->(void) const;
Pointer dereference operator. This operator should always be used to dereference the handle as it will validate the pointer. If it is not valid, it will throw an RWTHRInvalidPointer exception.
Body* orphan(void);
Relinquishes control over the current body (if any).
void transfer(Body* bodyP=rwnil);
Deletes the current body (if any), and assumes control of another body (if any).
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.