ArrayAutoPtr< Type > Class Template Reference

This reference page is linked to from the following overview topics: Smart Pointers (AutoPtr).



Detailed Description

template<typename Type>
class MaxSDK::ArrayAutoPtr< Type >

Standard implementation of a AutoPtr for pointer to array types.

This ArrayAutoPtr template is appropriate for any pointer to a dynamically allocated array (using new [] and delete []). To manage a single dynamically allocated object, use AutoPtr instead.

Please refer to AutoPtr's documentation for more information about AutoPtrs.

#include <autoptr.h>

Inheritance diagram for ArrayAutoPtr< Type >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

  ArrayAutoPtr (Type *p=NULL)
  Construct, assuming ownership of the pointed-to object.
  ArrayAutoPtr (const AutoPtrRef< Type > &ref)
  Construct from an AutoPtrRef.
template<typename OtherType >
  operator ArrayAutoPtr< OtherType > ()
  Destructive copy-convert allowing for cast of the pointer type.
Type &  operator[] (int index) const
  Convenience array-index operator for ArrayAutoPtrs.

Constructor & Destructor Documentation

ArrayAutoPtr ( Type *  p = NULL ) [inline, explicit]

Construct, assuming ownership of the pointed-to object.

Parameters:
p Plain pointer to an array - this AutoPtr will assume ownership of that object.
                                          : 
        AutoPtr<Type, ArrayPointerDestructor<Type> >(p)
    { };
ArrayAutoPtr ( const AutoPtrRef< Type > &  ref ) [inline]

Construct from an AutoPtrRef.

This may be done implicitly or explicitly. The Ref object exists to avoid temporarily needing to have two AutoPtrs own the same object.

Parameters:
ref helper object.
                                              :
        AutoPtr<Type, ArrayPointerDestructor<Type> >(ref.mPtr)
    { }

Member Function Documentation

operator ArrayAutoPtr< OtherType > ( ) [inline]

Destructive copy-convert allowing for cast of the pointer type.

    {
        return ArrayAutoPtr<OtherType>(this->Release());
    }
Type& operator[] ( int  index ) const [inline]

Convenience array-index operator for ArrayAutoPtrs.

Using this operator is the same as calling Get()[index]. Note that this operator does not check if the index is out of bounds. This is not a bounds checking smart pointer, it's just a handy guard object for dealing with memory ownership.

Precondition:
index must be within the underlying array's bounds.
Parameters:
index The index within the array
Returns:
a reference to the element at position index in the array.
    { 
        return Get()[index];
    }