Loading...
Searching...
No Matches
ASSA::AutoPtr< X > Class Template Reference

AutoPtr is based on SGI implementation of a auto_ptr template that makes memory handling a little bit easier. More...

`#include <AutoPtr.h>`

## Public Member Functions

| AutoPtr (X *p_=0)
| Construct an AutoPtr from a raw pointer.
| AutoPtr (AutoPtr &a_)
| Construct AutoPtr from another AutoPtr.
template<typename T>
| AutoPtr (AutoPtr< T > &a_)
| Construct AutoPtr from another AutoPtr of different (but related) type.
AutoPtr & | operator= (AutoPtr &a_)
| Assignment operator deletes memory it owns and transfers the ownership from a_ to itself.
template<class T>
AutoPtr & | operator= (AutoPtr< T > &a_)
| Assignment from another AutoPtr of a different but related type.
| ~AutoPtr ()
| When AutoPtr goes out of scope, the object it owns is deleted.
X & | operator* () const
| Smart pointer dereferencing.
X * | operator-> () const
| Smart pointer dereferencing.
X * | get () const
| Get a raw memory pointer without changing ownership status.
X * | release ()
| Give up the ownership of the memory.
void | reset (X *p_=0)
| Forcibly delete the managed object and assume the ownership of a_.
| AutoPtr (AutoPtrRef< X > ref_)
| Automagic conversions.
AutoPtr & | operator= (AutoPtrRef< X > ref_)
template<typename T>
| operator AutoPtrRef< T > ()
template<typename T>
| operator AutoPtr< T > ()

## Private Attributes

X * | m_ptr
| Pointer to the object we own.

## Detailed Description

template<class X>
class ASSA::AutoPtr< X >

AutoPtr is based on SGI implementation of a auto_ptr template that makes memory handling a little bit easier.

AutoPtr interface does not completely confirm to that of auto_ptr as specified in C++ Standard.

Definition at line 49 of file AutoPtr.h.

## Constructor & Destructor Documentation

## AutoPtr() [1/4]

template<class X>

ASSA::AutoPtr< X >::AutoPtr | ( | X * | p_ = 0 | ) |

inline explicit

Construct an AutoPtr from a raw pointer.

The word 'explicit' disallows implicit construction of objects, for example in function calls.

Parameters

  p_ | pointer (defaults to NULL) to assume ownerwhip for.

Definition at line 61 of file AutoPtr.h.

: m_ptr (p_) { /* no-op */ }
ASSA::AutoPtr
AutoPtr is based on SGI implementation of a auto_ptr template that makes memory handling a little bit...
Definition AutoPtr.h:49
ASSA::AutoPtr::m_ptr
X * m_ptr
Pointer to the object we own.
Definition AutoPtr.h:52

References m_ptr.

Referenced by AutoPtr(), AutoPtr(), operator AutoPtr< T >(), operator=(), operator=(), and operator=().

## AutoPtr() [2/4]

template<class X>

ASSA::AutoPtr< X >::AutoPtr | ( | AutoPtr< X > & | a_ | ) |

inline

Construct AutoPtr from another AutoPtr.

Parameters

  a_ | AutoPtr object that gives up its ownership.

Definition at line 67 of file AutoPtr.h.

: m_ptr (a_.release ()) {/* no-op */ }
ASSA::AutoPtr::release
X * release()
Give up the ownership of the memory.
Definition AutoPtr.h:130

References AutoPtr(), m_ptr, and release().

## AutoPtr() [3/4]

template<class X>
template<typename T>

ASSA::AutoPtr< X >::AutoPtr | ( | AutoPtr< T > & | a_ | ) |

inline

Construct AutoPtr from another AutoPtr of different (but related) type.

A pointer to T must be convertible to a pointer to X.

Note
  Nonconstant parameter

Parameters

  a_ | AutoPtr object that is released of ownership.

Definition at line 76 of file AutoPtr.h.

: m_ptr (a_.release ()) { /* no-op */ }

References AutoPtr(), m_ptr, and release().

## ~AutoPtr()

template<class X>

ASSA::AutoPtr< X >::~AutoPtr | ( |  | ) |

inline

When AutoPtr goes out of scope, the object it owns is deleted.

Not owning anything has no effect.

Definition at line 102 of file AutoPtr.h.

{
if (m_ptr) {
delete m_ptr;
}
}

References m_ptr.

## AutoPtr() [4/4]

template<class X>

ASSA::AutoPtr< X >::AutoPtr | ( | AutoPtrRef< X > | ref_ | ) |

inline

Automagic conversions.

These operations convert an AutoPtr into/from an AutoPtrRef as needed. This allows on-the-fly conversion between AutoPtr of different but related types (parent/child):

