PIPS-NLP
|
#include <SmartPointer.h>
Public Member Functions | |
SmartPointer () | |
~SmartPointer () | |
operator T * () | |
T * | ptr () const |
SmartPointer (T *t) | |
SmartPointer (const SmartPointer< T > &sp) | |
T & | operator* () |
const T & | operator* () const |
SmartPointer< T > & | operator= (const SmartPointer< T > &sp) |
T * | operator-> () |
const T * | operator-> () const |
Static Public Member Functions | |
static void | bind (SmartPointer< T > &sp, T **obj) |
static void | referTo (SmartPointer< T > &sp, T *obj) |
Protected Attributes | |
T * | obj |
A class whose instances act like pointers that manage their reference count automatically.
Use smart pointers when you wish to keep a reference to a instance of a subclass of IotrRefCount. Do not use a smart pointer to refer to an object passed in as a parameter to a routine, unless you intend to keep the reference after the routine has exited.
Instances of this class are created by value. In other words definitions such as
SmartPointer<T> t;
are encouraged, whereas pointers to objects of type SmartPointer<T> should not be used.
Method calls through a smart pointer look like calls to a regular pointer. In other words
is the preferred way to call T::myMethod through a smart pointer.
SmartPointers can be assigned a pointer to an object through the function SpReferTo(). It is never necessary to release a a SmartPointer, this will be done automatically whenever the SmartPointer goes out of scope. It is not possible, or necessary, to call IotrRelease() or IotrAddRef() on a SmartPointer.
Assignments between SmartPointers should work with the same semantics as assigment of traditional pointers.
or
or
So long as implicit conversion
is disallowed. SmartPointers should generally not be in the definition of parameters to routines or as return values. Use traditional pointers for these. Automatic conversion allows SmartPointers to be a "drop-in" replacement to traditional pointers when calling routines.
When returning pointers from a function, be sure to use SpAsPointer() to obtain the traditional pointer to the object.
|
inline |
Default constructor; creates a SmartPointer referring to nothing.
|
inline |
Copy constructor; creates a new smart pointer referring to the same object. Increments the reference count of the object.
sp | an existing reference to an object. This reference may be nil. |
|
inline |
Destructor; release the object (through a call to IotrRelease()) if the object is not nil.
|
inline |
Allow EXPLICIT conversion from a (T*) to a SmartPointer to T. Implicit conversion is not allowed, because this could have subtle, unintended consequences.
|
inlinestatic |
Converts a traditional pointer to a smart pointer, destroying the original pointer.
|
inline |
Automatically convert this object to a traditional pointer to an object that may be passed in as a paramter to function or method calls. For most other purposes SmartPointer::ptr() is more appropriate
|
inline |
Dereferencing operation. Return a reference to the object.
|
inline |
|
inline |
Send a message to, or access a data memeber of, the object to which this is a reference.
|
inline |
|
inline |
Assignment operator; cause this SmartPointer to refer to the same object that sp refers to.
sp | an existing reference to an object. This reference may be nil. |
|
inline |
Call SpAsPointer() instead; return a traditional pointer to the underlying object.
|
inlinestatic |
Call SpReferTo() instead of this method; make a SmartPointer refer to the same object as a traditional pointer.
|
protected |
a traditional pointer to the object being referenced.