AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Member Functions | List of all members
alexaClientSDK::avsCommon::utils::Optional< ValueT > Class Template Reference

#include <Optional.h>

Public Member Functions

 Optional ()
 
 Optional (const ValueT &value)
 
 Optional (const Optional< ValueT > &other)
 
void set (const ValueT &value)
 
void reset ()
 
bool hasValue () const
 
ValueT valueOr (const ValueT &other) const
 
ValueT value () const
 
 ~Optional ()
 
Optional< ValueT > & operator= (const Optional< ValueT > &rhs)
 
bool operator== (const Optional< ValueT > &rhs) const
 
bool operator!= (const Optional< ValueT > &rhs) const
 
Comparison operators.

Compare the current optional object against a second optional.

Parameters
rhsThe object to compare against this.
Returns
true if the comparison holds; false otherwise.
bool operator< (const Optional &rhs) const
 
bool operator> (const Optional &rhs) const
 
bool operator<= (const Optional &rhs) const
 
bool operator>= (const Optional &rhs) const
 

Detailed Description

template<typename ValueT>
class alexaClientSDK::avsCommon::utils::Optional< ValueT >

Auxiliary class that implements an optional object, where the value may or may not be present.

Note
ValueT MUST have a copy constructor.
Method value() is available only for ValueT types that have a default constructor.
Warning
This class is not thread-safe.

Constructor & Destructor Documentation

◆ Optional() [1/3]

template<typename ValueT >
alexaClientSDK::avsCommon::utils::Optional< ValueT >::Optional ( )

Creates an optional object with no valid value.

◆ Optional() [2/3]

template<typename ValueT>
alexaClientSDK::avsCommon::utils::Optional< ValueT >::Optional ( const ValueT &  value)

Creates an optional object with a valid value.

Parameters
valueObject used to initialize the new optional value.
Note
This method required ValueT to have a copy constructor is available.

◆ Optional() [3/3]

template<typename ValueT>
alexaClientSDK::avsCommon::utils::Optional< ValueT >::Optional ( const Optional< ValueT > &  other)

Copy constructor.

Parameters
otherObject used to initialize the new optional object.

◆ ~Optional()

template<typename ValueT >
alexaClientSDK::avsCommon::utils::Optional< ValueT >::~Optional ( )

Optional destructor.

Member Function Documentation

◆ hasValue()

template<typename ValueT >
bool alexaClientSDK::avsCommon::utils::Optional< ValueT >::hasValue ( ) const

Checks whether the optional contains a value or not.

Returns
true if it contains a value, false if it does not contain a value.

◆ operator!=()

template<typename ValueT>
bool alexaClientSDK::avsCommon::utils::Optional< ValueT >::operator!= ( const Optional< ValueT > &  rhs) const

Inequality operator.

Parameters
rhsThe object to compare *this against.
Returns
true if only one object holds a value, and false if both objects don't hold a value. If both optionals hold valid values, return the result of operator!= for their values.

◆ operator<()

template<typename ValueT >
bool alexaClientSDK::avsCommon::utils::Optional< ValueT >::operator< ( const Optional< ValueT > &  rhs) const

◆ operator<=()

template<typename ValueT >
bool alexaClientSDK::avsCommon::utils::Optional< ValueT >::operator<= ( const Optional< ValueT > &  rhs) const

◆ operator=()

template<typename ValueT>
Optional< ValueT > & alexaClientSDK::avsCommon::utils::Optional< ValueT >::operator= ( const Optional< ValueT > &  rhs)

Assignment operator.

Parameters
rhsThe optional object source of the assignment.
Returns
A reference to *this.

◆ operator==()

template<typename ValueT>
bool alexaClientSDK::avsCommon::utils::Optional< ValueT >::operator== ( const Optional< ValueT > &  rhs) const

Equality operator.

Parameters
rhsThe object to compare *this against.
Returns
true if both objects don't hold a value, and false if only one object holds a value. If both optionals hold valid values, return the result of operator== for their values.

◆ operator>()

template<typename ValueT >
bool alexaClientSDK::avsCommon::utils::Optional< ValueT >::operator> ( const Optional< ValueT > &  rhs) const

◆ operator>=()

template<typename ValueT >
bool alexaClientSDK::avsCommon::utils::Optional< ValueT >::operator>= ( const Optional< ValueT > &  rhs) const

◆ reset()

template<typename ValueT >
void alexaClientSDK::avsCommon::utils::Optional< ValueT >::reset ( )

Modifies the optional object so it no longer holds any valid value.

◆ set()

template<typename ValueT>
void alexaClientSDK::avsCommon::utils::Optional< ValueT >::set ( const ValueT &  value)

Sets optional value to the given ValueT.

Parameters
valueObject that will be assigned to the optional value.
Note
ValueT MUST have an assignment operator defined.

◆ value()

template<typename ValueT >
ValueT alexaClientSDK::avsCommon::utils::Optional< ValueT >::value ( ) const

Gets the value if present or return other. ValueT must have a default constructor.

Returns
The object being held by this if m_object is valid; otherwise, return ValueT().

◆ valueOr()

template<typename ValueT>
ValueT alexaClientSDK::avsCommon::utils::Optional< ValueT >::valueOr ( const ValueT &  other) const

Gets the value if present or return other. ValueT must have a copy constructor.

Parameters
otherObject that will be returned if this optional does not hold a value.
Returns
This optional value if *this has a value; otherwise, return other.

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

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0