PCL
pcl::Optional< T > Class Template Reference

An object that can be in a defined or undefined state. More...

#include <Optional.h>

+ Inheritance diagram for pcl::Optional< T >:

Public Member Functions

 Optional ()
 
 Optional (const Optional &)=default
 
 Optional (const T &value)
 
bool IsDefined () const
 
 operator const T & () const
 
const T & operator() () const
 
bool operator< (const Optional &x) const
 
bool operator< (const T &value) const
 
Optionaloperator= (const Optional &x)
 
Optionaloperator= (Optional &&x)
 
Optionaloperator= (const T &value)
 
bool operator== (const Optional &x) const
 
bool operator== (const T &value) const
 
const T & OrElse (const T &value) const
 
template<class E >
const T & OrElseThrow (const Exception &exception) const
 
const T & OrElseThrow (const String &message) const
 
void Undefine ()
 

Detailed Description

template<class T>
class pcl::Optional< T >

Optional stores an instance of the template argument T along with a defined state Boolean flag. Optional objects update their defined state automatically as they are created, copied and assigned.

This class is useful to deal with objects that can be defined optionally, when it is inconvenient to manage the object's value and its defined state as two separate items. Optional offers the power of encapsulation in object-oriented languages to solve these problems efficiently.

Definition at line 81 of file Optional.h.

Constructor & Destructor Documentation

◆ Optional() [1/3]

template<class T>
pcl::Optional< T >::Optional ( )
inline

Constructs an undefined Optional object.

The value instance will be default-constructed implicitly, which means that the type T must provide valid default construction semantics.

Definition at line 91 of file Optional.h.

◆ Optional() [2/3]

template<class T>
pcl::Optional< T >::Optional ( const Optional< T > &  )
default

Copy constructor.

The value instance will be copy-constructed implicitly, which means that the type T must provide valid copy construction semantics if this constructor is invoked.

◆ Optional() [3/3]

template<class T>
pcl::Optional< T >::Optional ( const T &  value)
inline

Constructs a defined Optional object with the specified value.

Definition at line 113 of file Optional.h.

Member Function Documentation

◆ IsDefined()

template<class T>
bool pcl::Optional< T >::IsDefined ( ) const
inline

Returns true if this Optional object has been defined.

Definition at line 180 of file Optional.h.

◆ operator const T &()

template<class T>
pcl::Optional< T >::operator const T & ( ) const
inline

Type conversion operator. Returns a reference to the value stored in this Optional object.

If this object is undefined, the returned value may be unpredictable, depending on construction semantics for the type T.

Definition at line 158 of file Optional.h.

◆ operator()()

template<class T>
const T& pcl::Optional< T >::operator() ( ) const
inline

Returns a reference to the value stored in this Optional object.

If this object is undefined, the returned value may be unpredictable, depending on construction semantics for the type T.

This function performs the same role as operator const T&(). It is required for cases where an automatic type conversion is not applicable.

Definition at line 172 of file Optional.h.

◆ operator<() [1/2]

template<class T>
bool pcl::Optional< T >::operator< ( const Optional< T > &  x) const
inline

Less than relational operator. Returns true iff this object has been defined and either x has not been defined (defined objects always precede undefined ones), or the value in this object precedes the value in x.

Definition at line 256 of file Optional.h.

◆ operator<() [2/2]

template<class T>
bool pcl::Optional< T >::operator< ( const T &  value) const
inline

Less-than-value relational operator. Returns true iff this object has been defined and its value precedes the specified value.

Definition at line 265 of file Optional.h.

◆ operator=() [1/3]

template<class T>
Optional& pcl::Optional< T >::operator= ( const Optional< T > &  x)
inline

Copy assignment operator. Returns a reference to this object.

Definition at line 122 of file Optional.h.

◆ operator=() [2/3]

template<class T>
Optional& pcl::Optional< T >::operator= ( Optional< T > &&  x)
inline

Move assignment operator. Returns a reference to this object.

Definition at line 132 of file Optional.h.

◆ operator=() [3/3]

template<class T>
Optional& pcl::Optional< T >::operator= ( const T &  value)
inline

Assigns the specified value to this object. Returns a reference to this object. After assigning a value, an Optional object will be in defined state.

Definition at line 144 of file Optional.h.

◆ operator==() [1/2]

template<class T>
bool pcl::Optional< T >::operator== ( const Optional< T > &  x) const
inline

Equality operator. Returns true iff one of the following condition holds:

  • This object has been defined, x has been defined, and the value in this object equals the value in x.
  • Neither this object nor x have been defined.

Definition at line 236 of file Optional.h.

◆ operator==() [2/2]

template<class T>
bool pcl::Optional< T >::operator== ( const T &  value) const
inline

Value equality operator. Returns true iff this object has been defined and its value equals the specified value.

Definition at line 245 of file Optional.h.

◆ OrElse()

template<class T>
const T& pcl::Optional< T >::OrElse ( const T &  value) const
inline

Returns the value stored in this object if it has been defined. Otherwise returns the specified value.

Definition at line 200 of file Optional.h.

◆ OrElseThrow() [1/2]

template<class T>
template<class E >
const T& pcl::Optional< T >::OrElseThrow ( const Exception exception) const
inline

Returns the value stored in this object if it has been defined. Otherwise throws the specified exception.

Definition at line 210 of file Optional.h.

◆ OrElseThrow() [2/2]

template<class T>
const T& pcl::Optional< T >::OrElseThrow ( const String message) const
inline

Returns the value stored in this object if it has been defined. Otherwise throws an Error exception with the specified message.

Definition at line 221 of file Optional.h.

◆ Undefine()

template<class T>
void pcl::Optional< T >::Undefine ( )
inline

Undefines this Optional object. Assigns a default-constructed object of type T to the value of this object, and sets the internal defined flag to false.

Definition at line 190 of file Optional.h.


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