blocxx
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
BLOCXX_NAMESPACE::COWIntrusiveReference< T > Class Template Reference

COWIntrusiveReference A smart pointer that uses intrusive reference counting. More...

#include <COWIntrusiveReference.hpp>

Public Types

typedef T element_type
 
typedef T *this_type::* unspecified_bool_type
 

Public Member Functions

 COWIntrusiveReference ()
 Default constructor The underlying object pointer will be NULL. More...
 
 COWIntrusiveReference (T *p, bool addRef=true)
 Construct a COWIntrusiveReference that will contain a pointer to a COWIntrusiveCountableBase object. More...
 
template<class U >
 COWIntrusiveReference (COWIntrusiveReference< U > const &rhs)
 Copy constructor. More...
 
 COWIntrusiveReference (COWIntrusiveReference const &rhs)
 Copy constructor. More...
 
 ~COWIntrusiveReference ()
 Destroy this COWIntrusiveReference. More...
 
template<class U >
COWIntrusiveReferenceoperator= (COWIntrusiveReference< U > const &rhs)
 Assignment operator that that takes a COWIntrusiveReference of a type derived from T. More...
 
COWIntrusiveReferenceoperator= (COWIntrusiveReference const &rhs)
 Assignment operator. More...
 
COWIntrusiveReferenceoperator= (T *rhs)
 Assignment operator. More...
 
const T * getPtr () const
 
const T & operator* () const
 
const T * operator-> () const
 
T & operator* ()
 
T * operator-> ()
 
 operator unspecified_bool_type () const
 
bool operator! () const
 Negation operator. More...
 
void swap (COWIntrusiveReference &rhs)
 

Private Types

typedef COWIntrusiveReference this_type
 

Private Member Functions

void getWriteLock ()
 Create a clone of the COWIntrusiveCountableBase object if there is more than one reference to it. More...
 

Private Attributes

T * m_pObj
 

Friends

template<class U >
class COWIntrusiveReference
 

Detailed Description

template<class T>
class BLOCXX_NAMESPACE::COWIntrusiveReference< T >

COWIntrusiveReference A smart pointer that uses intrusive reference counting.

It supports 'copy on write' functionality. The 'intrusive' in the class names comes from the fact that referenced objects are required to be sub-classes of COWIntrusiveCountableBase. If your looking for a non-intrusive smart smart pointer class that providers copy on write functionality, check out the COWReference class.

This class relies on calls to

 void COWIntrusiveReferenceAddRef(T* p);
 void COWIntrusiveReferenceRelease(T* p);
 bool COWIntrusiveReferenceUnique(T* p);
 T* COWIntrusiveReferenceClone(T* p);

     (p != 0)

The object is responsible for destroying itself.

If you want your class to be managed by COWIntrusiveReference, you can derive it from COWIntrusiveCountableBase, or write your own set of functions.

Definition at line 113 of file COWIntrusiveReference.hpp.

Member Typedef Documentation

◆ element_type

template<class T >
typedef T BLOCXX_NAMESPACE::COWIntrusiveReference< T >::element_type

Definition at line 148 of file COWIntrusiveReference.hpp.

◆ this_type

Definition at line 146 of file COWIntrusiveReference.hpp.

◆ unspecified_bool_type

template<class T >
typedef T* this_type::* BLOCXX_NAMESPACE::COWIntrusiveReference< T >::unspecified_bool_type

Definition at line 311 of file COWIntrusiveReference.hpp.

Constructor & Destructor Documentation

◆ COWIntrusiveReference() [1/4]

Default constructor The underlying object pointer will be NULL.

Definition at line 154 of file COWIntrusiveReference.hpp.

◆ COWIntrusiveReference() [2/4]

template<class T >
BLOCXX_NAMESPACE::COWIntrusiveReference< T >::COWIntrusiveReference ( T *  p,
bool  addRef = true 
)
inline

Construct a COWIntrusiveReference that will contain a pointer to a COWIntrusiveCountableBase object.

Parameters
pA pointer to a COWIntrusiveCountableBase derivative.
addRefIf true the reference count will be incremented before the constructor returns. Otherwise thre reference count is left alone.

Definition at line 164 of file COWIntrusiveReference.hpp.

◆ COWIntrusiveReference() [3/4]

template<class T >
template<class U >
BLOCXX_NAMESPACE::COWIntrusiveReference< T >::COWIntrusiveReference ( COWIntrusiveReference< U > const &  rhs)
inline

Copy constructor.

This takes a COWIntrusiveReference of a type derived from T. This constructor will cause this COWIntrusiveReference object to share the same underlying COWIntrusiveCountableBase pointer with another. This will cause the reference count to get incremented on the underlying object.

Parameters
rhsThe object to copy the COWIntrusiveCountableBase pointer from.

Definition at line 178 of file COWIntrusiveReference.hpp.

◆ COWIntrusiveReference() [4/4]

template<class T >
BLOCXX_NAMESPACE::COWIntrusiveReference< T >::COWIntrusiveReference ( COWIntrusiveReference< T > const &  rhs)
inline

Copy constructor.

This constructor will cause this COWIntrusiveReference object to share the same underlying COWIntrusiveCountableBase pointer with another. This will cause the reference count to get incremented on the underlying object.

Parameters
rhsThe object to copy the COWIntrusiveCountableBase pointer from.

