From e2ed782daee6ac867a71bc57573eaa740fca7cf8 Mon Sep 17 00:00:00 2001 From: Carlosespicur Date: Mon, 16 Sep 2024 07:49:45 +0200 Subject: [PATCH] Refs #21571: Add review changes Signed-off-by: Carlosespicur --- .../fastdds/ReaderHandler.cpp | 2 +- .../utils/dynamic_types_utils.cpp | 33 ++++++++---------- .../utils/dynamic_types_utils.hpp | 34 ++++--------------- 3 files changed, 22 insertions(+), 47 deletions(-) diff --git a/plugins/datastreamer_plugin/fastdds/ReaderHandler.cpp b/plugins/datastreamer_plugin/fastdds/ReaderHandler.cpp index 86edd96..756ee7a 100644 --- a/plugins/datastreamer_plugin/fastdds/ReaderHandler.cpp +++ b/plugins/datastreamer_plugin/fastdds/ReaderHandler.cpp @@ -52,7 +52,7 @@ ReaderHandler::ReaderHandler( { // Create data so it is not required to create it each time and avoid reallocation if possible data_ = DynamicDataFactory::get_instance()->create_data(type_); - + // Set this object as this reader's listener reader_->set_listener(this); } diff --git a/plugins/datastreamer_plugin/utils/dynamic_types_utils.cpp b/plugins/datastreamer_plugin/utils/dynamic_types_utils.cpp index b7bba96..2d42078 100644 --- a/plugins/datastreamer_plugin/utils/dynamic_types_utils.cpp +++ b/plugins/datastreamer_plugin/utils/dynamic_types_utils.cpp @@ -19,11 +19,11 @@ * @file dynamic_types_utils.cpp */ -#include +#include #include -#include #include -#include +#include +#include #include @@ -35,8 +35,8 @@ #include #include "dynamic_types_utils.hpp" -#include "utils.hpp" #include "Exception.hpp" +#include "utils.hpp" namespace eprosima { namespace plotjuggler { @@ -44,22 +44,17 @@ namespace utils { using namespace eprosima::fastdds::dds; using namespace eprosima::fastdds::rtps; -std::vector get_introspection_type_names( - const TypeIntrospectionNumericStruct& numeric_type_names) -{ - std::vector type_names; - for (const auto& type_name : numeric_type_names) - { - type_names.push_back(type_name.first); - } - return type_names; -} +template std::vector get_introspection_type_names( + const TypeIntrospectionNumericStruct& type_names_struct); +template std::vector get_introspection_type_names( + const TypeIntrospectionStringStruct& type_names_struct); +template std::vector get_introspection_type_names( - const TypeIntrospectionStringStruct& string_type_names) + const T& type_names_struct) { std::vector type_names; - for (const auto& type_name : string_type_names) + for (const auto& type_name : type_names_struct) { type_names.push_back(type_name.first); } @@ -80,7 +75,7 @@ void get_formatted_data( numeric_data.push_back({base_type_name, data.get()}); return; } - else if(is_kind_boolean(data)) + else if (is_kind_boolean(data)) { bool value = data.get(); numeric_data.push_back({base_type_name, static_cast(value)}); @@ -168,8 +163,8 @@ bool is_kind_string( } ReturnCode_t serialize_data ( - DynamicData::_ref_type data, - nlohmann::json& serialized_data) + DynamicData::_ref_type data, + nlohmann::json& serialized_data) { std::stringstream serializer_output; ReturnCode_t retcode; diff --git a/plugins/datastreamer_plugin/utils/dynamic_types_utils.hpp b/plugins/datastreamer_plugin/utils/dynamic_types_utils.hpp index eacf952..c7afe7b 100644 --- a/plugins/datastreamer_plugin/utils/dynamic_types_utils.hpp +++ b/plugins/datastreamer_plugin/utils/dynamic_types_utils.hpp @@ -31,41 +31,21 @@ namespace eprosima { namespace plotjuggler { namespace utils { -using SingleDataTypeIntrospectionInfo = - std::tuple< - types::DatumLabel, - std::vector, // Member Ids of the parents of the data member - std::vector, // Kind of the parents of the data member - eprosima::fastdds::dds::TypeKind>; // Kind of this member - -using TypeIntrospectionCollection = - std::vector; - using TypeIntrospectionNumericStruct = std::vector; using TypeIntrospectionStringStruct = std::vector; /** - * @brief Get the names of each label in a \c TypeIntrospectionCollection - * This function is used to obtain all the labels form by topics + data type members + * @brief This function is used to obtain all the names of a given collection of numeric/string data. * - * Iterate over every \c SingleDataTypeIntrospectionInfo and get the \c DatumLabel . + * Iterate over every member and get name. * * @param numeric_type_names collection to get all names * @return all label names */ +template std::vector get_introspection_type_names( - const TypeIntrospectionNumericStruct& numeric_type_names); - -/** - TODO (Carlosespicur): Add description -**/ -std::vector get_introspection_type_names( - const TypeIntrospectionStringStruct& string_type_names); - -/** - TODO (Carlosespicur): Add description -**/ + const T& type_names_struct); void get_formatted_data( const std::string& base_type_name, @@ -84,9 +64,9 @@ bool is_kind_boolean( bool is_kind_string( const nlohmann::json& data); -ReturnCode_t serialize_data ( - DynamicData::_ref_type data, - nlohmann::json& serialized_data); +eprosima::fastdds::dds::ReturnCode_t serialize_data ( + eprosima::fastdds::dds::DynamicData::_ref_type data, + nlohmann::json& serialized_data); } /* namespace utils */ } /* namespace plotjuggler */