ref_ptr Class Template Reference
[Smart Pointers library]

#include <stlsoft/smartptr/ref_ptr.hpp>

List of all members.


Detailed Description

template<typename T, typename I = T, typename U = I>
class stlsoft::ref_ptr< T, I, U >

This class provides RAII-safe handling of reference-counted interfaces (RCIs).

Its notable feature is that it supports forward declaration of the leaf interface so long as the base counting interface is visible in the scope of the template parameterisation.

Parameters:
T The counted type (i.e. a concrete class)
I The interface type
U The upcast intermediate type
Examples:

by_library/com_utility/creation_functions/creation_functions.cpp, by_library/com_utility/rot_functions/rot_functions.cpp, by_library/conversion/interface_cast/interface_cast.cpp, and by_project/comstl/comstl.cpp.


Public Types

Types
typedef bool_t bool_type
 The Boolean type.
typedef I interface_type
 The interface type: the type of the RCI (Reference-Counted Interface).
typedef T counted_type
 The counted type: the concrete type of the objects whose instances will be managed.
typedef U upcast_type
 The up-cast type: the type used to disambiguate upcasts between T and I.
typedef ref_ptr< T, I, U > class_type
 The current instantiation of the type.
typedef I element_type
 This to be member-type-compatible with std::auto_ptr.
typedef counted_typeresource_type
 This is to be compatible with the get_invoker component.
typedef counted_type const * const_resource_type

Public Member Functions

Construction
 ref_ptr ()
 Default constructor.
 ref_ptr (counted_type *c, bool_type bAddRef)
 Construct from a raw pointer to the counted type, and a boolean that indicates whether a reference should be taken on the instance.
 ref_ptr (class_type const &rhs)
 Creates a copy of the given ref_ptr instance, and increments the reference count on its referent object, if any.
template<typename T2, typename I2, typename U2>
 ref_ptr (ref_ptr< T2, I2, U2 > &rhs)
 Copy constructs from an instance with different interface and/or counted type.
 ~ref_ptr () throw ()
 Destructor.
class_typeoperator= (class_type const &rhs)
 Copy assignment from a ref_ptr instance of the same type.
template<typename T2, typename U2>
class_typeoperator= (ref_ptr< T2, I, U2 > &rhs)
 Copy assignment from an instance of ref_ptr with a different counted_type (but the same interface type).
Operations
void swap (class_type &rhs)
 Swaps the managed instance of this with rhs.
void set (counted_type *c, bool_type bAddRef)
 Assigns a reference-counted type to the smart pointer.
void close ()
 Closes the instance, releasing the managed pointer.
counted_typedetach ()
 Detaches the managed instance, and returns it to the caller, which takes responsibility for ensuring that the resource is not leaked.
Equality Comparison
bool_type equal (class_type const &rhs) const
 Evaluates whether two instances are equal.
Accessors
bool_type empty () const
 Determines whether the instance is empty.
bool_type operator! () const
 Determines whether the instance is empty.
counted_typeget () const
 Provides raw-pointer access to the instance.
counted_typeoperator-> ()
 Returns the interface pointer.
counted_type const * operator-> () const
 Returns the interface pointer.
counted_typeoperator* ()
 Returns a reference to the managed instance.
counted_type const & operator* () const
 Returns a reference to the managed instance.

Member Typedef Documentation

typedef bool_t bool_type

The Boolean type.

typedef I interface_type

The interface type: the type of the RCI (Reference-Counted Interface).

typedef T counted_type

The counted type: the concrete type of the objects whose instances will be managed.

typedef U upcast_type

The up-cast type: the type used to disambiguate upcasts between T and I.

typedef ref_ptr<T, I, U> class_type

The current instantiation of the type.

Reimplemented in interface_ptr.

typedef I element_type

This to be member-type-compatible with std::auto_ptr.

This is to be compatible with the get_invoker component.


Constructor & Destructor Documentation

ref_ptr (  )  [inline]

Default constructor.

Constructs and empty instance

ref_ptr ( counted_type c,
bool_type  bAddRef 
) [inline]

Construct from a raw pointer to the counted type, and a boolean that indicates whether a reference should be taken on the instance.

Parameters:
c Pointer to a counted_type. May be NULL
bAddRef parameter that determines whether reference will be consumed (false) or borrowed (true).
Note:
It is usual that ref_ptr is used to "sink" an instance, i.e. to take ownership of it. In such a case, false should be specified as the second parameter. If, however, a reference is being "borrowed", then true should be specified.

ref_ptr ( class_type const &  rhs  )  [inline]

Creates a copy of the given ref_ptr instance, and increments the reference count on its referent object, if any.

Parameters:
rhs The instance to copy

ref_ptr ( ref_ptr< T2, I2, U2 > &  rhs  )  [inline]

Copy constructs from an instance with different interface and/or counted type.

Note:
The interface types of the copying and copied instance must be compatible

~ref_ptr (  )  throw () [inline]

Destructor.

If the ref_ptr instance is still holding a pointer to a managed instance, it will be released.


Member Function Documentation

class_type& operator= ( class_type const &  rhs  )  [inline]

Copy assignment from a ref_ptr instance of the same type.

Note:
It is strongly exception-safe, as long as the implementations of the add-ref and release functions - as utilised in the add_reference() and release_reference() control shims - do not throw (which they must not).

class_type& operator= ( ref_ptr< T2, I, U2 > &  rhs  )  [inline]

Copy assignment from an instance of ref_ptr with a different counted_type (but the same interface type).

Note:
This function template uses the copy constructor template, and has the same instantiation restrictions

It is strongly exception-safe, as long as the implementations of the add-ref and release functions - as utilised in the add_reference() and release_reference() control shims - do not throw (which they must not).

void swap ( class_type rhs  )  [inline]

Swaps the managed instance of this with rhs.

Note:
It provides the no-throw guarantee

Referenced by ref_ptr< T >::operator=(), and ref_ptr< T >::set().

void set ( counted_type c,
bool_type  bAddRef 
) [inline]

Assigns a reference-counted type to the smart pointer.

Parameters:
c Pointer to a counted_type. May be NULL
bAddRef parameter that determines whether reference will be consumed (false) or borrowed (true).

void close (  )  [inline]

Closes the instance, releasing the managed pointer.

Note:
Calling this method more than once has no effect.

counted_type* detach (  )  [inline]

Detaches the managed instance, and returns it to the caller, which takes responsibility for ensuring that the resource is not leaked.

Reimplemented in interface_ptr.

bool_type equal ( class_type const &  rhs  )  const [inline]

Evaluates whether two instances are equal.

bool_type empty (  )  const [inline]

Determines whether the instance is empty.

Referenced by ref_ptr< T >::operator!().

bool_type operator! (  )  const [inline]

Determines whether the instance is empty.

counted_type* get (  )  const [inline]

Provides raw-pointer access to the instance.

Referenced by stlsoft::get_ptr(), and stlsoft::is_empty().

counted_type* operator-> (  )  [inline]

Returns the interface pointer.

Precondition:
The instance must not be empty; otherwise behaviour is undefined

counted_type const* operator-> (  )  const [inline]

Returns the interface pointer.

Precondition:
The instance must not be empty; otherwise behaviour is undefined

counted_type& operator* (  )  [inline]

Returns a reference to the managed instance.

Precondition:
The instance must not be empty; otherwise behaviour is undefined

counted_type const& operator* (  )  const [inline]

Returns a reference to the managed instance.

Precondition:
The instance must not be empty; otherwise behaviour is undefined


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

Generated on Thu Jun 10 08:58:56 2010 for STLSoft by  doxygen 1.5.6