Definition at line 190 of file COWIntrusiveReference.hpp.

◆ ~COWIntrusiveReference()

template<class T >
BLOCXX_NAMESPACE::COWIntrusiveReference< T >::~COWIntrusiveReference ( )
inline

Destroy this COWIntrusiveReference.

If the reference count to the underlying COWIntrusiveCountableBase object is zero after it is decremented in this method it will be deleted.

Definition at line 199 of file COWIntrusiveReference.hpp.

Member Function Documentation

◆ getPtr()

template<class T >
const T* BLOCXX_NAMESPACE::COWIntrusiveReference< T >::getPtr ( ) const
inline
Returns
A read only pointer to the underlying COWIntrusiveCountableBase object.

Definition at line 252 of file COWIntrusiveReference.hpp.

◆ getWriteLock()

template<class T >
void BLOCXX_NAMESPACE::COWIntrusiveReference< T >::getWriteLock ( )
inlineprivate

Create a clone of the COWIntrusiveCountableBase object if there is more than one reference to it.

This method is used to support the copy on write functionality.

Definition at line 345 of file COWIntrusiveReference.hpp.

◆ operator unspecified_bool_type()

template<class T >
BLOCXX_NAMESPACE::COWIntrusiveReference< T >::operator unspecified_bool_type ( ) const
inline

Definition at line 312 of file COWIntrusiveReference.hpp.

◆ operator!()

template<class T >
bool BLOCXX_NAMESPACE::COWIntrusiveReference< T >::operator! ( ) const
inline

Negation operator.

Returns
true if this objects COWIntrusiveCountableBase pointer is NULL.

Definition at line 322 of file COWIntrusiveReference.hpp.

◆ operator*() [1/2]

template<class T >
T& BLOCXX_NAMESPACE::COWIntrusiveReference< T >::operator* ( )
inline
Returns
A read/write reference to the underlying COWIntrusiveCountableBase object.

Definition at line 287 of file COWIntrusiveReference.hpp.

◆ operator*() [2/2]

template<class T >
const T& BLOCXX_NAMESPACE::COWIntrusiveReference< T >::operator* ( ) const
inline
Returns
A read only reference to the underlying COWIntrusiveCountableBase object.

Definition at line 261 of file COWIntrusiveReference.hpp.

◆ operator->() [1/2]

template<class T >
T* BLOCXX_NAMESPACE::COWIntrusiveReference< T >::operator-> ( )
inline
Returns
A read/write pointer to the underlying COWIntrusiveCountableBase object.

Definition at line 301 of file COWIntrusiveReference.hpp.

◆ operator->() [2/2]

template<class T >
const T* BLOCXX_NAMESPACE::COWIntrusiveReference< T >::operator-> ( ) const
inline
Returns
A read only pointer to the underlying COWIntrusiveCountableBase object.

Definition at line 274 of file COWIntrusiveReference.hpp.

◆ operator=() [1/3]

template<class T >
COWIntrusiveReference& BLOCXX_NAMESPACE::COWIntrusiveReference< T >::operator= ( COWIntrusiveReference< T > const &  rhs)
inline

Assignment operator.

This method will cause this COWIntrusiveReference object to share the same underlying COWIntrusiveCountableBase pointer with another. This will cause the reference count to get incremented on the underlying object.

Parameters
rhsThe object to copy the COWIntrusiveCountableBase pointer from.
Returns
A reference to this COWIntrusiveReference object.

Definition at line 230 of file COWIntrusiveReference.hpp.

◆ operator=() [2/3]

template<class T >
template<class U >
COWIntrusiveReference& BLOCXX_NAMESPACE::COWIntrusiveReference< T >::operator= ( COWIntrusiveReference< U > const &  rhs)
inline

Assignment operator that that takes a COWIntrusiveReference of a type derived from T.

This method will cause this COWIntrusiveReference object to share the same underlying COWIntrusiveCountableBase pointer with another. This will cause the reference count to get incremented on the underlying object.

Parameters
rhsThe object to copy the COWIntrusiveCountableBase pointer from.
Returns
A reference to this COWIntrusiveReference object.

Definition at line 215 of file COWIntrusiveReference.hpp.

◆ operator=() [3/3]

template<class T >
COWIntrusiveReference& BLOCXX_NAMESPACE::COWIntrusiveReference< T >::operator= ( T *  rhs)
inline

Assignment operator.

This changes the underlying COWIntrusiveCountableBase pointer to the one passed to this method.

Parameters
rhsA pointer to a COWIntrusiveCountableBase object. this will be the new underlying pointer for this object.
Returns
A reference to this COWIntrusiveReference object.

Definition at line 243 of file COWIntrusiveReference.hpp.

◆ swap()

template<class T >
void BLOCXX_NAMESPACE::COWIntrusiveReference< T >::swap ( COWIntrusiveReference< T > &  rhs)
inline

Definition at line 327 of file COWIntrusiveReference.hpp.

Referenced by BLOCXX_NAMESPACE::String::swap().

Friends And Related Function Documentation

◆ COWIntrusiveReference

template<class T >
template<class U >
friend class COWIntrusiveReference
friend

Definition at line 336 of file COWIntrusiveReference.hpp.

Member Data Documentation

◆ m_pObj

template<class T >
T* BLOCXX_NAMESPACE::COWIntrusiveReference< T >::m_pObj
private

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