RTI Connext Modern C++ API Version 7.2.0
|
<<value-type>> Represents an object that may not contain a valid value More...
#include <dds/core/Optional.hpp>
Public Member Functions | |
optional () OMG_NOEXCEPT | |
Create an unset optional object. More... | |
optional (const T &value) | |
Create an optional object with a copy of a value. More... | |
optional (T &&value) | |
<<C++11>> Create an optional object moving a value More... | |
optional (bool condition, const T &value) | |
Create an optional member conditionally set or unset. More... | |
optional (bool condition, T &&value) | |
<<C++11>> Creates an optional member conditionally set or unset by moving a value. More... | |
~optional () | |
Destroys the underlying object if it exists. More... | |
void | set (const T &value) |
Assigns a copy of an object. More... | |
void | set (T &&value) |
<<C++11>> Assigns an object by moving it More... | |
bool | is_set () const OMG_NOEXCEPT |
Checks if this optional instance contains a valid object. More... | |
bool | has_value () const OMG_NOEXCEPT |
Checks if this optional instance contains a valid object. More... | |
operator bool () const OMG_NOEXCEPT | |
<<C++11>> Returns has_value() More... | |
void | reset () |
Destroys the underlying object and leaves this optional with an invalid (unset) value. More... | |
const T & | value () const |
Retrieves the underlying object if it exists. More... | |
T & | value () |
Retrieves the underlying object if it exists. More... | |
const T & | get () const |
Retrieves the underlying object if it exists. More... | |
T & | get () |
Retrieves the underlying object if it exists. More... | |
const T * | get_ptr () const |
Returns &get() if the object is initialized or NULL otherwise. More... | |
T * | get_ptr () |
Returns &get() if the object is initialized or NULL otherwise. More... | |
const T & | operator* () const |
T & | operator* () |
const T * | operator-> () const |
T * | operator-> () |
optional< T > & | operator= (const optional< T > &other) |
Assignment operator. More... | |
optional< T > & | operator= (optional< T > &&other) OMG_NOEXCEPT |
<<C++11>> Move-assignment operator More... | |
optional< T > & | operator= (const T &value) |
Assign a (valid) value. More... | |
optional< T > & | operator= (T &&value) |
Assign a (valid) value by moving an object. More... | |
Friends | |
void | swap (optional< T > &left, optional< T > &right) OMG_NOEXCEPT |
Swaps the underlying objects. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T > | |
bool | operator== (const optional< T > &a, const optional< T > &b) |
Compares two optional values. More... | |
template<typename T > | |
bool | operator!= (const optional< T > &a, const optional< T > &b) |
Compares two optional values. More... | |
template<typename T > | |
bool | operator== (const optional< T > &optional_value, const T &value) |
Compares an optional member and a value of the underlying type. More... | |
template<typename T > | |
bool | operator== (const T &value, const optional< T > &optional_value) |
Compares an optional member and a value of the underlying type. More... | |
template<typename T > | |
bool | operator!= (const optional< T > &optional_value, const T &value) |
Compares an optional member and a value of the underlying type. More... | |
template<typename T > | |
bool | operator!= (const T &value, const optional< T > &optional_value) |
Compares an optional member and a value of the underlying type. More... | |
template<typename T > | |
std::ostream & | operator<< (std::ostream &out, const optional< T > &optional) |
Applies operator<< to *optional or to the string "NULL" if !optional.has_value() . More... | |
<<value-type>> Represents an object that may not contain a valid value
T | The type of the actual object this optional<T> wraps |
Members of an IDL type marked with the @optional
tag map to this C++ type.
When an optional value has a valid value has_value() returns true and operator*
returns a reference to the actual object of type T. Otherwise has_value() returns false and operator*
throws dds::core::PreconditionNotMetError. To assing a value you can use the assignment operator.
An optional object has full value-type semantics; copying an optional value copies the underlying object if it exists.
This type's API is similar to that of std::optional
.
|
inline |
Create an unset optional object.
|
inline |
Create an optional object with a copy of a value.
has_value() && *(*this) == value
|
inline |
<<C++11>> Create an optional object moving a value
|
inline |
Create an optional member conditionally set or unset.
condition | If true creates an optional member with value otherwise it creates an unset optional member |
value | The value to set if condition is true |
|
inline |
<<C++11>> Creates an optional member conditionally set or unset by moving a value.
Moves the value rather than copying it.
|
inline |
Destroys the underlying object if it exists.
|
inline |
Assigns a copy of an object.
[DEPRECATED] Use operator=
instead.
|
inline |
<<C++11>> Assigns an object by moving it
[DEPRECATED] Use operator=
instead.
|
inline |
Checks if this optional instance contains a valid object.
[DEPRECATED] Use has_value()
|
inline |
Checks if this optional instance contains a valid object.
If my_optional.has_value()
is true
, then *my_optional
returns a valid object
Referenced by dds::core::optional< T >::operator<<(), and dds::core::optional< T >::operator==().
|
inlineexplicit |
<<C++11>> Returns has_value()
|
inline |
Destroys the underlying object and leaves this optional with an invalid (unset) value.
|
inline |
Retrieves the underlying object if it exists.
This operation, unlike operator*
throws an exception if the underlying object doesn't exist.
dds::core::PreconditionNotMetError | if !has_value(). |
|
inline |
Retrieves the underlying object if it exists.
This operation, unlike operator*
throws an exception if the underlying object doesn't exist.
dds::core::PreconditionNotMetError | if !has_value(). |
|
inline |
Retrieves the underlying object if it exists.
[DEPRECATED] Use value() or operator*
dds::core::PreconditionNotMetError | if !has_value(). |
Referenced by dds::core::optional< T >::operator<<(), and dds::core::optional< T >::operator==().
|
inline |
Retrieves the underlying object if it exists.
[DEPRECATED] Use value() or operator*
dds::core::PreconditionNotMetError | if !has_value(). |
|
inline |
Returns &get() if the object is initialized or NULL otherwise.
[DEPRECATED]
|
inline |
Returns &get() if the object is initialized or NULL otherwise.
[DEPRECATED]
|
inline |
Get the value, without checking if it exists
|
inline |
Get the value, without checking if it exists
|
inline |
Get the value.
dds::core::PreconditionNotMetError | if !has_value() |
|
inline |
Get the value.
dds::core::PreconditionNotMetError | if !has_value() |
|
inline |
Assignment operator.
Copies *other
if it exists.
|
inline |
<<C++11>> Move-assignment operator
Moves *other
if it exists.
|
inline |
Assign a (valid) value.
value | The value to assign to this optional member |
*(*this) == value
|
inline |
Assign a (valid) value by moving an object.
value | The value to move into this optional member |
Swaps the underlying objects.
This operation is always O(1).
Compares two optional values.
*a == *b
. References dds::core::optional< T >::get(), and dds::core::optional< T >::has_value().
Compares two optional values.
*a == *b
.
|
related |
Compares an optional member and a value of the underlying type.
optional_value
is set and *optional_value == value
References dds::core::optional< T >::get(), and dds::core::optional< T >::has_value().
|
related |
Compares an optional member and a value of the underlying type.
*optional_value == value
|
related |
Compares an optional member and a value of the underlying type.
*optional_value == value
|
related |
Compares an optional member and a value of the underlying type.
*optional_value == value
|
related |
Applies operator<<
to *optional
or to the string "NULL"
if !optional.has_value()
.
References dds::core::optional< T >::get(), and dds::core::optional< T >::has_value().