claraty::Auto_Ref< T > Class Template Reference
#include <auto_reference.h>
Collaboration diagram for claraty::Auto_Ref< T >:

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_Ref & | operator= (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
| claraty::Auto_Ref< T >::Auto_Ref | ( | ) | [inline] |
| claraty::Auto_Ref< T >::Auto_Ref | ( | T *& | ptr | ) | [inline, explicit] |
| claraty::Auto_Ref< T >::Auto_Ref | ( | const Auto_Ref< T > & | rhs | ) | [inline] |
| claraty::Auto_Ref< T >::~Auto_Ref | ( | ) | [inline] |
Member Function Documentation
| 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; }
| Auto_Ref& claraty::Auto_Ref< T >::operator= | ( | const Auto_Ref< T > & | rhs | ) | [inline] |
| 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 }
| bool claraty::Auto_Ref< T >::operator!= | ( | const Auto_Ref< R > & | rhs | ) | const [inline] |
| 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 }
| void claraty::Auto_Ref< T >::cast_to | ( | Auto_Ref< T > & | rhs | ) | [inline] |
| 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().
| 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 }
| T* claraty::Auto_Ref< T >::get | ( | ) | const [inline] |
| void claraty::Auto_Ref< T >::get_ptr | ( | T *& | p | ) | const [inline] |
Definition at line 178 of file auto_reference.h.
00178 { 00179 p = dynamic_cast<U*>(_rc->_rep); 00180 }
| void claraty::Auto_Ref< T >::make_null_if_unique | ( | ) | [inline] |
| 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 }
| const T& claraty::Auto_Ref< T >::operator * | ( | ) | const [inline] |
| const T* claraty::Auto_Ref< T >::operator-> | ( | ) | const [inline] |
| T& claraty::Auto_Ref< T >::operator * | ( | ) | [inline] |
| T* claraty::Auto_Ref< T >::operator-> | ( | ) | [inline] |
| claraty::Auto_Ref< T >::operator bool | ( | ) | const [inline] |
| bool claraty::Auto_Ref< T >::operator! | ( | ) | const [inline] |
Friends And Related Function Documentation
friend class const_Auto_Ref< T > [friend] |
Definition at line 96 of file auto_reference.h.
Member Data Documentation
ref_counter<T>* claraty::Auto_Ref< T >::_rc [private] |
Definition at line 98 of file auto_reference.h.
Referenced by claraty::Auto_Ref< Item >::Auto_Ref(), claraty::Auto_Ref< Item >::cast_to(), claraty::const_Auto_Ref< T >::const_Auto_Ref(), claraty::Auto_Ref< Item >::get(), claraty::Auto_Ref< Item >::get_const_representation_pointer(), claraty::Auto_Ref< Item >::get_ptr(), claraty::Auto_Ref< Item >::make_null_if_unique(), claraty::Auto_Ref< Item >::make_unique(), claraty::Auto_Ref< Item >::operator *(), claraty::Auto_Ref< Item >::operator bool(), claraty::Auto_Ref< Item >::operator!(), claraty::Auto_Ref< Item >::operator->(), claraty::Auto_Ref< Item >::operator=(), claraty::Auto_Ref< Item >::operator==(), claraty::Auto_Ref< Item >::reset(), claraty::Auto_Ref< Item >::reset_rc(), and claraty::Auto_Ref< Item >::~Auto_Ref().
The documentation for this class was generated from the following file: