activemq-cpp-3.6.0
decaf::lang::Pointer< T, REFCOUNTER > Class Template Reference

Decaf's implementation of a Smart Pointer that is a template on a Type and is Thread Safe if the default Reference Counter is used. More...

#include <src/main/decaf/lang/Pointer.h>

Public Types

typedef T * PointerType
typedef T & ReferenceType
typedef REFCOUNTER CounterType

Public Member Functions

 Pointer ()
 Default Constructor.
 Pointer (const PointerType value)
 Explicit Constructor, creates a Pointer that contains value with a single reference.
 Pointer (const Pointer &value)
 Copy constructor.
template<typename T1 , typename R1 >
 Pointer (const Pointer< T1, R1 > &value)
 Copy constructor.
template<typename T1 , typename R1 >
 Pointer (const Pointer< T1, R1 > &value, const STATIC_CAST_TOKEN &)
 Static Cast constructor.
template<typename T1 , typename R1 >
 Pointer (const Pointer< T1, R1 > &value, const DYNAMIC_CAST_TOKEN &)
 Dynamic Cast constructor.
virtual ~Pointer ()
void reset (T *value=NULL)
 Resets the Pointer to hold the new value.
T * release ()
 Releases the Pointer held and resets the internal pointer value to Null.
PointerType get () const
 Gets the real pointer that is contained within this Pointer.
void swap (Pointer &value)
 Exception Safe Swap Function.
Pointeroperator= (const Pointer &right)
 Assigns the value of right to this Pointer and increments the reference Count.
template<typename T1 , typename R1 >
Pointeroperator= (const Pointer< T1, R1 > &right)
ReferenceType operator* ()
 Dereference Operator, returns a reference to the Contained value.
ReferenceType operator* () const
PointerType operator-> ()
 Indirection Operator, returns a pointer to the Contained value.
PointerType operator-> () const
bool operator! () const
template<typename T1 , typename R1 >
bool operator== (const Pointer< T1, R1 > &right) const
template<typename T1 , typename R1 >
bool operator!= (const Pointer< T1, R1 > &right) const
template<typename T1 >
Pointer< T1, CounterTypedynamicCast () const
template<typename T1 >
Pointer< T1, CounterTypestaticCast () const

Friends

bool operator== (const Pointer &left, const T *right)
bool operator== (const T *left, const Pointer &right)
bool operator!= (const Pointer &left, const T *right)
bool operator!= (const T *left, const Pointer &right)

Detailed Description

template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
class decaf::lang::Pointer< T, REFCOUNTER >

Decaf's implementation of a Smart Pointer that is a template on a Type and is Thread Safe if the default Reference Counter is used.

This Pointer type allows for the substitution of different Reference Counter implementations which provide a means of using invasive reference counting if desired using a custom implementation of ReferenceCounter.

The Decaf smart pointer provide comparison operators for comparing Pointer instances in the same manner as normal pointer, except that it does not provide an overload of operators ( <, <=, >, >= ). To allow use of a Pointer in a STL container that requires it, Pointer provides an implementation of std::less.

Since
1.0

Member Typedef Documentation

template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
typedef REFCOUNTER decaf::lang::Pointer< T, REFCOUNTER >::CounterType
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
typedef T* decaf::lang::Pointer< T, REFCOUNTER >::PointerType
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
typedef T& decaf::lang::Pointer< T, REFCOUNTER >::ReferenceType

Constructor & Destructor Documentation

template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
decaf::lang::Pointer< T, REFCOUNTER >::Pointer ( )
inline

Default Constructor.

Initialized the contained pointer to NULL, using the -> operator results in an exception unless reset to contain a real value.

Referenced by decaf::lang::Pointer< TransactionId >::reset().

template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
decaf::lang::Pointer< T, REFCOUNTER >::Pointer ( const PointerType  value)
inlineexplicit

Explicit Constructor, creates a Pointer that contains value with a single reference.

This object now has ownership until a call to release.

