Om  1.0.0
A universal framework for multimedia simulation
Public Member Functions | Static Public Member Functions | List of all members
om::lang::Shared< T > Class Template Reference

A class that implements a reference-counted thread-safe shared pointer. More...

#include <omShared.h>

Public Member Functions

 Shared ()
 Create a Shared object that is NULL. More...
 
 Shared (T *newShared)
 Create a Shared object that wraps the specified raw pointer. More...
 
template<typename U >
 Shared (U *newShared)
 Create a Shared object that wraps the specified raw pointer of a different type. More...
 
 Shared (const Shared &other)
 Create a copy of the specified Shared object, increasing its reference count by 1. More...
 
template<typename U >
 Shared (const Shared< U > &other)
 Create a copy of the specified Shared object, increasing its reference count by 1. More...
 
Sharedoperator= (const Shared &other)
 Assign the pointer stored by another Shared object to this object. More...
 
template<typename U >
Sharedoperator= (const Shared< U > &other)
 Assign the pointer stored by another Shared object of different templated type to this object. More...
 
 ~Shared ()
 Release this Shared's reference to the object. More...
 
 operator T * () const
 Cast this Shared object to a raw pointer. More...
 
template<typename U >
 operator U * () const
 Cast this Shared object to a raw pointer of a different type to allow polymorphism. More...
 
Bool operator== (const Shared &other) const
 Return whether or not this pointer is equal to another pointer. More...
 
template<typename U >
Bool operator== (const Shared< U > &other) const
 Return whether or not this pointer is equal to another pointer. More...
 
Bool operator!= (const Shared &other) const
 Return whether or not this pointer is not equal to another pointer. More...
 
template<typename U >
Bool operator!= (const Shared< U > &other) const
 Return whether or not this pointer is not equal to another pointer. More...
 
T & operator* () const
 Dereference the object referenced by this Shared. More...
 
T * operator-> () const
 Overload the indirection operator so that this Shared object behaves like a raw pointer. More...
 
T * getPointer () const
 Get a raw pointer to the object that this Shared references. More...
 
Bool isUnique () const
 Return whether or not if the object that this Shared references is not referenced by another Shared. More...
 
Bool isNull () const
 Return whether or not this pointer is equal to NULL. More...
 
Bool isSet () const
 Return whether or not this pointer is not equal to NULL. More...
 
 operator Bool () const
 Cast this pointer to a boolean value, indicating whether or not the pointer is NULL. More...
 
Size getReferenceCount () const
 Get the number of references there are to this Shared's object. More...
 
void release ()
 Release this pointer's reference to its object, resulting in a NULL pointer with 0 reference count. More...
 
template<typename U >
Shared< U > cast () const
 Cast this pointer to the template type using static_cast. More...
 
template<typename U >
Shared< U > dynamicCast () const
 Cast this pointer to the template type using dynamic_cast. More...
 

Static Public Member Functions

static Shared construct ()
 Construct an object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 >
static Shared construct (P1 p1)
 Construct an object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 >
static Shared construct (P1 p1, P2 p2)
 Construct an object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 , typename P3 >
static Shared construct (P1 p1, P2 p2, P3 p3)
 Construct an object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 >
static Shared construct (P1 p1, P2 p2, P3 p3, P4 p4)
 Construct an object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 >
