RTI Connext Modern C++ API  Version 6.1.0
rti::core::optional_value< T > Class Template Reference

<<extension>> Represents a value that can be initialized or not More...

#include <OptionalValue.hpp>

Public Member Functions

 optional_value ()
 Creates an uninitialized value. More...
 
 optional_value (const T &value)
 Creates an instance with a value. More...
 
 optional_value (bool condition, const T &value)
 Conditionally creates an instance that can be uninitialized or initialized with a value. More...
 
 optional_value (const optional_value< T > &other)
 Copy constructor. More...
 
bool is_set () const OMG_NOEXCEPT
 Returns true only if the value is initialized. More...
 
bool has_value () const OMG_NOEXCEPT
 Returns true only if the value is initialized. More...
 
 operator bool () const OMG_NOEXCEPT
 <<C++11>> Returns has_value() More...
 
void reset ()
 After calling this function, this optional_value is not set. 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 & operator* () const
 
T & operator* ()
 
const T * operator-> () const
 
T * operator-> ()
 

Friends

void swap (optional_value< T > &left, optional_value< T > &right) OMG_NOEXCEPT
 Swaps the underlying objects. More...
 

Detailed Description

template<typename T>
class rti::core::optional_value< T >

<<extension>> Represents a value that can be initialized or not

This class is similar to dds::core::optional and std::optional.

They have different implementations. dds::core::optional is only used in IDL-generated types, while rti::core::optional_value is used in parts of the API.

Constructor & Destructor Documentation

◆ optional_value() [1/4]

template<typename T>
rti::core::optional_value< T >::optional_value ( )
inline

Creates an uninitialized value.

Referenced by rti::core::optional_value< T >::optional_value().

◆ optional_value() [2/4]

template<typename T>
rti::core::optional_value< T >::optional_value ( const T &  value)
inline

Creates an instance with a value.

◆ optional_value() [3/4]

template<typename T>
rti::core::optional_value< T >::optional_value ( bool  condition,
const T &  value 
)
inline

Conditionally creates an instance that can be uninitialized or initialized with a value.

Parameters
conditionIf it is true it assigns value, otherwise this optional_value is uninitialized
valueThe value to use if condition is true.

References rti::core::optional_value< T >::value().

◆ optional_value() [4/4]

template<typename T>
rti::core::optional_value< T >::optional_value ( const optional_value< T > &  other)
inline

Member Function Documentation

◆ is_set()

template<typename T>
bool rti::core::optional_value< T >::is_set ( ) const
inline

Returns true only if the value is initialized.

[DEPRECATED] Use has_value()

◆ has_value()

template<typename T>
bool rti::core::optional_value< T >::has_value ( ) const
inline

Returns true only if the value is initialized.

Referenced by rti::core::optional_value< T >::optional_value(), and rti::core::optional_value< T >::value().

◆ operator bool()

template<typename T>
rti::core::optional_value< T >::operator bool ( ) const
inlineexplicit

◆ reset()

template<typename T>
void rti::core::optional_value< T >::reset ( )
inline

After calling this function, this optional_value is not set.

Referenced by rti::core::optional_value< T >::optional_value().

◆ value() [1/2]

template<typename T>
const T& rti::core::optional_value< T >::value ( ) const
inline

Retrieves the underlying object if it exists.

This operation, unlike operator* throws an exception if the underlying object doesn't exist.

Exceptions
dds::core::PreconditionNotMetErrorif !has_value().

References rti::core::optional_value< T >::has_value().

Referenced by rti::core::optional_value< T >::get(), rti::core::optional_value< T >::operator->(), and rti::core::optional_value< T >::optional_value().

◆ value() [2/2]

template<typename T>
T& rti::core::optional_value< T >::value ( )
inline

Retrieves the underlying object if it exists.

This operation, unlike operator* throws an exception if the underlying object doesn't exist.

Exceptions
dds::core::PreconditionNotMetErrorif !has_value().

References rti::core::optional_value< T >::has_value().

◆ get() [1/2]

template<typename T>
const T& rti::core::optional_value< T >::get ( ) const
inline

Retrieves the underlying object if it exists.

[DEPRECATED] Use value() or operator*

Exceptions
dds::core::PreconditionNotMetErrorif !has_value().

References rti::core::optional_value< T >::value().

Referenced by rti::core::optional_value< T >::optional_value().

◆ get() [2/2]

template<typename T>
T& rti::core::optional_value< T >::get ( )
inline

Retrieves the underlying object if it exists.

[DEPRECATED] Use value() or operator*

Exceptions
dds::core::PreconditionNotMetErrorif !has_value().

References rti::core::optional_value< T >::value().

◆ operator*() [1/2]

template<typename T>
const T& rti::core::optional_value< T >::operator* ( ) const
inline

Get the value, without checking if it exists

Precondition
has_value(), otherwise this operation has undefined behavior. See value().

◆ operator*() [2/2]

template<typename T>
T& rti::core::optional_value< T >::operator* ( )
inline

Get the value, without checking if it exists

Precondition
has_value(), otherwise this operation has undefined behavior. See value().

◆ operator->() [1/2]

template<typename T>
const T* rti::core::optional_value< T >::operator-> ( ) const
inline

Get the value.

Exceptions
dds::core::PreconditionNotMetErrorif !has_value()

References rti::core::optional_value< T >::value().

◆ operator->() [2/2]

template<typename T>
T* rti::core::optional_value< T >::operator-> ( )
inline

Get the value.

Exceptions
dds::core::PreconditionNotMetErrorif !has_value()

References rti::core::optional_value< T >::value().

Friends And Related Function Documentation

◆ swap

template<typename T>
void swap ( optional_value< T > &  left,
optional_value< T > &  right 
)
friend

Swaps the underlying objects.

It uses swap(*left, *right) if that function is defined for type T; otherwise it uses std::swap.