Cyclone ISO C++ API Reference Guide
dds::core::optional< T > Class Template Reference

#include "Optional.hpp"

Inherits dds::core::Value< D >.

Public Member Functions

 optional (const T &t)
 
T & get ()
 
const T & get () const
 
bool is_set () const
 
bool operator!= (const Value &other) const
 
D * operator-> ()
 
const D * operator-> () const
 
bool operator== (const Value &other) const
 
void reset ()
 

Detailed Description

template<typename T>
class dds::core::optional< T >

The optional class is used to wrap attributes annotated in the idl with the @optional annotation. This class provides a simple and safe way of accessing, setting and resetting the stored attribute.

IDL:

struct RadarTrack {
string id;
long x;
long y;
long z; //@Optional
};

C++ Representation:

class RadarTrack {
public:
RadarTrack();
RadarTrack(const std::string& id,
int32_t x,
int32_t y,
int32_t z);
public:
std::string& id() const;
void id(const std::string& s);
int32_t x() const;
void x(int32_t v);
int32_t y() const;
void y(int32_t v);
void z(int32_t v);
};

Definition at line 69 of file Optional.hpp.

Constructor & Destructor Documentation

◆ optional()

template<typename T>
dds::core::optional< T >::optional ( const T &  t)

Member Function Documentation

◆ get() [1/2]

template<typename T>
T& dds::core::optional< T >::get ( )

Get the attribute. An exception is thrown if the attribute is not set.

◆ get() [2/2]

template<typename T>
const T& dds::core::optional< T >::get ( ) const

Get the attribute. An exception is thrown if the attribute is not set.

◆ is_set()

template<typename T>
bool dds::core::optional< T >::is_set ( ) const

Returns true only if the attribute is set.

◆ operator!=()

template<typename D >
bool dds::core::Value< D >::operator!= ( const Value< D > &  other) const
inherited

Compare this Value with another Value

Parameters
otherValue
Returns
true if not equal

◆ operator->() [1/2]

template<typename D >
D* dds::core::Value< D >::operator-> ( )
inherited

The operator->() is provided to be able to directly invoke functions on the delegate.

The decision to provide direct access to the delegate was motivated by the need for providing a way that was not invasive with respect to the CXXDDS API and yet would allow for vendor-specific extension. Thus vendor-specific extensions can be invoked on the Value and on all its subclasses as follows:

my_dds_value.standard_function();
my_dds_value->vendor_specific_extension();
Returns
a reference to delegate.

◆ operator->() [2/2]

template<typename D >
const D* dds::core::Value< D >::operator-> ( ) const
inherited

The operator->() is provided to be able to directly invoke functions on the delegate.

The decision to provide direct access to the delegate was motivated by the need for providing a way that was not invasive with respect to the CXXDDS API and yet would allow for vendor-specific extension. Thus vendor-specific extensions can be invoked on the Value and on all its subclasses as follows:

my_dds_value.standard_function();
my_dds_value->vendor_specific_extension();
Returns
a reference to delegate.

◆ operator==()

template<typename D >
bool dds::core::Value< D >::operator== ( const Value< D > &  other) const
inherited

Compare this Value with another Value

Parameters
otherValue
Returns
true if equal

◆ reset()

template<typename T>
void dds::core::optional< T >::reset ( )

Reset the attribute.


The documentation for this class was generated from the following file:
dds::core::optional
Definition: Optional.hpp:69