19template<
typename MsgT,
typename DataT>
27 MessagePair(std::shared_ptr<DataT> data, std::shared_ptr<rclcpp::Clock> clock);
34 MessagePair(std::shared_ptr<DataT> data, std::shared_ptr<rclcpp::Clock> clock)
36 :
MessagePairInterface(MessageType::CUSTOM_MESSAGE), data_(std::move(data)), clock_(std::move(clock)) {}
57 [[nodiscard]] std::shared_ptr<DataT>
get_data()
const;
63 void set_data(
const std::shared_ptr<DataT>& data);
71 [[nodiscard]] MsgT write_translated_message()
const;
78 [[nodiscard]] MsgT write_encoded_message()
const;
84 [[nodiscard]] MsgT write_raw_message()
const;
91 void read_translated_message(
const MsgT& message);
98 void read_encoded_message(
const MsgT& message);
105 void read_raw_message(
const MsgT& message);
107 std::shared_ptr<DataT> data_;
108 std::shared_ptr<rclcpp::Clock> clock_;
111template<
typename MsgT,
typename DataT>
113 if (this->data_ ==
nullptr) {
119 message = write_raw_message();
120 }
else if constexpr (std::same_as<MsgT, EncodedState>) {
121 message = write_encoded_message();
123 message = write_translated_message();
128template<
typename MsgT,
typename DataT>
130 auto message = MsgT();
136inline EncodedState MessagePair<EncodedState, state_representation::State>::write_encoded_message()
const {
137 auto message = EncodedState();
142template<
typename MsgT,
typename DataT>
143inline MsgT MessagePair<MsgT, DataT>::write_raw_message()
const {
147template<
typename MsgT,
typename DataT>
149 if (this->data_ ==
nullptr) {
154 read_raw_message(message);
155 }
else if constexpr (std::same_as<MsgT, EncodedState>) {
156 read_encoded_message(message);
158 read_translated_message(message);
162template<
typename MsgT,
typename DataT>
168inline void MessagePair<EncodedState, state_representation::State>::read_encoded_message(
const EncodedState& message) {
172template<
typename MsgT,
typename DataT>
173inline void MessagePair<MsgT, DataT>::read_raw_message(
const MsgT& message) {
174 *this->data_ = message;
177template<
typename MsgT,
typename DataT>
182template<
typename MsgT,
typename DataT>
184 if (data ==
nullptr) {
190template<concepts::CoreDataT DataT>
191inline std::shared_ptr<MessagePairInterface>
192make_shared_message_pair(
const std::shared_ptr<DataT>& data,
const std::shared_ptr<rclcpp::Clock>& clock) {
193 return std::make_shared<MessagePair<EncodedState, state_representation::State>>(
194 std::dynamic_pointer_cast<state_representation::State>(data), clock);
197template<concepts::CustomT DataT>
198inline std::shared_ptr<MessagePairInterface>
199make_shared_message_pair(
const std::shared_ptr<DataT>& data,
const std::shared_ptr<rclcpp::Clock>& clock) {
200 return std::make_shared<MessagePair<DataT, DataT>>(data, clock);
203template<
typename DataT =
bool>
204inline std::shared_ptr<MessagePairInterface>
205make_shared_message_pair(
const std::shared_ptr<bool>& data,
const std::shared_ptr<rclcpp::Clock>& clock) {
206 return std::make_shared<MessagePair<std_msgs::msg::Bool, bool>>(data, clock);
209template<
typename DataT =
double>
210inline std::shared_ptr<MessagePairInterface>
211make_shared_message_pair(
const std::shared_ptr<double>& data,
const std::shared_ptr<rclcpp::Clock>& clock) {
212 return std::make_shared<MessagePair<std_msgs::msg::Float64, double>>(data, clock);
215template<
typename DataT = std::vector<
double>>
216inline std::shared_ptr<MessagePairInterface> make_shared_message_pair(
217 const std::shared_ptr<std::vector<double>>& data,
const std::shared_ptr<rclcpp::Clock>& clock) {
218 return std::make_shared<MessagePair<std_msgs::msg::Float64MultiArray, std::vector<double>>>(data, clock);
221template<
typename DataT =
int>
222inline std::shared_ptr<MessagePairInterface>
223make_shared_message_pair(
const std::shared_ptr<int>& data,
const std::shared_ptr<rclcpp::Clock>& clock) {
224 return std::make_shared<MessagePair<std_msgs::msg::Int32, int>>(data, clock);
227template<
typename DataT = std::
string>
228inline std::shared_ptr<MessagePairInterface>
229make_shared_message_pair(
const std::shared_ptr<std::string>& data,
const std::shared_ptr<rclcpp::Clock>& clock) {
230 return std::make_shared<MessagePair<std_msgs::msg::String, std::string>>(data, clock);