SharedPtr< T > Class Template Reference

Provides safe pointer management. More...

List of all members.

Public Member Functions

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.
template<typename Y >
SharedPtroperator= (const SharedPtr< Y > &rhs)
 Assignment operator.
SharedPtroperator= (const SharedPtr &rhs)
 Assignment operator.
SharedPtroperator= (T *ptr)
 Assignment operator.
void Reset (T *ptr=NULL)
 Reset the wrapped pointer in SharedPtr to other T*.
template<typename Y >
 SharedPtr (const SharedPtr< Y > &obj)
 Copy constructor.
 SharedPtr (const SharedPtr &obj)
 Copy constructor.
 SharedPtr (T *ptr=NULL)
 Default constructor.
void Swap (SharedPtr &in_other) throw ()
 Swaps the object pointed to by this SharedPtr and in_other.
 ~SharedPtr ()
 Destructor.

Friends

class SharedPtr

Detailed Description

template<typename T>
class Simba::Support::SharedPtr< T >

Provides safe pointer management.

SharedPtr stores a pointer to a dynamically allocated object. The object pointed to is guaranteed to be deleted when the last SharedPtr pointing to it is destroyed or reset.

Here are some guidelines for using the SharedPtr.


Constructor & Destructor Documentation

SharedPtr ( T *  ptr = NULL  )  [inline, explicit]

Default constructor.

Parameters:
ptr Pointer of explicit T type to initialize the owned pointer.
SharedPtr ( const SharedPtr< T > &  obj  )  [inline]

Copy constructor.

Create a SharedPtr from an existing SharedPtr. The reference count for the wrapped object would be increased by 1.

Parameters:
obj Const reference to another object containing the same type of owned pointer. The obj's reference count will increased by 1.
SharedPtr ( const SharedPtr< Y > &  obj  )  [inline]

Copy constructor.

Create a SharedPtr from an existing SharedPtr. The reference count for the wrapped object would be increased by 1.

Parameters:
obj Const reference to another object containing the same type of owned pointer. The obj's reference count will increased by 1.
~SharedPtr (  )  [inline]

Destructor.

Call the owned pointer Release method to decrease the reference count. It is the object itself to deallocate the memory if the reference reaches 0.


Member Function Documentation

T* Get (  )  const [inline]

Gives access to the contained pointer.

IMPORTANT: Don't call delete, Retain() and Release() on the returned pointer.

Returns:
the contained pointer. (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:
Dereferencing a NULL pointer will cause a segfault in Unix. Check the validity of the pointer by calling SharedPtr::IsNull() before dereferencing.
Returns:
a reference to the object pointed to by the contained pointer.
T* operator-> (  )  const [inline]

Return the owned pointer.

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

Returns:
the contained pointer. (NOT OWN)
SharedPtr& operator= ( const SharedPtr< Y > &  rhs  )  [inline]

Assignment operator.

Create a SharedPtr from an existing SharedPtr. The reference count for the wrapped object would be increased by 1.

Parameters:
rhs A SharedPtr object to initialize this object with its contained object pointer.
SharedPtr& operator= ( const SharedPtr< T > &  rhs  )  [inline]

Assignment operator.

Create a SharedPtr from an existing SharedPtr. The reference count for the wrapped object would be increased by 1.

Parameters:
rhs A SharedPtr object to initialize this object with its contained object pointer.
SharedPtr& operator= ( T *  ptr  )  [inline]

Assignment operator.

Create a SharedPtr from an existing pointer.

Parameters:
ptr A pointer to initialize this shared pointer with. The ptr's reference count will be increased by 1.
void Reset ( T *  ptr = NULL  )  [inline]

Reset the wrapped pointer in SharedPtr to other T*.

If the passed in pointer is NULL, then the wrapped pointer will be set to NULL. If the previous wrapped in pointer is not NULL, the object, which the pointer points to, will decrease the reference number. If the number is 0, the object's destructor will be called. Otherwise, if the argument ptr is not NULL, the wrapped in pointer is set to ptr. and Retain is called through ptr to increase the reference count.

Parameters:
ptr The pointer that SharedPtr object going to wrap.
void Swap ( SharedPtr< T > &  in_other  )  throw () [inline]

Swaps the object pointed to by this SharedPtr and in_other.

Parameters:
in_other The SharedPtr to swap with.

Friends And Related Function Documentation

friend class SharedPtr [friend]

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

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