AutoPtr< T, Deallocator > Class Template Reference

Provides pointer management. More...

List of all members.

Public Member Functions

void Attach (T *in_ptr)
 Replaces the contained pointer with the one passed in.
 AutoPtr (const AutoPtr &in_obj)
 Copy constructor.
 AutoPtr (T *in_ptr=NULL)
 Default constructor.
void Clear ()
 Delete the contained pointer (if any) and clear it to NULL.
T * Detach ()
 Releases ownership of the pointer and sets it to NULL.
T * Get () const
 Gives access to the contained pointer.
bool IsNull () const
 Check if the contained pointer is NULL.
T & operator* () const
 Return a reference to the object pointed to by the owned pointer.
T * operator-> () const
 Return the owned pointer.
AutoPtroperator= (const AutoPtr &in_rhs)
 Assignment operator.
AutoPtroperator= (T *in_rhs)
 Assignment operator.
void Swap (T *&io_ptr)
 Swap the contents of this object with another pointer.
void Swap (AutoPtr &io_other)
 Swap the contents of this object with that of another AutoPtr.
 ~AutoPtr ()
 Destructor.

Detailed Description

template<typename T, typename Deallocator = AutoPtr_DefaultDeallocator<T>>
class Simba::Support::AutoPtr< T, Deallocator >

Provides pointer management.

Wraps the owned pointer to guarantee its automatic deletion when the object goes out of scope.

You can copy and assign between AutoPtr objects. The ownership is always passed along. If trying to assign to a AutoPtr that already wraps a pointer, that pointer will be deleted before the next one is assigned.

We will protect against using NULL contained pointers with asserts to catch programmer errors. We will depend on callers using the new operator to throw exceptions on failure to protect at runtime.

This object should not be used in a container that requires that the objects have a copy constructor and assignment operator that have a const parameter. This means that it wants to make an exact copy. This is not the case with this object as the the AutoPtr objects being used for the copy construction or assignment are changed. These AutoPtr objects lose the pointers they contain when the other object is initialized with it.

Here are some guidelines for using the AutoPtr.


Constructor & Destructor Documentation

AutoPtr ( T *  in_ptr = NULL  )  [inline, explicit]

Default constructor.

Parameters:
in_ptr Pointer of explicit T type to initialize the owned pointer.
AutoPtr ( const AutoPtr< T, Deallocator > &  in_obj  )  [inline]

Copy constructor.

The AutoPtr object used to construct this object will give up ownership of its contained pointer to the object being constructed.

This is not like a typical copy constructor since the other AutoPtr is modified.

Parameters:
in_obj Const reference to another object containing the same type of owned. object pointer. The other object will lose its owned pointer by passing ownership to this instance.
~AutoPtr (  )  [inline]

Destructor.

Automatically cleans up the owned pointer using operator delete.


Member Function Documentation

void Attach ( T *  in_ptr  )  [inline]

Replaces the contained pointer with the one passed in.

If the pointer being passed in is not the same as the contained pointer, then the contained pointer is deleted and the new pointer takes its place.

Ownership transfer of in_ptr to this AutoPtr is guaranteed, even if the destructor of the previous pointer throws an exception.

Parameters:
in_ptr Pointer to replace the contained pointer. (OWNED)
void Clear (  )  [inline]

Delete the contained pointer (if any) and clear it to NULL.

This call is equivalent to Attach(NULL).

T* Detach (  )  [inline]

Releases ownership of the pointer and sets it to NULL.

The responsibility for managing and deleting the pointer is transferred to the caller of this method. The object retains no knowledge of its former contained pointer.

Returns:
the previously contained pointer. (OWN)
T* Get (  )  const [inline]

Gives access to the contained pointer.

Warning:
This method does not pass off ownership of the contained pointer.
Returns:
the contained pointer, const-qualified. (NOT OWN)
bool IsNull (  )  const [inline]

Check if the contained pointer is NULL.

This will only check if the pointer is NULL or not. It would still be possible to fool the object by passing in a bogus pointer.

Returns:
true if NULL, otherwise false.
T& operator* (  )  const [inline]

Return a reference to the object pointed to by the owned pointer.

Warning:
De-referencing a NULL pointer will cause a segfault in Unix. Check the validity of the pointer by calling AutoPtr::IsNull() before dereferencing.
Returns:
A reference to the object pointed to by the contained pointer, const-qualified.
T* operator-> (  )  const [inline]

Return the owned pointer.

This is used so that the AutoPtr can masquerade as the pointer it contains.

Returns:
the contained pointer, const-qualified. (NOT OWN)
AutoPtr& operator= ( const AutoPtr< T, Deallocator > &  in_rhs  )  [inline]

Assignment operator.

Note that the AutoPtr on the right hand hand of the assignment will give up ownership of its contained pointer. The receiving object will delete its own contained pointer and replace it with the one being passed in.

This is not a normal assignment operator because the right-hand side is modified.

Ownership transfer of in_rhs to this AutoPtr is guaranteed, even if the destructor of the previous pointer throws an exception.

Parameters:
in_rhs A AutoPtr object to initialize this object with its contained pointer.
Returns:
a reference to the object on the left-hand side of the assignment.
AutoPtr& operator= ( T *  in_rhs  )  [inline]

Assignment operator.

The receiving object will delete its own contained pointer and replace it with the one being passed in.

Ownership transfer of in_rhs to this AutoPtr is guaranteed, even if the destructor of the previous pointer throws an exception.

Parameters:
in_rhs A pointer that this object will own. (OWNED)
Returns:
a reference to the object on the left-hand side of the assignment.
void Swap ( T *&  io_ptr  )  [inline]

Swap the contents of this object with another pointer.

Parameters:
io_ptr The pointer to swap with the contents of this object. (OWN)

After this method returns, io_ptr will contain what this object contained initially, and vice-versa.

void Swap ( AutoPtr< T, Deallocator > &  io_other  )  [inline]

Swap the contents of this object with that of another AutoPtr.

Parameters:
io_other The other AutoPtr to swap contents with.

The documentation for this class was generated from the following file:

Generated on Wed May 17 14:21:18 2017 for SimbaEngine 10.1.3.1011 by simba