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

A class that implements a unique pointer that has a single owner. More...

#include <omUnique.h>

Public Member Functions

 Unique ()
 Create a unique pointer object that is NULL. More...
 
 Unique (T *newPointer)
 Create a unique pointer object that wraps the specified raw pointer. More...
 
template<typename U >
 Unique (U *newPointer)
 Create a unique pointer object that wraps the specified raw pointer of a different type. More...
 
 ~Unique ()
 Release this Unique's reference to the object. More...
 
 operator T * () const
 Cast this Unique object to a raw pointer. More...
 
template<typename U >
 operator U * () const
 Cast this Unique object to a raw pointer of a different type to allow polymorphism. More...
 
Bool operator== (const Unique &other) const
 Return whether or not this pointer is equal to another pointer. More...
 
template<typename U >
Bool operator== (const Unique< U > &other) const
 Return whether or not this pointer is equal to another pointer. More...
 
Bool operator!= (const Unique &other) const
 Return whether or not this pointer is not equal to another pointer. More...
 
template<typename U >
Bool operator!= (const Unique< 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 Unique. More...
 
T * operator-> () const
 Overload the indirection operator so that this Unique object behaves like a raw pointer. More...
 
T * getPointer () const
 Return a raw pointer to the object that this unique pointer references. 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...
 
void release ()
 Destruct this pointer's object, resulting in a NULL unique pointer. More...
 
void move (Unique< T > &unique)
 Transfer the ownership of this unique pointer to another one. More...
 
template<typename U >
U * cast () const
 Cast this pointer to the template type using static_cast. More...
 
template<typename U >
U * dynamicCast () const
 Cast this pointer to the template type using dynamic_cast. More...
 

Detailed Description

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

A class that implements a unique pointer that has a single owner.

A unique pointer is used to encapsulate objects that should be allocated on the heap and have definite lifetime determined by a single owner. The object pointed to by the unique pointer is destructed when the unique pointer is destroyed. The unique pointer cannot be directly copied, since that would violate the semantics. The unique pointer does not add any overhead over a raw pointer.

Constructor & Destructor Documentation

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

Create a unique pointer object that is NULL.

template<class T >
om::lang::Unique< T >::Unique ( T *  newPointer)
inlineexplicit

Create a unique pointer object that wraps the specified raw pointer.

By calling this constructor, the user acknowledges that the Unique object now owns the object pointed to by the raw pointer and will destroy it when the unique pointer object is destroyed.

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

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

By calling this constructor, the user acknowledges that the Unique object now owns the object pointed to by the raw pointer and will destroy it when the unique pointer object is destroyed.

Parameters
newPointer- the raw pointer which this Unique object should wrap.
template<class T >
om::lang::Unique< T >::~Unique ( )
inline

Release this Unique's reference to the object.

Member Function Documentation

template<class T >
om::lang::Unique< T >::operator T * ( ) const
inline

Cast this Unique object to a raw pointer.

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

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

template<class T >
Bool om::lang::Unique< T >::operator== ( const Unique< 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::Unique< T >::operator== ( const Unique< 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::Unique< T >::operator!= ( const Unique< 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::Unique< T >::operator!= ( const Unique< 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::Unique< T >::operator* ( ) const
inline

Dereference the object referenced by this Unique.

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

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

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

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

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

Return a raw pointer to the object that this unique pointer references.

template<class T >
Bool om::lang::Unique< T >::isNull ( ) const
inline

Return whether or not this pointer is equal to NULL.

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

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

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

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

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

Destruct this pointer's object, resulting in a NULL unique pointer.

template<class T >
void om::lang::Unique< T >::move ( Unique< T > &  unique)
inline

Transfer the ownership of this unique pointer to another one.

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

Cast this pointer to the template type using static_cast.

template<class T >
template<typename U >
U* om::lang::Unique< 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.


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