Parameters
value- The instance of the type we are containing here.
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
decaf::lang::Pointer< T, REFCOUNTER >::Pointer ( const Pointer< T, REFCOUNTER > &  value)
inline

Copy constructor.

Copies the value contained in the pointer to the new instance and increments the reference counter.

Parameters
valueAnother instance of a Pointer<T> that this Pointer will copy.
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
template<typename T1 , typename R1 >
decaf::lang::Pointer< T, REFCOUNTER >::Pointer ( const Pointer< T1, R1 > &  value)
inline

Copy constructor.

Copies the value contained in the pointer to the new instance and increments the reference counter.

Parameters
valueA different but compatible Pointer instance that this Pointer will copy.
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
template<typename T1 , typename R1 >
decaf::lang::Pointer< T, REFCOUNTER >::Pointer ( const Pointer< T1, R1 > &  value,
const STATIC_CAST_TOKEN  
)
inline

Static Cast constructor.

Copies the value contained in the pointer to the new instance and increments the reference counter performing a static cast on the value contained in the source Pointer object.

Parameters
valuePointer instance to cast to this type using a static_cast.
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
template<typename T1 , typename R1 >
decaf::lang::Pointer< T, REFCOUNTER >::Pointer ( const Pointer< T1, R1 > &  value,
const DYNAMIC_CAST_TOKEN  
)
inline

Dynamic Cast constructor.

Copies the value contained in the pointer to the new instance and increments the reference counter performing a dynamic cast on the value contained in the source Pointer object. If the cast fails and return NULL then this method throws a ClassCastException.

Parameters
valuePointer instance to cast to this type using a dynamic_cast.
Exceptions
ClassCastExceptionif the dynamic cast returns NULL
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
virtual decaf::lang::Pointer< T, REFCOUNTER >::~Pointer ( )
inlinevirtual

Member Function Documentation

template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
template<typename T1 >
Pointer<T1, CounterType> decaf::lang::Pointer< T, REFCOUNTER >::dynamicCast ( ) const
inline
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
PointerType decaf::lang::Pointer< T, REFCOUNTER >::get ( ) const
inline

Gets the real pointer that is contained within this Pointer.

This is not really safe since the caller could delete or alter the pointer but it mimics the STL auto_ptr and gives access in cases where the caller absolutely needs the real Pointer. Use at your own risk.

Returns
the contained pointer.

Referenced by activemq::commands::ActiveMQMessageTemplate< cms::ObjectMessage >::equals(), activemq::state::ConnectionState::getTransactionState(), decaf::lang::Pointer< TransactionId >::operator!=(), decaf::lang::operator!=(), std::less< decaf::lang::Pointer< T > >::operator()(), decaf::lang::Pointer< TransactionId >::operator==(), decaf::lang::operator==(), decaf::util::concurrent::LinkedBlockingQueue< Pointer< Transport > >::peek(), and decaf::util::concurrent::ExecutorService::submit().

template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
bool decaf::lang::Pointer< T, REFCOUNTER >::operator! ( ) const
inline
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
template<typename T1 , typename R1 >
bool decaf::lang::Pointer< T, REFCOUNTER >::operator!= ( const Pointer< T1, R1 > &  right) const
inline
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
ReferenceType decaf::lang::Pointer< T, REFCOUNTER >::operator* ( )
inline

Dereference Operator, returns a reference to the Contained value.

This method throws an NullPointerException if the contained value is NULL.

Returns
reference to the contained pointer.
Exceptions
NullPointerExceptionif the contained value is Null
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
ReferenceType decaf::lang::Pointer< T, REFCOUNTER >::operator* ( ) const
inline
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
PointerType decaf::lang::Pointer< T, REFCOUNTER >::operator-> ( )
inline

Indirection Operator, returns a pointer to the Contained value.

This method throws an NullPointerException if the contained value is NULL.

