#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 |
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
|
Default constructor Initializes the pointer and takes ownership.
|
|
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. |
|
Destructor. The pointer is deleted in case this class still has ownership |
|
|
|
|
|
get() method returns the pointer, currently owned by the class.
|
|
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. |
|
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. |
|
Assignment operator from an another oscl_auto_ptr.
|
|
release() method releases ownership of the pointer, currently owned by the class. It returns the pointer as well.
|
|
The takeOwnership function assigns the value with ownership.
|
|
The takeOwnership function assigns the value with ownership.
|
|
|