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

A class that is used to store a value that may or may not be set. More...

#include <omOptional.h>

Public Member Functions

 Optional ()
 Create an optional object whose value is not set. More...
 
 Optional (const T &newValue)
 Create an optional object with the specified value. More...
 
 Optional (const Optional &other)
 Create a copy of another Optional object. More...
 
 ~Optional ()
 Destroy an Optional object, destroying any value stored within. More...
 
Optionaloperator= (const Optional &other)
 Assign the value of another Optional object to this object. More...
 
 operator T & ()
 Get a reference to the value contained by this Optional object. More...
 
 operator const T & () const
 Get a const reference to the value contained by this Optional object. More...
 
T & get ()
 Get a reference to the value contained by this Optional object. More...
 
const T & get () const
 Get a const reference to the value contained by this Optional object. More...
 
void set (const T &newValue)
 Set the value contained by this Optional object. More...
 
Bool isSet () const
 Return whether or not the optional value is set. More...
 

Detailed Description

template<typename T>
class om::lang::Optional< T >

A class that is used to store a value that may or may not be set.

The Optional class is implemented using a pointer to a value that can be optionally NULL. When setting the value of an Optional object, the provided value is copy-constructed and stored internally. Accessing the contents of an Optional object that does not have a value will result in an assertion being raised.

Constructor & Destructor Documentation

template<typename T>
om::lang::Optional< T >::Optional ( )
inline

Create an optional object whose value is not set.

template<typename T>
om::lang::Optional< T >::Optional ( const T &  newValue)
inline

Create an optional object with the specified value.

Parameters
newValue- the value to use for this Optional object.
template<typename T>
om::lang::Optional< T >::Optional ( const Optional< T > &  other)
inline

Create a copy of another Optional object.

template<typename T>
om::lang::Optional< T >::~Optional ( )
inline

Destroy an Optional object, destroying any value stored within.

Member Function Documentation

template<typename T>
Optional& om::lang::Optional< T >::operator= ( const Optional< T > &  other)
inline

Assign the value of another Optional object to this object.

This method creates a copy of the value stored in the other object.

Parameters
other- the Optional object whose value should be copied.
Returns
a reference to this Optional object to allow assignment chaining.
template<typename T>
om::lang::Optional< T >::operator T & ( )
inline

Get a reference to the value contained by this Optional object.

If the value is not set, a debug assertion is raised.

Returns
a reference to the value contained by this Optional object.
template<typename T>
om::lang::Optional< T >::operator const T & ( ) const
inline

Get a const reference to the value contained by this Optional object.

If the value is not set, a debug assertion is raised.

Returns
a const reference to the value contained by this Optional object.
template<typename T>
T& om::lang::Optional< T >::get ( )
inline

Get a reference to the value contained by this Optional object.

If the value is not set, a debug assertion is raised.

Returns
a reference to the value contained by this Optional object.
template<typename T>
const T& om::lang::Optional< T >::get ( ) const
inline

Get a const reference to the value contained by this Optional object.

If the value is not set, a debug assertion is raised.

Returns
a const reference to the value contained by this Optional object.
template<typename T>
void om::lang::Optional< T >::set ( const T &  newValue)
inline

Set the value contained by this Optional object.

This method replaces any existing value with the new value. isSet() will always return TRUE after this method exits.

Parameters
newValue- the value to which the Optional should be set.
template<typename T>
Bool om::lang::Optional< T >::isSet ( ) const
inline

Return whether or not the optional value is set.

If the value is set, TRUE is returned. Otherwise FALSE is returned.

Returns
whether or not the optional value is set.

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