blocxx
Public Types | Public Member Functions | Private Member Functions | Private Attributes

BLOCXX_NAMESPACE::AutoPtr< X > Class Template Reference

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>

List of all members.

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.
AutoPtroperator= (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)
AutoPtroperator= (const AutoPtr &a)

Private Attributes

X * _ptr

Detailed Description

template<class X>
class BLOCXX_NAMESPACE::AutoPtr< X >

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.


Member Typedef Documentation

template<class X>
typedef X BLOCXX_NAMESPACE::AutoPtr< X >::element_type

Definition at line 72 of file AutoPtr.hpp.


Constructor & Destructor Documentation

template<class X>
BLOCXX_NAMESPACE::AutoPtr< X >::AutoPtr ( const AutoPtr< X > &  a) [private]
template<class X>
BLOCXX_NAMESPACE::AutoPtr< X >::AutoPtr ( X *  p = 0) [inline, explicit]

Construct a new AutoPtr object that assumes ownership of a given pointer.

Parameters:
ppointer to the object

Definition at line 129 of file AutoPtr.hpp.

template<class X >
BLOCXX_NAMESPACE::AutoPtr< X >::~AutoPtr ( ) [inline]

Destroy this AutoPtr object and the object it points to.

Definition at line 143 of file AutoPtr.hpp.


Member Function Documentation

template<class X >
X * BLOCXX_NAMESPACE::AutoPtr< X >::get ( ) const [inline]
Returns:
The underlying held pointer.

Definition at line 156 of file AutoPtr.hpp.

template<class X >
X & BLOCXX_NAMESPACE::AutoPtr< X >::operator* ( ) const [inline]
Returns:
A reference to the object to which the underlying held pointer points.

Definition at line 150 of file AutoPtr.hpp.

template<class X >
X * BLOCXX_NAMESPACE::AutoPtr< X >::operator-> ( ) const [inline]
Returns:
The underlying held pointer.

Definition at line 153 of file AutoPtr.hpp.

template<class X>
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.

Parameters:
pThe new pointer this AutoPtr object will own.
Returns:
A reference to this AutoPtr object.

Definition at line 132 of file AutoPtr.hpp.

template<class X>
AutoPtr& BLOCXX_NAMESPACE::AutoPtr< X >::operator= ( const AutoPtr< X > &  a) [private]
template<class X >
X * BLOCXX_NAMESPACE::AutoPtr< X >::release ( ) [inline]

Release ownership of the underlying pointer.

Returns:
The value of the underlying held pointer before the call to release

Definition at line 159 of file AutoPtr.hpp.

template<class X>
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.

Parameters:
pThe pointer this AutoPtr will take ownership of.

Definition at line 167 of file AutoPtr.hpp.

Referenced by BLOCXX_NAMESPACE::TempFileStream::reset().


Member Data Documentation

template<class X>
X* BLOCXX_NAMESPACE::AutoPtr< X >::_ptr [private]

Definition at line 65 of file AutoPtr.hpp.


The documentation for this class was generated from the following file: