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

OSCLMemAutoPtr< T, _Allocator > Class Template Reference
[OSCL Memory]

The oscl_auto_ptr 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 oscl_auto_ptr expires, its destructor uses delete to free the memory. More...

#include <oscl_mem_auto_ptr.h>


Public Methods

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

 OSCLMemAutoPtr (const OSCLMemAutoPtr< T > &_Y)
 Copy constructor.

OSCLMemAutoPtr< T, _Allocator > & operator= (const OSCLMemAutoPtr< T, _Allocator > &_Y)
 Assignment operator from an another oscl_auto_ptr.

 ~OSCLMemAutoPtr ()
 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.

void takeOwnership (T *ptr)
 The takeOwnership function assigns the value with ownership.

void allocate (oscl_memsize_t size)
void setWithoutOwnership (T *ptr)
 The takeOwnership function assigns the value with ownership.

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

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


Static Public Methods

void deallocate (T *ptr)

Data Fields

bool _Ownership


Detailed Description

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
class OSCLMemAutoPtr< T, _Allocator >

The oscl_auto_ptr 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 oscl_auto_ptr 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 oscl_auto_ptr 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 oscl_auto_ptr 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 _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
OSCLMemAutoPtr< T, _Allocator >::OSCLMemAutoPtr T *    inPtr = 0 [inline, explicit]
 

Default constructor Initializes the pointer and takes ownership.

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
OSCLMemAutoPtr< T, _Allocator >::OSCLMemAutoPtr const OSCLMemAutoPtr< T > &    _Y [inline]
 

Copy constructor.

Initializes the pointer and takes ownership from another oscl_auto_ptr. 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 _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
OSCLMemAutoPtr< T, _Allocator >::~OSCLMemAutoPtr   [inline]
 

Destructor.

The pointer is deleted in case this class still has ownership


Member Function Documentation

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
void OSCLMemAutoPtr< T, _Allocator >::allocate oscl_memsize_t    size [inline]
 

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
void OSCLMemAutoPtr< T, _Allocator >::deallocate T *    ptr [inline, static]
 

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
T* OSCLMemAutoPtr< T, _Allocator >::get   const [inline]
 

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

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
T& OSCLMemAutoPtr< T, _Allocator >::operator *   const [inline]
 

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

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

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
T* OSCLMemAutoPtr< T, _Allocator >::operator->   const [inline]
 

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

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

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
OSCLMemAutoPtr<T, _Allocator>& OSCLMemAutoPtr< T, _Allocator >::operator= const OSCLMemAutoPtr< T, _Allocator > &    _Y [inline]
 

Assignment operator from an another oscl_auto_ptr.

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

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
T* OSCLMemAutoPtr< T, _Allocator >::release   const [inline]
 

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

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
void OSCLMemAutoPtr< T, _Allocator >::setWithoutOwnership T *    ptr [inline]
 

The takeOwnership function assigns the value with ownership.

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
void OSCLMemAutoPtr< T, _Allocator >::takeOwnership T *    ptr [inline]
 

The takeOwnership function assigns the value with ownership.


Field Documentation

template<class T, class _Allocator = Oscl_TAlloc<T, OsclMemAllocator>>
bool OSCLMemAutoPtr< T, _Allocator >::_Ownership
 


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