blocxx
BLOCXX_NAMESPACE::AutoPtrVec< X > Class Template Reference

The AutoPtrVec class provides a simple class for smart pointers to a dynamically allocated array of objects. More...

#include <AutoPtr.hpp>

Public Types

typedef X element_type
 

Public Member Functions

 AutoPtrVec (X *p=0)
 Construct a new AutoPtrVec object that assumes ownership of a given array pointer.
 
 ~AutoPtrVec ()
 Destroy this AutoPtrVec object and the array it points to.
 
AutoPtrVecoperator= (X *p)
 Assignment operator Assign a new array pointer to this AutoPtrVec object.
 
X & operator* () const
 
X * operator-> () const
 
X & operator[] (unsigned n)
 
const X & operator[] (unsigned i) const
 
X * get () const
 
X * release ()
 Release ownership of the underlying array.
 
void reset (X *p=0)
 Delete the array the underlying pointer points to and take ownership of a new array pointer.
 

Private Member Functions

 AutoPtrVec (const AutoPtrVec &a)
 
AutoPtrVecoperator= (const AutoPtrVec &a)
 

Private Attributes

X * _ptr
 

Detailed Description

template<class X>
class BLOCXX_NAMESPACE::AutoPtrVec< X >

The AutoPtrVec class provides a simple class for smart pointers to a dynamically allocated array of objects.

It stores a pointer to the array obtained by way of the new operator and deletes the array when the AutoPtrVec object is destroyed. The AutoPtrVec class provides semantics of strict ownership. After construction an AutoPtrVec object owns the array whose pointer it holds. When an instantiation of AutoPtrVec is copied, ownership of the array is transferred to the destination AutoPtrVec. The behavior is undefined if more than one instantiation of AutoPtrVec owns the same array at the same time.

Definition at line 184 of file AutoPtr.hpp.

Member Typedef Documentation

◆ element_type

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

Definition at line 194 of file AutoPtr.hpp.

Constructor & Destructor Documentation

◆ AutoPtrVec() [1/2]

template<class X>
BLOCXX_NAMESPACE::AutoPtrVec< X >::AutoPtrVec ( const AutoPtrVec< X > & a)
private

References AutoPtrVec().

Referenced by AutoPtrVec(), operator=(), and operator=().

◆ AutoPtrVec() [2/2]

template<class X>
BLOCXX_NAMESPACE::AutoPtrVec< X >::AutoPtrVec ( X * p = 0)
inlineexplicit

Construct a new AutoPtrVec object that assumes ownership of a given array pointer.

Parameters
ppointer to the array.

Definition at line 264 of file AutoPtr.hpp.

References _ptr.

◆ ~AutoPtrVec()

template<class X>
BLOCXX_NAMESPACE::AutoPtrVec< X >::~AutoPtrVec ( )

Destroy this AutoPtrVec object and the array it points to.

Definition at line 278 of file AutoPtr.hpp.

References _ptr.

Member Function Documentation

◆ get()

◆ operator*()

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

Definition at line 285 of file AutoPtr.hpp.

References _ptr.

◆ operator->()

template<class X>
X * BLOCXX_NAMESPACE::AutoPtrVec< X >::operator-> ( ) const
Returns
The underlying held pointer.

Definition at line 288 of file AutoPtr.hpp.

References _ptr.

◆ operator=() [1/2]

template<class X>
AutoPtrVec & BLOCXX_NAMESPACE::AutoPtrVec< X >::operator= ( const AutoPtrVec< X > & a)
private

References AutoPtrVec().

◆ operator=() [2/2]

template<class X>
AutoPtrVec< X > & BLOCXX_NAMESPACE::AutoPtrVec< X >::operator= ( X * p)

Assignment operator Assign a new array pointer to this AutoPtrVec object.

If this AutoPtrVec object points to another array before this assignment, then that array will be destroyed first.

Parameters
pThe new array pointer this AutoPtrVec object will own.
Returns
A reference to this AutoPtrVec object.

Definition at line 267 of file AutoPtr.hpp.

References _ptr, AutoPtrVec(), and reset().

◆ operator[]() [1/2]

template<class X>
const X & BLOCXX_NAMESPACE::AutoPtrVec< X >::operator[] ( unsigned i) const
Returns
A read only reference to the nth element of the array owned by this AutoPtrVec object.

Definition at line 294 of file AutoPtr.hpp.

References _ptr.

◆ operator[]() [2/2]

template<class X>
X & BLOCXX_NAMESPACE::AutoPtrVec< X >::operator[] ( unsigned n)
Returns
A read/write reference to the nth element of the array owned by this AutoPtrVec object.

Definition at line 291 of file AutoPtr.hpp.

References _ptr.

◆ release()

template<class X>
X * BLOCXX_NAMESPACE::AutoPtrVec< X >::release ( )

Release ownership of the underlying array.

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

Definition at line 300 of file AutoPtr.hpp.

References _ptr.

Referenced by BLOCXX_NAMESPACE::UnnamedPipe::readString().

◆ reset()

template<class X>
void BLOCXX_NAMESPACE::AutoPtrVec< X >::reset ( X * p = 0)

Delete the array the underlying pointer points to and take ownership of a new array pointer.

This is similar to the assignment operator.

Parameters
pThe array pointer this AutoPtr will take ownership of.

Definition at line 308 of file AutoPtr.hpp.

References _ptr.

Referenced by operator=().

Member Data Documentation

◆ _ptr

template<class X>
X* BLOCXX_NAMESPACE::AutoPtrVec< X >::_ptr
private

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