opensurgsim
Public Member Functions | List of all members
SurgSim::DataStructures::OptionalValue< T > Class Template Reference

Container class that can indicate whether the object has been assigned a value. More...

#include <OptionalValue.h>

Public Member Functions

 OptionalValue ()
 Default Constructor, no value.
 
 OptionalValue (const T &value)
 Constructor that assigns a value. More...
 
 OptionalValue (const OptionalValue &other)
 Copy constructor. More...
 
bool hasValue () const
 Query if this object has been assigned a value. More...
 
void invalidate ()
 Mark this object as invalid.
 
void setValue (const T &val)
 Set the value of this object, and mark it as valid. More...
 
const T & getValue () const
 Gets the value. More...
 
const T & operator* () const
 Gets the value. More...
 
bool operator== (const OptionalValue< T > &rhs) const
 Equality operator. More...
 
bool operator== (const T &rhs) const
 Equality operator. More...
 
bool operator!= (const OptionalValue< T > &rhs) const
 Inequality operator. More...
 
bool operator!= (const T &rhs) const
 Inequality operator. More...
 
OptionalValueoperator= (const OptionalValue &rhs)
 Assignment operator. More...
 
OptionalValueoperator= (const T &rhs)
 Assignment operator from template type, after this hasValue() is true even if the right hand side was not initialized. More...
 

Detailed Description

template<class T>
class SurgSim::DataStructures::OptionalValue< T >

Container class that can indicate whether the object has been assigned a value.

Template Parameters
Classof the value that this object contains

Constructor & Destructor Documentation

§ OptionalValue() [1/2]

template<class T>
SurgSim::DataStructures::OptionalValue< T >::OptionalValue ( const T &  value)
inlineexplicit

Constructor that assigns a value.

Parameters
valueThe value that should be used.

§ OptionalValue() [2/2]

template<class T>
SurgSim::DataStructures::OptionalValue< T >::OptionalValue ( const OptionalValue< T > &  other)
inline

Copy constructor.

Parameters
otherThe value used for copying.

Member Function Documentation

§ getValue()

template<class T>
const T& SurgSim::DataStructures::OptionalValue< T >::getValue ( ) const
inline

Gets the value.

Exceptions
SurgSim::Framework::AssertionFailureif the value was not set
Returns
The assigned value if set.

§ hasValue()

template<class T>
bool SurgSim::DataStructures::OptionalValue< T >::hasValue ( ) const
inline

Query if this object has been assigned a value.

Returns
true if yes, false if not.

§ operator!=() [1/2]

template<class T>
bool SurgSim::DataStructures::OptionalValue< T >::operator!= ( const OptionalValue< T > &  rhs) const
inline

Inequality operator.

Parameters
rhsthe right hand side.
Returns
true if the parameters are not considered equivalent

§ operator!=() [2/2]

template<class T>
bool SurgSim::DataStructures::OptionalValue< T >::operator!= ( const T &  rhs) const
inline

Inequality operator.

Parameters
rhsthe right hand side.
Returns
true if the parameters are not considered equivalent

§ operator*()

template<class T>
const T& SurgSim::DataStructures::OptionalValue< T >::operator* ( ) const
inline

Gets the value.

Note
do not implement T& operator*(), because *optionalValue = X; would not be able to set the hasValue() property properly.
Exceptions
SurgSim::Framework::AssertionFailureif the value was not set
Returns
the contained value.

§ operator=() [1/2]

template<class T>
OptionalValue& SurgSim::DataStructures::OptionalValue< T >::operator= ( const OptionalValue< T > &  rhs)
inline

Assignment operator.

Parameters
rhsThe right hand side of the operator.
Returns
reference to this.

§ operator=() [2/2]

template<class T>
OptionalValue& SurgSim::DataStructures::OptionalValue< T >::operator= ( const T &  rhs)
inline

Assignment operator from template type, after this hasValue() is true even if the right hand side was not initialized.

Parameters
rhsthe value to be assigned to this optional value
Returns
reference to this.

§ operator==() [1/2]

template<class T>
bool SurgSim::DataStructures::OptionalValue< T >::operator== ( const OptionalValue< T > &  rhs) const
inline

Equality operator.

Parameters
rhsThe right hand side.
Returns
true if the parameters are considered equivalent.

§ operator==() [2/2]

template<class T>
bool SurgSim::DataStructures::OptionalValue< T >::operator== ( const T &  rhs) const
inline

Equality operator.

Parameters
rhsThe right hand side with the specific template type.
Returns
true if the parameters are considered equivalent.

§ setValue()

template<class T>
void SurgSim::DataStructures::OptionalValue< T >::setValue ( const T &  val)
inline

Set the value of this object, and mark it as valid.

Parameters
valThe value of the object

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