blocxx
|
The AutoPtr class provides a simple class for smart pointers to single objects (for multiple, see AutoPtrVec); it stores a pointer to an object obtained by way of the new operator and deletes that object when the AutoPtr object is destroyed. More...
#include <AutoPtr.hpp>
Public Types | |
typedef X | element_type |
Public Member Functions | |
AutoPtr (X *p=0) | |
Construct a new AutoPtr object that assumes ownership of a given pointer. | |
~AutoPtr () | |
Destroy this AutoPtr object and the object it points to. | |
AutoPtr & | operator= (X *p) |
Assignment operator Assign a new pointer to this AutoPtr object. | |
X & | operator* () const |
X * | operator-> () const |
X * | get () const |
X * | release () |
Release ownership of the underlying pointer. | |
void | reset (X *p=0) |
Delete the object the underlying pointer points to and take ownership of a new pointer. | |
Private Member Functions | |
AutoPtr (const AutoPtr &a) | |
AutoPtr & | operator= (const AutoPtr &a) |
Private Attributes | |
X * | _ptr |
The AutoPtr class provides a simple class for smart pointers to single objects (for multiple, see AutoPtrVec); it stores a pointer to an object obtained by way of the new operator and deletes that object when the AutoPtr object is destroyed.
The AutoPtr class provides semantics of strict ownership. After construction an AutoPtr object owns the object whose pointer it holds. When an instantiation of AutoPtr is copied, ownership of the object is transferred to the destination AutoPtr. The behavior is undefined if more than one instantiation of AutoPtr owns the same object at the same time. Note: This class should not be used for a smart pointer to a dynamically allocated array. AutoPtrVec should be used for that. If AutoPtr holds a pointer to an array, the destructor for all objects in the array will not be called when AutoPtr delete the pointer
Definition at line 62 of file AutoPtr.hpp.
typedef X BLOCXX_NAMESPACE::AutoPtr< X >::element_type |
Definition at line 72 of file AutoPtr.hpp.
BLOCXX_NAMESPACE::AutoPtr< X >::AutoPtr | ( | const AutoPtr< X > & | a | ) | [private] |
BLOCXX_NAMESPACE::AutoPtr< X >::AutoPtr | ( | X * | p = 0 | ) | [inline, explicit] |
Construct a new AutoPtr object that assumes ownership of a given pointer.
p | pointer to the object |
Definition at line 129 of file AutoPtr.hpp.
BLOCXX_NAMESPACE::AutoPtr< X >::~AutoPtr | ( | ) | [inline] |
Destroy this AutoPtr object and the object it points to.
Definition at line 143 of file AutoPtr.hpp.
X * BLOCXX_NAMESPACE::AutoPtr< X >::get | ( | ) | const [inline] |
Definition at line 156 of file AutoPtr.hpp.
X & BLOCXX_NAMESPACE::AutoPtr< X >::operator* | ( | ) | const [inline] |
Definition at line 150 of file AutoPtr.hpp.
X * BLOCXX_NAMESPACE::AutoPtr< X >::operator-> | ( | ) | const [inline] |
Definition at line 153 of file AutoPtr.hpp.
AutoPtr< X > & BLOCXX_NAMESPACE::AutoPtr< X >::operator= | ( | X * | p | ) | [inline] |
Assignment operator Assign a new pointer to this AutoPtr object.
If this AutoPtr object points to another object before this assignment, then that object will be destroyed first.
p | The new pointer this AutoPtr object will own. |
Definition at line 132 of file AutoPtr.hpp.
AutoPtr& BLOCXX_NAMESPACE::AutoPtr< X >::operator= | ( | const AutoPtr< X > & | a | ) | [private] |
X * BLOCXX_NAMESPACE::AutoPtr< X >::release | ( | ) | [inline] |
Release ownership of the underlying pointer.
Definition at line 159 of file AutoPtr.hpp.
void BLOCXX_NAMESPACE::AutoPtr< X >::reset | ( | X * | p = 0 | ) | [inline] |
Delete the object the underlying pointer points to and take ownership of a new pointer.
This is similar to the assignment operator.
p | The pointer this AutoPtr will take ownership of. |
Definition at line 167 of file AutoPtr.hpp.
Referenced by BLOCXX_NAMESPACE::TempFileStream::reset().
X* BLOCXX_NAMESPACE::AutoPtr< X >::_ptr [private] |
Definition at line 65 of file AutoPtr.hpp.