Main Page   Modules   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

OsclExclusivePtr< T > Class Template Reference
[OSCL Base]

The OsclExclusivePtr class is a template class that defines a pointer like object intended to be assigned an address obtanined (directly or or indirectly) by new. When the OsclExclusivePtr expires, its destructor uses delete to free the memory. More...

#include <oscl_exclusive_ptr.h>


Public Methods

 OsclExclusivePtr (T *inPtr=0)
 Default constructor Initializes the pointer and takes ownership.

 OsclExclusivePtr (OsclExclusivePtr< T > &_Y)
 Copy constructor.

OsclExclusivePtr< T > & operator= (OsclExclusivePtr< T > &_Y)
 Assignment operator from an another OsclExclusivePtr.

virtual ~OsclExclusivePtr ()
 Destructor.

T & operator * () const
 The indirection operator (*) accesses a value indirectly, through a pointer.

T * operator-> () const
 The indirection operator (->) accesses a value indirectly, through a pointer.

T * get () const
 get() method returns the pointer, currently owned by the class.

T * release ()
 release() method releases ownership of the pointer, currently owned by the class. It returns the pointer as well.

bool set (T *ptr)
 set() method sets ownership to the pointer, passed. This method is needed when the class is created with a default constructor. Returns false in case the class is non-empty.


Protected Attributes

T * _Ptr


Detailed Description

template<class T>
class OsclExclusivePtr< T >

The OsclExclusivePtr class is a template class that defines a pointer like object intended to be assigned an address obtanined (directly or or indirectly) by new. When the OsclExclusivePtr expires, its destructor uses delete to free the memory.

The purpose of this class is to provide a way to prevent accidental memory leaks in a class or a method, due to "not remembering to delete" variables allocated on the heap. Thus if you assign an address returned by new to an OsclExclusivePtr object, you don't have to remember to free the memory later, it will be freed automatically when the object goes out of scope. The OsclExclusivePtr is an example of a smart pointer, an object that acts like a pointer, but with additional features. The class is defined so that it acts like a regular pointer in most respects


Constructor & Destructor Documentation

template<class T>
OsclExclusivePtr< T >::OsclExclusivePtr T *    inPtr = 0 [inline, explicit]
 

Default constructor Initializes the pointer and takes ownership.

template<class T>
OsclExclusivePtr< T >::OsclExclusivePtr OsclExclusivePtr< T > &    _Y [inline]
 

Copy constructor.

Initializes the pointer and takes ownership from another OsclExclusivePtr. Note that the other class does NOT own the pointer any longer, and hence it is NOT its responsibility to free it.

template<class T>
virtual OsclExclusivePtr< T >::~OsclExclusivePtr   [inline, virtual]
 

Destructor.

The pointer is deleted in case this class still has ownership


Member Function Documentation

template<class T>
T* OsclExclusivePtr< T >::get   const [inline]
 

get() method returns the pointer, currently owned by the class.

template<class T>
T& OsclExclusivePtr< T >::operator *   const [inline]
 

The indirection operator (*) accesses a value indirectly, through a pointer.

This operator ensures that the OsclExclusivePtr can be used like the regular pointer that it was initialized with.

template<class T>
T* OsclExclusivePtr< T >::operator->   const [inline]
 

The indirection operator (->) accesses a value indirectly, through a pointer.

This operator ensures that the OsclExclusivePtr can be used like the regular pointer that it was initialized with.

template<class T>
OsclExclusivePtr<T>& OsclExclusivePtr< T >::operator= OsclExclusivePtr< T > &    _Y [inline]
 

Assignment operator from an another OsclExclusivePtr.

Parameters:
_Y  The value parameter should be another OsclExclusivePtr
Returns:
Returns a reference to this OsclExclusivePtr instance with pointer initialized.
Precondition:
The input class should be non-null and should point to a valid pointer.
This assignment operator initializes the class to the contents of the OsclExclusivePtr given as the input parameter. The ownership of the pointer is transferred.

template<class T>
T* OsclExclusivePtr< T >::release   [inline]
 

release() method releases ownership of the pointer, currently owned by the class. It returns the pointer as well.

template<class T>
bool OsclExclusivePtr< T >::set T *    ptr [inline]
 

set() method sets ownership to the pointer, passed. This method is needed when the class is created with a default constructor. Returns false in case the class is non-empty.


Field Documentation

template<class T>
T* OsclExclusivePtr< T >::_Ptr [protected]
 


The documentation for this class was generated from the following file:
OSCL API
Posting Version: OPENCORE_20090310