Main Page   Namespace List   Class Hierarchy   Compound List   File List   Header Files   Namespace Members   Compound Members   File Members  

arg::counted_ptr Class Reference

"Smart pointer" template which owns the referenced object and shares ownership on copy/assignment - the last owner is responsible for destroying the referenced object. More...

#include <arg_shared.h>

Class diagram for arg::counted_ptr:

arg::typed_reference arg::generic_reference

List of all members.


Public Members

 counted_ptr ()
"0 initialised" pointer.

explicit counted_ptr (pointee_type* p)
Takes ownership of p.

 counted_ptr (const counted_ptr& rhs)
Take value of rhs.

 counted_ptr (const base_type& rhs)
Acquire share of ownership from rhs.

 ~counted_ptr () throw ()
pointee_type* get () const
Returns contents.

pointee_type* operator-> () const
Indirection operator.

pointee_type& operator * () const
Dereference operator.

counted_ptr& operator= (const base_type& rhs)
Acquire share of ownership from rhs (and destroy old referent if last owner).

counted_ptr& operator= (const counted_ptr& rhs)
Acquire share of ownership from rhs (and destroy old referent if last owner).

void reset (pointee_type* p)
Delete existing contents (and take ownership of p).

void swap (base_type& with) throw ()
Swaps contents with "with".


Detailed Description

template<typename pointee_type> class arg::counted_ptr

"Smart pointer" template which owns the referenced object and shares ownership on copy/assignment - the last owner is responsible for destroying the referenced object.

"counted_ptr" gives non-intrusive strong reference counting and is copy compatable with "uncounted_ptr" (which gives weak reference counting).

counted_ptr and uncounted_ptr are described in an article: Uncounted pointers in C++.

All methods support the strong exception safety guarantee with the proviso that the referenced type must have a non-throwing destructor.

Author(s):
Alan Griffiths

Member Function Documentation

template<typename pointee_type>
arg::counted_ptr<pointee_type>::counted_ptr<pointee_type> ()

"0 initialised" pointer.

template<typename pointee_type>
explicit arg::counted_ptr<pointee_type>::counted_ptr<pointee_type> (pointee_type * p)

Takes ownership of p.

template<typename pointee_type>
arg::counted_ptr<pointee_type>::counted_ptr<pointee_type> (const counted_ptr<pointee_type> & rhs)

Take value of rhs.

template<typename pointee_type>
arg::counted_ptr<pointee_type>::counted_ptr<pointee_type> (const base_type & rhs)

Acquire share of ownership from rhs.

template<typename pointee_type>
arg::counted_ptr<pointee_type>::~counted_ptr<pointee_type> () throw () [inline]

template<typename pointee_type>
pointee_type * arg::counted_ptr<pointee_type>::get () const [inline]

Returns contents.

Reimplemented from arg::generic_reference.

template<typename pointee_type>
pointee_type * arg::counted_ptr<pointee_type>::operator-> () const [inline]

Indirection operator.

template<typename pointee_type>
pointee_type & arg::counted_ptr<pointee_type>::operator * () const [inline]

Dereference operator.

template<typename pointee_type>
counted_ptr<pointee_type> & arg::counted_ptr<pointee_type>::operator= (const base_type & rhs) [inline]

Acquire share of ownership from rhs (and destroy old referent if last owner).

template<typename pointee_type>
counted_ptr<pointee_type> & arg::counted_ptr<pointee_type>::operator= (const counted_ptr<pointee_type> & rhs) [inline]

Acquire share of ownership from rhs (and destroy old referent if last owner).

template<typename pointee_type>
void arg::counted_ptr<pointee_type>::reset (pointee_type * p) [inline]

Delete existing contents (and take ownership of p).

template<typename pointee_type>
void arg::counted_ptr<pointee_type>::swap (base_type & with) throw () [inline]

Swaps contents with "with".


The documentation for this class was generated from the following file:
Copyright 1999-2000 Alan Griffiths