Main Page   Namespace List   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

RazorBack::Derivhdl_ Class Template Reference

This class implements a reference-counted storage for objects derived from the same base class. More...

#include <Derivhdl.hh>

Collaboration diagram for RazorBack::Derivhdl_:

Collaboration graph
[legend]
List of all members.

Public Methods

 Derivhdl_ ()
 default ctor: init to empty.

 Derivhdl_ (const BaseT_ &B)
 init with a BaseT_ object, stores a deep copy: also BaseT_ -> wrapper conversion.

 Derivhdl_ (const Derivhdl_ &D)
 copy ctor, implements shallow copy.

 ~Derivhdl_ ()
 destructor.

Derivhdl_& operator= (const Derivhdl_ &Rhs)
 assignment.

bool empty () const
 empty().

const BaseT_& ref () const
 ref(): access to the underlying BaseT_ object. More...

BaseT_& ref ()
const BaseT_* ptr () const
 ptr(): returns a pointer to the underlying BaseT_ object. More...

BaseT_* ptr ()
template<class DerivedT_> const DerivedT_* real_ptr () const
 real_ptr(): returns a pointer to the wrapped object of type DerivedT_. More...

template<class DerivedT_> DerivedT_* real_ptr ()
bool operator< (const Derivhdl_< BaseT_ > &Rhs) const
 <: comparison for STL algorithms Empty objects are always "smaller" than non-empty ones Uses the < operator of BaseT_.


Protected Methods

void unlink_old ()

Private Attributes

Refcount_Dataptr

Detailed Description

template<class BaseT_> class RazorBack::Derivhdl_

This class implements a reference-counted storage for objects derived from the same base class.

The Derivhdl_<BaseT_> provides the external interface, and holds a pointer to a Refcount_<BaseT_> object. The Refcount_<BaseT_> class may be pointed to by several Derivhdl_ classes. Refcount_<BaseT_> holds one BaseT_ base type pointer and owns the object pointed to by BaseT_. That object itself may be of type BaseT_ or any class derived from BaseT_.

   Derivhdl_<BaseT_>  Derivhdl_<BaseT_>
       |                 |
       +------+   +------+
              |...|
              V   V
         Refcount_<BaseT_>
              |
              V
            BaseT_
   
The purpose of all this is to provide an interface for storing a mixture of class objects derived from the same BaseT_ in STL containers. My other reference counter storage template (see "Refstorage.hh") was designed for storing objects of the same type. BaseT_ class requirements:-
   1) The BaseT_ class must have a virtual constructor method
   that looks like
   
   BaseT_* T_::virtual_ctor() const { return new T_(*this); }
   
   where T_ is a type possibly derived from BaseT_. This function
   shall return a BaseT_ pointer to a freshly allocated
   copy of the calling object.
   
   2) BaseT_ shall provide the less-than comparison operator <
   to be used by the STL. This is called via the comparison operator
   of Derivhdl_.
   

Definition at line 70 of file Derivhdl.hh.


Constructor & Destructor Documentation

template<class BaseT_>
RazorBack::Derivhdl_<BaseT_>::Derivhdl_<BaseT_> ( ) [inline]
 

default ctor: init to empty.

Definition at line 108 of file Derivhdl.hh.

template<class BaseT_>
RazorBack::Derivhdl_<BaseT_>::Derivhdl_<BaseT_> ( const BaseT_ & B ) [inline]
 

init with a BaseT_ object, stores a deep copy: also BaseT_ -> wrapper conversion.

Definition at line 111 of file Derivhdl.hh.

template<class BaseT_>
RazorBack::Derivhdl_<BaseT_>::Derivhdl_<BaseT_> ( const Derivhdl_<BaseT_> & D ) [inline]
 

copy ctor, implements shallow copy.

Definition at line 117 of file Derivhdl.hh.

template<class BaseT_>
RazorBack::Derivhdl_<BaseT_>::~Derivhdl_<BaseT_> ( ) [inline]
 

destructor.

Definition at line 123 of file Derivhdl.hh.


Member Function Documentation

template<class BaseT_>
Derivhdl_<BaseT_> & RazorBack::Derivhdl_<BaseT_>::operator= ( const Derivhdl_<BaseT_> & Rhs )
 

assignment.

template<class BaseT_>
bool RazorBack::Derivhdl_<BaseT_>::empty ( ) const [inline]
 

empty().

Definition at line 129 of file Derivhdl.hh.

Referenced by operator<().

template<class BaseT_>
const BaseT_ & RazorBack::Derivhdl_<BaseT_>::ref ( ) const
 

ref(): access to the underlying BaseT_ object.

Throws Emptyexc_ if the calling object is empty.

Referenced by operator<().

template<class BaseT_>
BaseT_& RazorBack::Derivhdl_<BaseT_>::ref ( )
 

template<class BaseT_>
const BaseT_ * RazorBack::Derivhdl_<BaseT_>::ptr ( ) const
 

ptr(): returns a pointer to the underlying BaseT_ object.

Returns NULL if the calling object is empty.

Referenced by real_ptr().

template<class BaseT_>
BaseT_* RazorBack::Derivhdl_<BaseT_>::ptr ( )
 

template<class BaseT_>
template<class DerivedT_>
const DerivedT_ * RazorBack::Derivhdl_<BaseT_>::real_ptr ( ) const [inline]
 

real_ptr(): returns a pointer to the wrapped object of type DerivedT_.

dynamic_cast must be able to convert from BaseT_* to DerivedT_*. In general, you should manipulate the wrapped objects only through their virtual methods. However, under some circumstances it might be useful to know and use the "real" type of the polymorphic object wrapped in Derivhdl_ (for instance when doing I/O). If the conversion was unsuccessful or the wrapper was empty then NULL is returned. Use this at least as carefully as you would dynamic_cast! Always test the returned pointer!

Definition at line 157 of file Derivhdl.hh.

template<class BaseT_>
template<class DerivedT_>
DerivedT_ * RazorBack::Derivhdl_<BaseT_>::real_ptr ( ) [inline]
 

Definition at line 162 of file Derivhdl.hh.

template<class BaseT_>
bool RazorBack::Derivhdl_<BaseT_>::operator< ( const Derivhdl_< BaseT_ > & Rhs ) const [inline]
 

<: comparison for STL algorithms Empty objects are always "smaller" than non-empty ones Uses the < operator of BaseT_.

Definition at line 172 of file Derivhdl.hh.

template<class BaseT_>
void RazorBack::Derivhdl_<BaseT_>::unlink_old ( ) [protected]
 

Referenced by ~Derivhdl_().


Member Data Documentation

template<class BaseT_>
Refcount_* RazorBack::Derivhdl_<BaseT_>::Dataptr [private]
 

Definition at line 102 of file Derivhdl.hh.


The documentation for this class was generated from the following file:
Generated at Wed Aug 21 09:33:41 2002 for The Razorback C++ Library: Miscellaneous by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001