SurgSim::DataStructures::OptionalValue< T > Class Template Reference

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

`#include <SurgSim/DataStructures/OptionalValue.h>`

## Public Member Functions

| OptionalValue ()
| Default Constructor, no value. More...
| 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. More...
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...
OptionalValue & | operator= (const OptionalValue &rhs)
| Assignment operator. More...
OptionalValue & | operator= (const T &rhs)
| Assignment operator from template type, after this hasValue() is true even if the right hand side was not initialized. More...

## Private Attributes

bool | m_hasValue
T | m_value

## 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

  Class | of the value that this object contains

## Constructor & Destructor Documentation

## OptionalValue() [1/3]

template<class T>

SurgSim::DataStructures::OptionalValue< T >::OptionalValue | ( |  | ) |

inline

Default Constructor, no value.

## OptionalValue() [2/3]

template<class T>

SurgSim::DataStructures::OptionalValue< T >::OptionalValue | ( | const T & | value | ) |

inline explicit

Constructor that assigns a value.

Parameters

  value | The value that should be used.

## OptionalValue() [3/3]

template<class T>

SurgSim::DataStructures::OptionalValue< T >::OptionalValue | ( | const OptionalValue< T > & | other | ) |

inline

Copy constructor.

Parameters

  other | The 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::AssertionFailure | if 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.

## invalidate()

template<class T>

void SurgSim::DataStructures::OptionalValue< T >::invalidate | ( |  | ) |

inline

Mark this object as invalid.

## operator!=() [1/2]

template<class T>

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

inline

Inequality operator.

Parameters

  rhs | the 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

  rhs | the 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::AssertionFailure | if 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

  rhs | The 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

  rhs | the 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

  rhs | The 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

  rhs | The 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

  val | The value of the object

## Member Data Documentation

## m_hasValue

template<class T>

bool SurgSim::DataStructures::OptionalValue< T >::m_hasValue

private

## m_value

template<class T>

T SurgSim::DataStructures::OptionalValue< T >::m_value

private

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

- SurgSim/DataStructures/OptionalValue.h