static Shared construct (P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
 Construct an object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6 >
static Shared construct (P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
 Construct an object of the templated type with the specified arguments for its constructor. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6 , typename P7 >
static Shared construct (P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
 Construct an object of the templated type with the specified arguments for its constructor. More...
 

Detailed Description

template<class T>
class om::lang::Shared< T >

A class that implements a reference-counted thread-safe shared pointer.

A shared pointer should be used to encapsulate objects that have a lifetime that is not easily known or that need to be shared by more than one system. The internal pointer is owned by the shared pointer and is destructed and freed when its reference count reaches 0.

An atomic reference count is used to make the pointer thread-safe.

Constructor & Destructor Documentation

template<class T>
om::lang::Shared< T >::Shared ( )
inline

Create a Shared object that is NULL.

template<class T>
om::lang::Shared< T >::Shared ( T *  newShared)
inlineexplicit

Create a Shared object that wraps the specified raw pointer.

If the specified raw pointer is equal to NULL, the reference count for the pointer is set to 0. Otherwise, the reference count for the Shared is 1. By calling this constructor, the user acknowledges that the Shared object now owns the object pointed to by the raw pointer and retains the right to destroy it when the reference count reaches 0.

Parameters
newShared- the raw pointer which this Shared object should wrap.
template<class T>
template<typename U >
om::lang::Shared< T >::Shared ( U *  newShared)
inlineexplicit

Create a Shared object that wraps the specified raw pointer of a different type.

If the specified raw pointer is equal to NULL, the reference count for the pointer is set to 0. Otherwise, the reference count for the Shared is 1. By calling this constructor, the user acknowledges that the Shared object now owns the object pointed to by the raw pointer and retains the right to destroy it when the reference count reaches 0.

Parameters
newShared- the raw pointer which this Shared object should wrap.
template<class T>
om::lang::Shared< T >::Shared ( const Shared< T > &  other)
inline

Create a copy of the specified Shared object, increasing its reference count by 1.

template<class T>
template<typename U >
om::lang::Shared< T >::Shared ( const Shared< U > &  other)
inline

Create a copy of the specified Shared object, increasing its reference count by 1.

template<class T>
om::lang::Shared< T >::~Shared ( )
inline

Release this Shared's reference to the object.

Member Function Documentation

template<class T>
Shared& om::lang::Shared< T >::operator= ( const Shared< T > &  other)
inline

Assign the pointer stored by another Shared object to this object.

The reference count of the old pointer stored in this object is reduced by 1 and the pointer is copied from the other Shared object. The reference count for the new pointer is increased by 1.

Parameters
other- the Shared object whose pointer should be copied.
Returns
a reference to this Shared object to allow assignment chaining.
template<class T>
template<typename U >
Shared& om::lang::Shared< T >::operator= ( const Shared< U > &  other)
inline

Assign the pointer stored by another Shared object of different templated type to this object.

The reference count of the old pointer stored in this object is reduced by 1 and the pointer is copied from the other Shared object. The reference count for the new pointer is increased by 1.

Parameters
other- the Shared object whose pointer should be copied.
Returns
a reference to this Shared object to allow assignment chaining.
template<class T>
om::lang::Shared< T >::operator T * ( ) const
inline

Cast this Shared object to a raw pointer.

template<class T>
template<typename U >
om::lang::Shared< T >::operator U * ( ) const
inline

Cast this Shared object to a raw pointer of a different type to allow polymorphism.

template<class T>
Bool om::lang::Shared< T >::operator== ( const Shared< T > &  other) const
inline

Return whether or not this pointer is equal to another pointer.

This method compares the pointers themselves, not the objects pointed to by the pointers.

Parameters
other- the pointer to compare for equality.
Returns
whether or not this pointer is equal the other.
template<class T>
template<typename U >
Bool om::lang::Shared< T >::operator== ( const Shared< U > &  other) const
inline

Return whether or not this pointer is equal to another pointer.

This method compares the pointers themselves, not the objects pointed to by the pointers.

Parameters
other- the pointer to compare for equality.
Returns
whether or not this pointer is equal the other.
template<class T>
Bool om::lang::Shared< T >::operator!= ( const Shared< T > &  other) const
inline

Return whether or not this pointer is not equal to another pointer.

This method compares the pointers themselves, not the objects pointed to by the pointers.

Parameters
other- the pointer to compare for inequality.
Returns
whether or not this pointer is not equal the other.
template<class T>
template<typename U >
Bool om::lang::Shared< T >::operator!= ( const Shared< U > &  other) const
inline

Return whether or not this pointer is not equal to another pointer.

This method compares the pointers themselves, not the objects pointed to by the pointers.

Parameters
other- the pointer to compare for inequality.
Returns
whether or not this pointer is not equal the other.
template<class T>
T& om::lang::Shared< T >::operator* ( ) const
inline

Dereference the object referenced by this Shared.

If the pointer is NULL, a debug assertion is raised.

Returns
a reference to the object that this Shared has a reference to.
template<class T>
T* om::lang::Shared< T >::operator-> ( ) const
inline

Overload the indirection operator so that this Shared object behaves like a raw pointer.

If the pointer is NULL, a debug assertion is raised.

Returns
the raw pointer that this Shared object has a reference to.
template<class T>
T* om::lang::Shared< T >::getPointer ( ) const
inline

Get a raw pointer to the object that this Shared references.

template<class T>
Bool om::lang::Shared< T >::isUnique ( ) const
inline

Return whether or not if the object that this Shared references is not referenced by another Shared.

The method returns TRUE if the reference count for the Shared is 1 or if the pointer is equal to NULL.

Returns
whether or not the reference count for the Shared is equal to 1.
template<class T>
Bool om::lang::Shared< T >::isNull ( ) const
inline

Return whether or not this pointer is equal to NULL.

template<class T>
Bool om::lang::Shared< T >::isSet ( ) const
inline

Return whether or not this pointer is not equal to NULL.

template<class T>
om::lang::Shared< T >::operator Bool ( ) const
inline

Cast this pointer to a boolean value, indicating whether or not the pointer is NULL.

template<class T>
Size om::lang::Shared< T >::getReferenceCount ( ) const
inline

Get the number of references there are to this Shared's object.

template<class T>
void om::lang::Shared< T >::release ( )
inline

Release this pointer's reference to its object, resulting in a NULL pointer with 0 reference count.

template<class T>
template<typename U >
Shared<U> om::lang::Shared< T >::cast ( ) const
inline

Cast this pointer to the template type using static_cast.

template<class T>
template<typename U >
Shared<U> om::lang::Shared< T >::dynamicCast ( ) const
inline

Cast this pointer to the template type using dynamic_cast.

If the cast was invalid and not able to performed, a NULL pointer is returned.

template<class T>
static Shared om::lang::Shared< T >::construct ( )
inlinestatic

Construct an object of the templated type with the specified arguments for its constructor.

template<class T>
template<typename P1 >
static Shared om::lang::Shared< T >::construct ( P1  p1)
inlinestatic

Construct an object of the templated type with the specified arguments for its constructor.

template<class T>
template<typename P1 , typename P2 >
static Shared om::lang::Shared< T >::construct ( P1  p1,
P2  p2 
)
inlinestatic

Construct an object of the templated type with the specified arguments for its constructor.

template<class T>
template<typename P1 , typename P2 , typename P3 >
static Shared om::lang::Shared< T >::construct ( P1  p1,
P2  p2,
P3  p3 
)
inlinestatic

Construct an object of the templated type with the specified arguments for its constructor.

template<class T>
template<typename P1 , typename P2 , typename P3 , typename P4 >
static Shared om::lang::Shared< T >::construct ( P1  p1,
P2  p2,
P3  p3,
P4  p4 
)
inlinestatic

Construct an object of the templated type with the specified arguments for its constructor.

template<class T>
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 >
static Shared om::lang::Shared< T >::construct ( P1  p1,
P2  p2,
P3  p3,
P4  p4,
P5  p5 
)
inlinestatic

Construct an object of the templated type with the specified arguments for its constructor.

template<class T>
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6 >
static Shared om::lang::Shared< T >::construct ( P1  p1,
P2  p2,
P3  p3,
P4  p4,
P5  p5,
P6  p6 
)
inlinestatic

Construct an object of the templated type with the specified arguments for its constructor.

template<class T>
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6 , typename P7 >
static Shared om::lang::Shared< T >::construct ( P1  p1,
P2  p2,
P3  p3,
P4  p4,
P5  p5,
P6  p6,
P7  p7 
)
inlinestatic

Construct an object of the templated type with the specified arguments for its constructor.


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