Follow this link to skip to the main content

claraty::Auto_Ref< T > Class Template Reference

#include <auto_reference.h>

Collaboration diagram for claraty::Auto_Ref< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Auto_Ref ()
 Auto_Ref (T *&ptr)
 Auto_Ref (const Auto_Ref &rhs)
 ~Auto_Ref ()
const void * get_const_representation_pointer () const
Auto_Refoperator= (const Auto_Ref &rhs)
template<class R>
bool operator== (const Auto_Ref< R > &rhs) const
template<class R>
bool operator!= (const Auto_Ref< R > &rhs) const
template<class S>
void cast_to (Auto_Ref< S > &rhs)
void cast_to (Auto_Ref< T > &rhs)
void reset_rc (ref_counter< T > *new_rc)
void reset (T *&ptr)
T * get () const
void get_ptr (T *&p) const
template<class U>
void get_ptr (U *&p)
void make_null_if_unique ()
void make_unique ()
const T & operator * () const
const T * operator-> () const
T & operator * ()
T * operator-> ()
 operator bool () const
bool operator! () const

Private Attributes

ref_counter< T > * _rc

Friends

class const_Auto_Ref< T >

Detailed Description

template<class T>
class claraty::Auto_Ref< T >

Definition at line 95 of file auto_reference.h.


Constructor & Destructor Documentation

template<class T>
claraty::Auto_Ref< T >::Auto_Ref (  )  [inline]

Definition at line 101 of file auto_reference.h.

00101 { _rc= new ref_counter<T>(); }

template<class T>
claraty::Auto_Ref< T >::Auto_Ref ( T *&  ptr  )  [inline, explicit]

Definition at line 102 of file auto_reference.h.

00102 { _rc = new ref_counter<T>(ptr); ptr = 0; }

template<class T>
claraty::Auto_Ref< T >::Auto_Ref ( const Auto_Ref< T > &  rhs  )  [inline]

Definition at line 103 of file auto_reference.h.

00103                                 {
00104     _rc = rhs._rc;
00105     _rc->inc();
00106   }

template<class T>
claraty::Auto_Ref< T >::~Auto_Ref (  )  [inline]

Definition at line 107 of file auto_reference.h.

00107               {
00108     if (_rc->dec() == 0) delete _rc;
00109   }


Member Function Documentation

template<class T>
const void* claraty::Auto_Ref< T >::get_const_representation_pointer (  )  const [inline]

Definition at line 114 of file auto_reference.h.

Referenced by claraty::Auto_Ref< Item >::operator==().

00114 { return _rc; }

template<class T>
Auto_Ref& claraty::Auto_Ref< T >::operator= ( const Auto_Ref< T > &  rhs  )  [inline]

Definition at line 116 of file auto_reference.h.

00116                                            {
00117     if (_rc != rhs._rc) {
00118       if (_rc->dec() == 0) delete _rc;
00119       _rc = rhs._rc;
00120       _rc->inc();
00121     }
00122     return *this;
00123   }

template<class T>
template<class R>
bool claraty::Auto_Ref< T >::operator== ( const Auto_Ref< R > &  rhs  )  const [inline]

Definition at line 126 of file auto_reference.h.

Referenced by claraty::Auto_Ref< Item >::operator!=().

00126                                                 {
00127     return static_cast<void*>(_rc) == rhs.get_const_representation_pointer();
00128   }

template<class T>
template<class R>
bool claraty::Auto_Ref< T >::operator!= ( const Auto_Ref< R > &  rhs  )  const [inline]

Definition at line 131 of file auto_reference.h.

00131                                                 {
00132     return !operator==(rhs);
00133   }

template<class T>
template<class S>
void claraty::Auto_Ref< T >::cast_to ( Auto_Ref< S > &  rhs  )  [inline]

Definition at line 139 of file auto_reference.h.

00139                                  {
00140     if (dynamic_cast<S*>(_rc->_rep) == NULL) {
00141       std::cerr << "Illegal attempt to cast an Auto_Ref<T> to an Auto_Ref<U> where "
00142         "U is not castable from T (or from a NULL Auto_Ref)" << std::endl;
00143       S& dummy = dynamic_cast<S&>(*_rc->_rep); // will throw bad_cast
00144     }
00145     ref_counter<S> *rc_subclass = reinterpret_cast<ref_counter<S>*>(_rc);
00146     rhs.reset_rc(rc_subclass);
00147   }

