- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Exponent::Collections::TAutomaticPointer< TypeName > Class Template Reference

List of all members.

## Detailed Description

### template<class TypeName>
class Exponent::Collections::TAutomaticPointer< TypeName >

An automatic pointer that can be created on the stack to automatically delete any dynamically allocated resources.

In use, this class is very simple. Inside a function, rather than using delete on a variable do something like this

     void foo()
     {
         TAutomaticPointer<CPoint> variable = new CPoint(10, 10);
         // ...
         // Do some processing here
         // ...
         // variable is automatically delete here, which deletes the point too
     }

Note that you can use a TAutomaticPointer in the same way as a normal pointer

     void foo()
     {
         TAutomaticPointer<CPoint> variable = new CPoint(10, 10);
         const long x = variable->getXPosition();      // Overloaded arrow operator returns the pointer
         *variable.setXPosition(x + 10);               // Overloaded deference operator returns deferenced pointer
     }

It should also be pointed out that this class can use any standard ObjectDeleter, as used by the arrays
This means that you can make it operate like both the STL auto_ptr and the Boost smart_ptr in operation
STL auto_ptr:

     TAutomaticPointer<CPoint> ptr(new CPoint(x,y), TObjectDeleter<CPoint>);

Boost smart_ptr:

     TAutomaticPointer<CPoint> variable = new CPoint(10, 10);

See also:
  TCountedObjectDeleter

Date:
  03/05/2006

Author:
  Paul Chana

Version:
  1.0.0 Initial version

Note:
  All contents of this source code are copyright 2005 Exp Digital Uk.
  This source file is covered by the licence conditions of the Infinity API. You should have recieved a copy
  with the source code. If you didnt, please refer to http://www.expdigital.co.uk All content is the Intellectual property of Exp Digital Uk.
  Certain sections of this code may come from other sources. They are credited where applicable.
  If you have comments, suggestions or bug reports please visit http://support.expdigital.co.uk

  This class is intended for internal types and counted objects.
  It will not work for 'built in' c++ types. If you need this functionality you can use any of the items below:

See also:
  Exponent::Basics::CFloat

  Exponent::Basics::CString

  Exponent::Basics::CDouble

  Exponent::Basics::CLong

  Exponent::Basics::CBool

Id
  TAutomaticPointer.hpp,v 1.11 2007/02/11 02:15:54 paul Exp

Definition at line 71 of file TAutomaticPointer.hpp.

## Public Member Functions

- void freePointer ()
- TypeName * getMutablePointer ()
- const TypeName * getPointer () const
- TypeName & operator * ()
- TypeName * operator-> ()
- TAutomaticPointer< TypeName > & operator= (TypeName *pointer)
- TAutomaticPointer< TypeName > & operator= (const TAutomaticPointer< TypeName > &pointer)
- bool pointerIsValid () const
- TAutomaticPointer (const TAutomaticPointer< TypeName > &pointer, TPointerDeleter< TypeName > *pointerDeleter=&TAUTOMATICPOINTER_DEFAULT_DELETER)
- TAutomaticPointer (TypeName *pointer, TPointerDeleter< TypeName > *pointerDeleter=&TAUTOMATICPOINTER_DEFAULT_DELETER)
- TAutomaticPointer (TPointerDeleter< TypeName > *pointerDeleter=&TAUTOMATICPOINTER_DEFAULT_DELETER)
- virtual ~TAutomaticPointer ()

## Static Public Attributes

- static TCountedObjectDeleter<
  TypeName > TAUTOMATICPOINTER_DEFAULT_DELETER

## Protected Attributes

- TypeName * m_pointer
- TPointerDeleter< TypeName > * m_pointerDeletionHandler

## Constructor & Destructor Documentation

template<class TypeName>

Exponent::Collections::TAutomaticPointer< TypeName >::TAutomaticPointer | ( | TPointerDeleter< TypeName > * | pointerDeleter = `&TAUTOMATICPOINTER_DEFAULT_DELETER` | ) | `[inline]`

Construction

Parameters:

  | pointerDeleter | The object used for addition and deletion of pointers, can be NULL for deletion of a pointer as default

Definition at line 92 of file TAutomaticPointer.hpp.

template<class TypeName>

Exponent::Collections::TAutomaticPointer< TypeName >::TAutomaticPointer | ( | TypeName * | pointer,
|  | TPointerDeleter< TypeName > * | pointerDeleter = `&TAUTOMATICPOINTER_DEFAULT_DELETER` |
| ) |  |  | `[inline]`

Construction

Parameters:

  | pointer | The pointer to store
  | pointerDeleter | The object used for addition and deletion of pointers, can be NULL for deletion of a pointer as default

