Key Enhancements in RTI Connext’s Modern C++ DDS API
Since we introduced the modern C++ API for DDS, we’ve seen significant interest from our customers. Many have begun building new systems using C++11, and we’ve continued to refine the API with a number of impactful enhancements.
Enhanced IDL Mapping to Modern C++
RTI’s Code Generator now offers a new -stl option, used in conjunction with -language C++03 or -language C++11. This option updates the mapping of several IDL types:
- Unbounded sequences →
std::vector(requires -unboundedSupport) - Bounded sequences →
rti::core::bounded_sequence<T, Bound>. This type behaves likestd::vectorbut is optimized for deserialization. For lower‑latency scenarios you may preferstd::vectorusing the@use_vectorannotation. - String and wide string types →
std::stringandstd::wstring - Members annotated with
@external(the “*” pointer notation) becomedds::core::external<T>, a safer wrapper similar toshared_ptr. This protects external members from being overwritten when the middleware loans memory (e.g., reading from aLoanedSamplescontainer).
For example, given the following IDL type:
struct MyType {
sequence<long> my_unbounded_seq;
sequence<long, 10> my_bounded_seq;
@use_vector sequence<long, 10> my_other_bounded_seq
string my_str;
@external long my_external;
};
Using the command rtiddsgen -language C++11 -stl -unboundedSupport MyType.idl, the generated C++11 class looks like this:
class MyType {
public:
MyType();
...
MyType (MyType&&) = default;
MyType& operator=(MyType&&) = default;
MyType& operator=(const MyType&) = default;
MyType(const MyType&) = default;
std::vector<int32_t>& my_unbounded_seq() noexcept;
const std::vector<int32_t>& my_unbounded_seq() const noexcept;
void my_unbounded_seq(const std::vector<int32_t>& value);
rti::core::bounded_sequence<int32_t, 10>& my_bounded_seq() noexcept;
const rti::core::bounded_sequence<int32_t, 10>& my_bounded_seq() const noexcept;
void my_bounded_seq(const rti::core::bounded_sequence<int32_t, 10>& value);
std::vector<int32_t>& my_other_bounded_seq() noexcept;
const std::vector<int32_t>& my_other_bounded_seq() const noexcept;
void my_other_bounded_seq(const std::vector<int32_t>& value);
std::string& my_str() noexcept;
const std::string& my_str() const noexcept;
void my_str(const std::string& value);
dds::core::external<int32_t>& my_external() noexcept;
const dds::core::external<int32_t>& my_external() const noexcept;
void my_external(dds::core::external<int32_t> value);
...
};
Request‑Reply API for Modern C++
The API now includes two new entities: rti::request::Requester and rti::request::Replier. These provide a native request‑reply pattern, which is already available in other languages and has been introduced in a prototype in version 5.3 and is production‑ready in 5.3.0.7.
A concise code example is available here.
Smaller API Enhancements
We’ve simplified several common tasks:
- Condition handlers in a
WaitSetcan now accept the condition as an argument, eliminating the need for no‑argument functors:
condition.handler([]() {
// do something
});
// or, with the new signature
condition.handler([](dds::core::cond::Condition c) {
// do something (condition == c)
});
TopicQuery for On‑Demand Historical Data
TopicQuery, introduced in 5.3, allows applications to retrieve historical data on‑demand. In the modern C++ API you can create a TopicQuery from a DataReader like this:
rti::sub::TopicQuery my_topic_query(
my_reader,
rti::sub::TopicQuerySelection(dds::topic::Filter("x < 10"))
);
You can then take historical samples that match the filter while still receiving live data normally.
Looking Ahead
With C++17 now approved and C++20 on the horizon, RTI Connext will continue to evolve the C++ API with modern language features and performance improvements. Stay tuned or subscribe to the RTI Blog for the latest updates.
Internet of Things Technology
- Introducing A3: New AI Community, Tools, and Guides for Automation Leaders
- CatalystEX 4.5: New Features, Enhanced Compatibility, and GrabCad Print Integration
- Augmented Reality: Transforming Connected Field Service
- Why 5G Rollout Is Slowed: Cost, Spectrum, and Coverage Challenges
- G.hn: Powering the Industrial IoT Revolution for Cost‑Effective, Reliable Connectivity
- Cyber‑Physical Security: Why Hacking Risks Are Expanding Beyond the Virtual Realm
- C# vs C++: A Clear Comparison of Features, Performance, and Use Cases
- C++ vs Java: Key Differences, History, and When to Use Each
- Industry 5.0: Redefining Manufacturing for the Future
- Unlocking HR Excellence in Modern Manufacturing: Proven Strategies & Secrets