Returns
reference to the contained pointer.
Exceptions
NullPointerExceptionif the contained value is Null
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
PointerType decaf::lang::Pointer< T, REFCOUNTER >::operator-> ( ) const
inline
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
Pointer& decaf::lang::Pointer< T, REFCOUNTER >::operator= ( const Pointer< T, REFCOUNTER > &  right)
inline

Assigns the value of right to this Pointer and increments the reference Count.

Parameters
right- Pointer on the right hand side of an operator= call to this.
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
template<typename T1 , typename R1 >
Pointer& decaf::lang::Pointer< T, REFCOUNTER >::operator= ( const Pointer< T1, R1 > &  right)
inline
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
template<typename T1 , typename R1 >
bool decaf::lang::Pointer< T, REFCOUNTER >::operator== ( const Pointer< T1, R1 > &  right) const
inline
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
T* decaf::lang::Pointer< T, REFCOUNTER >::release ( )
inline

Releases the Pointer held and resets the internal pointer value to Null.

This method is not guaranteed to be safe if the Pointer is held by more than one object or this method is called from more than one thread.

Returns
The pointer instance that was held by this Pointer object, the pointer is no longer owned by this Pointer and won't be freed when this Pointer goes out of scope.

Referenced by decaf::lang::Pointer< TransactionId >::Pointer(), and decaf::util::concurrent::ExecutorService::submit().

template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
void decaf::lang::Pointer< T, REFCOUNTER >::reset ( T *  value = NULL)
inline

Resets the Pointer to hold the new value.

Before the new value is stored reset checks if the old value should be destroyed and if so calls delete. Call reset with a value of NULL is supported and acts to set this Pointer to a NULL pointer.

Parameters
valueThe new value to contain or NULL to empty the pointer (default NULL if not set).

Referenced by decaf::util::concurrent::CopyOnWriteArrayList< E >::CopyOnWriteArrayList(), decaf::util::StlMap< std::string, cms::Topic * >::entrySet(), decaf::util::HashMap< K, V, HASHCODE >::entrySet(), decaf::util::concurrent::ConcurrentStlMap< Pointer< ProducerId >, Pointer< ProducerState >, ProducerId::COMPARATOR >::entrySet(), decaf::util::StlMap< std::string, cms::Topic * >::keySet(), decaf::util::HashMap< K, V, HASHCODE >::keySet(), decaf::util::concurrent::ConcurrentStlMap< Pointer< ProducerId >, Pointer< ProducerState >, ProducerId::COMPARATOR >::keySet(), decaf::util::concurrent::CopyOnWriteArrayList< E >::removeAll(), decaf::util::concurrent::CopyOnWriteArrayList< E >::removeAt(), decaf::util::concurrent::CopyOnWriteArrayList< E >::retainAll(), decaf::util::StlMap< std::string, cms::Topic * >::values(), decaf::util::HashMap< K, V, HASHCODE >::values(), decaf::util::concurrent::ConcurrentStlMap< Pointer< ProducerId >, Pointer< ProducerState >, ProducerId::COMPARATOR >::values(), decaf::util::concurrent::CopyOnWriteArrayList< E >::ArrayListIterator::~ArrayListIterator(), and decaf::util::concurrent::CopyOnWriteArrayList< E >::~CopyOnWriteArrayList().

template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
template<typename T1 >
Pointer<T1, CounterType> decaf::lang::Pointer< T, REFCOUNTER >::staticCast ( ) const
inline

Friends And Related Function Documentation

template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
bool operator!= ( const Pointer< T, REFCOUNTER > &  left,
const T *  right 
)
friend
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
bool operator!= ( const T *  left,
const Pointer< T, REFCOUNTER > &  right 
)
friend
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
bool operator== ( const Pointer< T, REFCOUNTER > &  left,
const T *  right 
)
friend
template<typename T, typename REFCOUNTER = decaf::util::concurrent::atomic::AtomicRefCounter>
bool operator== ( const T *  left,
const Pointer< T, REFCOUNTER > &  right 
)
friend

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