template<class T>
void claraty::Auto_Ref< T >::cast_to ( Auto_Ref< T > &  rhs  )  [inline]

Definition at line 150 of file auto_reference.h.

00150                                  {
00151     rhs = *this;
00152   }

template<class T>
void claraty::Auto_Ref< T >::reset_rc ( ref_counter< T > *  new_rc  )  [inline]

Definition at line 157 of file auto_reference.h.

Referenced by claraty::Auto_Ref< Item >::cast_to().

00157                                         {
00158     if (_rc->dec() == 0) delete _rc;
00159     _rc = new_rc;
00160     _rc->inc();
00161   }

template<class T>
void claraty::Auto_Ref< T >::reset ( T *&  ptr  )  [inline]

Definition at line 163 of file auto_reference.h.

00163                       {
00164     if (_rc->dec() == 0) delete _rc;
00165     _rc = new ref_counter<T>(ptr);
00166     ptr = 0;
00167   }

template<class T>
T* claraty::Auto_Ref< T >::get (  )  const [inline]

Definition at line 169 of file auto_reference.h.

00169                  {
00170     return _rc->_rep;
00171   }

template<class T>
void claraty::Auto_Ref< T >::get_ptr ( T *&  p  )  const [inline]

Definition at line 173 of file auto_reference.h.

00173                             {
00174     p = _rc->_rep;
00175   }

template<class T>
template<class U>
void claraty::Auto_Ref< T >::get_ptr ( U *&  p  )  [inline]

Definition at line 178 of file auto_reference.h.

00178                       {
00179     p = dynamic_cast<U*>(_rc->_rep);
00180   }

template<class T>
void claraty::Auto_Ref< T >::make_null_if_unique (  )  [inline]

Definition at line 184 of file auto_reference.h.

00184                              {
00185     _rc->make_null_if_unique();
00186   }

template<class T>
void claraty::Auto_Ref< T >::make_unique (  )  [inline]

Definition at line 188 of file auto_reference.h.

00188                      {
00189     _rc->lock.acquire();
00190     if (_rc->get_count() <= 1) {
00191       assert(_rc->get_count() == 1); // should never get to zero while we care
00192       _rc->lock.release();
00193     } else {
00194       T *copy = _rc->_rep->clone();
00195       ref_counter<T> *rc = new ref_counter<T>(copy);
00196       _rc->dec();
00197       assert(_rc->get_count() > 0); // since we know it was greater than 1
00198       _rc->lock.release();
00199       _rc = rc;
00200     }
00201   }

template<class T>
const T& claraty::Auto_Ref< T >::operator * (  )  const [inline]

Definition at line 203 of file auto_reference.h.

00203                              {
00204     return *_rc->_rep;
00205   }

template<class T>
const T* claraty::Auto_Ref< T >::operator-> (  )  const [inline]

Definition at line 207 of file auto_reference.h.

00207                               {
00208     return _rc->_rep;
00209   }

template<class T>
T& claraty::Auto_Ref< T >::operator * (  )  [inline]

Definition at line 211 of file auto_reference.h.

00211                  {
00212     return *_rc->_rep;
00213   }

template<class T>
T* claraty::Auto_Ref< T >::operator-> (  )  [inline]

Definition at line 215 of file auto_reference.h.

00215                   {
00216     return _rc->_rep;
00217   }

template<class T>
claraty::Auto_Ref< T >::operator bool (  )  const [inline]

Definition at line 219 of file auto_reference.h.

00219                         {
00220     return !!_rc->_rep;
00221   }

template<class T>
bool claraty::Auto_Ref< T >::operator! (  )  const [inline]

Definition at line 222 of file auto_reference.h.

00222                          {
00223     return !_rc->_rep;
00224   }


Friends And Related Function Documentation

template<class T>
friend class const_Auto_Ref< T > [friend]

Definition at line 96 of file auto_reference.h.


Member Data Documentation


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