|
RTI Connext Modern C++ API Version 7.6.0
|
How IDL types map to C++ classes. More...
Classes | |
| class | Foo |
| An example topic-type. More... | |
How IDL types map to C++ classes.
The following IDL code defines the types we will use in these examples.
To generate C++ code for these types, see the Code Generator User's Manual.
C++ types generated from IDL have value semantics and provide a default constructor, a copy constructor, a move constructor <<C++11>>, a constructor with parameters to set all the type's members, a destructor, a copy-assignment operator, and a move-assignment operator <<C++11>>. Types also include equality operators, the operator << to std::ostream <<extension>> and a namespace-level swap function.
In addition to that, a number of traits provide additional information and utilities for IDL-generated types.
Struct members are public. Setters and getters provide access to union members.
The following table summarizes how different IDL types map to C++.
| IDL type | C++ type |
|---|---|
string | std::string |
bounded sequence (sequence<T, M>) | rti::core::bounded_sequence<T, M> |
unbounded sequence (sequence<T>) | std::vector<T> |
array (T member[N]) | std::array<T, N> |
optional member (@optional T member; ) | dds::core::optional<T> |
external member (@external T member; ) | dds::core::external<T> |
The type rti::core::bounded_sequence offers similar functionality to that of a std::vector. But because it has an upper bound M, it provides two advantages:
1) A better memory management strategy for deserializing data samples in a DataReader, improving the overall performance of the middleware.
2) Its member functions check for out-of-bounds growth.
It is possible to use std::vector for bounded sequences by annotating them with @use_vector in IDL. For example:
The type dds::core::array is just an alias of std::array if available, or an alias of boost::array otherwise.
IDL enums map to enum class types in C++.
IDL unions map to C++ classes with getters and setters for each member, plus a especial getter and setter for the discriminator, _d(). At any moment only one member, the one selected by the discriminator, is considered active. A member getter will throw dds::core::PreconditionNotMetError if the discriminator selects a different member.
Member setters set the correct discriminator value automatically.
The default constructor default-constructs all the members and selects the discriminator returned by the static member function default_discriminator().
The following example shows an IDL union and C++ code to manipulate it.