RTI Connext Modern C++ API
Version 5.3.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> | same |
optional annotation (T member ; //@optional ) | dds::core::optional<T> | same |
external annotation (T member ; //@external ) | 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 supported by the compiler, or an alias of boost::array
otherwise.
The following example shows how to use getters and setters and work with different IDL types.