AutoPtr<Derived> FooReturnsAutoPtr () { ... };
AutoPtr<Base> aptr = FooReturnsAutoPtr ();
ASSA::AutoPtr::AutoPtr
AutoPtr(X *p_=0)
Construct an AutoPtr from a raw pointer.
Definition AutoPtr.h:61

Definition at line 159 of file AutoPtr.h.

: m_ptr (ref_.m_ptr) { /* no-op */ }

References m_ptr.

## Member Function Documentation

## get()

template<class X>

X * ASSA::AutoPtr< X >::get | ( |  | ) | const

inline

Get a raw memory pointer without changing ownership status.

Usefull when you need to pass a pointer to the function.

Returns
  The raw pointer being managed.

Definition at line 123 of file AutoPtr.h.

{ return m_ptr; }

References m_ptr.

Referenced by ASSA::Logger::log_open(), and operator=().

## operator AutoPtr< T >()

template<class X>
template<typename T>

ASSA::AutoPtr< X >::operator AutoPtr< T > | ( |  | ) |

inline

Definition at line 173 of file AutoPtr.h.

{ return AutoPtr<T> (release ()); }

References AutoPtr(), and release().

## operator AutoPtrRef< T >()

template<class X>
template<typename T>

ASSA::AutoPtr< X >::operator AutoPtrRef< T > | ( |  | ) |

inline

Definition at line 170 of file AutoPtr.h.

{ return AutoPtrRef<T> (release ()); }

References release().

## operator*()

template<class X>

X & ASSA::AutoPtr< X >::operator* | ( |  | ) | const

inline

Smart pointer dereferencing.

Definition at line 111 of file AutoPtr.h.

{ return *m_ptr; }

References m_ptr.

## operator->()

template<class X>

X * ASSA::AutoPtr< X >::operator-> | ( |  | ) | const

inline

Smart pointer dereferencing.

Definition at line 116 of file AutoPtr.h.

{ return m_ptr; }

References m_ptr.

## operator=() [1/3]

template<class X>

AutoPtr & ASSA::AutoPtr< X >::operator= | ( | AutoPtr< X > & | a_ | ) |

inline

Assignment operator deletes memory it owns and transfers the ownership from a_ to itself.

Parameters

  a_ | another AutoPtr of the same type.

Definition at line 83 of file AutoPtr.h.

{
reset (a_.release ());
return *this;
}
ASSA::AutoPtr::reset
void reset(X *p_=0)
Forcibly delete the managed object and assume the ownership of a_.
Definition AutoPtr.h:140

References AutoPtr(), release(), and reset().

## operator=() [2/3]

template<class X>
template<class T>

AutoPtr & ASSA::AutoPtr< X >::operator= | ( | AutoPtr< T > & | a_ | ) |

inline

Assignment from another AutoPtr of a different but related type.

Note
  Nonconstant parameter

Parameters

  a_ | AutoPtr to assume ownership of

Definition at line 93 of file AutoPtr.h.

{
reset (a_.release ());
return *this;
}

References AutoPtr(), release(), and reset().

## operator=() [3/3]

template<class X>

AutoPtr & ASSA::AutoPtr< X >::operator= | ( | AutoPtrRef< X > | ref_ | ) |

inline

Definition at line 161 of file AutoPtr.h.

{
if (ref_.m_ptr != get ()) {
delete m_ptr;
m_ptr = ref_.m_ptr;
}
return *this;
}
ASSA::AutoPtr::get
X * get() const
Get a raw memory pointer without changing ownership status.
Definition AutoPtr.h:123

References AutoPtr(), get(), m_ptr, and ASSA::AutoPtrRef< R >::m_ptr.

## release()

template<class X>

X * ASSA::AutoPtr< X >::release | ( |  | ) |

inline

Give up the ownership of the memory.

When AutoPtr gets out of scope, nothing happens. The caller becomes responsible for the memory management.

Definition at line 130 of file AutoPtr.h.

{
X* tmp = m_ptr;
m_ptr = NULL;
return tmp;
}

References m_ptr.

Referenced by AutoPtr(), AutoPtr(), ASSA::Logger::log_open(), operator AutoPtr< T >(), operator AutoPtrRef< T >(), operator=(), and operator=().

## reset()

template<class X>

void ASSA::AutoPtr< X >::reset | ( | X * | p_ = 0 | ) |

inline

Forcibly delete the managed object and assume the ownership of a_.

Definition at line 140 of file AutoPtr.h.

{
if (p_ != m_ptr) {
delete m_ptr;
m_ptr = p_;
}
}

References m_ptr.

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

## Member Data Documentation

## m_ptr

template<class X>

X* ASSA::AutoPtr< X >::m_ptr

private

Pointer to the object we own.

Definition at line 52 of file AutoPtr.h.

Referenced by AutoPtr(), AutoPtr(), AutoPtr(), AutoPtr(), get(), operator*(), operator->(), operator=(), release(), reset(), and ~AutoPtr().

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

- AutoPtr.h