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

OsclExclusivePtrA< T, Alloc > Class Template Reference
[OSCL Base]

The OsclExclusivePtrA class is a template class that defines any pointer like object intended to be assigned an address obtanined (directly or or indirectly) through Alloc. When the OsclExclusivePtrA expires, Alloc is used to free the memory. More...

#include <oscl_exclusive_ptr.h>


Public Methods

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

 OsclExclusivePtrA (OsclExclusivePtrA< T, Alloc > &_Y)
 Copy constructor.

OsclExclusivePtrA< T, Alloc > & operator= (OsclExclusivePtrA< T, Alloc > &_Y)
 Assignment operator from an another OsclExclusiveArrayPtr.

virtual ~OsclExclusivePtrA ()
 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 Alloc>
class OsclExclusivePtrA< T, Alloc >

The OsclExclusivePtrA class is a template class that defines any pointer like object intended to be assigned an address obtanined (directly or or indirectly) through Alloc. When the OsclExclusivePtrA expires, Alloc is used 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, class Alloc>
OsclExclusivePtrA< T, Alloc >::OsclExclusivePtrA T *    inPtr = 0 [inline, explicit]
 

Default constructor Initializes the pointer and takes ownership.

template<class T, class Alloc>
OsclExclusivePtrA< T, Alloc >::OsclExclusivePtrA OsclExclusivePtrA< T, Alloc > &    _Y [inline]
 

Copy constructor.

Initializes the pointer and takes ownership from another OsclExclusiveArrayPtr. 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, class Alloc>
virtual OsclExclusivePtrA< T, Alloc >::~OsclExclusivePtrA   [inline, virtual]
 

Destructor.

The pointer is deleted in case this class still has ownership


Member Function Documentation

template<class T, class Alloc>
T* OsclExclusivePtrA< T, Alloc >::get   const [inline]
 

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

template<class T, class Alloc>
T& OsclExclusivePtrA< T, Alloc >::operator *   const [inline]
 

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

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

template<class T, class Alloc>
T* OsclExclusivePtrA< T, Alloc >::operator->   const [inline]
 

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

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

template<class T, class Alloc>
OsclExclusivePtrA<T, Alloc>& OsclExclusivePtrA< T, Alloc >::operator= OsclExclusivePtrA< T, Alloc > &    _Y [inline]
 

Assignment operator from an another OsclExclusiveArrayPtr.

Parameters:
_Y  The value parameter should be another OsclExclusiveArrayPtr
Returns:
Returns a reference to this OsclExclusiveArrayPtr 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 OsclExclusiveArrayPtr given as the input parameter. The ownership of the pointer is transferred.

template<class T, class Alloc>
T* OsclExclusivePtrA< T, Alloc >::release   [inline]
 

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

template<class T, class Alloc>
bool OsclExclusivePtrA< T, Alloc >::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, class Alloc>
T* OsclExclusivePtrA< T, Alloc >::_Ptr [protected]
 


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