Definition at line 104 of file TAutomaticPointer.hpp.

template<class TypeName>

Exponent::Collections::TAutomaticPointer< TypeName >::TAutomaticPointer | ( | const TAutomaticPointer< TypeName > & | pointer,
|  | TPointerDeleter< TypeName > * | pointerDeleter = `&TAUTOMATICPOINTER_DEFAULT_DELETER` |
| ) |  |  | `[inline]`

Copy Construction

Parameters:

  | pointer | The pointer to store
  | pointerDeleter | The object used for addition and deletion of pointers, can be NULL for deletion of a pointer as default

Definition at line 129 of file TAutomaticPointer.hpp.

template<class TypeName>

virtual Exponent::Collections::TAutomaticPointer< TypeName >::~TAutomaticPointer | ( |  | ) | `[inline, virtual]`

Destruction

Definition at line 140 of file TAutomaticPointer.hpp.

## Member Function Documentation

template<class TypeName>

void Exponent::Collections::TAutomaticPointer< TypeName >::freePointer | ( |  | ) | `[inline]`

Free the pointer held internally, called automatically at destruction

Definition at line 245 of file TAutomaticPointer.hpp.

Referenced by Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::~TAutomaticPointer().

template<class TypeName>

TypeName* Exponent::Collections::TAutomaticPointer< TypeName >::getMutablePointer | ( |  | ) | `[inline]`

Get the pointer

Return values:

  | TypeName* | The pointer

Definition at line 270 of file TAutomaticPointer.hpp.

template<class TypeName>

const TypeName* Exponent::Collections::TAutomaticPointer< TypeName >::getPointer | ( |  | ) | const`[inline]`

Get the pointer

Return values:

  | const | TypeName* The pointer

Definition at line 264 of file TAutomaticPointer.hpp.

template<class TypeName>

TypeName& Exponent::Collections::TAutomaticPointer< TypeName >::operator * | ( |  | ) | `[inline]`

Deference operator

Return values:

  | TypeName& | A reference to the inner pointer

Definition at line 234 of file TAutomaticPointer.hpp.

template<class TypeName>

TypeName* Exponent::Collections::TAutomaticPointer< TypeName >::operator-> | ( |  | ) | `[inline]`

Pointer operator

Return values:

  | TypeName* | A pointer to the innner data

Definition at line 228 of file TAutomaticPointer.hpp.

template<class TypeName>

TAutomaticPointer<TypeName>& Exponent::Collections::TAutomaticPointer< TypeName >::operator= | ( | TypeName * | pointer | ) | `[inline]`

Assignment operator

Parameters:

  | pointer | The pointer to store

Return values:

  | TAutomaticPointer<TypeName>& | A reference to this

Definition at line 189 of file TAutomaticPointer.hpp.

template<class TypeName>

TAutomaticPointer<TypeName>& Exponent::Collections::TAutomaticPointer< TypeName >::operator= | ( | const TAutomaticPointer< TypeName > & | pointer | ) | `[inline]`

Assignment operator

Parameters:

  | pointer | The pointer to store

Return values:

  | TAutomaticPointer<TypeName>& | A reference to this

Definition at line 153 of file TAutomaticPointer.hpp.

template<class TypeName>

bool Exponent::Collections::TAutomaticPointer< TypeName >::pointerIsValid | ( |  | ) | const`[inline]`

Is the pointer valid

Return values:

  | bool | True if pointer is non NULL, false otherwise

Definition at line 240 of file TAutomaticPointer.hpp.

## Member Data Documentation

template<class TypeName>

TypeName* Exponent::Collections::TAutomaticPointer< TypeName >::m_pointer`[protected]`

The pointer object

Definition at line 278 of file TAutomaticPointer.hpp.

Referenced by Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::freePointer(), Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::getMutablePointer(), Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::getPointer(), Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::operator *(), Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::operator->(), Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::operator=(), Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::pointerIsValid(), and Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::TAutomaticPointer().

template<class TypeName>

TPointerDeleter<TypeName>* Exponent::Collections::TAutomaticPointer< TypeName >::m_pointerDeletionHandler`[protected]`

Deletion handler

Definition at line 279 of file TAutomaticPointer.hpp.

Referenced by Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::freePointer(), Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::operator=(), and Exponent::Collections::TAutomaticPointer< Exponent::GUI::Controls::CMenuItem >::TAutomaticPointer().

template<class TypeName>

TCountedObjectDeleter<TypeName> Exponent::Collections::TAutomaticPointer< TypeName >::TAUTOMATICPOINTER_DEFAULT_DELETER`[static]`

The default handler for pointer deletion

Definition at line 83 of file TAutomaticPointer.hpp.