RTI Connext Modern C++ API
Version 6.0.0
|
How IDL types map to C++ classes. More...
Classes | |
class | Foo |
A hypothetical 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 Create user data types using rtiddsgen
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.
Setters and getters allow accessing the type members.
The following table summarizes how different IDL types map to C++. The mapping is different depending on whether the option "-stl" is specified or not:
IDL type | C++ type (with -stl) | C++ type (without -stl) |
---|---|---|
string | std::string | dds::core::string |
bounded sequence (sequence<T, M> ) | rti::core::bounded_sequence<T, M> | dds::core::vector<T> |
unbounded sequence (sequence<T> ) | std::vector<T> | dds::core::vector<T> |
array (T member [N]) | dds::core::array<T, N> | dds::core::array<T, N> |
optional annotation (@optional T member ; ) | dds::core::optional<T> | dds::core::optional<T> |
external annotation (@external T member ; ) | dds::core::external<T> | 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.
The following example shows how to use getters and setters and work with different IDL types.
IDL enums map to an instantiation of the C++ dds::core::safe_enum class, which provides a scoped, type-safe enum.
For example, given the following IDL enum:
This is how to use it 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.