Template Class optional

Inheritance Relationships

Base Type

Class Documentation

template<typename T, template<typename Q> class DELEGATE>
class optional : public dds::core::Value<DELEGATE<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);

    dds::core::optional<int32_t>& z() const;
    void z(int32_t v);
    void z(const dds::core::optional<int32_t>& z)
};

Public Functions

optional(const T &t)
bool is_set() const

Returns true only if the attribute is set.

void reset()

Reset the attribute.

const T &get() const

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

T &get()

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