diff --git a/include/fastdds/dds/xtypes/utils.hpp b/include/fastdds/dds/xtypes/utils.hpp index 4ee461daf84..48706c9e9a1 100644 --- a/include/fastdds/dds/xtypes/utils.hpp +++ b/include/fastdds/dds/xtypes/utils.hpp @@ -20,9 +20,11 @@ #define FASTDDS_DDS_XTYPES__UTILS_HPP #include +#include #include #include +#include #include namespace eprosima { @@ -35,6 +37,17 @@ enum class DynamicDataJsonFormat EPROSIMA, }; +/** + * @brief Serializes a @ref DynamicType into its IDL representation. + * + * @param [in] dynamic_type The @ref DynamicType to serialize. + * @param [in,out] output \c std::ostream reference containing the IDL representation. + * @retval RETCODE_OK when serialization fully succeeds, and inner (member serialization) failing code otherwise. + */ +FASTDDS_EXPORTED_API ReturnCode_t idl_serialize( + const DynamicType::_ref_type& dynamic_type, + std::ostream& output) noexcept; + /*! * Serializes a @ref DynamicData into a JSON object, which is then dumped into an \c std::ostream. * @param[in] data @ref DynamicData reference to be serialized. diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 045a63b3fae..21896a47f92 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -104,6 +104,7 @@ set(${PROJECT_NAME}_source_files fastdds/xtypes/dynamic_types/TypeDescriptorImpl.cpp fastdds/xtypes/dynamic_types/VerbatimTextDescriptorImpl.cpp fastdds/xtypes/exception/Exception.cpp + fastdds/xtypes/serializers/idl/dynamic_type_idl.cpp fastdds/xtypes/serializers/json/dynamic_data_json.cpp fastdds/xtypes/type_representation/dds_xtypes_typeobjectPubSubTypes.cxx fastdds/xtypes/type_representation/TypeObjectRegistry.cpp diff --git a/src/cpp/fastdds/xtypes/CMakeLists.txt b/src/cpp/fastdds/xtypes/CMakeLists.txt index 394a6928fb7..c55ce04fad1 100644 --- a/src/cpp/fastdds/xtypes/CMakeLists.txt +++ b/src/cpp/fastdds/xtypes/CMakeLists.txt @@ -78,6 +78,8 @@ target_sources(fastdds-xtypes-dynamic-types-impl INTERFACE dynamic_types/TypeDescriptorImpl.hpp dynamic_types/VerbatimTextDescriptorImpl.cpp dynamic_types/VerbatimTextDescriptorImpl.hpp + serializers/idl/dynamic_type_idl.cpp + serializers/idl/dynamic_type_idl.hpp serializers/json/dynamic_data_json.cpp serializers/json/dynamic_data_json.hpp utils.cpp diff --git a/src/cpp/fastdds/xtypes/serializers/idl/dynamic_type_idl.cpp b/src/cpp/fastdds/xtypes/serializers/idl/dynamic_type_idl.cpp new file mode 100644 index 00000000000..421abaf6252 --- /dev/null +++ b/src/cpp/fastdds/xtypes/serializers/idl/dynamic_type_idl.cpp @@ -0,0 +1,1176 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "dynamic_type_idl.hpp" + +namespace eprosima { +namespace fastdds { +namespace dds { + +using namespace eprosima::utilities::collections; + +constexpr auto TYPE_OPENING = "\n{\n"; +constexpr auto TYPE_CLOSURE = "};\n"; +constexpr auto TAB_SEPARATOR = " "; + +////////////////////////// +// DYNAMIC TYPE TO TREE // +////////////////////////// + +ReturnCode_t dyn_type_to_tree( + const DynamicType::_ref_type& type, + const std::string& member_name, + TreeNode& node) noexcept +{ + ReturnCode_t ret = RETCODE_OK; + + const auto kind = type->get_kind(); + + if (kind == TK_STRUCTURE) + { + // If is struct, the call is recursive. + // Create new tree node + node = TreeNode(member_name, type->get_name().to_string(), type); + + // Get its base class + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + ret = type->get_descriptor(type_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting type descriptor of " << node << "."); + return ret; + } + + // Add base class as a new branch + const auto base_type = type_descriptor->base_type(); + std::uint32_t first_member = 0; + + if (nullptr != base_type) + { + TreeNode base; + ret = dyn_type_to_tree(base_type, "PARENT", base); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting base type of " << node << "."); + return ret; + } + + base.info.is_base = true; + + // If the struct is derived from a base, according to the xtypes standard, the first members of the + // struct are the members of the base. + first_member = base_type->get_member_count(); + + node.add_branch(base); + } + + // Add each member as a new branch except for the members of its base class + for (std::uint32_t index = first_member; index < type->get_member_count(); index++) + { + traits::ref_type member; + ret = type->get_member_by_index(member, index); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting member of " << node << " at index " << index << "."); + return ret; + } + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + ret = member->get_descriptor(member_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting member descriptor of member " << member->get_name() << + " of " << node << "."); + return ret; + } + + TreeNode child; + ret = dyn_type_to_tree(member_descriptor->type(), member_descriptor->name().to_string(), child); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error building tree of member " << member->get_name() << + " of " << node << "."); + return ret; + } + + child.info.is_key = member_descriptor->is_key(); + + // Add each member with its name as a new child in a branch (recursion) + node.add_branch(child); + } + } + else + { + std::stringstream idl; + ret = type_kind_to_idl(type, idl); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting IDL representation of " << type->get_name().to_string() << "."); + return ret; + } + + node = TreeNode(member_name, idl.str(), type); + + if (kind == TK_ALIAS) + { + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + ret = node.info.dynamic_type->get_descriptor(type_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting type descriptor of " << node << "."); + return ret; + } + + // Add a branch for the base type of the alias + TreeNode base; + ret = dyn_type_to_tree(type_descriptor->base_type(), "BASE", base); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error building tree of " << base << "."); + return ret; + } + + node.add_branch(base); + } + else if (kind == TK_ARRAY || kind == TK_MAP || kind == TK_SEQUENCE) + { + // Add a branch for the element type of the container + DynamicType::_ref_type element_type; + ret = get_element_type(type, element_type); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting element type of " << node << "."); + return ret; + } + + TreeNode child; + ret = dyn_type_to_tree(element_type, "CONTAINER_MEMBER", child); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error building tree of " << child << "."); + return ret; + } + + node.add_branch(child); + } + else if (kind == TK_UNION) + { + // Add each member as a new branch + for (std::uint32_t index = 1; index < type->get_member_count(); index++) + { + traits::ref_type member; + ret = type->get_member_by_index(member, index); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting member of " << node << " at index " << index << "."); + return ret; + } + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + ret = member->get_descriptor(member_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting member descriptor of member " << member->get_name() << + " of " << node << "."); + return ret; + } + + TreeNode child; + ret = dyn_type_to_tree(member_descriptor->type(), member_descriptor->name().to_string(), child); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error building tree of member " << member->get_name() << + " of " << node << "."); + return ret; + } + + node.add_branch(child); + } + } + } + + return ret; +} + +ReturnCode_t type_kind_to_idl( + const DynamicType::_ref_type& dyn_type, + std::ostream& idl) noexcept +{ + ReturnCode_t ret = RETCODE_OK; + + const auto kind = dyn_type->get_kind(); + + switch (kind) + { + case TK_BOOLEAN: + { + idl << "boolean"; + break; + } + case TK_BYTE: + { + idl << "octet"; + break; + } + case TK_INT8: + { + idl << "int8"; + break; + } + case TK_INT16: + { + idl << "short"; + break; + } + case TK_INT32: + { + idl << "long"; + break; + } + case TK_INT64: + { + idl << "long long"; + break; + } + case TK_UINT8: + { + idl << "uint8"; + break; + } + case TK_UINT16: + { + idl << "unsigned short"; + break; + } + case TK_UINT32: + { + idl << "unsigned long"; + break; + } + case TK_UINT64: + { + idl << "unsigned long long"; + break; + } + case TK_FLOAT32: + { + idl << "float"; + break; + } + case TK_FLOAT64: + { + idl << "double"; + break; + } + case TK_FLOAT128: + { + idl << "long double"; + break; + } + case TK_CHAR8: + { + idl << "char"; + break; + } + case TK_CHAR16: + { + idl << "wchar"; + break; + } + case TK_STRING8: + case TK_STRING16: + { + ret = string_kind_to_idl(dyn_type, idl); + break; + } + case TK_ARRAY: + { + ret = array_kind_to_idl(dyn_type, idl); + break; + } + case TK_SEQUENCE: + { + ret = sequence_kind_to_idl(dyn_type, idl); + break; + } + case TK_MAP: + { + ret = map_kind_to_idl(dyn_type, idl); + break; + } + case TK_ALIAS: + case TK_BITMASK: + case TK_BITSET: + case TK_ENUM: + case TK_STRUCTURE: + case TK_UNION: + { + idl << dyn_type->get_name().to_string(); + break; + } + case TK_NONE: + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Failed to convert TK_NONE to stream."); + ret = RETCODE_UNSUPPORTED; + break; + } + default: + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Failed to convert unknown type (" << kind << ") to stream."); + ret = RETCODE_BAD_PARAMETER; + break; + } + } + + return ret; +} + +ReturnCode_t array_kind_to_idl( + const DynamicType::_ref_type& dyn_type, + std::ostream& idl) noexcept +{ + assert(dyn_type->get_kind() == TK_ARRAY); + + ReturnCode_t ret = RETCODE_OK; + + DynamicType::_ref_type element_type; + ret = get_element_type(dyn_type, element_type); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting element type of " << dyn_type->get_name().to_string() << "."); + return ret; + } + + ret = type_kind_to_idl(element_type, idl); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting IDL representation of " << element_type->get_name().to_string() << "."); + return ret; + } + + BoundSeq bounds; + ret = get_bounds(dyn_type, bounds); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting bounds of " << dyn_type->get_name().to_string() << "."); + return ret; + } + + for (const auto& bound : bounds) + { + idl << "[" << std::to_string(bound) << "]"; + } + + return ret; +} + +ReturnCode_t map_kind_to_idl( + const DynamicType::_ref_type& dyn_type, + std::ostream& idl) noexcept +{ + assert(dyn_type->get_kind() == TK_MAP); + + ReturnCode_t ret = RETCODE_OK; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + ret = dyn_type->get_descriptor(type_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting type descriptor of " << dyn_type->get_name().to_string() << "."); + return ret; + } + + idl << "map<"; + + const auto key_type = type_descriptor->key_element_type(); + ret = type_kind_to_idl(key_type, idl); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting IDL representation of " << key_type->get_name().to_string() << "."); + return ret; + } + + idl << ", "; + + const auto value_type = type_descriptor->element_type(); + ret = type_kind_to_idl(value_type, idl); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting IDL representation of " << value_type->get_name().to_string() << "."); + return ret; + } + + BoundSeq bounds; + ret = get_bounds(dyn_type, bounds); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting bounds of " << dyn_type->get_name().to_string() << "."); + return ret; + } + + assert(bounds.size() <= 1); + + if (1 == bounds.size()) + { + idl << ", " << std::to_string(bounds[0]); + } + + idl << ">"; + + return ret; +} + +ReturnCode_t sequence_kind_to_idl( + const DynamicType::_ref_type& dyn_type, + std::ostream& idl) noexcept +{ + assert(dyn_type->get_kind() == TK_SEQUENCE); + + ReturnCode_t ret = RETCODE_OK; + + DynamicType::_ref_type element_type; + ret = get_element_type(dyn_type, element_type); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting element type of " << dyn_type->get_name().to_string() << "."); + return ret; + } + + idl << "sequence<"; + + ret = type_kind_to_idl(element_type, idl); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting IDL representation of " << element_type->get_name().to_string() << "."); + return ret; + } + + BoundSeq bounds; + ret = get_bounds(dyn_type, bounds); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting bounds of " << dyn_type->get_name().to_string() << "."); + return ret; + } + + assert(bounds.size() <= 1); + + if (1 == bounds.size()) + { + idl << ", " << std::to_string(bounds[0]); + } + + idl << ">"; + + return ret; +} + +ReturnCode_t string_kind_to_idl( + const DynamicType::_ref_type& dyn_type, + std::ostream& idl) noexcept +{ + assert(dyn_type->get_kind() == TK_STRING8 || dyn_type->get_kind() == TK_STRING16); + + ReturnCode_t ret = RETCODE_OK; + + if (dyn_type->get_kind() == TK_STRING16) + { + idl << "wstring"; + } + else + { + idl << "string"; + } + + BoundSeq bounds; + ret = get_bounds(dyn_type, bounds); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting bounds of " << dyn_type->get_name().to_string() << "."); + return ret; + } + + assert(bounds.size() <= 1); + + if (1 == bounds.size()) + { + idl << "<" << std::to_string(bounds[0]) << ">"; + } + + return ret; +} + +////////////////////////////// +// DYNAMIC TYPE TREE TO IDL // +////////////////////////////// + +ReturnCode_t dyn_type_tree_to_idl( + const TreeNode& root, + std::ostream& idl) noexcept +{ + ReturnCode_t ret = RETCODE_OK; + + std::set types_written; + + // Write the dependencies of the root node + for (const auto& node : root.all_nodes()) + { + if (types_written.find(node.info.type_kind_name) != types_written.end()) + { + // The type has already been written. Skip it. + continue; + } + + const auto kind = node.info.dynamic_type->get_kind(); + + switch (kind) + { + case TK_ALIAS: + { + ret = alias_to_idl(node, idl); + break; + } + case TK_BITMASK: + { + ret = bitmask_to_idl(node, idl); + break; + } + case TK_BITSET: + { + ret = bitset_to_idl(node, idl); + break; + } + case TK_ENUM: + { + ret = enum_to_idl(node, idl); + break; + } + case TK_STRUCTURE: + { + ret = struct_to_idl(node, idl); + break; + } + case TK_UNION: + { + ret = union_to_idl(node, idl); + break; + } + default: + { + continue; + } + } + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error writing " << node.info.type_kind_name << " to IDL."); + return ret; + } + + idl << "\n"; + types_written.insert(node.info.type_kind_name); + } + + // Write the struct root node at last, after all its dependencies + ret = struct_to_idl(root, idl); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error writing " << root.info.type_kind_name << " to IDL."); + return ret; + } + + return ret; +} + +ReturnCode_t alias_to_idl( + const TreeNode& node, + std::ostream& idl) noexcept +{ + assert(node.info.dynamic_type->get_kind() == TK_ALIAS); + + ReturnCode_t ret = RETCODE_OK; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + ret = node.info.dynamic_type->get_descriptor(type_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting type descriptor of " << node << "."); + return ret; + } + + idl << "typedef "; + + // Find the base type of the alias + ret = type_kind_to_idl(type_descriptor->base_type(), idl); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting IDL representation of " << node << "."); + return ret; + } + + idl << " " << node.info.type_kind_name << ";\n"; + + return ret; +} + +ReturnCode_t bitmask_to_idl( + const TreeNode& node, + std::ostream& idl) noexcept +{ + assert(node.info.dynamic_type->get_kind() == TK_BITMASK); + + ReturnCode_t ret = RETCODE_OK; + + BoundSeq bounds; + ret = get_bounds(node.info.dynamic_type, bounds); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting bounds of " << node << "."); + return ret; + } + + if (1 != bounds.size()) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Bitmask type has " << bounds.size() << " bounds instead of one."); + return RETCODE_BAD_PARAMETER; + } + + // Annotation with the bitmask size + static constexpr std::uint32_t DEFAULT_BITMASK_SIZE = 32; + const auto bitmask_size = bounds[0]; + + if (DEFAULT_BITMASK_SIZE != bitmask_size) + { + idl << "@bit_bound(" << std::to_string(bitmask_size) << ")\n"; + } + + idl << "bitmask " << node.info.type_kind_name << TYPE_OPENING; + + const auto member_count = node.info.dynamic_type->get_member_count(); + + std::uint32_t pos = 0; + + for (std::uint32_t index = 0; index < member_count; index++) + { + DynamicTypeMember::_ref_type member; + ret = node.info.dynamic_type->get_member_by_index(member, index); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting member of " << node << " at index " << index << "."); + return ret; + } + + idl << TAB_SEPARATOR; + + // Annotation with the position + const auto id = member->get_id(); + + if (id != pos) + { + idl << "@position(" << std::to_string(id) << ") "; + } + + idl << member->get_name().to_string(); + + // Add comma if not last member + if (index < member_count - 1) + { + idl << ","; + } + + idl << "\n"; + + // The position is always sequential + pos = id + 1; + } + + // Close definition + idl << TYPE_CLOSURE; + + return ret; +} + +ReturnCode_t bitset_to_idl( + const TreeNode& node, + std::ostream& idl) noexcept +{ + assert(node.info.dynamic_type->get_kind() == TK_BITSET); + + ReturnCode_t ret = RETCODE_OK; + + idl << "bitset " << node.info.type_kind_name << TYPE_OPENING; + + // Find the bits that each bitfield occupies + BoundSeq bounds; + ret = get_bounds(node.info.dynamic_type, bounds); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting bounds of " << node.info.dynamic_type->get_name().to_string() << "."); + return ret; + } + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + ret = node.info.dynamic_type->get_descriptor(type_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting type descriptor of " << node << "."); + return ret; + } + + std::uint32_t bits_set = 0; + + for (std::uint32_t index = 0; index < node.info.dynamic_type->get_member_count(); index++) + { + traits::ref_type member; + ret = node.info.dynamic_type->get_member_by_index(member, index); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting member of " << node << " at index " << index << "."); + return ret; + } + + // The id of the member is the position in the bitset + const auto id = member->get_id(); + + if (id > bits_set) + { + // If the id is higher than the bits set, there must have been an empty bitfield (i.e. a gap) + const auto gap = id - bits_set; + bits_set += gap; + + idl << TAB_SEPARATOR << "bitfield<" << std::to_string(gap) << ">;\n"; + } + + idl << TAB_SEPARATOR << "bitfield<" << std::to_string(bounds[index]); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + ret = member->get_descriptor(member_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting member descriptor of " << member->get_name() << "."); + return ret; + } + + TypeKind default_type_kind; + ret = get_default_type_kind(bounds[index], default_type_kind); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting default type kind."); + return ret; + } + + // WARNING: If a user had explicitly set the type to be the default type, the serialization to IDL will not + // set it explicitly. + if (member_descriptor->type()->get_kind() != default_type_kind) + { + idl << ", "; + + // The type of the bitfield is not the default type. Write it. + type_kind_to_idl(member_descriptor->type(), idl); + } + + idl << "> " << member->get_name().to_string() << ";\n"; + + bits_set += bounds[index]; + } + + // Close definition + idl << TYPE_CLOSURE; + + return ret; +} + +ReturnCode_t enum_to_idl( + const TreeNode& node, + std::ostream& idl) noexcept +{ + assert(node.info.dynamic_type->get_kind() == TK_ENUM); + + ReturnCode_t ret = RETCODE_OK; + + idl << "enum " << node.info.type_kind_name << TYPE_OPENING << TAB_SEPARATOR; + + for (std::uint32_t index = 0; index < node.info.dynamic_type->get_member_count(); index++) + { + traits::ref_type member; + ret = node.info.dynamic_type->get_member_by_index(member, index); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting member of " << node << " at index " << index << "."); + return ret; + } + + if (0 != index) + { + idl << ",\n" << TAB_SEPARATOR; + } + + idl << member->get_name().to_string(); + } + + // Close definition + idl << "\n" << TYPE_CLOSURE; + + return ret; +} + +ReturnCode_t struct_to_idl( + const TreeNode& node, + std::ostream& idl) noexcept +{ + assert(node.info.dynamic_type->get_kind() == TK_STRUCTURE); + + ReturnCode_t ret = RETCODE_OK; + + // Annotation with the extensibility kind + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + ret = node.info.dynamic_type->get_descriptor(type_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting type descriptor of " << node << "."); + return ret; + } + + switch (type_descriptor->extensibility_kind()) + { + case ExtensibilityKind::FINAL: + { + idl << "@extensibility(FINAL)\n"; + break; + } + case ExtensibilityKind::MUTABLE: + { + idl << "@extensibility(MUTABLE)\n"; + break; + } + case ExtensibilityKind::APPENDABLE: + { + // Appendable is the default extensibility kind + break; + } + default: + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Extensibility kind not supported."); + return RETCODE_BAD_PARAMETER; + } + } + + // Add types name + idl << "struct " << node.info.type_kind_name; + + const auto base_type = type_descriptor->base_type(); + + // Add inheritance + if (nullptr != base_type) + { + idl << " : "; + + ret = type_kind_to_idl(base_type, idl); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting IDL representation of " << base_type->get_name().to_string() << "."); + return ret; + } + } + + idl << TYPE_OPENING; + + // Add struct attributes + for (auto const& child : node.branches()) + { + if (child.info.is_base) + { + continue; + } + + node_to_idl(child.info, idl); + + idl << ";\n"; + } + + // Close definition + idl << TYPE_CLOSURE; + + return ret; +} + +ReturnCode_t union_to_idl( + const TreeNode& node, + std::ostream& idl) noexcept +{ + assert(node.info.dynamic_type->get_kind() == TK_UNION); + + ReturnCode_t ret = RETCODE_OK; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + ret = node.info.dynamic_type->get_descriptor(type_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting type descriptor of " << node << "."); + return ret; + } + + idl << "union " << node.info.type_kind_name << " switch ("; + + ret = type_kind_to_idl(type_descriptor->discriminator_type(), idl); + + if (RETCODE_OK != ret) + { + return ret; + } + + idl << ")" << TYPE_OPENING; + + for (std::uint32_t index = 1; index < node.info.dynamic_type->get_member_count(); index++) + { + traits::ref_type member; + ret = node.info.dynamic_type->get_member_by_index(member, index); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + ret = member->get_descriptor(member_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Error getting member descriptor of " << member->get_name() << "."); + return ret; + } + + const auto labels = member_descriptor->label(); // WARNING: There might be casting issues as discriminant type is currently not taken into consideration + + for (const auto& label : labels) + { + idl << TAB_SEPARATOR << "case " << std::to_string(label) << ":\n"; + } + + if (member_descriptor->is_default_label()) + { + idl << TAB_SEPARATOR << "default:\n"; + } + + idl << TAB_SEPARATOR << TAB_SEPARATOR; + + ret = type_kind_to_idl(member_descriptor->type(), idl); + + if (RETCODE_OK != ret) + { + return ret; + } + + idl << " " << member->get_name().to_string() << ";\n"; + } + + // Close definition + idl << TYPE_CLOSURE; + + return ret; +} + +ReturnCode_t node_to_idl( + const TreeNode& node, + std::ostream& idl) noexcept +{ + idl << TAB_SEPARATOR; + + if (node.info.is_key) + { + idl << "@key "; + } + + if (TK_ARRAY == node.info.dynamic_type->get_kind()) + { + const auto dim_pos = node.info.type_kind_name.find("["); + + if (std::string::npos == dim_pos) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Array type name is not well formed."); + return RETCODE_BAD_PARAMETER; + } + + const auto kind_name_str = node.info.type_kind_name.substr(0, dim_pos); + const auto dim_str = node.info.type_kind_name.substr(dim_pos, std::string::npos); + + idl << kind_name_str << " " << node.info.member_name << dim_str; + } + else + { + idl << node.info.type_kind_name << " " << node.info.member_name; + } + + return RETCODE_OK; +} + +/////////////////////// +// AUXILIARY METHODS // +/////////////////////// + +ReturnCode_t get_element_type( + const DynamicType::_ref_type& dyn_type, + DynamicType::_ref_type& element_type) noexcept +{ + ReturnCode_t ret = RETCODE_OK; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + ret = dyn_type->get_descriptor(type_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting type descriptor of " << dyn_type->get_name().to_string() << "."); + return ret; + } + + element_type = type_descriptor->element_type(); + + return ret; +} + +ReturnCode_t get_bounds( + const DynamicType::_ref_type& dyn_type, + BoundSeq& bounds) noexcept +{ + ReturnCode_t ret = RETCODE_OK; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + ret = dyn_type->get_descriptor(type_descriptor); + + if (RETCODE_OK != ret) + { + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, + "Error getting type descriptor of " << dyn_type->get_name().to_string() << "."); + return ret; + } + + bounds = type_descriptor->bound(); + + static constexpr auto UNBOUNDED = static_cast(LENGTH_UNLIMITED); + + if (1 == bounds.size() && UNBOUNDED == bounds[0]) + { + bounds.clear(); + } + + return ret; +} + +ReturnCode_t get_default_type_kind( + const std::uint32_t size, + TypeKind& default_type) noexcept +{ + if (size == 1) + { + default_type = TK_BOOLEAN; + } + else if (size <= 8) + { + default_type = TK_UINT8; + } + else if (size <= 16) + { + default_type = TK_UINT16; + } + else if (size <= 32) + { + default_type = TK_UINT32; + } + else if (size <= 64) + { + default_type = TK_UINT64; + } + else + { + // Set to none to avoid `may be used uninitialized` error + default_type = TK_NONE; + + EPROSIMA_LOG_ERROR(DYNAMIC_TYPE_IDL, "Size " << size << " is not supported."); + return RETCODE_BAD_PARAMETER; + } + + return RETCODE_OK; +} + +} // namespace dds +} // namespace fastdds +} // namespace eprosima diff --git a/src/cpp/fastdds/xtypes/serializers/idl/dynamic_type_idl.hpp b/src/cpp/fastdds/xtypes/serializers/idl/dynamic_type_idl.hpp new file mode 100644 index 00000000000..80ed0d1ae8a --- /dev/null +++ b/src/cpp/fastdds/xtypes/serializers/idl/dynamic_type_idl.hpp @@ -0,0 +1,262 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file dynamic_type_idl.hpp + */ + +#ifndef FASTDDS_DDS_XTYPES_SERIALIZERS_IDL__DYNAMIC_TYPE_IDL_HPP +#define FASTDDS_DDS_XTYPES_SERIALIZERS_IDL__DYNAMIC_TYPE_IDL_HPP + +#include +#include +#include + +#include +#include +#include +#include + +#include "utils/collections/TreeNode.hpp" + +namespace eprosima { +namespace fastdds { +namespace dds { + +struct TreeNodeType +{ + TreeNodeType() + { + } + + TreeNodeType( + const std::string& member_name, + const std::string& type_kind_name, + const DynamicType::_ref_type& dynamic_type, + const bool is_base = false, + const bool is_key = false) + : member_name(member_name) + , type_kind_name(type_kind_name) + , dynamic_type(dynamic_type) + , is_base(is_base) + , is_key(is_key) + { + } + + std::string member_name; + std::string type_kind_name; + DynamicType::_ref_type dynamic_type; + bool is_base; + bool is_key; +}; + +inline std::ostream& operator <<( + std::ostream& output, + const TreeNodeType& info) +{ + output << info.type_kind_name; + return output; +} + +////////////////////////// +// DYNAMIC TYPE TO TREE // +////////////////////////// + +/** + * @brief Converts a DynamicType to a tree. + * + * @param type The DynamicType to represent as a tree. + * @param member_name The name of the root node. + * @param node The root node of the tree. + */ +ReturnCode_t dyn_type_to_tree( + const DynamicType::_ref_type& type, + const std::string& member_name, + utilities::collections::TreeNode& node) noexcept; + +/** + * @brief Converts a DynamicType to a string. + * + * @param dyn_type The DynamicType to convert. + * @param idl The idl representation of the DynamicType. + */ +ReturnCode_t type_kind_to_idl( + const DynamicType::_ref_type& dyn_type, + std::ostream& idl) noexcept; + +/** + * @brief Converts a DynamicType of \c TK_ARRAY kind to an idl. + * + * @param dyn_type The DynamicType kind to convert. + * @param array_str The string representation of the DynamicType kind. + */ +ReturnCode_t array_kind_to_idl( + const DynamicType::_ref_type& dyn_type, + std::ostream& idl) noexcept; + +/** + * @brief Converts a DynamicType of \c TK_MAP kind to an idl. + * + * @param dyn_type The DynamicType to convert. + * @param idl The idl representation of the DynamicType. + */ +ReturnCode_t map_kind_to_idl( + const DynamicType::_ref_type& dyn_type, + std::ostream& idl) noexcept; + +/** + * @brief Converts a DynamicType of \c TK_SEQUENCE kind to an idl. + * + * @param dyn_type The DynamicType to convert. + * @param idl The idl representation of the DynamicType. + */ +ReturnCode_t sequence_kind_to_idl( + const DynamicType::_ref_type& dyn_type, + std::ostream& idl) noexcept; + +/** + * @brief Converts a DynamicType of \c TK_STRING8 or \c TK_STRING16 kind to an idl. + * + * @param dyn_type The DynamicType to convert. + * @param idl The idl representation of the DynamicType. + */ +ReturnCode_t string_kind_to_idl( + const DynamicType::_ref_type& dyn_type, + std::ostream& idl) noexcept; + +////////////////////////////// +// DYNAMIC TYPE TREE TO IDL // +////////////////////////////// + +/** + * @brief Converts a tree to an IDL stream. + * + * @param root The root node of the tree. + * @param idl The idl representation of the tree. + */ +ReturnCode_t dyn_type_tree_to_idl( + const utilities::collections::TreeNode& root, + std::ostream& idl) noexcept; + +/** + * @brief Converts a tree with a \c TK_ALIAS root to an IDL stream. + * + * @param node The root node of the tree. + * @param idl The idl representation of the tree. + */ +ReturnCode_t alias_to_idl( + const utilities::collections::TreeNode& node, + std::ostream& idl) noexcept; + +/** + * @brief Converts a tree with a \c TK_BITMASK root to an IDL stream. + * + * @param node The root node of the tree. + * @param idl The idl representation of the tree. + */ +ReturnCode_t bitmask_to_idl( + const utilities::collections::TreeNode& node, + std::ostream& idl) noexcept; + +/** + * @brief Converts a tree with a \c TK_BITSET root to an IDL stream. + * + * @param node The root node of the tree. + * @param idl The idl representation of the tree. + */ +ReturnCode_t bitset_to_idl( + const utilities::collections::TreeNode& node, + std::ostream& idl) noexcept; + +/** + * @brief Converts a tree with a \c TK_ENUM root to an IDL stream. + * + * @param node The root node of the tree. + * @param idl The idl representation of the tree. + */ +ReturnCode_t enum_to_idl( + const utilities::collections::TreeNode& node, + std::ostream& idl) noexcept; + +/** + * @brief Converts a tree with a \c TK_STRUCTURE root to an IDL stream. + * + * @param node The root node of the tree. + * @param idl The idl representation of the tree. + */ +ReturnCode_t struct_to_idl( + const utilities::collections::TreeNode& node, + std::ostream& idl) noexcept; + +/** + * @brief Converts a tree with a \c TK_UNION root to an IDL stream. + * + * @param node The root node of the tree. + * @param idl The idl representation of the tree. + */ +ReturnCode_t union_to_idl( + const utilities::collections::TreeNode& node, + std::ostream& idl) noexcept; + +/** + * @brief Converts a simple tree to an IDL string. + * + * @param node The root node of the tree. + * @param idl The idl representation of the tree. + */ +ReturnCode_t node_to_idl( + const utilities::collections::TreeNode& node, + std::ostream& idl) noexcept; + +/////////////////////// +// AUXILIARY METHODS // +/////////////////////// + +/** + * @brief Gathers the \c element_type of the @ref DynamicType. + * + * @param dyn_type The DynamicType to gather the \c element_type from. + * @param element_type The element type of the DynamicType's \c type_descriptor. + */ +ReturnCode_t get_element_type( + const DynamicType::_ref_type& dyn_type, + DynamicType::_ref_type& element_type) noexcept; + +/** + * @brief Gathers the \c bounds of the @ref DynamicType. + * + * If there is a single bound of LENGTH_UNLIMITED, the bounds will be empty. + * + * @param dyn_type The DynamicType to gather the \c bounds from. + * @param bounds The bounds of the DynamicType's \c type_descriptor. + */ +ReturnCode_t get_bounds( + const DynamicType::_ref_type& dyn_type, + BoundSeq& bounds) noexcept; + +/** + * @brief Finds the default type kind for a variable with a given size. + * + * @param size The size of the variable. + * @param default_type The default type kind. + */ +ReturnCode_t get_default_type_kind( + const std::uint32_t size, + TypeKind& default_type) noexcept; + +} // dds +} // fastdds +} // eprosima + +#endif // FASTDDS_DDS_XTYPES_SERIALIZERS_IDL__DYNAMIC_TYPE_IDL_HPP diff --git a/src/cpp/fastdds/xtypes/utils.cpp b/src/cpp/fastdds/xtypes/utils.cpp index 31382ffe19a..657eb9c8cd7 100644 --- a/src/cpp/fastdds/xtypes/utils.cpp +++ b/src/cpp/fastdds/xtypes/utils.cpp @@ -16,19 +16,52 @@ #include -#include - #include #include +#include #include "dynamic_types/DynamicDataImpl.hpp" - +#include "serializers/idl/dynamic_type_idl.hpp" #include "serializers/json/dynamic_data_json.hpp" +#include "utils/collections/TreeNode.hpp" + +#include + namespace eprosima { namespace fastdds { namespace dds { +ReturnCode_t idl_serialize( + const DynamicType::_ref_type& dynamic_type, + std::ostream& output) noexcept +{ + ReturnCode_t ret = RETCODE_OK; + + // Create a tree representation of the dynamic type + utilities::collections::TreeNode root; + ret = dyn_type_to_tree(dynamic_type, "ROOT", root); + + if (ret != RETCODE_OK) + { + EPROSIMA_LOG_ERROR(XTYPES_UTILS, + "Failed to convert DynamicType to tree."); + return ret; + } + + // Serialize the tree to IDL + ret = dyn_type_tree_to_idl(root, output); + + if (ret != RETCODE_OK) + { + EPROSIMA_LOG_ERROR(XTYPES_UTILS, + "Failed to convert DynamicType tree to IDL."); + return ret; + } + + return RETCODE_OK; +} + ReturnCode_t json_serialize( const DynamicData::_ref_type& data, const DynamicDataJsonFormat format, diff --git a/src/cpp/utils/UnitsParser.hpp b/src/cpp/utils/UnitsParser.hpp index d04e4f6625d..2101d3bc0ab 100644 --- a/src/cpp/utils/UnitsParser.hpp +++ b/src/cpp/utils/UnitsParser.hpp @@ -32,7 +32,7 @@ namespace utils { * * @param [in] st String to convert */ -inline void to_uppercase( +void to_uppercase( std::string& st) noexcept; /** diff --git a/src/cpp/utils/collections/TreeNode.hpp b/src/cpp/utils/collections/TreeNode.hpp new file mode 100644 index 00000000000..97001e58868 --- /dev/null +++ b/src/cpp/utils/collections/TreeNode.hpp @@ -0,0 +1,97 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file TreeNode.hpp + */ + +#ifndef FASTDDS_UTILS_COLLECTIONS__TREE_NODE_HPP +#define FASTDDS_UTILS_COLLECTIONS__TREE_NODE_HPP + +#include + +namespace eprosima { +namespace utilities { +namespace collections { + +/** + * Generic data struct of with an internal value of type \c Info . + */ +template +struct Node +{ +public: + + Node(); + Node( + const Info& inner_info); + Node( + Info&& inner_info); + + template + Node( + Args... args); + + Info info; +}; + +/** + * Class that represents each of the Nodes that form a Tree, including the source and the leaves. + */ +template +class TreeNode : public Node +{ +public: + + using Node::Node; + + void add_branch( + const Info& inner_info); + void add_branch( + Info&& inner_info); + void add_branch( + const TreeNode& node); + void add_branch( + TreeNode&& node); + + bool leaf() const noexcept; + + unsigned int depth() const noexcept; + + const std::list& branches() const noexcept; + + std::list all_nodes() const noexcept; + +protected: + + std::list branches_; +}; + +template +inline std::ostream& operator <<( + std::ostream& output, + const TreeNode& node) +{ + output << node.info; + return output; +} + +} /* namespace collections */ +} /* namespace utilities */ +} /* namespace eprosima */ + +// Include implementation template file +#include "impl/TreeNode.ipp" + +#endif /* FASTDDS_UTILS_COLLECTIONS__TREE_NODE_HPP */ diff --git a/src/cpp/utils/collections/impl/TreeNode.ipp b/src/cpp/utils/collections/impl/TreeNode.ipp new file mode 100644 index 00000000000..843295aa86d --- /dev/null +++ b/src/cpp/utils/collections/impl/TreeNode.ipp @@ -0,0 +1,133 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file TreeNode.ipp + */ + +#ifndef FASTDDS_UTILS_COLLECTIONS_IMPL__TREE_NODE_IPP +#define FASTDDS_UTILS_COLLECTIONS_IMPL__TREE_NODE_IPP + +#include + + +namespace eprosima { +namespace utilities { +namespace collections { + +template +Node::Node() +{ + // Do nothing +} + +template +Node::Node( + const Info& inner_info) + : info(inner_info) +{ + // Do nothing +} + +template +Node::Node( + Info&& inner_info) + : info(std::move(inner_info)) +{ + // Do nothing +} + +template +template +Node::Node( + Args... args) + : info(args ...) +{ + // Do nothing +} + +template +void TreeNode::add_branch( + const Info& inner_info) +{ + branches_.push_back(TreeNode(inner_info)); +} + +template +void TreeNode::add_branch( + Info&& inner_info) +{ + branches_.push_back(TreeNode(std::move(inner_info))); +} + +template +void TreeNode::add_branch( + const TreeNode& node) +{ + branches_.push_back(node); +} + +template +void TreeNode::add_branch( + TreeNode&& node) +{ + branches_.push_back(std::move(node)); +} + +template +bool TreeNode::leaf() const noexcept +{ + return branches_.empty(); +} + +template +unsigned int TreeNode::depth() const noexcept +{ + unsigned int max_child_depth = 0; + + for (const auto& branch : branches_) + { + const auto child_depth = branch.depth() + 1; + max_child_depth = std::max(max_child_depth, child_depth); + } + + return max_child_depth; +} + +template +const std::list>& TreeNode::branches() const noexcept +{ + return branches_; +} + +template +std::list> TreeNode::all_nodes() const noexcept +{ + std::list> nodes; + + for (const auto& child : branches_) + { + auto branch_nodes = child.all_nodes(); + nodes.splice(nodes.end(), branch_nodes); + nodes.push_back(child); + } + + return nodes; +} + +} /* namespace collections */ +} /* namespace utilities */ +} /* namespace eprosima */ + +#endif /* FASTDDS_UTILS_COLLECTIONS_IMPL__TREE_NODE_IPP */ diff --git a/test/unittest/dds/xtypes/serializers/CMakeLists.txt b/test/unittest/dds/xtypes/serializers/CMakeLists.txt index ef7c1507986..04eaea02b54 100644 --- a/test/unittest/dds/xtypes/serializers/CMakeLists.txt +++ b/test/unittest/dds/xtypes/serializers/CMakeLists.txt @@ -12,4 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. +add_subdirectory(idl) add_subdirectory(json) diff --git a/test/unittest/dds/xtypes/serializers/idl/CMakeLists.txt b/test/unittest/dds/xtypes/serializers/idl/CMakeLists.txt new file mode 100644 index 00000000000..2bf25855870 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/CMakeLists.txt @@ -0,0 +1,58 @@ +# Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Recursively find all .idl files in the types directory +file(GLOB_RECURSE IDL_FILES ${CMAKE_CURRENT_SOURCE_DIR}/types/*.idl) + +# Iterate over each .idl file found +foreach(IDL_FILE ${IDL_FILES}) + # Get the relative path of the .idl file + file(RELATIVE_PATH RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${IDL_FILE}) + + # Determine the destination directory + set(DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/${RELATIVE_PATH}) + get_filename_component(DEST_DIR ${DEST_DIR} DIRECTORY) + + # Ensure the destination directory exists + file(MAKE_DIRECTORY ${DEST_DIR}) + + # Copy the .idl file to the destination directory + configure_file(${IDL_FILE} ${DEST_DIR} COPYONLY) +endforeach() + +set(RESOURCEDYNTYPETOIDLTESTS_SOURCE + DynTypeIDLTests.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/UnitsParser.cpp) + +file(GLOB DATATYPE_SOURCES "types/**/gen/*.cxx") + +if(WIN32) + add_definitions(-D_WIN32_WINNT=0x0601) +endif() + +add_executable(DynTypeIDLTests ${RESOURCEDYNTYPETOIDLTESTS_SOURCE} ${DATATYPE_SOURCES}) +target_compile_definitions(DynTypeIDLTests PRIVATE + $<$>,$>:__DEBUG> + $<$:__INTERNALDEBUG> # Internal debug activated. + ) +target_include_directories(DynTypeIDLTests PRIVATE + ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include + ${PROJECT_SOURCE_DIR}/src/cpp + ) +target_link_libraries(DynTypeIDLTests + fastcdr + fastdds + GTest::gtest + ${CMAKE_DL_LIBS}) +gtest_discover_tests(DynTypeIDLTests SOURCES ${TYPEOBJECTUTILSTESTS_SOURCE}) diff --git a/test/unittest/dds/xtypes/serializers/idl/DynTypeIDLTests.cpp b/test/unittest/dds/xtypes/serializers/idl/DynTypeIDLTests.cpp new file mode 100644 index 00000000000..e27efe0ce56 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/DynTypeIDLTests.cpp @@ -0,0 +1,134 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "types/all_types.hpp" + +using namespace eprosima; +using namespace eprosima::fastdds::dds; + + +class DynTypeIDLTests : public ::testing::TestWithParam +{ +protected: + + void get_dynamic_type( + const std::string& type_name, + DynamicType::_ref_type& dyn_type) + { + // Find TypeObjects for the type + xtypes::TypeObjectPair type_objs; + ASSERT_EQ(DomainParticipantFactory::get_instance()->type_object_registry().get_type_objects( + type_name, type_objs), + fastdds::dds::RETCODE_OK); + + // Create DynamicType from TypeObject + dyn_type = DynamicTypeBuilderFactory::get_instance()->create_type_w_type_object( + type_objs.complete_type_object)->build(); + } + + std::string snake_to_camel( + const std::string& snake_case) + { + std::string camel_case; + bool to_upper = true; + + for (const auto& ch : snake_case) + { + if (ch == '_') + { + to_upper = true; + } + else if (to_upper) + { + std::string ch_str(1, ch); + utils::to_uppercase(ch_str); + camel_case += ch_str; + to_upper = false; + } + else + { + camel_case += ch; + } + } + + return camel_case; + } + +}; + +/** + * Verify that the IDL serialization of a DynamicType generated with Fast-DDS Gen matches its IDL file. + * + * CASES: + * - Verify that the IDL file was opened successfully. + * - Verify that the IDL serialization finished successfully. + * - Verify that the two IDLs match. + */ +TEST_P(DynTypeIDLTests, to_idl) +{ + const std::string type = GetParam(); + + test::register_type_object_representation(type); + + // Read the IDL file as a string + const auto file_name = std::string("types/") + type + "/" + type + ".idl"; + + std::ifstream file(file_name); + ASSERT_TRUE(file.is_open()); + + const std::string idl_file{std::istreambuf_iterator(file), std::istreambuf_iterator()}; + + // Get Dynamic type + DynamicType::_ref_type dyn_type; + get_dynamic_type(snake_to_camel(type), dyn_type); + ASSERT_NE(dyn_type, nullptr); + + // Serialize DynamicType to IDL + std::stringstream idl_serialization; + ASSERT_EQ(idl_serialize(dyn_type, idl_serialization), RETCODE_OK); + + // Compare IDLs + ASSERT_EQ(idl_file, idl_serialization.str()); +} + +INSTANTIATE_TEST_SUITE_P( + DynTypeIDLTests, + DynTypeIDLTests, + ::testing::ValuesIn(test::supported_types) + ); + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/alias_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/alias_struct.idl new file mode 100644 index 00000000000..bee9e3e2028 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/alias_struct.idl @@ -0,0 +1,17 @@ +typedef unsigned long MyLong; + +typedef short MyShort; + +typedef MyShort MyRecursiveShort; + +typedef boolean MyBoolean; + +typedef MyBoolean MyRecursiveBoolean; + +struct AliasStruct +{ + MyLong my_long; + MyRecursiveShort my_recursive_short; + MyRecursiveBoolean my_recursive_boolean; + MyBoolean my_boolean; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_struct.hpp new file mode 100644 index 00000000000..5eb80d5f9b4 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_struct.hpp @@ -0,0 +1,299 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file alias_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ALIAS_STRUCT_HPP +#define FAST_DDS_GENERATED__ALIAS_STRUCT_HPP + +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(ALIAS_STRUCT_SOURCE) +#define ALIAS_STRUCT_DllAPI __declspec( dllexport ) +#else +#define ALIAS_STRUCT_DllAPI __declspec( dllimport ) +#endif // ALIAS_STRUCT_SOURCE +#else +#define ALIAS_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define ALIAS_STRUCT_DllAPI +#endif // _WIN32 + +typedef uint32_t MyLong; + +typedef int16_t MyShort; + +typedef MyShort MyRecursiveShort; + +typedef bool MyBoolean; + +typedef MyBoolean MyRecursiveBoolean; + +/*! + * @brief This class represents the structure AliasStruct defined by the user in the IDL file. + * @ingroup alias_struct + */ +class AliasStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport AliasStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~AliasStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object AliasStruct that will be copied. + */ + eProsima_user_DllExport AliasStruct( + const AliasStruct& x) + { + m_my_long = x.m_my_long; + + m_my_recursive_short = x.m_my_recursive_short; + + m_my_recursive_boolean = x.m_my_recursive_boolean; + + m_my_boolean = x.m_my_boolean; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object AliasStruct that will be copied. + */ + eProsima_user_DllExport AliasStruct( + AliasStruct&& x) noexcept + { + m_my_long = x.m_my_long; + m_my_recursive_short = x.m_my_recursive_short; + m_my_recursive_boolean = x.m_my_recursive_boolean; + m_my_boolean = x.m_my_boolean; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object AliasStruct that will be copied. + */ + eProsima_user_DllExport AliasStruct& operator =( + const AliasStruct& x) + { + + m_my_long = x.m_my_long; + + m_my_recursive_short = x.m_my_recursive_short; + + m_my_recursive_boolean = x.m_my_recursive_boolean; + + m_my_boolean = x.m_my_boolean; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object AliasStruct that will be copied. + */ + eProsima_user_DllExport AliasStruct& operator =( + AliasStruct&& x) noexcept + { + + m_my_long = x.m_my_long; + m_my_recursive_short = x.m_my_recursive_short; + m_my_recursive_boolean = x.m_my_recursive_boolean; + m_my_boolean = x.m_my_boolean; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x AliasStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const AliasStruct& x) const + { + return (m_my_long == x.m_my_long && + m_my_recursive_short == x.m_my_recursive_short && + m_my_recursive_boolean == x.m_my_recursive_boolean && + m_my_boolean == x.m_my_boolean); + } + + /*! + * @brief Comparison operator. + * @param x AliasStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const AliasStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_long + * @param _my_long New value for member my_long + */ + eProsima_user_DllExport void my_long( + MyLong _my_long) + { + m_my_long = _my_long; + } + + /*! + * @brief This function returns the value of member my_long + * @return Value of member my_long + */ + eProsima_user_DllExport MyLong my_long() const + { + return m_my_long; + } + + /*! + * @brief This function returns a reference to member my_long + * @return Reference to member my_long + */ + eProsima_user_DllExport MyLong& my_long() + { + return m_my_long; + } + + + /*! + * @brief This function sets a value in member my_recursive_short + * @param _my_recursive_short New value for member my_recursive_short + */ + eProsima_user_DllExport void my_recursive_short( + MyRecursiveShort _my_recursive_short) + { + m_my_recursive_short = _my_recursive_short; + } + + /*! + * @brief This function returns the value of member my_recursive_short + * @return Value of member my_recursive_short + */ + eProsima_user_DllExport MyRecursiveShort my_recursive_short() const + { + return m_my_recursive_short; + } + + /*! + * @brief This function returns a reference to member my_recursive_short + * @return Reference to member my_recursive_short + */ + eProsima_user_DllExport MyRecursiveShort& my_recursive_short() + { + return m_my_recursive_short; + } + + + /*! + * @brief This function sets a value in member my_recursive_boolean + * @param _my_recursive_boolean New value for member my_recursive_boolean + */ + eProsima_user_DllExport void my_recursive_boolean( + MyRecursiveBoolean _my_recursive_boolean) + { + m_my_recursive_boolean = _my_recursive_boolean; + } + + /*! + * @brief This function returns the value of member my_recursive_boolean + * @return Value of member my_recursive_boolean + */ + eProsima_user_DllExport MyRecursiveBoolean my_recursive_boolean() const + { + return m_my_recursive_boolean; + } + + /*! + * @brief This function returns a reference to member my_recursive_boolean + * @return Reference to member my_recursive_boolean + */ + eProsima_user_DllExport MyRecursiveBoolean& my_recursive_boolean() + { + return m_my_recursive_boolean; + } + + + /*! + * @brief This function sets a value in member my_boolean + * @param _my_boolean New value for member my_boolean + */ + eProsima_user_DllExport void my_boolean( + MyBoolean _my_boolean) + { + m_my_boolean = _my_boolean; + } + + /*! + * @brief This function returns the value of member my_boolean + * @return Value of member my_boolean + */ + eProsima_user_DllExport MyBoolean my_boolean() const + { + return m_my_boolean; + } + + /*! + * @brief This function returns a reference to member my_boolean + * @return Reference to member my_boolean + */ + eProsima_user_DllExport MyBoolean& my_boolean() + { + return m_my_boolean; + } + + + +private: + + MyLong m_my_long{0}; + MyRecursiveShort m_my_recursive_short{0}; + MyRecursiveBoolean m_my_recursive_boolean{false}; + MyBoolean m_my_boolean{false}; + +}; + +#endif // _FAST_DDS_GENERATED_ALIAS_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structCdrAux.hpp new file mode 100644 index 00000000000..d66f04beecd --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structCdrAux.hpp @@ -0,0 +1,51 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file alias_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ALIAS_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__ALIAS_STRUCTCDRAUX_HPP + +#include "alias_struct.hpp" + +constexpr uint32_t AliasStruct_max_cdr_typesize {12UL}; +constexpr uint32_t AliasStruct_max_key_cdr_typesize {0UL}; + + + + + + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const AliasStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__ALIAS_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structCdrAux.ipp new file mode 100644 index 00000000000..1ef275df173 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structCdrAux.ipp @@ -0,0 +1,142 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file alias_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ALIAS_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__ALIAS_STRUCTCDRAUX_IPP + +#include "alias_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const AliasStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_long(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_recursive_short(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_recursive_boolean(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3), + data.my_boolean(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const AliasStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_long() + << eprosima::fastcdr::MemberId(1) << data.my_recursive_short() + << eprosima::fastcdr::MemberId(2) << data.my_recursive_boolean() + << eprosima::fastcdr::MemberId(3) << data.my_boolean() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + AliasStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_long(); + break; + + case 1: + dcdr >> data.my_recursive_short(); + break; + + case 2: + dcdr >> data.my_recursive_boolean(); + break; + + case 3: + dcdr >> data.my_boolean(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const AliasStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__ALIAS_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.cxx new file mode 100644 index 00000000000..5957e1d7df1 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.cxx @@ -0,0 +1,229 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file alias_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "alias_structPubSubTypes.hpp" + +#include +#include + +#include "alias_structCdrAux.hpp" +#include "alias_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +AliasStructPubSubType::AliasStructPubSubType() +{ + setName("AliasStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(AliasStruct::getMaxCdrSerializedSize()); +#else + AliasStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = AliasStruct_max_key_cdr_typesize > 16 ? AliasStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +AliasStructPubSubType::~AliasStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool AliasStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const AliasStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool AliasStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + AliasStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function AliasStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* AliasStructPubSubType::createData() +{ + return reinterpret_cast(new AliasStruct()); +} + +void AliasStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool AliasStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const AliasStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + AliasStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || AliasStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void AliasStructPubSubType::register_type_object_representation() +{ + register_AliasStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "alias_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.hpp new file mode 100644 index 00000000000..efef4820a40 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structPubSubTypes.hpp @@ -0,0 +1,138 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file alias_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__ALIAS_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__ALIAS_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "alias_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated alias_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + +typedef uint32_t MyLong; +typedef int16_t MyShort; +typedef MyShort MyRecursiveShort; +typedef bool MyBoolean; +typedef MyBoolean MyRecursiveBoolean; + +/*! + * @brief This class represents the TopicDataType of the type AliasStruct defined by the user in the IDL file. + * @ingroup alias_struct + */ +class AliasStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef AliasStruct type; + + eProsima_user_DllExport AliasStructPubSubType(); + + eProsima_user_DllExport ~AliasStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__ALIAS_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..f285da0197f --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structTypeObjectSupport.cxx @@ -0,0 +1,428 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file alias_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "alias_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "alias_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +void register_MyLong_type_identifier( + TypeIdentifierPair& type_ids_MyLong) +{ + ReturnCode_t return_code_MyLong {eprosima::fastdds::dds::RETCODE_OK}; + return_code_MyLong = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MyLong", type_ids_MyLong); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MyLong) + { + AliasTypeFlag alias_flags_MyLong = 0; + QualifiedTypeName type_name_MyLong = "MyLong"; + eprosima::fastcdr::optional type_ann_builtin_MyLong; + eprosima::fastcdr::optional ann_custom_MyLong; + CompleteTypeDetail detail_MyLong = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_MyLong, ann_custom_MyLong, type_name_MyLong.to_string()); + CompleteAliasHeader header_MyLong = TypeObjectUtils::build_complete_alias_header(detail_MyLong); + AliasMemberFlag related_flags_MyLong = 0; + return_code_MyLong = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_uint32_t", type_ids_MyLong); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MyLong) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "MyLong related TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool common_MyLong_ec {false}; + CommonAliasBody common_MyLong {TypeObjectUtils::build_common_alias_body(related_flags_MyLong, + TypeObjectUtils::retrieve_complete_type_identifier(type_ids_MyLong, common_MyLong_ec))}; + if (!common_MyLong_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "MyLong related TypeIdentifier inconsistent."); + return; + } + eprosima::fastcdr::optional member_ann_builtin_MyLong; + ann_custom_MyLong.reset(); + CompleteAliasBody body_MyLong = TypeObjectUtils::build_complete_alias_body(common_MyLong, + member_ann_builtin_MyLong, ann_custom_MyLong); + CompleteAliasType alias_type_MyLong = TypeObjectUtils::build_complete_alias_type(alias_flags_MyLong, + header_MyLong, body_MyLong); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_alias_type_object(alias_type_MyLong, + type_name_MyLong.to_string(), type_ids_MyLong)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "MyLong already registered in TypeObjectRegistry for a different type."); + } + } +} + +void register_MyShort_type_identifier( + TypeIdentifierPair& type_ids_MyShort) +{ + ReturnCode_t return_code_MyShort {eprosima::fastdds::dds::RETCODE_OK}; + return_code_MyShort = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MyShort", type_ids_MyShort); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MyShort) + { + AliasTypeFlag alias_flags_MyShort = 0; + QualifiedTypeName type_name_MyShort = "MyShort"; + eprosima::fastcdr::optional type_ann_builtin_MyShort; + eprosima::fastcdr::optional ann_custom_MyShort; + CompleteTypeDetail detail_MyShort = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_MyShort, ann_custom_MyShort, type_name_MyShort.to_string()); + CompleteAliasHeader header_MyShort = TypeObjectUtils::build_complete_alias_header(detail_MyShort); + AliasMemberFlag related_flags_MyShort = 0; + return_code_MyShort = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int16_t", type_ids_MyShort); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MyShort) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "MyShort related TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool common_MyShort_ec {false}; + CommonAliasBody common_MyShort {TypeObjectUtils::build_common_alias_body(related_flags_MyShort, + TypeObjectUtils::retrieve_complete_type_identifier(type_ids_MyShort, common_MyShort_ec))}; + if (!common_MyShort_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "MyShort related TypeIdentifier inconsistent."); + return; + } + eprosima::fastcdr::optional member_ann_builtin_MyShort; + ann_custom_MyShort.reset(); + CompleteAliasBody body_MyShort = TypeObjectUtils::build_complete_alias_body(common_MyShort, + member_ann_builtin_MyShort, ann_custom_MyShort); + CompleteAliasType alias_type_MyShort = TypeObjectUtils::build_complete_alias_type(alias_flags_MyShort, + header_MyShort, body_MyShort); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_alias_type_object(alias_type_MyShort, + type_name_MyShort.to_string(), type_ids_MyShort)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "MyShort already registered in TypeObjectRegistry for a different type."); + } + } +} + +void register_MyRecursiveShort_type_identifier( + TypeIdentifierPair& type_ids_MyRecursiveShort) +{ + ReturnCode_t return_code_MyRecursiveShort {eprosima::fastdds::dds::RETCODE_OK}; + return_code_MyRecursiveShort = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MyRecursiveShort", type_ids_MyRecursiveShort); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MyRecursiveShort) + { + AliasTypeFlag alias_flags_MyRecursiveShort = 0; + QualifiedTypeName type_name_MyRecursiveShort = "MyRecursiveShort"; + eprosima::fastcdr::optional type_ann_builtin_MyRecursiveShort; + eprosima::fastcdr::optional ann_custom_MyRecursiveShort; + CompleteTypeDetail detail_MyRecursiveShort = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_MyRecursiveShort, ann_custom_MyRecursiveShort, type_name_MyRecursiveShort.to_string()); + CompleteAliasHeader header_MyRecursiveShort = TypeObjectUtils::build_complete_alias_header(detail_MyRecursiveShort); + AliasMemberFlag related_flags_MyRecursiveShort = 0; + return_code_MyRecursiveShort = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MyShort", type_ids_MyRecursiveShort); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MyRecursiveShort) + { + ::register_MyShort_type_identifier(type_ids_MyRecursiveShort); + } + bool common_MyRecursiveShort_ec {false}; + CommonAliasBody common_MyRecursiveShort {TypeObjectUtils::build_common_alias_body(related_flags_MyRecursiveShort, + TypeObjectUtils::retrieve_complete_type_identifier(type_ids_MyRecursiveShort, common_MyRecursiveShort_ec))}; + if (!common_MyRecursiveShort_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "MyRecursiveShort related TypeIdentifier inconsistent."); + return; + } + eprosima::fastcdr::optional member_ann_builtin_MyRecursiveShort; + ann_custom_MyRecursiveShort.reset(); + CompleteAliasBody body_MyRecursiveShort = TypeObjectUtils::build_complete_alias_body(common_MyRecursiveShort, + member_ann_builtin_MyRecursiveShort, ann_custom_MyRecursiveShort); + CompleteAliasType alias_type_MyRecursiveShort = TypeObjectUtils::build_complete_alias_type(alias_flags_MyRecursiveShort, + header_MyRecursiveShort, body_MyRecursiveShort); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_alias_type_object(alias_type_MyRecursiveShort, + type_name_MyRecursiveShort.to_string(), type_ids_MyRecursiveShort)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "MyRecursiveShort already registered in TypeObjectRegistry for a different type."); + } + } +} + +void register_MyBoolean_type_identifier( + TypeIdentifierPair& type_ids_MyBoolean) +{ + ReturnCode_t return_code_MyBoolean {eprosima::fastdds::dds::RETCODE_OK}; + return_code_MyBoolean = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MyBoolean", type_ids_MyBoolean); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MyBoolean) + { + AliasTypeFlag alias_flags_MyBoolean = 0; + QualifiedTypeName type_name_MyBoolean = "MyBoolean"; + eprosima::fastcdr::optional type_ann_builtin_MyBoolean; + eprosima::fastcdr::optional ann_custom_MyBoolean; + CompleteTypeDetail detail_MyBoolean = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_MyBoolean, ann_custom_MyBoolean, type_name_MyBoolean.to_string()); + CompleteAliasHeader header_MyBoolean = TypeObjectUtils::build_complete_alias_header(detail_MyBoolean); + AliasMemberFlag related_flags_MyBoolean = 0; + return_code_MyBoolean = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_bool", type_ids_MyBoolean); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MyBoolean) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "MyBoolean related TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool common_MyBoolean_ec {false}; + CommonAliasBody common_MyBoolean {TypeObjectUtils::build_common_alias_body(related_flags_MyBoolean, + TypeObjectUtils::retrieve_complete_type_identifier(type_ids_MyBoolean, common_MyBoolean_ec))}; + if (!common_MyBoolean_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "MyBoolean related TypeIdentifier inconsistent."); + return; + } + eprosima::fastcdr::optional member_ann_builtin_MyBoolean; + ann_custom_MyBoolean.reset(); + CompleteAliasBody body_MyBoolean = TypeObjectUtils::build_complete_alias_body(common_MyBoolean, + member_ann_builtin_MyBoolean, ann_custom_MyBoolean); + CompleteAliasType alias_type_MyBoolean = TypeObjectUtils::build_complete_alias_type(alias_flags_MyBoolean, + header_MyBoolean, body_MyBoolean); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_alias_type_object(alias_type_MyBoolean, + type_name_MyBoolean.to_string(), type_ids_MyBoolean)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "MyBoolean already registered in TypeObjectRegistry for a different type."); + } + } +} + +void register_MyRecursiveBoolean_type_identifier( + TypeIdentifierPair& type_ids_MyRecursiveBoolean) +{ + ReturnCode_t return_code_MyRecursiveBoolean {eprosima::fastdds::dds::RETCODE_OK}; + return_code_MyRecursiveBoolean = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MyRecursiveBoolean", type_ids_MyRecursiveBoolean); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MyRecursiveBoolean) + { + AliasTypeFlag alias_flags_MyRecursiveBoolean = 0; + QualifiedTypeName type_name_MyRecursiveBoolean = "MyRecursiveBoolean"; + eprosima::fastcdr::optional type_ann_builtin_MyRecursiveBoolean; + eprosima::fastcdr::optional ann_custom_MyRecursiveBoolean; + CompleteTypeDetail detail_MyRecursiveBoolean = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_MyRecursiveBoolean, ann_custom_MyRecursiveBoolean, type_name_MyRecursiveBoolean.to_string()); + CompleteAliasHeader header_MyRecursiveBoolean = TypeObjectUtils::build_complete_alias_header(detail_MyRecursiveBoolean); + AliasMemberFlag related_flags_MyRecursiveBoolean = 0; + return_code_MyRecursiveBoolean = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MyBoolean", type_ids_MyRecursiveBoolean); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MyRecursiveBoolean) + { + ::register_MyBoolean_type_identifier(type_ids_MyRecursiveBoolean); + } + bool common_MyRecursiveBoolean_ec {false}; + CommonAliasBody common_MyRecursiveBoolean {TypeObjectUtils::build_common_alias_body(related_flags_MyRecursiveBoolean, + TypeObjectUtils::retrieve_complete_type_identifier(type_ids_MyRecursiveBoolean, common_MyRecursiveBoolean_ec))}; + if (!common_MyRecursiveBoolean_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "MyRecursiveBoolean related TypeIdentifier inconsistent."); + return; + } + eprosima::fastcdr::optional member_ann_builtin_MyRecursiveBoolean; + ann_custom_MyRecursiveBoolean.reset(); + CompleteAliasBody body_MyRecursiveBoolean = TypeObjectUtils::build_complete_alias_body(common_MyRecursiveBoolean, + member_ann_builtin_MyRecursiveBoolean, ann_custom_MyRecursiveBoolean); + CompleteAliasType alias_type_MyRecursiveBoolean = TypeObjectUtils::build_complete_alias_type(alias_flags_MyRecursiveBoolean, + header_MyRecursiveBoolean, body_MyRecursiveBoolean); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_alias_type_object(alias_type_MyRecursiveBoolean, + type_name_MyRecursiveBoolean.to_string(), type_ids_MyRecursiveBoolean)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "MyRecursiveBoolean already registered in TypeObjectRegistry for a different type."); + } + } +} + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_AliasStruct_type_identifier( + TypeIdentifierPair& type_ids_AliasStruct) +{ + + ReturnCode_t return_code_AliasStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_AliasStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "AliasStruct", type_ids_AliasStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_AliasStruct) + { + StructTypeFlag struct_flags_AliasStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_AliasStruct = "AliasStruct"; + eprosima::fastcdr::optional type_ann_builtin_AliasStruct; + eprosima::fastcdr::optional ann_custom_AliasStruct; + CompleteTypeDetail detail_AliasStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_AliasStruct, ann_custom_AliasStruct, type_name_AliasStruct.to_string()); + CompleteStructHeader header_AliasStruct; + header_AliasStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_AliasStruct); + CompleteStructMemberSeq member_seq_AliasStruct; + { + TypeIdentifierPair type_ids_my_long; + ReturnCode_t return_code_my_long {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_long = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MyLong", type_ids_my_long); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_long) + { + ::register_MyLong_type_identifier(type_ids_my_long); + } + StructMemberFlag member_flags_my_long = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_long = 0x00000000; + bool common_my_long_ec {false}; + CommonStructMember common_my_long {TypeObjectUtils::build_common_struct_member(member_id_my_long, member_flags_my_long, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_long, common_my_long_ec))}; + if (!common_my_long_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_long member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_long = "my_long"; + eprosima::fastcdr::optional member_ann_builtin_my_long; + ann_custom_AliasStruct.reset(); + CompleteMemberDetail detail_my_long = TypeObjectUtils::build_complete_member_detail(name_my_long, member_ann_builtin_my_long, ann_custom_AliasStruct); + CompleteStructMember member_my_long = TypeObjectUtils::build_complete_struct_member(common_my_long, detail_my_long); + TypeObjectUtils::add_complete_struct_member(member_seq_AliasStruct, member_my_long); + } + { + TypeIdentifierPair type_ids_my_recursive_short; + ReturnCode_t return_code_my_recursive_short {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_recursive_short = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MyRecursiveShort", type_ids_my_recursive_short); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_recursive_short) + { + ::register_MyRecursiveShort_type_identifier(type_ids_my_recursive_short); + } + StructMemberFlag member_flags_my_recursive_short = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_recursive_short = 0x00000001; + bool common_my_recursive_short_ec {false}; + CommonStructMember common_my_recursive_short {TypeObjectUtils::build_common_struct_member(member_id_my_recursive_short, member_flags_my_recursive_short, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_recursive_short, common_my_recursive_short_ec))}; + if (!common_my_recursive_short_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_recursive_short member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_recursive_short = "my_recursive_short"; + eprosima::fastcdr::optional member_ann_builtin_my_recursive_short; + ann_custom_AliasStruct.reset(); + CompleteMemberDetail detail_my_recursive_short = TypeObjectUtils::build_complete_member_detail(name_my_recursive_short, member_ann_builtin_my_recursive_short, ann_custom_AliasStruct); + CompleteStructMember member_my_recursive_short = TypeObjectUtils::build_complete_struct_member(common_my_recursive_short, detail_my_recursive_short); + TypeObjectUtils::add_complete_struct_member(member_seq_AliasStruct, member_my_recursive_short); + } + { + TypeIdentifierPair type_ids_my_recursive_boolean; + ReturnCode_t return_code_my_recursive_boolean {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_recursive_boolean = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MyRecursiveBoolean", type_ids_my_recursive_boolean); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_recursive_boolean) + { + ::register_MyRecursiveBoolean_type_identifier(type_ids_my_recursive_boolean); + } + StructMemberFlag member_flags_my_recursive_boolean = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_recursive_boolean = 0x00000002; + bool common_my_recursive_boolean_ec {false}; + CommonStructMember common_my_recursive_boolean {TypeObjectUtils::build_common_struct_member(member_id_my_recursive_boolean, member_flags_my_recursive_boolean, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_recursive_boolean, common_my_recursive_boolean_ec))}; + if (!common_my_recursive_boolean_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_recursive_boolean member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_recursive_boolean = "my_recursive_boolean"; + eprosima::fastcdr::optional member_ann_builtin_my_recursive_boolean; + ann_custom_AliasStruct.reset(); + CompleteMemberDetail detail_my_recursive_boolean = TypeObjectUtils::build_complete_member_detail(name_my_recursive_boolean, member_ann_builtin_my_recursive_boolean, ann_custom_AliasStruct); + CompleteStructMember member_my_recursive_boolean = TypeObjectUtils::build_complete_struct_member(common_my_recursive_boolean, detail_my_recursive_boolean); + TypeObjectUtils::add_complete_struct_member(member_seq_AliasStruct, member_my_recursive_boolean); + } + { + TypeIdentifierPair type_ids_my_boolean; + ReturnCode_t return_code_my_boolean {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_boolean = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MyBoolean", type_ids_my_boolean); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_boolean) + { + ::register_MyBoolean_type_identifier(type_ids_my_boolean); + } + StructMemberFlag member_flags_my_boolean = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_boolean = 0x00000003; + bool common_my_boolean_ec {false}; + CommonStructMember common_my_boolean {TypeObjectUtils::build_common_struct_member(member_id_my_boolean, member_flags_my_boolean, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_boolean, common_my_boolean_ec))}; + if (!common_my_boolean_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_boolean member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_boolean = "my_boolean"; + eprosima::fastcdr::optional member_ann_builtin_my_boolean; + ann_custom_AliasStruct.reset(); + CompleteMemberDetail detail_my_boolean = TypeObjectUtils::build_complete_member_detail(name_my_boolean, member_ann_builtin_my_boolean, ann_custom_AliasStruct); + CompleteStructMember member_my_boolean = TypeObjectUtils::build_complete_struct_member(common_my_boolean, detail_my_boolean); + TypeObjectUtils::add_complete_struct_member(member_seq_AliasStruct, member_my_boolean); + } + CompleteStructType struct_type_AliasStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_AliasStruct, header_AliasStruct, member_seq_AliasStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_AliasStruct, type_name_AliasStruct.to_string(), type_ids_AliasStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "AliasStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..8b82170cc4c --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/alias_struct/gen/alias_structTypeObjectSupport.hpp @@ -0,0 +1,126 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file alias_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ALIAS_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__ALIAS_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register MyLong related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_MyLong_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +/** + * @brief Register MyShort related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_MyShort_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +/** + * @brief Register MyRecursiveShort related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_MyRecursiveShort_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +/** + * @brief Register MyBoolean related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_MyBoolean_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +/** + * @brief Register MyRecursiveBoolean related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_MyRecursiveBoolean_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +/** + * @brief Register AliasStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_AliasStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__ALIAS_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/all_types.hpp b/test/unittest/dds/xtypes/serializers/idl/types/all_types.hpp new file mode 100644 index 00000000000..2f87e7a6299 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/all_types.hpp @@ -0,0 +1,170 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file all_types.hpp + */ + +#ifndef TEST_UNITTEST_DDS_XTYPES_SERIALIZERS_IDL_TYPES__ALL_TYPES_HPP +#define TEST_UNITTEST_DDS_XTYPES_SERIALIZERS_IDL_TYPES__ALL_TYPES_HPP + +#include + +#include + +#include "alias_struct/gen/alias_struct.hpp" +#include "alias_struct/gen/alias_structPubSubTypes.hpp" + +#include "array_struct/gen/array_struct.hpp" +#include "array_struct/gen/array_structPubSubTypes.hpp" + +#include "bitmask_struct/gen/bitmask_struct.hpp" +#include "bitmask_struct/gen/bitmask_structPubSubTypes.hpp" + +#include "bitset_struct/gen/bitset_struct.hpp" +#include "bitset_struct/gen/bitset_structPubSubTypes.hpp" + +#include "enum_struct/gen/enum_struct.hpp" +#include "enum_struct/gen/enum_structPubSubTypes.hpp" + +#include "extensibility_struct/gen/extensibility_struct.hpp" +#include "extensibility_struct/gen/extensibility_structPubSubTypes.hpp" + +#include "key_struct/gen/key_struct.hpp" +#include "key_struct/gen/key_structPubSubTypes.hpp" + +#include "map_struct/gen/map_struct.hpp" +#include "map_struct/gen/map_structPubSubTypes.hpp" + +#include "primitives_struct/gen/primitives_struct.hpp" +#include "primitives_struct/gen/primitives_structPubSubTypes.hpp" + +#include "sequence_struct/gen/sequence_struct.hpp" +#include "sequence_struct/gen/sequence_structPubSubTypes.hpp" + +#include "string_struct/gen/string_struct.hpp" +#include "string_struct/gen/string_structPubSubTypes.hpp" + +#include "struct_struct/gen/struct_struct.hpp" +#include "struct_struct/gen/struct_structPubSubTypes.hpp" + +#include "union_struct/gen/union_struct.hpp" +#include "union_struct/gen/union_structPubSubTypes.hpp" + +namespace test { + +namespace SupportedTypes { + +const std::string ALIAS_STRUCT{"alias_struct"}; +const std::string ARRAY_STRUCT{"array_struct"}; +const std::string BITMASK_STRUCT{"bitmask_struct"}; +const std::string BITSET_STRUCT{"bitset_struct"}; +const std::string ENUM_STRUCT{"enum_struct"}; +const std::string EXTENSIBILITY_STRUCT{"extensibility_struct"}; +const std::string KEY_STRUCT{"key_struct"}; +const std::string MAP_STRUCT{"map_struct"}; +const std::string PRIMITIVE_STRUCT{"primitives_struct"}; +const std::string SEQUENCE_STRUCT{"sequence_struct"}; +const std::string STRING_STRUCT{"string_struct"}; +const std::string STRUCT_STRUCT{"struct_struct"}; +const std::string UNION_STRUCT{"union_struct"}; + +} // namespace SupportedTypes + +const std::vector supported_types = { + SupportedTypes::ALIAS_STRUCT, + SupportedTypes::ARRAY_STRUCT, + SupportedTypes::BITMASK_STRUCT, + SupportedTypes::BITSET_STRUCT, + SupportedTypes::ENUM_STRUCT, + SupportedTypes::EXTENSIBILITY_STRUCT, + SupportedTypes::KEY_STRUCT, + SupportedTypes::MAP_STRUCT, + SupportedTypes::PRIMITIVE_STRUCT, + SupportedTypes::SEQUENCE_STRUCT, + SupportedTypes::STRING_STRUCT, + SupportedTypes::STRUCT_STRUCT, + SupportedTypes::UNION_STRUCT +}; + +void register_type_object_representation( + const std::string& type_name) +{ + using namespace eprosima::fastdds::dds; + + TypeSupport type_support; + + if (type_name == SupportedTypes::ALIAS_STRUCT) + { + type_support.reset(new AliasStructPubSubType()); + } + else if (type_name == SupportedTypes::ARRAY_STRUCT) + { + type_support.reset(new ArrayStructPubSubType()); + } + else if (type_name == SupportedTypes::BITMASK_STRUCT) + { + type_support.reset(new BitmaskStructPubSubType()); + } + else if (type_name == SupportedTypes::BITSET_STRUCT) + { + type_support.reset(new BitsetStructPubSubType()); + } + else if (type_name == SupportedTypes::ENUM_STRUCT) + { + type_support.reset(new EnumStructPubSubType()); + } + else if (type_name == SupportedTypes::EXTENSIBILITY_STRUCT) + { + type_support.reset(new ExtensibilityStructPubSubType()); + } + else if (type_name == SupportedTypes::KEY_STRUCT) + { + type_support.reset(new KeyStructPubSubType()); + } + else if (type_name == SupportedTypes::MAP_STRUCT) + { + type_support.reset(new MapStructPubSubType()); + } + else if (type_name == SupportedTypes::PRIMITIVE_STRUCT) + { + type_support.reset(new PrimitivesStructPubSubType()); + } + else if (type_name == SupportedTypes::SEQUENCE_STRUCT) + { + type_support.reset(new SequenceStructPubSubType()); + } + else if (type_name == SupportedTypes::STRING_STRUCT) + { + type_support.reset(new StringStructPubSubType()); + } + else if (type_name == SupportedTypes::STRUCT_STRUCT) + { + type_support.reset(new StructStructPubSubType()); + } + else if (type_name == SupportedTypes::UNION_STRUCT) + { + type_support.reset(new UnionStructPubSubType()); + } + else + { + ASSERT_FALSE(true) << "Type not supported"; + } + + type_support->register_type_object_representation(); +} + +} /* namespace test */ + +#endif /* TEST_UNITTEST_DDS_XTYPES_SERIALIZERS_IDL_TYPES__ALL_TYPES_HPP */ diff --git a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/array_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/array_struct.idl new file mode 100644 index 00000000000..34e24973ed8 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/array_struct.idl @@ -0,0 +1,19 @@ +struct NestedArrayElement +{ + string my_string; +}; + +struct ComplexArrayElement +{ + long my_number; + boolean my_boolean; + NestedArrayElement my_nested_element; +}; + +struct ArrayStruct +{ + long my_basic_array[10]; + long my_multidimensional_array[10][10][10]; + ComplexArrayElement my_complex_array[10]; + ComplexArrayElement my_multidimensional_complex_array[10][10]; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_struct.hpp new file mode 100644 index 00000000000..bb946a48bdc --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_struct.hpp @@ -0,0 +1,672 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file array_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ARRAY_STRUCT_HPP +#define FAST_DDS_GENERATED__ARRAY_STRUCT_HPP + +#include +#include +#include +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(ARRAY_STRUCT_SOURCE) +#define ARRAY_STRUCT_DllAPI __declspec( dllexport ) +#else +#define ARRAY_STRUCT_DllAPI __declspec( dllimport ) +#endif // ARRAY_STRUCT_SOURCE +#else +#define ARRAY_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define ARRAY_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure NestedArrayElement defined by the user in the IDL file. + * @ingroup array_struct + */ +class NestedArrayElement +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport NestedArrayElement() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~NestedArrayElement() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object NestedArrayElement that will be copied. + */ + eProsima_user_DllExport NestedArrayElement( + const NestedArrayElement& x) + { + m_my_string = x.m_my_string; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object NestedArrayElement that will be copied. + */ + eProsima_user_DllExport NestedArrayElement( + NestedArrayElement&& x) noexcept + { + m_my_string = std::move(x.m_my_string); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object NestedArrayElement that will be copied. + */ + eProsima_user_DllExport NestedArrayElement& operator =( + const NestedArrayElement& x) + { + + m_my_string = x.m_my_string; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object NestedArrayElement that will be copied. + */ + eProsima_user_DllExport NestedArrayElement& operator =( + NestedArrayElement&& x) noexcept + { + + m_my_string = std::move(x.m_my_string); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x NestedArrayElement object to compare. + */ + eProsima_user_DllExport bool operator ==( + const NestedArrayElement& x) const + { + return (m_my_string == x.m_my_string); + } + + /*! + * @brief Comparison operator. + * @param x NestedArrayElement object to compare. + */ + eProsima_user_DllExport bool operator !=( + const NestedArrayElement& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member my_string + * @param _my_string New value to be copied in member my_string + */ + eProsima_user_DllExport void my_string( + const std::string& _my_string) + { + m_my_string = _my_string; + } + + /*! + * @brief This function moves the value in member my_string + * @param _my_string New value to be moved in member my_string + */ + eProsima_user_DllExport void my_string( + std::string&& _my_string) + { + m_my_string = std::move(_my_string); + } + + /*! + * @brief This function returns a constant reference to member my_string + * @return Constant reference to member my_string + */ + eProsima_user_DllExport const std::string& my_string() const + { + return m_my_string; + } + + /*! + * @brief This function returns a reference to member my_string + * @return Reference to member my_string + */ + eProsima_user_DllExport std::string& my_string() + { + return m_my_string; + } + + + +private: + + std::string m_my_string; + +}; +/*! + * @brief This class represents the structure ComplexArrayElement defined by the user in the IDL file. + * @ingroup array_struct + */ +class ComplexArrayElement +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport ComplexArrayElement() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~ComplexArrayElement() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object ComplexArrayElement that will be copied. + */ + eProsima_user_DllExport ComplexArrayElement( + const ComplexArrayElement& x) + { + m_my_number = x.m_my_number; + + m_my_boolean = x.m_my_boolean; + + m_my_nested_element = x.m_my_nested_element; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object ComplexArrayElement that will be copied. + */ + eProsima_user_DllExport ComplexArrayElement( + ComplexArrayElement&& x) noexcept + { + m_my_number = x.m_my_number; + m_my_boolean = x.m_my_boolean; + m_my_nested_element = std::move(x.m_my_nested_element); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object ComplexArrayElement that will be copied. + */ + eProsima_user_DllExport ComplexArrayElement& operator =( + const ComplexArrayElement& x) + { + + m_my_number = x.m_my_number; + + m_my_boolean = x.m_my_boolean; + + m_my_nested_element = x.m_my_nested_element; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object ComplexArrayElement that will be copied. + */ + eProsima_user_DllExport ComplexArrayElement& operator =( + ComplexArrayElement&& x) noexcept + { + + m_my_number = x.m_my_number; + m_my_boolean = x.m_my_boolean; + m_my_nested_element = std::move(x.m_my_nested_element); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x ComplexArrayElement object to compare. + */ + eProsima_user_DllExport bool operator ==( + const ComplexArrayElement& x) const + { + return (m_my_number == x.m_my_number && + m_my_boolean == x.m_my_boolean && + m_my_nested_element == x.m_my_nested_element); + } + + /*! + * @brief Comparison operator. + * @param x ComplexArrayElement object to compare. + */ + eProsima_user_DllExport bool operator !=( + const ComplexArrayElement& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_number + * @param _my_number New value for member my_number + */ + eProsima_user_DllExport void my_number( + int32_t _my_number) + { + m_my_number = _my_number; + } + + /*! + * @brief This function returns the value of member my_number + * @return Value of member my_number + */ + eProsima_user_DllExport int32_t my_number() const + { + return m_my_number; + } + + /*! + * @brief This function returns a reference to member my_number + * @return Reference to member my_number + */ + eProsima_user_DllExport int32_t& my_number() + { + return m_my_number; + } + + + /*! + * @brief This function sets a value in member my_boolean + * @param _my_boolean New value for member my_boolean + */ + eProsima_user_DllExport void my_boolean( + bool _my_boolean) + { + m_my_boolean = _my_boolean; + } + + /*! + * @brief This function returns the value of member my_boolean + * @return Value of member my_boolean + */ + eProsima_user_DllExport bool my_boolean() const + { + return m_my_boolean; + } + + /*! + * @brief This function returns a reference to member my_boolean + * @return Reference to member my_boolean + */ + eProsima_user_DllExport bool& my_boolean() + { + return m_my_boolean; + } + + + /*! + * @brief This function copies the value in member my_nested_element + * @param _my_nested_element New value to be copied in member my_nested_element + */ + eProsima_user_DllExport void my_nested_element( + const NestedArrayElement& _my_nested_element) + { + m_my_nested_element = _my_nested_element; + } + + /*! + * @brief This function moves the value in member my_nested_element + * @param _my_nested_element New value to be moved in member my_nested_element + */ + eProsima_user_DllExport void my_nested_element( + NestedArrayElement&& _my_nested_element) + { + m_my_nested_element = std::move(_my_nested_element); + } + + /*! + * @brief This function returns a constant reference to member my_nested_element + * @return Constant reference to member my_nested_element + */ + eProsima_user_DllExport const NestedArrayElement& my_nested_element() const + { + return m_my_nested_element; + } + + /*! + * @brief This function returns a reference to member my_nested_element + * @return Reference to member my_nested_element + */ + eProsima_user_DllExport NestedArrayElement& my_nested_element() + { + return m_my_nested_element; + } + + + +private: + + int32_t m_my_number{0}; + bool m_my_boolean{false}; + NestedArrayElement m_my_nested_element; + +}; +/*! + * @brief This class represents the structure ArrayStruct defined by the user in the IDL file. + * @ingroup array_struct + */ +class ArrayStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport ArrayStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~ArrayStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object ArrayStruct that will be copied. + */ + eProsima_user_DllExport ArrayStruct( + const ArrayStruct& x) + { + m_my_basic_array = x.m_my_basic_array; + + m_my_multidimensional_array = x.m_my_multidimensional_array; + + m_my_complex_array = x.m_my_complex_array; + + m_my_multidimensional_complex_array = x.m_my_multidimensional_complex_array; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object ArrayStruct that will be copied. + */ + eProsima_user_DllExport ArrayStruct( + ArrayStruct&& x) noexcept + { + m_my_basic_array = std::move(x.m_my_basic_array); + m_my_multidimensional_array = std::move(x.m_my_multidimensional_array); + m_my_complex_array = std::move(x.m_my_complex_array); + m_my_multidimensional_complex_array = std::move(x.m_my_multidimensional_complex_array); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object ArrayStruct that will be copied. + */ + eProsima_user_DllExport ArrayStruct& operator =( + const ArrayStruct& x) + { + + m_my_basic_array = x.m_my_basic_array; + + m_my_multidimensional_array = x.m_my_multidimensional_array; + + m_my_complex_array = x.m_my_complex_array; + + m_my_multidimensional_complex_array = x.m_my_multidimensional_complex_array; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object ArrayStruct that will be copied. + */ + eProsima_user_DllExport ArrayStruct& operator =( + ArrayStruct&& x) noexcept + { + + m_my_basic_array = std::move(x.m_my_basic_array); + m_my_multidimensional_array = std::move(x.m_my_multidimensional_array); + m_my_complex_array = std::move(x.m_my_complex_array); + m_my_multidimensional_complex_array = std::move(x.m_my_multidimensional_complex_array); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x ArrayStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const ArrayStruct& x) const + { + return (m_my_basic_array == x.m_my_basic_array && + m_my_multidimensional_array == x.m_my_multidimensional_array && + m_my_complex_array == x.m_my_complex_array && + m_my_multidimensional_complex_array == x.m_my_multidimensional_complex_array); + } + + /*! + * @brief Comparison operator. + * @param x ArrayStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const ArrayStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member my_basic_array + * @param _my_basic_array New value to be copied in member my_basic_array + */ + eProsima_user_DllExport void my_basic_array( + const std::array& _my_basic_array) + { + m_my_basic_array = _my_basic_array; + } + + /*! + * @brief This function moves the value in member my_basic_array + * @param _my_basic_array New value to be moved in member my_basic_array + */ + eProsima_user_DllExport void my_basic_array( + std::array&& _my_basic_array) + { + m_my_basic_array = std::move(_my_basic_array); + } + + /*! + * @brief This function returns a constant reference to member my_basic_array + * @return Constant reference to member my_basic_array + */ + eProsima_user_DllExport const std::array& my_basic_array() const + { + return m_my_basic_array; + } + + /*! + * @brief This function returns a reference to member my_basic_array + * @return Reference to member my_basic_array + */ + eProsima_user_DllExport std::array& my_basic_array() + { + return m_my_basic_array; + } + + + /*! + * @brief This function copies the value in member my_multidimensional_array + * @param _my_multidimensional_array New value to be copied in member my_multidimensional_array + */ + eProsima_user_DllExport void my_multidimensional_array( + const std::array, 10>, 10>& _my_multidimensional_array) + { + m_my_multidimensional_array = _my_multidimensional_array; + } + + /*! + * @brief This function moves the value in member my_multidimensional_array + * @param _my_multidimensional_array New value to be moved in member my_multidimensional_array + */ + eProsima_user_DllExport void my_multidimensional_array( + std::array, 10>, 10>&& _my_multidimensional_array) + { + m_my_multidimensional_array = std::move(_my_multidimensional_array); + } + + /*! + * @brief This function returns a constant reference to member my_multidimensional_array + * @return Constant reference to member my_multidimensional_array + */ + eProsima_user_DllExport const std::array, 10>, 10>& my_multidimensional_array() const + { + return m_my_multidimensional_array; + } + + /*! + * @brief This function returns a reference to member my_multidimensional_array + * @return Reference to member my_multidimensional_array + */ + eProsima_user_DllExport std::array, 10>, 10>& my_multidimensional_array() + { + return m_my_multidimensional_array; + } + + + /*! + * @brief This function copies the value in member my_complex_array + * @param _my_complex_array New value to be copied in member my_complex_array + */ + eProsima_user_DllExport void my_complex_array( + const std::array& _my_complex_array) + { + m_my_complex_array = _my_complex_array; + } + + /*! + * @brief This function moves the value in member my_complex_array + * @param _my_complex_array New value to be moved in member my_complex_array + */ + eProsima_user_DllExport void my_complex_array( + std::array&& _my_complex_array) + { + m_my_complex_array = std::move(_my_complex_array); + } + + /*! + * @brief This function returns a constant reference to member my_complex_array + * @return Constant reference to member my_complex_array + */ + eProsima_user_DllExport const std::array& my_complex_array() const + { + return m_my_complex_array; + } + + /*! + * @brief This function returns a reference to member my_complex_array + * @return Reference to member my_complex_array + */ + eProsima_user_DllExport std::array& my_complex_array() + { + return m_my_complex_array; + } + + + /*! + * @brief This function copies the value in member my_multidimensional_complex_array + * @param _my_multidimensional_complex_array New value to be copied in member my_multidimensional_complex_array + */ + eProsima_user_DllExport void my_multidimensional_complex_array( + const std::array, 10>& _my_multidimensional_complex_array) + { + m_my_multidimensional_complex_array = _my_multidimensional_complex_array; + } + + /*! + * @brief This function moves the value in member my_multidimensional_complex_array + * @param _my_multidimensional_complex_array New value to be moved in member my_multidimensional_complex_array + */ + eProsima_user_DllExport void my_multidimensional_complex_array( + std::array, 10>&& _my_multidimensional_complex_array) + { + m_my_multidimensional_complex_array = std::move(_my_multidimensional_complex_array); + } + + /*! + * @brief This function returns a constant reference to member my_multidimensional_complex_array + * @return Constant reference to member my_multidimensional_complex_array + */ + eProsima_user_DllExport const std::array, 10>& my_multidimensional_complex_array() const + { + return m_my_multidimensional_complex_array; + } + + /*! + * @brief This function returns a reference to member my_multidimensional_complex_array + * @return Reference to member my_multidimensional_complex_array + */ + eProsima_user_DllExport std::array, 10>& my_multidimensional_complex_array() + { + return m_my_multidimensional_complex_array; + } + + + +private: + + std::array m_my_basic_array{0}; + std::array, 10>, 10> m_my_multidimensional_array{ {{ {{0}} }} }; + std::array m_my_complex_array; + std::array, 10> m_my_multidimensional_complex_array; + +}; + +#endif // _FAST_DDS_GENERATED_ARRAY_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structCdrAux.hpp new file mode 100644 index 00000000000..2635950d60d --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structCdrAux.hpp @@ -0,0 +1,60 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file array_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ARRAY_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__ARRAY_STRUCTCDRAUX_HPP + +#include "array_struct.hpp" + +constexpr uint32_t NestedArrayElement_max_cdr_typesize {264UL}; +constexpr uint32_t NestedArrayElement_max_key_cdr_typesize {0UL}; + +constexpr uint32_t ArrayStruct_max_cdr_typesize {34412UL}; +constexpr uint32_t ArrayStruct_max_key_cdr_typesize {0UL}; + +constexpr uint32_t ComplexArrayElement_max_cdr_typesize {276UL}; +constexpr uint32_t ComplexArrayElement_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const NestedArrayElement& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ComplexArrayElement& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ArrayStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__ARRAY_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structCdrAux.ipp new file mode 100644 index 00000000000..31c4a5014f1 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structCdrAux.ipp @@ -0,0 +1,310 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file array_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ARRAY_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__ARRAY_STRUCTCDRAUX_IPP + +#include "array_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const NestedArrayElement& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_string(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const NestedArrayElement& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_string() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + NestedArrayElement& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_string(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const NestedArrayElement& data) +{ + static_cast(scdr); + static_cast(data); +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const ComplexArrayElement& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_number(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_boolean(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_nested_element(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const ComplexArrayElement& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_number() + << eprosima::fastcdr::MemberId(1) << data.my_boolean() + << eprosima::fastcdr::MemberId(2) << data.my_nested_element() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + ComplexArrayElement& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_number(); + break; + + case 1: + dcdr >> data.my_boolean(); + break; + + case 2: + dcdr >> data.my_nested_element(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ComplexArrayElement& data) +{ + static_cast(scdr); + static_cast(data); +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const ArrayStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_basic_array(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_multidimensional_array(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_complex_array(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3), + data.my_multidimensional_complex_array(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const ArrayStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_basic_array() + << eprosima::fastcdr::MemberId(1) << data.my_multidimensional_array() + << eprosima::fastcdr::MemberId(2) << data.my_complex_array() + << eprosima::fastcdr::MemberId(3) << data.my_multidimensional_complex_array() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + ArrayStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_basic_array(); + break; + + case 1: + dcdr >> data.my_multidimensional_array(); + break; + + case 2: + dcdr >> data.my_complex_array(); + break; + + case 3: + dcdr >> data.my_multidimensional_complex_array(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ArrayStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__ARRAY_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.cxx new file mode 100644 index 00000000000..21aa3f8ab17 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.cxx @@ -0,0 +1,615 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file array_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "array_structPubSubTypes.hpp" + +#include +#include + +#include "array_structCdrAux.hpp" +#include "array_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +NestedArrayElementPubSubType::NestedArrayElementPubSubType() +{ + setName("NestedArrayElement"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(NestedArrayElement::getMaxCdrSerializedSize()); +#else + NestedArrayElement_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = NestedArrayElement_max_key_cdr_typesize > 16 ? NestedArrayElement_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +NestedArrayElementPubSubType::~NestedArrayElementPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool NestedArrayElementPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const NestedArrayElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool NestedArrayElementPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + NestedArrayElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function NestedArrayElementPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* NestedArrayElementPubSubType::createData() +{ + return reinterpret_cast(new NestedArrayElement()); +} + +void NestedArrayElementPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool NestedArrayElementPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const NestedArrayElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + NestedArrayElement_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || NestedArrayElement_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void NestedArrayElementPubSubType::register_type_object_representation() +{ + register_NestedArrayElement_type_identifier(type_identifiers_); +} + +ComplexArrayElementPubSubType::ComplexArrayElementPubSubType() +{ + setName("ComplexArrayElement"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(ComplexArrayElement::getMaxCdrSerializedSize()); +#else + ComplexArrayElement_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = ComplexArrayElement_max_key_cdr_typesize > 16 ? ComplexArrayElement_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +ComplexArrayElementPubSubType::~ComplexArrayElementPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool ComplexArrayElementPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const ComplexArrayElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool ComplexArrayElementPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + ComplexArrayElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function ComplexArrayElementPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* ComplexArrayElementPubSubType::createData() +{ + return reinterpret_cast(new ComplexArrayElement()); +} + +void ComplexArrayElementPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool ComplexArrayElementPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const ComplexArrayElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + ComplexArrayElement_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || ComplexArrayElement_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void ComplexArrayElementPubSubType::register_type_object_representation() +{ + register_ComplexArrayElement_type_identifier(type_identifiers_); +} + +ArrayStructPubSubType::ArrayStructPubSubType() +{ + setName("ArrayStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(ArrayStruct::getMaxCdrSerializedSize()); +#else + ArrayStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = ArrayStruct_max_key_cdr_typesize > 16 ? ArrayStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +ArrayStructPubSubType::~ArrayStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool ArrayStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const ArrayStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool ArrayStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + ArrayStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function ArrayStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* ArrayStructPubSubType::createData() +{ + return reinterpret_cast(new ArrayStruct()); +} + +void ArrayStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool ArrayStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const ArrayStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + ArrayStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || ArrayStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void ArrayStructPubSubType::register_type_object_representation() +{ + register_ArrayStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "array_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.hpp new file mode 100644 index 00000000000..0d0672b8fc1 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structPubSubTypes.hpp @@ -0,0 +1,315 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file array_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__ARRAY_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__ARRAY_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "array_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated array_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type NestedArrayElement defined by the user in the IDL file. + * @ingroup array_struct + */ +class NestedArrayElementPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef NestedArrayElement type; + + eProsima_user_DllExport NestedArrayElementPubSubType(); + + eProsima_user_DllExport ~NestedArrayElementPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +/*! + * @brief This class represents the TopicDataType of the type ComplexArrayElement defined by the user in the IDL file. + * @ingroup array_struct + */ +class ComplexArrayElementPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef ComplexArrayElement type; + + eProsima_user_DllExport ComplexArrayElementPubSubType(); + + eProsima_user_DllExport ~ComplexArrayElementPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +/*! + * @brief This class represents the TopicDataType of the type ArrayStruct defined by the user in the IDL file. + * @ingroup array_struct + */ +class ArrayStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef ArrayStruct type; + + eProsima_user_DllExport ArrayStructPubSubType(); + + eProsima_user_DllExport ~ArrayStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__ARRAY_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..3296426196d --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structTypeObjectSupport.cxx @@ -0,0 +1,512 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file array_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "array_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "array_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_NestedArrayElement_type_identifier( + TypeIdentifierPair& type_ids_NestedArrayElement) +{ + + ReturnCode_t return_code_NestedArrayElement {eprosima::fastdds::dds::RETCODE_OK}; + return_code_NestedArrayElement = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "NestedArrayElement", type_ids_NestedArrayElement); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_NestedArrayElement) + { + StructTypeFlag struct_flags_NestedArrayElement = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_NestedArrayElement = "NestedArrayElement"; + eprosima::fastcdr::optional type_ann_builtin_NestedArrayElement; + eprosima::fastcdr::optional ann_custom_NestedArrayElement; + CompleteTypeDetail detail_NestedArrayElement = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_NestedArrayElement, ann_custom_NestedArrayElement, type_name_NestedArrayElement.to_string()); + CompleteStructHeader header_NestedArrayElement; + header_NestedArrayElement = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_NestedArrayElement); + CompleteStructMemberSeq member_seq_NestedArrayElement; + { + TypeIdentifierPair type_ids_my_string; + ReturnCode_t return_code_my_string {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_string = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_my_string); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_string) + { + { + SBound bound = 0; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "anonymous_string_unbounded", type_ids_my_string)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_string = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_string = 0x00000000; + bool common_my_string_ec {false}; + CommonStructMember common_my_string {TypeObjectUtils::build_common_struct_member(member_id_my_string, member_flags_my_string, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_string, common_my_string_ec))}; + if (!common_my_string_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_string member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_string = "my_string"; + eprosima::fastcdr::optional member_ann_builtin_my_string; + ann_custom_NestedArrayElement.reset(); + CompleteMemberDetail detail_my_string = TypeObjectUtils::build_complete_member_detail(name_my_string, member_ann_builtin_my_string, ann_custom_NestedArrayElement); + CompleteStructMember member_my_string = TypeObjectUtils::build_complete_struct_member(common_my_string, detail_my_string); + TypeObjectUtils::add_complete_struct_member(member_seq_NestedArrayElement, member_my_string); + } + CompleteStructType struct_type_NestedArrayElement = TypeObjectUtils::build_complete_struct_type(struct_flags_NestedArrayElement, header_NestedArrayElement, member_seq_NestedArrayElement); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_NestedArrayElement, type_name_NestedArrayElement.to_string(), type_ids_NestedArrayElement)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "NestedArrayElement already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_ComplexArrayElement_type_identifier( + TypeIdentifierPair& type_ids_ComplexArrayElement) +{ + + ReturnCode_t return_code_ComplexArrayElement {eprosima::fastdds::dds::RETCODE_OK}; + return_code_ComplexArrayElement = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ComplexArrayElement", type_ids_ComplexArrayElement); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ComplexArrayElement) + { + StructTypeFlag struct_flags_ComplexArrayElement = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_ComplexArrayElement = "ComplexArrayElement"; + eprosima::fastcdr::optional type_ann_builtin_ComplexArrayElement; + eprosima::fastcdr::optional ann_custom_ComplexArrayElement; + CompleteTypeDetail detail_ComplexArrayElement = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ComplexArrayElement, ann_custom_ComplexArrayElement, type_name_ComplexArrayElement.to_string()); + CompleteStructHeader header_ComplexArrayElement; + header_ComplexArrayElement = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_ComplexArrayElement); + CompleteStructMemberSeq member_seq_ComplexArrayElement; + { + TypeIdentifierPair type_ids_my_number; + ReturnCode_t return_code_my_number {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_number = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_my_number); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_number) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_number Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_number = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_number = 0x00000000; + bool common_my_number_ec {false}; + CommonStructMember common_my_number {TypeObjectUtils::build_common_struct_member(member_id_my_number, member_flags_my_number, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_number, common_my_number_ec))}; + if (!common_my_number_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_number member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_number = "my_number"; + eprosima::fastcdr::optional member_ann_builtin_my_number; + ann_custom_ComplexArrayElement.reset(); + CompleteMemberDetail detail_my_number = TypeObjectUtils::build_complete_member_detail(name_my_number, member_ann_builtin_my_number, ann_custom_ComplexArrayElement); + CompleteStructMember member_my_number = TypeObjectUtils::build_complete_struct_member(common_my_number, detail_my_number); + TypeObjectUtils::add_complete_struct_member(member_seq_ComplexArrayElement, member_my_number); + } + { + TypeIdentifierPair type_ids_my_boolean; + ReturnCode_t return_code_my_boolean {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_boolean = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_bool", type_ids_my_boolean); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_boolean) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_boolean Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_boolean = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_boolean = 0x00000001; + bool common_my_boolean_ec {false}; + CommonStructMember common_my_boolean {TypeObjectUtils::build_common_struct_member(member_id_my_boolean, member_flags_my_boolean, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_boolean, common_my_boolean_ec))}; + if (!common_my_boolean_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_boolean member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_boolean = "my_boolean"; + eprosima::fastcdr::optional member_ann_builtin_my_boolean; + ann_custom_ComplexArrayElement.reset(); + CompleteMemberDetail detail_my_boolean = TypeObjectUtils::build_complete_member_detail(name_my_boolean, member_ann_builtin_my_boolean, ann_custom_ComplexArrayElement); + CompleteStructMember member_my_boolean = TypeObjectUtils::build_complete_struct_member(common_my_boolean, detail_my_boolean); + TypeObjectUtils::add_complete_struct_member(member_seq_ComplexArrayElement, member_my_boolean); + } + { + TypeIdentifierPair type_ids_my_nested_element; + ReturnCode_t return_code_my_nested_element {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_nested_element = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "NestedArrayElement", type_ids_my_nested_element); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_nested_element) + { + ::register_NestedArrayElement_type_identifier(type_ids_my_nested_element); + } + StructMemberFlag member_flags_my_nested_element = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_nested_element = 0x00000002; + bool common_my_nested_element_ec {false}; + CommonStructMember common_my_nested_element {TypeObjectUtils::build_common_struct_member(member_id_my_nested_element, member_flags_my_nested_element, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_nested_element, common_my_nested_element_ec))}; + if (!common_my_nested_element_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_nested_element member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_nested_element = "my_nested_element"; + eprosima::fastcdr::optional member_ann_builtin_my_nested_element; + ann_custom_ComplexArrayElement.reset(); + CompleteMemberDetail detail_my_nested_element = TypeObjectUtils::build_complete_member_detail(name_my_nested_element, member_ann_builtin_my_nested_element, ann_custom_ComplexArrayElement); + CompleteStructMember member_my_nested_element = TypeObjectUtils::build_complete_struct_member(common_my_nested_element, detail_my_nested_element); + TypeObjectUtils::add_complete_struct_member(member_seq_ComplexArrayElement, member_my_nested_element); + } + CompleteStructType struct_type_ComplexArrayElement = TypeObjectUtils::build_complete_struct_type(struct_flags_ComplexArrayElement, header_ComplexArrayElement, member_seq_ComplexArrayElement); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_ComplexArrayElement, type_name_ComplexArrayElement.to_string(), type_ids_ComplexArrayElement)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ComplexArrayElement already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_ArrayStruct_type_identifier( + TypeIdentifierPair& type_ids_ArrayStruct) +{ + + ReturnCode_t return_code_ArrayStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_ArrayStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ArrayStruct", type_ids_ArrayStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ArrayStruct) + { + StructTypeFlag struct_flags_ArrayStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_ArrayStruct = "ArrayStruct"; + eprosima::fastcdr::optional type_ann_builtin_ArrayStruct; + eprosima::fastcdr::optional ann_custom_ArrayStruct; + CompleteTypeDetail detail_ArrayStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ArrayStruct, ann_custom_ArrayStruct, type_name_ArrayStruct.to_string()); + CompleteStructHeader header_ArrayStruct; + header_ArrayStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_ArrayStruct); + CompleteStructMemberSeq member_seq_ArrayStruct; + { + TypeIdentifierPair type_ids_my_basic_array; + ReturnCode_t return_code_my_basic_array {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_basic_array = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_array_int32_t_10", type_ids_my_basic_array); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_basic_array) + { + return_code_my_basic_array = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_my_basic_array); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_basic_array) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Array element TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool element_identifier_anonymous_array_int32_t_10_ec {false}; + TypeIdentifier* element_identifier_anonymous_array_int32_t_10 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_basic_array, element_identifier_anonymous_array_int32_t_10_ec))}; + if (!element_identifier_anonymous_array_int32_t_10_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Array element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_array_int32_t_10 = EK_COMPLETE; + if (TK_NONE == type_ids_my_basic_array.type_identifier2()._d()) + { + equiv_kind_anonymous_array_int32_t_10 = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_array_int32_t_10 = 0; + PlainCollectionHeader header_anonymous_array_int32_t_10 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_array_int32_t_10, element_flags_anonymous_array_int32_t_10); + { + SBoundSeq array_bound_seq; + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(10)); + + PlainArraySElemDefn array_sdefn = TypeObjectUtils::build_plain_array_s_elem_defn(header_anonymous_array_int32_t_10, array_bound_seq, + eprosima::fastcdr::external(element_identifier_anonymous_array_int32_t_10)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_array_type_identifier(array_sdefn, "anonymous_array_int32_t_10", type_ids_my_basic_array)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_array_int32_t_10 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_basic_array = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_basic_array = 0x00000000; + bool common_my_basic_array_ec {false}; + CommonStructMember common_my_basic_array {TypeObjectUtils::build_common_struct_member(member_id_my_basic_array, member_flags_my_basic_array, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_basic_array, common_my_basic_array_ec))}; + if (!common_my_basic_array_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_basic_array member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_basic_array = "my_basic_array"; + eprosima::fastcdr::optional member_ann_builtin_my_basic_array; + ann_custom_ArrayStruct.reset(); + CompleteMemberDetail detail_my_basic_array = TypeObjectUtils::build_complete_member_detail(name_my_basic_array, member_ann_builtin_my_basic_array, ann_custom_ArrayStruct); + CompleteStructMember member_my_basic_array = TypeObjectUtils::build_complete_struct_member(common_my_basic_array, detail_my_basic_array); + TypeObjectUtils::add_complete_struct_member(member_seq_ArrayStruct, member_my_basic_array); + } + { + TypeIdentifierPair type_ids_my_multidimensional_array; + ReturnCode_t return_code_my_multidimensional_array {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_multidimensional_array = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_array_int32_t_10_10_10", type_ids_my_multidimensional_array); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_multidimensional_array) + { + return_code_my_multidimensional_array = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_my_multidimensional_array); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_multidimensional_array) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Array element TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool element_identifier_anonymous_array_int32_t_10_10_10_ec {false}; + TypeIdentifier* element_identifier_anonymous_array_int32_t_10_10_10 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_multidimensional_array, element_identifier_anonymous_array_int32_t_10_10_10_ec))}; + if (!element_identifier_anonymous_array_int32_t_10_10_10_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Array element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_array_int32_t_10_10_10 = EK_COMPLETE; + if (TK_NONE == type_ids_my_multidimensional_array.type_identifier2()._d()) + { + equiv_kind_anonymous_array_int32_t_10_10_10 = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_array_int32_t_10_10_10 = 0; + PlainCollectionHeader header_anonymous_array_int32_t_10_10_10 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_array_int32_t_10_10_10, element_flags_anonymous_array_int32_t_10_10_10); + { + SBoundSeq array_bound_seq; + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(10)); + + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(10)); + + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(10)); + + PlainArraySElemDefn array_sdefn = TypeObjectUtils::build_plain_array_s_elem_defn(header_anonymous_array_int32_t_10_10_10, array_bound_seq, + eprosima::fastcdr::external(element_identifier_anonymous_array_int32_t_10_10_10)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_array_type_identifier(array_sdefn, "anonymous_array_int32_t_10_10_10", type_ids_my_multidimensional_array)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_array_int32_t_10_10_10 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_multidimensional_array = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_multidimensional_array = 0x00000001; + bool common_my_multidimensional_array_ec {false}; + CommonStructMember common_my_multidimensional_array {TypeObjectUtils::build_common_struct_member(member_id_my_multidimensional_array, member_flags_my_multidimensional_array, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_multidimensional_array, common_my_multidimensional_array_ec))}; + if (!common_my_multidimensional_array_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_multidimensional_array member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_multidimensional_array = "my_multidimensional_array"; + eprosima::fastcdr::optional member_ann_builtin_my_multidimensional_array; + ann_custom_ArrayStruct.reset(); + CompleteMemberDetail detail_my_multidimensional_array = TypeObjectUtils::build_complete_member_detail(name_my_multidimensional_array, member_ann_builtin_my_multidimensional_array, ann_custom_ArrayStruct); + CompleteStructMember member_my_multidimensional_array = TypeObjectUtils::build_complete_struct_member(common_my_multidimensional_array, detail_my_multidimensional_array); + TypeObjectUtils::add_complete_struct_member(member_seq_ArrayStruct, member_my_multidimensional_array); + } + { + TypeIdentifierPair type_ids_my_complex_array; + ReturnCode_t return_code_my_complex_array {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_complex_array = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_array_ComplexArrayElement_10", type_ids_my_complex_array); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_array) + { + return_code_my_complex_array = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ComplexArrayElement", type_ids_my_complex_array); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_array) + { + ::register_ComplexArrayElement_type_identifier(type_ids_my_complex_array); + } + bool element_identifier_anonymous_array_ComplexArrayElement_10_ec {false}; + TypeIdentifier* element_identifier_anonymous_array_ComplexArrayElement_10 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_array, element_identifier_anonymous_array_ComplexArrayElement_10_ec))}; + if (!element_identifier_anonymous_array_ComplexArrayElement_10_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Array element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_array_ComplexArrayElement_10 = EK_COMPLETE; + if (TK_NONE == type_ids_my_complex_array.type_identifier2()._d()) + { + equiv_kind_anonymous_array_ComplexArrayElement_10 = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_array_ComplexArrayElement_10 = 0; + PlainCollectionHeader header_anonymous_array_ComplexArrayElement_10 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_array_ComplexArrayElement_10, element_flags_anonymous_array_ComplexArrayElement_10); + { + SBoundSeq array_bound_seq; + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(10)); + + PlainArraySElemDefn array_sdefn = TypeObjectUtils::build_plain_array_s_elem_defn(header_anonymous_array_ComplexArrayElement_10, array_bound_seq, + eprosima::fastcdr::external(element_identifier_anonymous_array_ComplexArrayElement_10)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_array_type_identifier(array_sdefn, "anonymous_array_ComplexArrayElement_10", type_ids_my_complex_array)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_array_ComplexArrayElement_10 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_complex_array = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_complex_array = 0x00000002; + bool common_my_complex_array_ec {false}; + CommonStructMember common_my_complex_array {TypeObjectUtils::build_common_struct_member(member_id_my_complex_array, member_flags_my_complex_array, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_array, common_my_complex_array_ec))}; + if (!common_my_complex_array_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_complex_array member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_complex_array = "my_complex_array"; + eprosima::fastcdr::optional member_ann_builtin_my_complex_array; + ann_custom_ArrayStruct.reset(); + CompleteMemberDetail detail_my_complex_array = TypeObjectUtils::build_complete_member_detail(name_my_complex_array, member_ann_builtin_my_complex_array, ann_custom_ArrayStruct); + CompleteStructMember member_my_complex_array = TypeObjectUtils::build_complete_struct_member(common_my_complex_array, detail_my_complex_array); + TypeObjectUtils::add_complete_struct_member(member_seq_ArrayStruct, member_my_complex_array); + } + { + TypeIdentifierPair type_ids_my_multidimensional_complex_array; + ReturnCode_t return_code_my_multidimensional_complex_array {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_multidimensional_complex_array = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_array_ComplexArrayElement_10_10", type_ids_my_multidimensional_complex_array); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_multidimensional_complex_array) + { + return_code_my_multidimensional_complex_array = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ComplexArrayElement", type_ids_my_multidimensional_complex_array); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_multidimensional_complex_array) + { + ::register_ComplexArrayElement_type_identifier(type_ids_my_multidimensional_complex_array); + } + bool element_identifier_anonymous_array_ComplexArrayElement_10_10_ec {false}; + TypeIdentifier* element_identifier_anonymous_array_ComplexArrayElement_10_10 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_multidimensional_complex_array, element_identifier_anonymous_array_ComplexArrayElement_10_10_ec))}; + if (!element_identifier_anonymous_array_ComplexArrayElement_10_10_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Array element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_array_ComplexArrayElement_10_10 = EK_COMPLETE; + if (TK_NONE == type_ids_my_multidimensional_complex_array.type_identifier2()._d()) + { + equiv_kind_anonymous_array_ComplexArrayElement_10_10 = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_array_ComplexArrayElement_10_10 = 0; + PlainCollectionHeader header_anonymous_array_ComplexArrayElement_10_10 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_array_ComplexArrayElement_10_10, element_flags_anonymous_array_ComplexArrayElement_10_10); + { + SBoundSeq array_bound_seq; + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(10)); + + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(10)); + + PlainArraySElemDefn array_sdefn = TypeObjectUtils::build_plain_array_s_elem_defn(header_anonymous_array_ComplexArrayElement_10_10, array_bound_seq, + eprosima::fastcdr::external(element_identifier_anonymous_array_ComplexArrayElement_10_10)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_array_type_identifier(array_sdefn, "anonymous_array_ComplexArrayElement_10_10", type_ids_my_multidimensional_complex_array)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_array_ComplexArrayElement_10_10 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_multidimensional_complex_array = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_multidimensional_complex_array = 0x00000003; + bool common_my_multidimensional_complex_array_ec {false}; + CommonStructMember common_my_multidimensional_complex_array {TypeObjectUtils::build_common_struct_member(member_id_my_multidimensional_complex_array, member_flags_my_multidimensional_complex_array, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_multidimensional_complex_array, common_my_multidimensional_complex_array_ec))}; + if (!common_my_multidimensional_complex_array_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_multidimensional_complex_array member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_multidimensional_complex_array = "my_multidimensional_complex_array"; + eprosima::fastcdr::optional member_ann_builtin_my_multidimensional_complex_array; + ann_custom_ArrayStruct.reset(); + CompleteMemberDetail detail_my_multidimensional_complex_array = TypeObjectUtils::build_complete_member_detail(name_my_multidimensional_complex_array, member_ann_builtin_my_multidimensional_complex_array, ann_custom_ArrayStruct); + CompleteStructMember member_my_multidimensional_complex_array = TypeObjectUtils::build_complete_struct_member(common_my_multidimensional_complex_array, detail_my_multidimensional_complex_array); + TypeObjectUtils::add_complete_struct_member(member_seq_ArrayStruct, member_my_multidimensional_complex_array); + } + CompleteStructType struct_type_ArrayStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_ArrayStruct, header_ArrayStruct, member_seq_ArrayStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_ArrayStruct, type_name_ArrayStruct.to_string(), type_ids_ArrayStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ArrayStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..1677b876be7 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/array_struct/gen/array_structTypeObjectSupport.hpp @@ -0,0 +1,80 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file array_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ARRAY_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__ARRAY_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register NestedArrayElement related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_NestedArrayElement_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register ComplexArrayElement related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_ComplexArrayElement_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register ArrayStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_ArrayStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__ARRAY_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/bitmask_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/bitmask_struct.idl new file mode 100644 index 00000000000..2d6cd006c79 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/bitmask_struct.idl @@ -0,0 +1,13 @@ +@bit_bound(8) +bitmask ColorBitmask +{ + red, + @position(2) green, + blue, + @position(5) yellow +}; + +struct BitmaskStruct +{ + ColorBitmask my_bitmask; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_struct.hpp new file mode 100644 index 00000000000..83ee6c64fc2 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_struct.hpp @@ -0,0 +1,200 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitmask_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BITMASK_STRUCT_HPP +#define FAST_DDS_GENERATED__BITMASK_STRUCT_HPP + +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(BITMASK_STRUCT_SOURCE) +#define BITMASK_STRUCT_DllAPI __declspec( dllexport ) +#else +#define BITMASK_STRUCT_DllAPI __declspec( dllimport ) +#endif // BITMASK_STRUCT_SOURCE +#else +#define BITMASK_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define BITMASK_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This enumeration represents the ColorBitmask bitflags defined by the user in the IDL file. + * @ingroup bitmask_struct + */ +enum ColorBitmaskBits : uint8_t +{ + red = 0x01ull << 0, + green = 0x01ull << 2, + blue = 0x01ull << 3, + yellow = 0x01ull << 5 +}; +typedef uint8_t ColorBitmask; +/*! + * @brief This class represents the structure BitmaskStruct defined by the user in the IDL file. + * @ingroup bitmask_struct + */ +class BitmaskStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport BitmaskStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~BitmaskStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object BitmaskStruct that will be copied. + */ + eProsima_user_DllExport BitmaskStruct( + const BitmaskStruct& x) + { + m_my_bitmask = x.m_my_bitmask; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object BitmaskStruct that will be copied. + */ + eProsima_user_DllExport BitmaskStruct( + BitmaskStruct&& x) noexcept + { + m_my_bitmask = std::move(x.m_my_bitmask); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object BitmaskStruct that will be copied. + */ + eProsima_user_DllExport BitmaskStruct& operator =( + const BitmaskStruct& x) + { + + m_my_bitmask = x.m_my_bitmask; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object BitmaskStruct that will be copied. + */ + eProsima_user_DllExport BitmaskStruct& operator =( + BitmaskStruct&& x) noexcept + { + + m_my_bitmask = std::move(x.m_my_bitmask); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x BitmaskStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const BitmaskStruct& x) const + { + return (m_my_bitmask == x.m_my_bitmask); + } + + /*! + * @brief Comparison operator. + * @param x BitmaskStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const BitmaskStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member my_bitmask + * @param _my_bitmask New value to be copied in member my_bitmask + */ + eProsima_user_DllExport void my_bitmask( + const ColorBitmask& _my_bitmask) + { + m_my_bitmask = _my_bitmask; + } + + /*! + * @brief This function moves the value in member my_bitmask + * @param _my_bitmask New value to be moved in member my_bitmask + */ + eProsima_user_DllExport void my_bitmask( + ColorBitmask&& _my_bitmask) + { + m_my_bitmask = std::move(_my_bitmask); + } + + /*! + * @brief This function returns a constant reference to member my_bitmask + * @return Constant reference to member my_bitmask + */ + eProsima_user_DllExport const ColorBitmask& my_bitmask() const + { + return m_my_bitmask; + } + + /*! + * @brief This function returns a reference to member my_bitmask + * @return Reference to member my_bitmask + */ + eProsima_user_DllExport ColorBitmask& my_bitmask() + { + return m_my_bitmask; + } + + + +private: + + ColorBitmask m_my_bitmask{0}; + +}; + +#endif // _FAST_DDS_GENERATED_BITMASK_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structCdrAux.hpp new file mode 100644 index 00000000000..20178cc24bc --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structCdrAux.hpp @@ -0,0 +1,46 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitmask_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BITMASK_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__BITMASK_STRUCTCDRAUX_HPP + +#include "bitmask_struct.hpp" + +constexpr uint32_t BitmaskStruct_max_cdr_typesize {5UL}; +constexpr uint32_t BitmaskStruct_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BitmaskStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BITMASK_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structCdrAux.ipp new file mode 100644 index 00000000000..e8b6c9e5e61 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structCdrAux.ipp @@ -0,0 +1,118 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitmask_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BITMASK_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__BITMASK_STRUCTCDRAUX_IPP + +#include "bitmask_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const BitmaskStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_bitmask(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const BitmaskStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_bitmask() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + BitmaskStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_bitmask(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BitmaskStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BITMASK_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.cxx new file mode 100644 index 00000000000..a42af45f42c --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.cxx @@ -0,0 +1,229 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitmask_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "bitmask_structPubSubTypes.hpp" + +#include +#include + +#include "bitmask_structCdrAux.hpp" +#include "bitmask_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +BitmaskStructPubSubType::BitmaskStructPubSubType() +{ + setName("BitmaskStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(BitmaskStruct::getMaxCdrSerializedSize()); +#else + BitmaskStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = BitmaskStruct_max_key_cdr_typesize > 16 ? BitmaskStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +BitmaskStructPubSubType::~BitmaskStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool BitmaskStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const BitmaskStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool BitmaskStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + BitmaskStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function BitmaskStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* BitmaskStructPubSubType::createData() +{ + return reinterpret_cast(new BitmaskStruct()); +} + +void BitmaskStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool BitmaskStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const BitmaskStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + BitmaskStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || BitmaskStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void BitmaskStructPubSubType::register_type_object_representation() +{ + register_BitmaskStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "bitmask_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.hpp new file mode 100644 index 00000000000..df42d2f96aa --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structPubSubTypes.hpp @@ -0,0 +1,133 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitmask_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__BITMASK_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__BITMASK_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "bitmask_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated bitmask_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type BitmaskStruct defined by the user in the IDL file. + * @ingroup bitmask_struct + */ +class BitmaskStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef BitmaskStruct type; + + eProsima_user_DllExport BitmaskStructPubSubType(); + + eProsima_user_DllExport ~BitmaskStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__BITMASK_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..08699ae6d97 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structTypeObjectSupport.cxx @@ -0,0 +1,186 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitmask_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "bitmask_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "bitmask_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +void register_ColorBitmask_type_identifier( + TypeIdentifierPair& type_ids_ColorBitmask) +{ + ReturnCode_t return_code_ColorBitmask {eprosima::fastdds::dds::RETCODE_OK}; + return_code_ColorBitmask = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ColorBitmask", type_ids_ColorBitmask); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ColorBitmask) + { + BitmaskTypeFlag bitmask_flags_ColorBitmask = 0; + BitBound bit_bound_ColorBitmask = 8; + CommonEnumeratedHeader common_ColorBitmask = TypeObjectUtils::build_common_enumerated_header(bit_bound_ColorBitmask, true); + QualifiedTypeName type_name_ColorBitmask = "ColorBitmask"; + eprosima::fastcdr::optional type_ann_builtin_ColorBitmask; + eprosima::fastcdr::optional ann_custom_ColorBitmask; + AppliedAnnotationSeq tmp_ann_custom_ColorBitmask; + eprosima::fastcdr::optional verbatim_ColorBitmask; + if (!tmp_ann_custom_ColorBitmask.empty()) + { + ann_custom_ColorBitmask = tmp_ann_custom_ColorBitmask; + } + + CompleteTypeDetail detail_ColorBitmask = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ColorBitmask, ann_custom_ColorBitmask, type_name_ColorBitmask.to_string()); + CompleteEnumeratedHeader header_ColorBitmask = TypeObjectUtils::build_complete_enumerated_header(common_ColorBitmask, detail_ColorBitmask, true); + CompleteBitflagSeq flag_seq_ColorBitmask; + { + uint16_t position_red = 0; + BitflagFlag flags_red = 0; + CommonBitflag common_red = TypeObjectUtils::build_common_bitflag(position_red, flags_red); + eprosima::fastcdr::optional member_ann_builtin_red; + ann_custom_ColorBitmask.reset(); + MemberName name_red = "red"; + CompleteMemberDetail detail_red = TypeObjectUtils::build_complete_member_detail(name_red, member_ann_builtin_red, ann_custom_ColorBitmask); + CompleteBitflag bitflag_red = TypeObjectUtils::build_complete_bitflag(common_red, detail_red); + TypeObjectUtils::add_complete_bitflag(flag_seq_ColorBitmask, bitflag_red); + } + { + uint16_t position_green = 2; + BitflagFlag flags_green = 0; + CommonBitflag common_green = TypeObjectUtils::build_common_bitflag(position_green, flags_green); + eprosima::fastcdr::optional member_ann_builtin_green; + ann_custom_ColorBitmask.reset(); + AppliedAnnotationSeq tmp_ann_custom_green; + if (!tmp_ann_custom_green.empty()) + { + ann_custom_ColorBitmask = tmp_ann_custom_green; + } + MemberName name_green = "green"; + CompleteMemberDetail detail_green = TypeObjectUtils::build_complete_member_detail(name_green, member_ann_builtin_green, ann_custom_ColorBitmask); + CompleteBitflag bitflag_green = TypeObjectUtils::build_complete_bitflag(common_green, detail_green); + TypeObjectUtils::add_complete_bitflag(flag_seq_ColorBitmask, bitflag_green); + } + { + uint16_t position_blue = 3; + BitflagFlag flags_blue = 0; + CommonBitflag common_blue = TypeObjectUtils::build_common_bitflag(position_blue, flags_blue); + eprosima::fastcdr::optional member_ann_builtin_blue; + ann_custom_ColorBitmask.reset(); + MemberName name_blue = "blue"; + CompleteMemberDetail detail_blue = TypeObjectUtils::build_complete_member_detail(name_blue, member_ann_builtin_blue, ann_custom_ColorBitmask); + CompleteBitflag bitflag_blue = TypeObjectUtils::build_complete_bitflag(common_blue, detail_blue); + TypeObjectUtils::add_complete_bitflag(flag_seq_ColorBitmask, bitflag_blue); + } + { + uint16_t position_yellow = 5; + BitflagFlag flags_yellow = 0; + CommonBitflag common_yellow = TypeObjectUtils::build_common_bitflag(position_yellow, flags_yellow); + eprosima::fastcdr::optional member_ann_builtin_yellow; + ann_custom_ColorBitmask.reset(); + AppliedAnnotationSeq tmp_ann_custom_yellow; + if (!tmp_ann_custom_yellow.empty()) + { + ann_custom_ColorBitmask = tmp_ann_custom_yellow; + } + MemberName name_yellow = "yellow"; + CompleteMemberDetail detail_yellow = TypeObjectUtils::build_complete_member_detail(name_yellow, member_ann_builtin_yellow, ann_custom_ColorBitmask); + CompleteBitflag bitflag_yellow = TypeObjectUtils::build_complete_bitflag(common_yellow, detail_yellow); + TypeObjectUtils::add_complete_bitflag(flag_seq_ColorBitmask, bitflag_yellow); + } + CompleteBitmaskType bitmask_type_ColorBitmask = TypeObjectUtils::build_complete_bitmask_type(bitmask_flags_ColorBitmask, header_ColorBitmask, flag_seq_ColorBitmask); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_bitmask_type_object(bitmask_type_ColorBitmask, + type_name_ColorBitmask.to_string(), type_ids_ColorBitmask)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ColorBitmask already registered in TypeObjectRegistry for a different type."); + } + } +}// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_BitmaskStruct_type_identifier( + TypeIdentifierPair& type_ids_BitmaskStruct) +{ + + ReturnCode_t return_code_BitmaskStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_BitmaskStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "BitmaskStruct", type_ids_BitmaskStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_BitmaskStruct) + { + StructTypeFlag struct_flags_BitmaskStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_BitmaskStruct = "BitmaskStruct"; + eprosima::fastcdr::optional type_ann_builtin_BitmaskStruct; + eprosima::fastcdr::optional ann_custom_BitmaskStruct; + CompleteTypeDetail detail_BitmaskStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_BitmaskStruct, ann_custom_BitmaskStruct, type_name_BitmaskStruct.to_string()); + CompleteStructHeader header_BitmaskStruct; + header_BitmaskStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_BitmaskStruct); + CompleteStructMemberSeq member_seq_BitmaskStruct; + { + TypeIdentifierPair type_ids_my_bitmask; + ReturnCode_t return_code_my_bitmask {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_bitmask = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ColorBitmask", type_ids_my_bitmask); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_bitmask) + { + ::register_ColorBitmask_type_identifier(type_ids_my_bitmask); + } + StructMemberFlag member_flags_my_bitmask = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_bitmask = 0x00000000; + bool common_my_bitmask_ec {false}; + CommonStructMember common_my_bitmask {TypeObjectUtils::build_common_struct_member(member_id_my_bitmask, member_flags_my_bitmask, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_bitmask, common_my_bitmask_ec))}; + if (!common_my_bitmask_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_bitmask member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_bitmask = "my_bitmask"; + eprosima::fastcdr::optional member_ann_builtin_my_bitmask; + ann_custom_BitmaskStruct.reset(); + CompleteMemberDetail detail_my_bitmask = TypeObjectUtils::build_complete_member_detail(name_my_bitmask, member_ann_builtin_my_bitmask, ann_custom_BitmaskStruct); + CompleteStructMember member_my_bitmask = TypeObjectUtils::build_complete_struct_member(common_my_bitmask, detail_my_bitmask); + TypeObjectUtils::add_complete_struct_member(member_seq_BitmaskStruct, member_my_bitmask); + } + CompleteStructType struct_type_BitmaskStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_BitmaskStruct, header_BitmaskStruct, member_seq_BitmaskStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_BitmaskStruct, type_name_BitmaskStruct.to_string(), type_ids_BitmaskStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "BitmaskStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..bf618436431 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/gen/bitmask_structTypeObjectSupport.hpp @@ -0,0 +1,68 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitmask_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BITMASK_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__BITMASK_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register ColorBitmask related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_ColorBitmask_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register BitmaskStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_BitmaskStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__BITMASK_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/bitset_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/bitset_struct.idl new file mode 100644 index 00000000000..2fea014e0e3 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/bitset_struct.idl @@ -0,0 +1,13 @@ +bitset ColorBitset +{ + bitfield<3> red; + bitfield<1> green; + bitfield<4>; + bitfield<10> blue; + bitfield<12, short> yellow; +}; + +struct BitsetStruct +{ + ColorBitset my_bitset; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_struct.hpp new file mode 100644 index 00000000000..b364db5f1d2 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_struct.hpp @@ -0,0 +1,228 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitset_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BITSET_STRUCT_HPP +#define FAST_DDS_GENERATED__BITSET_STRUCT_HPP + +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(BITSET_STRUCT_SOURCE) +#define BITSET_STRUCT_DllAPI __declspec( dllexport ) +#else +#define BITSET_STRUCT_DllAPI __declspec( dllimport ) +#endif // BITSET_STRUCT_SOURCE +#else +#define BITSET_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define BITSET_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This structure represents the bitset ColorBitset defined by the user in the IDL file. + * @ingroup bitset_struct + */ +struct ColorBitset +{ + uint8_t red : 3; + + bool green : 1; + + uint8_t : 4; + + uint16_t blue : 10; + + int16_t yellow : 12; + + + /*! + * @brief Comparison operator. + * @param x ColorBitset object to compare. + */ + eProsima_user_DllExport bool operator ==( + const ColorBitset& x) const + { + return (red == x.red && + green == x.green && + blue == x.blue && + yellow == x.yellow); + } + + /*! + * @brief Comparison operator. + * @param x ColorBitset object to compare. + */ + eProsima_user_DllExport bool operator !=( + const ColorBitset& x) const + { + return !(*this == x); + } +}; +/*! + * @brief This class represents the structure BitsetStruct defined by the user in the IDL file. + * @ingroup bitset_struct + */ +class BitsetStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport BitsetStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~BitsetStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object BitsetStruct that will be copied. + */ + eProsima_user_DllExport BitsetStruct( + const BitsetStruct& x) + { + m_my_bitset = x.m_my_bitset; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object BitsetStruct that will be copied. + */ + eProsima_user_DllExport BitsetStruct( + BitsetStruct&& x) noexcept + { + m_my_bitset = std::move(x.m_my_bitset); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object BitsetStruct that will be copied. + */ + eProsima_user_DllExport BitsetStruct& operator =( + const BitsetStruct& x) + { + + m_my_bitset = x.m_my_bitset; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object BitsetStruct that will be copied. + */ + eProsima_user_DllExport BitsetStruct& operator =( + BitsetStruct&& x) noexcept + { + + m_my_bitset = std::move(x.m_my_bitset); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x BitsetStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const BitsetStruct& x) const + { + return (m_my_bitset == x.m_my_bitset); + } + + /*! + * @brief Comparison operator. + * @param x BitsetStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const BitsetStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member my_bitset + * @param _my_bitset New value to be copied in member my_bitset + */ + eProsima_user_DllExport void my_bitset( + const ColorBitset& _my_bitset) + { + m_my_bitset = _my_bitset; + } + + /*! + * @brief This function moves the value in member my_bitset + * @param _my_bitset New value to be moved in member my_bitset + */ + eProsima_user_DllExport void my_bitset( + ColorBitset&& _my_bitset) + { + m_my_bitset = std::move(_my_bitset); + } + + /*! + * @brief This function returns a constant reference to member my_bitset + * @return Constant reference to member my_bitset + */ + eProsima_user_DllExport const ColorBitset& my_bitset() const + { + return m_my_bitset; + } + + /*! + * @brief This function returns a reference to member my_bitset + * @return Reference to member my_bitset + */ + eProsima_user_DllExport ColorBitset& my_bitset() + { + return m_my_bitset; + } + + + +private: + + ColorBitset m_my_bitset{}; + +}; + +#endif // _FAST_DDS_GENERATED_BITSET_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structCdrAux.hpp new file mode 100644 index 00000000000..07befbf4d58 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structCdrAux.hpp @@ -0,0 +1,46 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitset_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BITSET_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__BITSET_STRUCTCDRAUX_HPP + +#include "bitset_struct.hpp" + +constexpr uint32_t BitsetStruct_max_cdr_typesize {8UL}; +constexpr uint32_t BitsetStruct_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BitsetStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BITSET_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structCdrAux.ipp new file mode 100644 index 00000000000..57e875e58b8 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structCdrAux.ipp @@ -0,0 +1,176 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitset_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BITSET_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__BITSET_STRUCTCDRAUX_IPP + +#include "bitset_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const ColorBitset&, + size_t& current_alignment) +{ + return calculator.calculate_serialized_size(std::bitset<30>{}, current_alignment); +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const ColorBitset& data) +{ + std::bitset<30> bitset; + + bitset <<= 12; + bitset |= (data.yellow & 0xFFF); + + bitset <<= 10; + bitset |= (data.blue & 0x3FF); + + bitset <<= 4; + + bitset <<= 1; + bitset |= (data.green & 0x1); + + bitset <<= 3; + bitset |= (data.red & 0x7); + + + scdr << bitset; +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& dcdr, + ColorBitset& data) +{ + std::bitset<30> bitset; + dcdr >> bitset; + + data.red = static_cast(bitset.to_ullong() & 0x7); + bitset >>= 3; + + data.green = static_cast(bitset.to_ullong() & 0x1); + bitset >>= 1; + + bitset >>= 4; + + data.blue = static_cast(bitset.to_ullong() & 0x3FF); + bitset >>= 10; + + data.yellow = static_cast(bitset.to_ullong() & 0xFFF); + bitset >>= 12; + +} + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const BitsetStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_bitset(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const BitsetStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_bitset() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + BitsetStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_bitset(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BitsetStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BITSET_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.cxx new file mode 100644 index 00000000000..d327fd7adb3 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.cxx @@ -0,0 +1,229 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitset_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "bitset_structPubSubTypes.hpp" + +#include +#include + +#include "bitset_structCdrAux.hpp" +#include "bitset_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +BitsetStructPubSubType::BitsetStructPubSubType() +{ + setName("BitsetStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(BitsetStruct::getMaxCdrSerializedSize()); +#else + BitsetStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = BitsetStruct_max_key_cdr_typesize > 16 ? BitsetStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +BitsetStructPubSubType::~BitsetStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool BitsetStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const BitsetStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool BitsetStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + BitsetStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function BitsetStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* BitsetStructPubSubType::createData() +{ + return reinterpret_cast(new BitsetStruct()); +} + +void BitsetStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool BitsetStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const BitsetStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + BitsetStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || BitsetStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void BitsetStructPubSubType::register_type_object_representation() +{ + register_BitsetStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "bitset_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.hpp new file mode 100644 index 00000000000..299306c4338 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structPubSubTypes.hpp @@ -0,0 +1,133 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitset_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__BITSET_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__BITSET_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "bitset_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated bitset_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type BitsetStruct defined by the user in the IDL file. + * @ingroup bitset_struct + */ +class BitsetStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef BitsetStruct type; + + eProsima_user_DllExport BitsetStructPubSubType(); + + eProsima_user_DllExport ~BitsetStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__BITSET_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..cbe8e365e93 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structTypeObjectSupport.cxx @@ -0,0 +1,175 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitset_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "bitset_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "bitset_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +void register_ColorBitset_type_identifier( + TypeIdentifierPair& type_ids_ColorBitset) +{ + ReturnCode_t return_code_ColorBitset {eprosima::fastdds::dds::RETCODE_OK}; + return_code_ColorBitset = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ColorBitset", type_ids_ColorBitset); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ColorBitset) + { + BitsetTypeFlag bitset_flags_ColorBitset = 0; + QualifiedTypeName type_name_ColorBitset = "ColorBitset"; + eprosima::fastcdr::optional type_ann_builtin_ColorBitset; + eprosima::fastcdr::optional ann_custom_ColorBitset; + CompleteTypeDetail detail_ColorBitset = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ColorBitset, ann_custom_ColorBitset, type_name_ColorBitset.to_string()); + CompleteBitsetHeader header_ColorBitset = TypeObjectUtils::build_complete_bitset_header(detail_ColorBitset); + CompleteBitfieldSeq field_seq_ColorBitset; + { + uint16_t position_red = 0; + BitsetMemberFlag flags_red = 0; + uint8_t bitcount_red = 3; + TypeKind holder_type_red = TK_UINT8; + CommonBitfield common_red = TypeObjectUtils::build_common_bitfield(position_red, flags_red, bitcount_red, holder_type_red); + eprosima::fastcdr::optional member_ann_builtin_red; + ann_custom_ColorBitset.reset(); + MemberName name_red = "red"; + CompleteMemberDetail detail_red = TypeObjectUtils::build_complete_member_detail(name_red, member_ann_builtin_red, ann_custom_ColorBitset); + CompleteBitfield bitfield_red = TypeObjectUtils::build_complete_bitfield(common_red, detail_red); + TypeObjectUtils::add_complete_bitfield(field_seq_ColorBitset, bitfield_red); + } + { + uint16_t position_green = 3; + BitsetMemberFlag flags_green = 0; + uint8_t bitcount_green = 1; + TypeKind holder_type_green = TK_BOOLEAN; + CommonBitfield common_green = TypeObjectUtils::build_common_bitfield(position_green, flags_green, bitcount_green, holder_type_green); + eprosima::fastcdr::optional member_ann_builtin_green; + ann_custom_ColorBitset.reset(); + MemberName name_green = "green"; + CompleteMemberDetail detail_green = TypeObjectUtils::build_complete_member_detail(name_green, member_ann_builtin_green, ann_custom_ColorBitset); + CompleteBitfield bitfield_green = TypeObjectUtils::build_complete_bitfield(common_green, detail_green); + TypeObjectUtils::add_complete_bitfield(field_seq_ColorBitset, bitfield_green); + } + { + uint16_t position_blue = 8; + BitsetMemberFlag flags_blue = 0; + uint8_t bitcount_blue = 10; + TypeKind holder_type_blue = TK_UINT16; + CommonBitfield common_blue = TypeObjectUtils::build_common_bitfield(position_blue, flags_blue, bitcount_blue, holder_type_blue); + eprosima::fastcdr::optional member_ann_builtin_blue; + ann_custom_ColorBitset.reset(); + MemberName name_blue = "blue"; + CompleteMemberDetail detail_blue = TypeObjectUtils::build_complete_member_detail(name_blue, member_ann_builtin_blue, ann_custom_ColorBitset); + CompleteBitfield bitfield_blue = TypeObjectUtils::build_complete_bitfield(common_blue, detail_blue); + TypeObjectUtils::add_complete_bitfield(field_seq_ColorBitset, bitfield_blue); + } + { + uint16_t position_yellow = 18; + BitsetMemberFlag flags_yellow = 0; + uint8_t bitcount_yellow = 12; + TypeKind holder_type_yellow = TK_INT16; + CommonBitfield common_yellow = TypeObjectUtils::build_common_bitfield(position_yellow, flags_yellow, bitcount_yellow, holder_type_yellow); + eprosima::fastcdr::optional member_ann_builtin_yellow; + ann_custom_ColorBitset.reset(); + MemberName name_yellow = "yellow"; + CompleteMemberDetail detail_yellow = TypeObjectUtils::build_complete_member_detail(name_yellow, member_ann_builtin_yellow, ann_custom_ColorBitset); + CompleteBitfield bitfield_yellow = TypeObjectUtils::build_complete_bitfield(common_yellow, detail_yellow); + TypeObjectUtils::add_complete_bitfield(field_seq_ColorBitset, bitfield_yellow); + } + CompleteBitsetType bitset_type_ColorBitset = TypeObjectUtils::build_complete_bitset_type(bitset_flags_ColorBitset, header_ColorBitset, field_seq_ColorBitset); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_bitset_type_object(bitset_type_ColorBitset, + type_name_ColorBitset.to_string(), type_ids_ColorBitset)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ColorBitset already registered in TypeObjectRegistry for a different type."); + } + } +}// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_BitsetStruct_type_identifier( + TypeIdentifierPair& type_ids_BitsetStruct) +{ + + ReturnCode_t return_code_BitsetStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_BitsetStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "BitsetStruct", type_ids_BitsetStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_BitsetStruct) + { + StructTypeFlag struct_flags_BitsetStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_BitsetStruct = "BitsetStruct"; + eprosima::fastcdr::optional type_ann_builtin_BitsetStruct; + eprosima::fastcdr::optional ann_custom_BitsetStruct; + CompleteTypeDetail detail_BitsetStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_BitsetStruct, ann_custom_BitsetStruct, type_name_BitsetStruct.to_string()); + CompleteStructHeader header_BitsetStruct; + header_BitsetStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_BitsetStruct); + CompleteStructMemberSeq member_seq_BitsetStruct; + { + TypeIdentifierPair type_ids_my_bitset; + ReturnCode_t return_code_my_bitset {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_bitset = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ColorBitset", type_ids_my_bitset); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_bitset) + { + ::register_ColorBitset_type_identifier(type_ids_my_bitset); + } + StructMemberFlag member_flags_my_bitset = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_bitset = 0x00000000; + bool common_my_bitset_ec {false}; + CommonStructMember common_my_bitset {TypeObjectUtils::build_common_struct_member(member_id_my_bitset, member_flags_my_bitset, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_bitset, common_my_bitset_ec))}; + if (!common_my_bitset_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_bitset member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_bitset = "my_bitset"; + eprosima::fastcdr::optional member_ann_builtin_my_bitset; + ann_custom_BitsetStruct.reset(); + CompleteMemberDetail detail_my_bitset = TypeObjectUtils::build_complete_member_detail(name_my_bitset, member_ann_builtin_my_bitset, ann_custom_BitsetStruct); + CompleteStructMember member_my_bitset = TypeObjectUtils::build_complete_struct_member(common_my_bitset, detail_my_bitset); + TypeObjectUtils::add_complete_struct_member(member_seq_BitsetStruct, member_my_bitset); + } + CompleteStructType struct_type_BitsetStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_BitsetStruct, header_BitsetStruct, member_seq_BitsetStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_BitsetStruct, type_name_BitsetStruct.to_string(), type_ids_BitsetStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "BitsetStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..e464ae9f29f --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/gen/bitset_structTypeObjectSupport.hpp @@ -0,0 +1,68 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file bitset_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BITSET_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__BITSET_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register ColorBitset related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_ColorBitset_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register BitsetStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_BitsetStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__BITSET_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/enum_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/enum_struct.idl new file mode 100644 index 00000000000..951dd5e147f --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/enum_struct.idl @@ -0,0 +1,11 @@ +enum ColorEnum +{ + RED, + GREEN, + BLUE +}; + +struct EnumStruct +{ + ColorEnum enum_value; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_struct.hpp new file mode 100644 index 00000000000..b832414f09a --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_struct.hpp @@ -0,0 +1,188 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file enum_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ENUM_STRUCT_HPP +#define FAST_DDS_GENERATED__ENUM_STRUCT_HPP + +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(ENUM_STRUCT_SOURCE) +#define ENUM_STRUCT_DllAPI __declspec( dllexport ) +#else +#define ENUM_STRUCT_DllAPI __declspec( dllimport ) +#endif // ENUM_STRUCT_SOURCE +#else +#define ENUM_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define ENUM_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the enumeration ColorEnum defined by the user in the IDL file. + * @ingroup enum_struct + */ +enum class ColorEnum : int32_t +{ + RED, + GREEN, + BLUE +}; +/*! + * @brief This class represents the structure EnumStruct defined by the user in the IDL file. + * @ingroup enum_struct + */ +class EnumStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport EnumStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~EnumStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object EnumStruct that will be copied. + */ + eProsima_user_DllExport EnumStruct( + const EnumStruct& x) + { + m_enum_value = x.m_enum_value; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object EnumStruct that will be copied. + */ + eProsima_user_DllExport EnumStruct( + EnumStruct&& x) noexcept + { + m_enum_value = x.m_enum_value; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object EnumStruct that will be copied. + */ + eProsima_user_DllExport EnumStruct& operator =( + const EnumStruct& x) + { + + m_enum_value = x.m_enum_value; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object EnumStruct that will be copied. + */ + eProsima_user_DllExport EnumStruct& operator =( + EnumStruct&& x) noexcept + { + + m_enum_value = x.m_enum_value; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x EnumStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const EnumStruct& x) const + { + return (m_enum_value == x.m_enum_value); + } + + /*! + * @brief Comparison operator. + * @param x EnumStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const EnumStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member enum_value + * @param _enum_value New value for member enum_value + */ + eProsima_user_DllExport void enum_value( + ColorEnum _enum_value) + { + m_enum_value = _enum_value; + } + + /*! + * @brief This function returns the value of member enum_value + * @return Value of member enum_value + */ + eProsima_user_DllExport ColorEnum enum_value() const + { + return m_enum_value; + } + + /*! + * @brief This function returns a reference to member enum_value + * @return Reference to member enum_value + */ + eProsima_user_DllExport ColorEnum& enum_value() + { + return m_enum_value; + } + + + +private: + + ColorEnum m_enum_value{ColorEnum::RED}; + +}; + +#endif // _FAST_DDS_GENERATED_ENUM_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structCdrAux.hpp new file mode 100644 index 00000000000..7bb13168503 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structCdrAux.hpp @@ -0,0 +1,47 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file enum_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ENUM_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__ENUM_STRUCTCDRAUX_HPP + +#include "enum_struct.hpp" + +constexpr uint32_t EnumStruct_max_cdr_typesize {8UL}; +constexpr uint32_t EnumStruct_max_key_cdr_typesize {0UL}; + + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const EnumStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__ENUM_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structCdrAux.ipp new file mode 100644 index 00000000000..33876ba2bba --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structCdrAux.ipp @@ -0,0 +1,118 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file enum_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ENUM_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__ENUM_STRUCTCDRAUX_IPP + +#include "enum_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const EnumStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.enum_value(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const EnumStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.enum_value() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + EnumStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.enum_value(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const EnumStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__ENUM_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.cxx new file mode 100644 index 00000000000..e6d63cec8b4 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.cxx @@ -0,0 +1,229 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file enum_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "enum_structPubSubTypes.hpp" + +#include +#include + +#include "enum_structCdrAux.hpp" +#include "enum_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +EnumStructPubSubType::EnumStructPubSubType() +{ + setName("EnumStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(EnumStruct::getMaxCdrSerializedSize()); +#else + EnumStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = EnumStruct_max_key_cdr_typesize > 16 ? EnumStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +EnumStructPubSubType::~EnumStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool EnumStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const EnumStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool EnumStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + EnumStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function EnumStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* EnumStructPubSubType::createData() +{ + return reinterpret_cast(new EnumStruct()); +} + +void EnumStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool EnumStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const EnumStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + EnumStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || EnumStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void EnumStructPubSubType::register_type_object_representation() +{ + register_EnumStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "enum_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.hpp new file mode 100644 index 00000000000..4a0e3122b01 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structPubSubTypes.hpp @@ -0,0 +1,133 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file enum_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__ENUM_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__ENUM_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "enum_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated enum_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type EnumStruct defined by the user in the IDL file. + * @ingroup enum_struct + */ +class EnumStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef EnumStruct type; + + eProsima_user_DllExport EnumStructPubSubType(); + + eProsima_user_DllExport ~EnumStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__ENUM_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..38a0fbf0761 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structTypeObjectSupport.cxx @@ -0,0 +1,155 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file enum_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "enum_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "enum_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +void register_ColorEnum_type_identifier( + TypeIdentifierPair& type_ids_ColorEnum) +{ + ReturnCode_t return_code_ColorEnum {eprosima::fastdds::dds::RETCODE_OK}; + return_code_ColorEnum = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ColorEnum", type_ids_ColorEnum); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ColorEnum) + { + EnumTypeFlag enum_flags_ColorEnum = 0; + BitBound bit_bound_ColorEnum = 32; + CommonEnumeratedHeader common_ColorEnum = TypeObjectUtils::build_common_enumerated_header(bit_bound_ColorEnum); + QualifiedTypeName type_name_ColorEnum = "ColorEnum"; + eprosima::fastcdr::optional type_ann_builtin_ColorEnum; + eprosima::fastcdr::optional ann_custom_ColorEnum; + CompleteTypeDetail detail_ColorEnum = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ColorEnum, ann_custom_ColorEnum, type_name_ColorEnum.to_string()); + CompleteEnumeratedHeader header_ColorEnum = TypeObjectUtils::build_complete_enumerated_header(common_ColorEnum, detail_ColorEnum); + CompleteEnumeratedLiteralSeq literal_seq_ColorEnum; + { + EnumeratedLiteralFlag flags_RED = TypeObjectUtils::build_enumerated_literal_flag(false); + CommonEnumeratedLiteral common_RED = TypeObjectUtils::build_common_enumerated_literal(0, flags_RED); + eprosima::fastcdr::optional member_ann_builtin_RED; + ann_custom_ColorEnum.reset(); + MemberName name_RED = "RED"; + CompleteMemberDetail detail_RED = TypeObjectUtils::build_complete_member_detail(name_RED, member_ann_builtin_RED, ann_custom_ColorEnum); + CompleteEnumeratedLiteral literal_RED = TypeObjectUtils::build_complete_enumerated_literal(common_RED, detail_RED); + TypeObjectUtils::add_complete_enumerated_literal(literal_seq_ColorEnum, literal_RED); + } + { + EnumeratedLiteralFlag flags_GREEN = TypeObjectUtils::build_enumerated_literal_flag(false); + CommonEnumeratedLiteral common_GREEN = TypeObjectUtils::build_common_enumerated_literal(1, flags_GREEN); + eprosima::fastcdr::optional member_ann_builtin_GREEN; + ann_custom_ColorEnum.reset(); + MemberName name_GREEN = "GREEN"; + CompleteMemberDetail detail_GREEN = TypeObjectUtils::build_complete_member_detail(name_GREEN, member_ann_builtin_GREEN, ann_custom_ColorEnum); + CompleteEnumeratedLiteral literal_GREEN = TypeObjectUtils::build_complete_enumerated_literal(common_GREEN, detail_GREEN); + TypeObjectUtils::add_complete_enumerated_literal(literal_seq_ColorEnum, literal_GREEN); + } + { + EnumeratedLiteralFlag flags_BLUE = TypeObjectUtils::build_enumerated_literal_flag(false); + CommonEnumeratedLiteral common_BLUE = TypeObjectUtils::build_common_enumerated_literal(2, flags_BLUE); + eprosima::fastcdr::optional member_ann_builtin_BLUE; + ann_custom_ColorEnum.reset(); + MemberName name_BLUE = "BLUE"; + CompleteMemberDetail detail_BLUE = TypeObjectUtils::build_complete_member_detail(name_BLUE, member_ann_builtin_BLUE, ann_custom_ColorEnum); + CompleteEnumeratedLiteral literal_BLUE = TypeObjectUtils::build_complete_enumerated_literal(common_BLUE, detail_BLUE); + TypeObjectUtils::add_complete_enumerated_literal(literal_seq_ColorEnum, literal_BLUE); + } + CompleteEnumeratedType enumerated_type_ColorEnum = TypeObjectUtils::build_complete_enumerated_type(enum_flags_ColorEnum, header_ColorEnum, + literal_seq_ColorEnum); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_enumerated_type_object(enumerated_type_ColorEnum, type_name_ColorEnum.to_string(), type_ids_ColorEnum)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ColorEnum already registered in TypeObjectRegistry for a different type."); + } + } +}// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_EnumStruct_type_identifier( + TypeIdentifierPair& type_ids_EnumStruct) +{ + + ReturnCode_t return_code_EnumStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_EnumStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "EnumStruct", type_ids_EnumStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_EnumStruct) + { + StructTypeFlag struct_flags_EnumStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_EnumStruct = "EnumStruct"; + eprosima::fastcdr::optional type_ann_builtin_EnumStruct; + eprosima::fastcdr::optional ann_custom_EnumStruct; + CompleteTypeDetail detail_EnumStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_EnumStruct, ann_custom_EnumStruct, type_name_EnumStruct.to_string()); + CompleteStructHeader header_EnumStruct; + header_EnumStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_EnumStruct); + CompleteStructMemberSeq member_seq_EnumStruct; + { + TypeIdentifierPair type_ids_enum_value; + ReturnCode_t return_code_enum_value {eprosima::fastdds::dds::RETCODE_OK}; + return_code_enum_value = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ColorEnum", type_ids_enum_value); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_enum_value) + { + ::register_ColorEnum_type_identifier(type_ids_enum_value); + } + StructMemberFlag member_flags_enum_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_enum_value = 0x00000000; + bool common_enum_value_ec {false}; + CommonStructMember common_enum_value {TypeObjectUtils::build_common_struct_member(member_id_enum_value, member_flags_enum_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_enum_value, common_enum_value_ec))}; + if (!common_enum_value_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure enum_value member TypeIdentifier inconsistent."); + return; + } + MemberName name_enum_value = "enum_value"; + eprosima::fastcdr::optional member_ann_builtin_enum_value; + ann_custom_EnumStruct.reset(); + CompleteMemberDetail detail_enum_value = TypeObjectUtils::build_complete_member_detail(name_enum_value, member_ann_builtin_enum_value, ann_custom_EnumStruct); + CompleteStructMember member_enum_value = TypeObjectUtils::build_complete_struct_member(common_enum_value, detail_enum_value); + TypeObjectUtils::add_complete_struct_member(member_seq_EnumStruct, member_enum_value); + } + CompleteStructType struct_type_EnumStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_EnumStruct, header_EnumStruct, member_seq_EnumStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_EnumStruct, type_name_EnumStruct.to_string(), type_ids_EnumStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "EnumStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..ac765dcafd5 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/enum_struct/gen/enum_structTypeObjectSupport.hpp @@ -0,0 +1,68 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file enum_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__ENUM_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__ENUM_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register ColorEnum related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_ColorEnum_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register EnumStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_EnumStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__ENUM_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/extensibility_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/extensibility_struct.idl new file mode 100644 index 00000000000..ae252ac00a9 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/extensibility_struct.idl @@ -0,0 +1,23 @@ +@extensibility(FINAL) +struct FinalStruct +{ + octet my_value; +}; + +@extensibility(MUTABLE) +struct MutableStruct +{ + octet my_value; +}; + +struct AppendableStruct +{ + octet my_value; +}; + +struct ExtensibilityStruct +{ + FinalStruct my_final_struct; + MutableStruct my_mutable_struct; + AppendableStruct my_appendable_struct; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_struct.hpp new file mode 100644 index 00000000000..9922d45e9b3 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_struct.hpp @@ -0,0 +1,651 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file extensibility_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__EXTENSIBILITY_STRUCT_HPP +#define FAST_DDS_GENERATED__EXTENSIBILITY_STRUCT_HPP + +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(EXTENSIBILITY_STRUCT_SOURCE) +#define EXTENSIBILITY_STRUCT_DllAPI __declspec( dllexport ) +#else +#define EXTENSIBILITY_STRUCT_DllAPI __declspec( dllimport ) +#endif // EXTENSIBILITY_STRUCT_SOURCE +#else +#define EXTENSIBILITY_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define EXTENSIBILITY_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure FinalStruct defined by the user in the IDL file. + * @ingroup extensibility_struct + */ +class FinalStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport FinalStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~FinalStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object FinalStruct that will be copied. + */ + eProsima_user_DllExport FinalStruct( + const FinalStruct& x) + { + m_my_value = x.m_my_value; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object FinalStruct that will be copied. + */ + eProsima_user_DllExport FinalStruct( + FinalStruct&& x) noexcept + { + m_my_value = x.m_my_value; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object FinalStruct that will be copied. + */ + eProsima_user_DllExport FinalStruct& operator =( + const FinalStruct& x) + { + + m_my_value = x.m_my_value; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object FinalStruct that will be copied. + */ + eProsima_user_DllExport FinalStruct& operator =( + FinalStruct&& x) noexcept + { + + m_my_value = x.m_my_value; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x FinalStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const FinalStruct& x) const + { + return (m_my_value == x.m_my_value); + } + + /*! + * @brief Comparison operator. + * @param x FinalStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const FinalStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_value + * @param _my_value New value for member my_value + */ + eProsima_user_DllExport void my_value( + uint8_t _my_value) + { + m_my_value = _my_value; + } + + /*! + * @brief This function returns the value of member my_value + * @return Value of member my_value + */ + eProsima_user_DllExport uint8_t my_value() const + { + return m_my_value; + } + + /*! + * @brief This function returns a reference to member my_value + * @return Reference to member my_value + */ + eProsima_user_DllExport uint8_t& my_value() + { + return m_my_value; + } + + + +private: + + uint8_t m_my_value{0}; + +}; +/*! + * @brief This class represents the structure MutableStruct defined by the user in the IDL file. + * @ingroup extensibility_struct + */ +class MutableStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport MutableStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~MutableStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object MutableStruct that will be copied. + */ + eProsima_user_DllExport MutableStruct( + const MutableStruct& x) + { + m_my_value = x.m_my_value; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object MutableStruct that will be copied. + */ + eProsima_user_DllExport MutableStruct( + MutableStruct&& x) noexcept + { + m_my_value = x.m_my_value; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object MutableStruct that will be copied. + */ + eProsima_user_DllExport MutableStruct& operator =( + const MutableStruct& x) + { + + m_my_value = x.m_my_value; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object MutableStruct that will be copied. + */ + eProsima_user_DllExport MutableStruct& operator =( + MutableStruct&& x) noexcept + { + + m_my_value = x.m_my_value; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x MutableStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const MutableStruct& x) const + { + return (m_my_value == x.m_my_value); + } + + /*! + * @brief Comparison operator. + * @param x MutableStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const MutableStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_value + * @param _my_value New value for member my_value + */ + eProsima_user_DllExport void my_value( + uint8_t _my_value) + { + m_my_value = _my_value; + } + + /*! + * @brief This function returns the value of member my_value + * @return Value of member my_value + */ + eProsima_user_DllExport uint8_t my_value() const + { + return m_my_value; + } + + /*! + * @brief This function returns a reference to member my_value + * @return Reference to member my_value + */ + eProsima_user_DllExport uint8_t& my_value() + { + return m_my_value; + } + + + +private: + + uint8_t m_my_value{0}; + +}; +/*! + * @brief This class represents the structure AppendableStruct defined by the user in the IDL file. + * @ingroup extensibility_struct + */ +class AppendableStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport AppendableStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~AppendableStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object AppendableStruct that will be copied. + */ + eProsima_user_DllExport AppendableStruct( + const AppendableStruct& x) + { + m_my_value = x.m_my_value; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object AppendableStruct that will be copied. + */ + eProsima_user_DllExport AppendableStruct( + AppendableStruct&& x) noexcept + { + m_my_value = x.m_my_value; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object AppendableStruct that will be copied. + */ + eProsima_user_DllExport AppendableStruct& operator =( + const AppendableStruct& x) + { + + m_my_value = x.m_my_value; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object AppendableStruct that will be copied. + */ + eProsima_user_DllExport AppendableStruct& operator =( + AppendableStruct&& x) noexcept + { + + m_my_value = x.m_my_value; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x AppendableStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const AppendableStruct& x) const + { + return (m_my_value == x.m_my_value); + } + + /*! + * @brief Comparison operator. + * @param x AppendableStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const AppendableStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_value + * @param _my_value New value for member my_value + */ + eProsima_user_DllExport void my_value( + uint8_t _my_value) + { + m_my_value = _my_value; + } + + /*! + * @brief This function returns the value of member my_value + * @return Value of member my_value + */ + eProsima_user_DllExport uint8_t my_value() const + { + return m_my_value; + } + + /*! + * @brief This function returns a reference to member my_value + * @return Reference to member my_value + */ + eProsima_user_DllExport uint8_t& my_value() + { + return m_my_value; + } + + + +private: + + uint8_t m_my_value{0}; + +}; +/*! + * @brief This class represents the structure ExtensibilityStruct defined by the user in the IDL file. + * @ingroup extensibility_struct + */ +class ExtensibilityStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport ExtensibilityStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~ExtensibilityStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object ExtensibilityStruct that will be copied. + */ + eProsima_user_DllExport ExtensibilityStruct( + const ExtensibilityStruct& x) + { + m_my_final_struct = x.m_my_final_struct; + + m_my_mutable_struct = x.m_my_mutable_struct; + + m_my_appendable_struct = x.m_my_appendable_struct; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object ExtensibilityStruct that will be copied. + */ + eProsima_user_DllExport ExtensibilityStruct( + ExtensibilityStruct&& x) noexcept + { + m_my_final_struct = std::move(x.m_my_final_struct); + m_my_mutable_struct = std::move(x.m_my_mutable_struct); + m_my_appendable_struct = std::move(x.m_my_appendable_struct); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object ExtensibilityStruct that will be copied. + */ + eProsima_user_DllExport ExtensibilityStruct& operator =( + const ExtensibilityStruct& x) + { + + m_my_final_struct = x.m_my_final_struct; + + m_my_mutable_struct = x.m_my_mutable_struct; + + m_my_appendable_struct = x.m_my_appendable_struct; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object ExtensibilityStruct that will be copied. + */ + eProsima_user_DllExport ExtensibilityStruct& operator =( + ExtensibilityStruct&& x) noexcept + { + + m_my_final_struct = std::move(x.m_my_final_struct); + m_my_mutable_struct = std::move(x.m_my_mutable_struct); + m_my_appendable_struct = std::move(x.m_my_appendable_struct); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x ExtensibilityStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const ExtensibilityStruct& x) const + { + return (m_my_final_struct == x.m_my_final_struct && + m_my_mutable_struct == x.m_my_mutable_struct && + m_my_appendable_struct == x.m_my_appendable_struct); + } + + /*! + * @brief Comparison operator. + * @param x ExtensibilityStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const ExtensibilityStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member my_final_struct + * @param _my_final_struct New value to be copied in member my_final_struct + */ + eProsima_user_DllExport void my_final_struct( + const FinalStruct& _my_final_struct) + { + m_my_final_struct = _my_final_struct; + } + + /*! + * @brief This function moves the value in member my_final_struct + * @param _my_final_struct New value to be moved in member my_final_struct + */ + eProsima_user_DllExport void my_final_struct( + FinalStruct&& _my_final_struct) + { + m_my_final_struct = std::move(_my_final_struct); + } + + /*! + * @brief This function returns a constant reference to member my_final_struct + * @return Constant reference to member my_final_struct + */ + eProsima_user_DllExport const FinalStruct& my_final_struct() const + { + return m_my_final_struct; + } + + /*! + * @brief This function returns a reference to member my_final_struct + * @return Reference to member my_final_struct + */ + eProsima_user_DllExport FinalStruct& my_final_struct() + { + return m_my_final_struct; + } + + + /*! + * @brief This function copies the value in member my_mutable_struct + * @param _my_mutable_struct New value to be copied in member my_mutable_struct + */ + eProsima_user_DllExport void my_mutable_struct( + const MutableStruct& _my_mutable_struct) + { + m_my_mutable_struct = _my_mutable_struct; + } + + /*! + * @brief This function moves the value in member my_mutable_struct + * @param _my_mutable_struct New value to be moved in member my_mutable_struct + */ + eProsima_user_DllExport void my_mutable_struct( + MutableStruct&& _my_mutable_struct) + { + m_my_mutable_struct = std::move(_my_mutable_struct); + } + + /*! + * @brief This function returns a constant reference to member my_mutable_struct + * @return Constant reference to member my_mutable_struct + */ + eProsima_user_DllExport const MutableStruct& my_mutable_struct() const + { + return m_my_mutable_struct; + } + + /*! + * @brief This function returns a reference to member my_mutable_struct + * @return Reference to member my_mutable_struct + */ + eProsima_user_DllExport MutableStruct& my_mutable_struct() + { + return m_my_mutable_struct; + } + + + /*! + * @brief This function copies the value in member my_appendable_struct + * @param _my_appendable_struct New value to be copied in member my_appendable_struct + */ + eProsima_user_DllExport void my_appendable_struct( + const AppendableStruct& _my_appendable_struct) + { + m_my_appendable_struct = _my_appendable_struct; + } + + /*! + * @brief This function moves the value in member my_appendable_struct + * @param _my_appendable_struct New value to be moved in member my_appendable_struct + */ + eProsima_user_DllExport void my_appendable_struct( + AppendableStruct&& _my_appendable_struct) + { + m_my_appendable_struct = std::move(_my_appendable_struct); + } + + /*! + * @brief This function returns a constant reference to member my_appendable_struct + * @return Constant reference to member my_appendable_struct + */ + eProsima_user_DllExport const AppendableStruct& my_appendable_struct() const + { + return m_my_appendable_struct; + } + + /*! + * @brief This function returns a reference to member my_appendable_struct + * @return Reference to member my_appendable_struct + */ + eProsima_user_DllExport AppendableStruct& my_appendable_struct() + { + return m_my_appendable_struct; + } + + + +private: + + FinalStruct m_my_final_struct; + MutableStruct m_my_mutable_struct; + AppendableStruct m_my_appendable_struct; + +}; + +#endif // _FAST_DDS_GENERATED_EXTENSIBILITY_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structCdrAux.hpp new file mode 100644 index 00000000000..43a956fa458 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structCdrAux.hpp @@ -0,0 +1,67 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file extensibility_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__EXTENSIBILITY_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__EXTENSIBILITY_STRUCTCDRAUX_HPP + +#include "extensibility_struct.hpp" + +constexpr uint32_t MutableStruct_max_cdr_typesize {12UL}; +constexpr uint32_t MutableStruct_max_key_cdr_typesize {0UL}; + +constexpr uint32_t ExtensibilityStruct_max_cdr_typesize {25UL}; +constexpr uint32_t ExtensibilityStruct_max_key_cdr_typesize {0UL}; + +constexpr uint32_t FinalStruct_max_cdr_typesize {1UL}; +constexpr uint32_t FinalStruct_max_key_cdr_typesize {0UL}; + +constexpr uint32_t AppendableStruct_max_cdr_typesize {5UL}; +constexpr uint32_t AppendableStruct_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const FinalStruct& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const MutableStruct& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const AppendableStruct& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ExtensibilityStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__EXTENSIBILITY_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structCdrAux.ipp new file mode 100644 index 00000000000..58f6583fc39 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structCdrAux.ipp @@ -0,0 +1,362 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file extensibility_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__EXTENSIBILITY_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__EXTENSIBILITY_STRUCTCDRAUX_IPP + +#include "extensibility_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const FinalStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_value(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const FinalStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_value() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + FinalStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_value(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const FinalStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const MutableStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0x00000000), + data.my_value(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const MutableStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR); + + scdr + << eprosima::fastcdr::MemberId(0x00000000) << data.my_value() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + MutableStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0x00000000: + dcdr >> data.my_value(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const MutableStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const AppendableStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_value(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const AppendableStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_value() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + AppendableStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_value(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const AppendableStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const ExtensibilityStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_final_struct(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_mutable_struct(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_appendable_struct(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const ExtensibilityStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_final_struct() + << eprosima::fastcdr::MemberId(1) << data.my_mutable_struct() + << eprosima::fastcdr::MemberId(2) << data.my_appendable_struct() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + ExtensibilityStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_final_struct(); + break; + + case 1: + dcdr >> data.my_mutable_struct(); + break; + + case 2: + dcdr >> data.my_appendable_struct(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ExtensibilityStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__EXTENSIBILITY_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.cxx new file mode 100644 index 00000000000..87070348864 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.cxx @@ -0,0 +1,808 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file extensibility_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "extensibility_structPubSubTypes.hpp" + +#include +#include + +#include "extensibility_structCdrAux.hpp" +#include "extensibility_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +FinalStructPubSubType::FinalStructPubSubType() +{ + setName("FinalStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(FinalStruct::getMaxCdrSerializedSize()); +#else + FinalStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = FinalStruct_max_key_cdr_typesize > 16 ? FinalStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +FinalStructPubSubType::~FinalStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool FinalStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const FinalStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool FinalStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + FinalStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function FinalStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* FinalStructPubSubType::createData() +{ + return reinterpret_cast(new FinalStruct()); +} + +void FinalStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool FinalStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const FinalStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + FinalStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || FinalStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void FinalStructPubSubType::register_type_object_representation() +{ + register_FinalStruct_type_identifier(type_identifiers_); +} + +MutableStructPubSubType::MutableStructPubSubType() +{ + setName("MutableStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(MutableStruct::getMaxCdrSerializedSize()); +#else + MutableStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = MutableStruct_max_key_cdr_typesize > 16 ? MutableStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +MutableStructPubSubType::~MutableStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool MutableStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const MutableStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool MutableStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + MutableStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function MutableStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* MutableStructPubSubType::createData() +{ + return reinterpret_cast(new MutableStruct()); +} + +void MutableStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool MutableStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const MutableStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + MutableStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || MutableStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void MutableStructPubSubType::register_type_object_representation() +{ + register_MutableStruct_type_identifier(type_identifiers_); +} + +AppendableStructPubSubType::AppendableStructPubSubType() +{ + setName("AppendableStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(AppendableStruct::getMaxCdrSerializedSize()); +#else + AppendableStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = AppendableStruct_max_key_cdr_typesize > 16 ? AppendableStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +AppendableStructPubSubType::~AppendableStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool AppendableStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const AppendableStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool AppendableStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + AppendableStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function AppendableStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* AppendableStructPubSubType::createData() +{ + return reinterpret_cast(new AppendableStruct()); +} + +void AppendableStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool AppendableStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const AppendableStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + AppendableStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || AppendableStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void AppendableStructPubSubType::register_type_object_representation() +{ + register_AppendableStruct_type_identifier(type_identifiers_); +} + +ExtensibilityStructPubSubType::ExtensibilityStructPubSubType() +{ + setName("ExtensibilityStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(ExtensibilityStruct::getMaxCdrSerializedSize()); +#else + ExtensibilityStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = ExtensibilityStruct_max_key_cdr_typesize > 16 ? ExtensibilityStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +ExtensibilityStructPubSubType::~ExtensibilityStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool ExtensibilityStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const ExtensibilityStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool ExtensibilityStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + ExtensibilityStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function ExtensibilityStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* ExtensibilityStructPubSubType::createData() +{ + return reinterpret_cast(new ExtensibilityStruct()); +} + +void ExtensibilityStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool ExtensibilityStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const ExtensibilityStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + ExtensibilityStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || ExtensibilityStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void ExtensibilityStructPubSubType::register_type_object_representation() +{ + register_ExtensibilityStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "extensibility_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.hpp new file mode 100644 index 00000000000..28ad65cb910 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structPubSubTypes.hpp @@ -0,0 +1,461 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file extensibility_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__EXTENSIBILITY_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__EXTENSIBILITY_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "extensibility_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated extensibility_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +#ifndef SWIG +namespace detail { + +template +struct FinalStruct_rob +{ + friend constexpr typename Tag::type get( + Tag) + { + return M; + } + +}; + +struct FinalStruct_f +{ + typedef uint8_t FinalStruct::* type; + friend constexpr type get( + FinalStruct_f); +}; + +template struct FinalStruct_rob; + +template +inline size_t constexpr FinalStruct_offset_of() +{ + return ((::size_t) &reinterpret_cast((((T*)0)->*get(Tag())))); +} + +} // namespace detail +#endif // ifndef SWIG + + +/*! + * @brief This class represents the TopicDataType of the type FinalStruct defined by the user in the IDL file. + * @ingroup extensibility_struct + */ +class FinalStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef FinalStruct type; + + eProsima_user_DllExport FinalStructPubSubType(); + + eProsima_user_DllExport ~FinalStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return is_plain_xcdrv1_impl(); + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + if (data_representation == eprosima::fastdds::dds::DataRepresentationId_t::XCDR2_DATA_REPRESENTATION) + { + return is_plain_xcdrv2_impl(); + } + else + { + return is_plain_xcdrv1_impl(); + } + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + new (memory) FinalStruct(); + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +private: + + static constexpr bool is_plain_xcdrv1_impl() + { + return 1ULL == + (detail::FinalStruct_offset_of() + + sizeof(uint8_t)); + } + + static constexpr bool is_plain_xcdrv2_impl() + { + return 1ULL == + (detail::FinalStruct_offset_of() + + sizeof(uint8_t)); + } + +}; + +/*! + * @brief This class represents the TopicDataType of the type MutableStruct defined by the user in the IDL file. + * @ingroup extensibility_struct + */ +class MutableStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef MutableStruct type; + + eProsima_user_DllExport MutableStructPubSubType(); + + eProsima_user_DllExport ~MutableStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +/*! + * @brief This class represents the TopicDataType of the type AppendableStruct defined by the user in the IDL file. + * @ingroup extensibility_struct + */ +class AppendableStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef AppendableStruct type; + + eProsima_user_DllExport AppendableStructPubSubType(); + + eProsima_user_DllExport ~AppendableStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +/*! + * @brief This class represents the TopicDataType of the type ExtensibilityStruct defined by the user in the IDL file. + * @ingroup extensibility_struct + */ +class ExtensibilityStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef ExtensibilityStruct type; + + eProsima_user_DllExport ExtensibilityStructPubSubType(); + + eProsima_user_DllExport ~ExtensibilityStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__EXTENSIBILITY_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..f3eca37a9d0 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structTypeObjectSupport.cxx @@ -0,0 +1,345 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file extensibility_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "extensibility_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "extensibility_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_FinalStruct_type_identifier( + TypeIdentifierPair& type_ids_FinalStruct) +{ + + ReturnCode_t return_code_FinalStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_FinalStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "FinalStruct", type_ids_FinalStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_FinalStruct) + { + StructTypeFlag struct_flags_FinalStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::FINAL, + false, false); + QualifiedTypeName type_name_FinalStruct = "FinalStruct"; + eprosima::fastcdr::optional type_ann_builtin_FinalStruct; + eprosima::fastcdr::optional ann_custom_FinalStruct; + AppliedAnnotationSeq tmp_ann_custom_FinalStruct; + eprosima::fastcdr::optional verbatim_FinalStruct; + if (!tmp_ann_custom_FinalStruct.empty()) + { + ann_custom_FinalStruct = tmp_ann_custom_FinalStruct; + } + + CompleteTypeDetail detail_FinalStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_FinalStruct, ann_custom_FinalStruct, type_name_FinalStruct.to_string()); + CompleteStructHeader header_FinalStruct; + header_FinalStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_FinalStruct); + CompleteStructMemberSeq member_seq_FinalStruct; + { + TypeIdentifierPair type_ids_my_value; + ReturnCode_t return_code_my_value {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_value = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_byte", type_ids_my_value); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_value) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_value = 0x00000000; + bool common_my_value_ec {false}; + CommonStructMember common_my_value {TypeObjectUtils::build_common_struct_member(member_id_my_value, member_flags_my_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_value, common_my_value_ec))}; + if (!common_my_value_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_value member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_value = "my_value"; + eprosima::fastcdr::optional member_ann_builtin_my_value; + ann_custom_FinalStruct.reset(); + CompleteMemberDetail detail_my_value = TypeObjectUtils::build_complete_member_detail(name_my_value, member_ann_builtin_my_value, ann_custom_FinalStruct); + CompleteStructMember member_my_value = TypeObjectUtils::build_complete_struct_member(common_my_value, detail_my_value); + TypeObjectUtils::add_complete_struct_member(member_seq_FinalStruct, member_my_value); + } + CompleteStructType struct_type_FinalStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_FinalStruct, header_FinalStruct, member_seq_FinalStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_FinalStruct, type_name_FinalStruct.to_string(), type_ids_FinalStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "FinalStruct already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_MutableStruct_type_identifier( + TypeIdentifierPair& type_ids_MutableStruct) +{ + + ReturnCode_t return_code_MutableStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_MutableStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MutableStruct", type_ids_MutableStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MutableStruct) + { + StructTypeFlag struct_flags_MutableStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::MUTABLE, + false, false); + QualifiedTypeName type_name_MutableStruct = "MutableStruct"; + eprosima::fastcdr::optional type_ann_builtin_MutableStruct; + eprosima::fastcdr::optional ann_custom_MutableStruct; + AppliedAnnotationSeq tmp_ann_custom_MutableStruct; + eprosima::fastcdr::optional verbatim_MutableStruct; + if (!tmp_ann_custom_MutableStruct.empty()) + { + ann_custom_MutableStruct = tmp_ann_custom_MutableStruct; + } + + CompleteTypeDetail detail_MutableStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_MutableStruct, ann_custom_MutableStruct, type_name_MutableStruct.to_string()); + CompleteStructHeader header_MutableStruct; + header_MutableStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_MutableStruct); + CompleteStructMemberSeq member_seq_MutableStruct; + { + TypeIdentifierPair type_ids_my_value; + ReturnCode_t return_code_my_value {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_value = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_byte", type_ids_my_value); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_value) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_value = 0x00000000; + bool common_my_value_ec {false}; + CommonStructMember common_my_value {TypeObjectUtils::build_common_struct_member(member_id_my_value, member_flags_my_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_value, common_my_value_ec))}; + if (!common_my_value_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_value member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_value = "my_value"; + eprosima::fastcdr::optional member_ann_builtin_my_value; + ann_custom_MutableStruct.reset(); + CompleteMemberDetail detail_my_value = TypeObjectUtils::build_complete_member_detail(name_my_value, member_ann_builtin_my_value, ann_custom_MutableStruct); + CompleteStructMember member_my_value = TypeObjectUtils::build_complete_struct_member(common_my_value, detail_my_value); + TypeObjectUtils::add_complete_struct_member(member_seq_MutableStruct, member_my_value); + } + CompleteStructType struct_type_MutableStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_MutableStruct, header_MutableStruct, member_seq_MutableStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_MutableStruct, type_name_MutableStruct.to_string(), type_ids_MutableStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "MutableStruct already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_AppendableStruct_type_identifier( + TypeIdentifierPair& type_ids_AppendableStruct) +{ + + ReturnCode_t return_code_AppendableStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_AppendableStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "AppendableStruct", type_ids_AppendableStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_AppendableStruct) + { + StructTypeFlag struct_flags_AppendableStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_AppendableStruct = "AppendableStruct"; + eprosima::fastcdr::optional type_ann_builtin_AppendableStruct; + eprosima::fastcdr::optional ann_custom_AppendableStruct; + CompleteTypeDetail detail_AppendableStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_AppendableStruct, ann_custom_AppendableStruct, type_name_AppendableStruct.to_string()); + CompleteStructHeader header_AppendableStruct; + header_AppendableStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_AppendableStruct); + CompleteStructMemberSeq member_seq_AppendableStruct; + { + TypeIdentifierPair type_ids_my_value; + ReturnCode_t return_code_my_value {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_value = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_byte", type_ids_my_value); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_value) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_value = 0x00000000; + bool common_my_value_ec {false}; + CommonStructMember common_my_value {TypeObjectUtils::build_common_struct_member(member_id_my_value, member_flags_my_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_value, common_my_value_ec))}; + if (!common_my_value_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_value member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_value = "my_value"; + eprosima::fastcdr::optional member_ann_builtin_my_value; + ann_custom_AppendableStruct.reset(); + CompleteMemberDetail detail_my_value = TypeObjectUtils::build_complete_member_detail(name_my_value, member_ann_builtin_my_value, ann_custom_AppendableStruct); + CompleteStructMember member_my_value = TypeObjectUtils::build_complete_struct_member(common_my_value, detail_my_value); + TypeObjectUtils::add_complete_struct_member(member_seq_AppendableStruct, member_my_value); + } + CompleteStructType struct_type_AppendableStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_AppendableStruct, header_AppendableStruct, member_seq_AppendableStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_AppendableStruct, type_name_AppendableStruct.to_string(), type_ids_AppendableStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "AppendableStruct already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_ExtensibilityStruct_type_identifier( + TypeIdentifierPair& type_ids_ExtensibilityStruct) +{ + + ReturnCode_t return_code_ExtensibilityStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_ExtensibilityStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ExtensibilityStruct", type_ids_ExtensibilityStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ExtensibilityStruct) + { + StructTypeFlag struct_flags_ExtensibilityStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_ExtensibilityStruct = "ExtensibilityStruct"; + eprosima::fastcdr::optional type_ann_builtin_ExtensibilityStruct; + eprosima::fastcdr::optional ann_custom_ExtensibilityStruct; + CompleteTypeDetail detail_ExtensibilityStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ExtensibilityStruct, ann_custom_ExtensibilityStruct, type_name_ExtensibilityStruct.to_string()); + CompleteStructHeader header_ExtensibilityStruct; + header_ExtensibilityStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_ExtensibilityStruct); + CompleteStructMemberSeq member_seq_ExtensibilityStruct; + { + TypeIdentifierPair type_ids_my_final_struct; + ReturnCode_t return_code_my_final_struct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_final_struct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "FinalStruct", type_ids_my_final_struct); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_final_struct) + { + ::register_FinalStruct_type_identifier(type_ids_my_final_struct); + } + StructMemberFlag member_flags_my_final_struct = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_final_struct = 0x00000000; + bool common_my_final_struct_ec {false}; + CommonStructMember common_my_final_struct {TypeObjectUtils::build_common_struct_member(member_id_my_final_struct, member_flags_my_final_struct, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_final_struct, common_my_final_struct_ec))}; + if (!common_my_final_struct_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_final_struct member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_final_struct = "my_final_struct"; + eprosima::fastcdr::optional member_ann_builtin_my_final_struct; + ann_custom_ExtensibilityStruct.reset(); + CompleteMemberDetail detail_my_final_struct = TypeObjectUtils::build_complete_member_detail(name_my_final_struct, member_ann_builtin_my_final_struct, ann_custom_ExtensibilityStruct); + CompleteStructMember member_my_final_struct = TypeObjectUtils::build_complete_struct_member(common_my_final_struct, detail_my_final_struct); + TypeObjectUtils::add_complete_struct_member(member_seq_ExtensibilityStruct, member_my_final_struct); + } + { + TypeIdentifierPair type_ids_my_mutable_struct; + ReturnCode_t return_code_my_mutable_struct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_mutable_struct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MutableStruct", type_ids_my_mutable_struct); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_mutable_struct) + { + ::register_MutableStruct_type_identifier(type_ids_my_mutable_struct); + } + StructMemberFlag member_flags_my_mutable_struct = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_mutable_struct = 0x00000001; + bool common_my_mutable_struct_ec {false}; + CommonStructMember common_my_mutable_struct {TypeObjectUtils::build_common_struct_member(member_id_my_mutable_struct, member_flags_my_mutable_struct, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_mutable_struct, common_my_mutable_struct_ec))}; + if (!common_my_mutable_struct_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_mutable_struct member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_mutable_struct = "my_mutable_struct"; + eprosima::fastcdr::optional member_ann_builtin_my_mutable_struct; + ann_custom_ExtensibilityStruct.reset(); + CompleteMemberDetail detail_my_mutable_struct = TypeObjectUtils::build_complete_member_detail(name_my_mutable_struct, member_ann_builtin_my_mutable_struct, ann_custom_ExtensibilityStruct); + CompleteStructMember member_my_mutable_struct = TypeObjectUtils::build_complete_struct_member(common_my_mutable_struct, detail_my_mutable_struct); + TypeObjectUtils::add_complete_struct_member(member_seq_ExtensibilityStruct, member_my_mutable_struct); + } + { + TypeIdentifierPair type_ids_my_appendable_struct; + ReturnCode_t return_code_my_appendable_struct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_appendable_struct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "AppendableStruct", type_ids_my_appendable_struct); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_appendable_struct) + { + ::register_AppendableStruct_type_identifier(type_ids_my_appendable_struct); + } + StructMemberFlag member_flags_my_appendable_struct = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_appendable_struct = 0x00000002; + bool common_my_appendable_struct_ec {false}; + CommonStructMember common_my_appendable_struct {TypeObjectUtils::build_common_struct_member(member_id_my_appendable_struct, member_flags_my_appendable_struct, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_appendable_struct, common_my_appendable_struct_ec))}; + if (!common_my_appendable_struct_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_appendable_struct member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_appendable_struct = "my_appendable_struct"; + eprosima::fastcdr::optional member_ann_builtin_my_appendable_struct; + ann_custom_ExtensibilityStruct.reset(); + CompleteMemberDetail detail_my_appendable_struct = TypeObjectUtils::build_complete_member_detail(name_my_appendable_struct, member_ann_builtin_my_appendable_struct, ann_custom_ExtensibilityStruct); + CompleteStructMember member_my_appendable_struct = TypeObjectUtils::build_complete_struct_member(common_my_appendable_struct, detail_my_appendable_struct); + TypeObjectUtils::add_complete_struct_member(member_seq_ExtensibilityStruct, member_my_appendable_struct); + } + CompleteStructType struct_type_ExtensibilityStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_ExtensibilityStruct, header_ExtensibilityStruct, member_seq_ExtensibilityStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_ExtensibilityStruct, type_name_ExtensibilityStruct.to_string(), type_ids_ExtensibilityStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ExtensibilityStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..7622fe245c8 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/gen/extensibility_structTypeObjectSupport.hpp @@ -0,0 +1,92 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file extensibility_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__EXTENSIBILITY_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__EXTENSIBILITY_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register FinalStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_FinalStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register MutableStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_MutableStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register AppendableStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_AppendableStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register ExtensibilityStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_ExtensibilityStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__EXTENSIBILITY_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_struct.hpp new file mode 100644 index 00000000000..0d4526b9a6d --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_struct.hpp @@ -0,0 +1,508 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file key_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__KEY_STRUCT_HPP +#define FAST_DDS_GENERATED__KEY_STRUCT_HPP + +#include +#include +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(KEY_STRUCT_SOURCE) +#define KEY_STRUCT_DllAPI __declspec( dllexport ) +#else +#define KEY_STRUCT_DllAPI __declspec( dllimport ) +#endif // KEY_STRUCT_SOURCE +#else +#define KEY_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define KEY_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure ImportantStruct defined by the user in the IDL file. + * @ingroup key_struct + */ +class ImportantStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport ImportantStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~ImportantStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object ImportantStruct that will be copied. + */ + eProsima_user_DllExport ImportantStruct( + const ImportantStruct& x) + { + m_my_first_value = x.m_my_first_value; + + m_my_second_value = x.m_my_second_value; + + m_my_third_value = x.m_my_third_value; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object ImportantStruct that will be copied. + */ + eProsima_user_DllExport ImportantStruct( + ImportantStruct&& x) noexcept + { + m_my_first_value = x.m_my_first_value; + m_my_second_value = x.m_my_second_value; + m_my_third_value = x.m_my_third_value; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object ImportantStruct that will be copied. + */ + eProsima_user_DllExport ImportantStruct& operator =( + const ImportantStruct& x) + { + + m_my_first_value = x.m_my_first_value; + + m_my_second_value = x.m_my_second_value; + + m_my_third_value = x.m_my_third_value; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object ImportantStruct that will be copied. + */ + eProsima_user_DllExport ImportantStruct& operator =( + ImportantStruct&& x) noexcept + { + + m_my_first_value = x.m_my_first_value; + m_my_second_value = x.m_my_second_value; + m_my_third_value = x.m_my_third_value; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x ImportantStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const ImportantStruct& x) const + { + return (m_my_first_value == x.m_my_first_value && + m_my_second_value == x.m_my_second_value && + m_my_third_value == x.m_my_third_value); + } + + /*! + * @brief Comparison operator. + * @param x ImportantStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const ImportantStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_first_value + * @param _my_first_value New value for member my_first_value + */ + eProsima_user_DllExport void my_first_value( + int32_t _my_first_value) + { + m_my_first_value = _my_first_value; + } + + /*! + * @brief This function returns the value of member my_first_value + * @return Value of member my_first_value + */ + eProsima_user_DllExport int32_t my_first_value() const + { + return m_my_first_value; + } + + /*! + * @brief This function returns a reference to member my_first_value + * @return Reference to member my_first_value + */ + eProsima_user_DllExport int32_t& my_first_value() + { + return m_my_first_value; + } + + + /*! + * @brief This function sets a value in member my_second_value + * @param _my_second_value New value for member my_second_value + */ + eProsima_user_DllExport void my_second_value( + int32_t _my_second_value) + { + m_my_second_value = _my_second_value; + } + + /*! + * @brief This function returns the value of member my_second_value + * @return Value of member my_second_value + */ + eProsima_user_DllExport int32_t my_second_value() const + { + return m_my_second_value; + } + + /*! + * @brief This function returns a reference to member my_second_value + * @return Reference to member my_second_value + */ + eProsima_user_DllExport int32_t& my_second_value() + { + return m_my_second_value; + } + + + /*! + * @brief This function sets a value in member my_third_value + * @param _my_third_value New value for member my_third_value + */ + eProsima_user_DllExport void my_third_value( + int32_t _my_third_value) + { + m_my_third_value = _my_third_value; + } + + /*! + * @brief This function returns the value of member my_third_value + * @return Value of member my_third_value + */ + eProsima_user_DllExport int32_t my_third_value() const + { + return m_my_third_value; + } + + /*! + * @brief This function returns a reference to member my_third_value + * @return Reference to member my_third_value + */ + eProsima_user_DllExport int32_t& my_third_value() + { + return m_my_third_value; + } + + + +private: + + int32_t m_my_first_value{0}; + int32_t m_my_second_value{0}; + int32_t m_my_third_value{0}; + +}; +/*! + * @brief This class represents the structure KeyStruct defined by the user in the IDL file. + * @ingroup key_struct + */ +class KeyStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport KeyStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~KeyStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object KeyStruct that will be copied. + */ + eProsima_user_DllExport KeyStruct( + const KeyStruct& x) + { + m_my_short = x.m_my_short; + + m_my_long = x.m_my_long; + + m_my_string = x.m_my_string; + + m_my_important_struct = x.m_my_important_struct; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object KeyStruct that will be copied. + */ + eProsima_user_DllExport KeyStruct( + KeyStruct&& x) noexcept + { + m_my_short = x.m_my_short; + m_my_long = x.m_my_long; + m_my_string = std::move(x.m_my_string); + m_my_important_struct = std::move(x.m_my_important_struct); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object KeyStruct that will be copied. + */ + eProsima_user_DllExport KeyStruct& operator =( + const KeyStruct& x) + { + + m_my_short = x.m_my_short; + + m_my_long = x.m_my_long; + + m_my_string = x.m_my_string; + + m_my_important_struct = x.m_my_important_struct; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object KeyStruct that will be copied. + */ + eProsima_user_DllExport KeyStruct& operator =( + KeyStruct&& x) noexcept + { + + m_my_short = x.m_my_short; + m_my_long = x.m_my_long; + m_my_string = std::move(x.m_my_string); + m_my_important_struct = std::move(x.m_my_important_struct); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x KeyStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const KeyStruct& x) const + { + return (m_my_short == x.m_my_short && + m_my_long == x.m_my_long && + m_my_string == x.m_my_string && + m_my_important_struct == x.m_my_important_struct); + } + + /*! + * @brief Comparison operator. + * @param x KeyStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const KeyStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_short + * @param _my_short New value for member my_short + */ + eProsima_user_DllExport void my_short( + int16_t _my_short) + { + m_my_short = _my_short; + } + + /*! + * @brief This function returns the value of member my_short + * @return Value of member my_short + */ + eProsima_user_DllExport int16_t my_short() const + { + return m_my_short; + } + + /*! + * @brief This function returns a reference to member my_short + * @return Reference to member my_short + */ + eProsima_user_DllExport int16_t& my_short() + { + return m_my_short; + } + + + /*! + * @brief This function sets a value in member my_long + * @param _my_long New value for member my_long + */ + eProsima_user_DllExport void my_long( + int32_t _my_long) + { + m_my_long = _my_long; + } + + /*! + * @brief This function returns the value of member my_long + * @return Value of member my_long + */ + eProsima_user_DllExport int32_t my_long() const + { + return m_my_long; + } + + /*! + * @brief This function returns a reference to member my_long + * @return Reference to member my_long + */ + eProsima_user_DllExport int32_t& my_long() + { + return m_my_long; + } + + + /*! + * @brief This function copies the value in member my_string + * @param _my_string New value to be copied in member my_string + */ + eProsima_user_DllExport void my_string( + const std::string& _my_string) + { + m_my_string = _my_string; + } + + /*! + * @brief This function moves the value in member my_string + * @param _my_string New value to be moved in member my_string + */ + eProsima_user_DllExport void my_string( + std::string&& _my_string) + { + m_my_string = std::move(_my_string); + } + + /*! + * @brief This function returns a constant reference to member my_string + * @return Constant reference to member my_string + */ + eProsima_user_DllExport const std::string& my_string() const + { + return m_my_string; + } + + /*! + * @brief This function returns a reference to member my_string + * @return Reference to member my_string + */ + eProsima_user_DllExport std::string& my_string() + { + return m_my_string; + } + + + /*! + * @brief This function copies the value in member my_important_struct + * @param _my_important_struct New value to be copied in member my_important_struct + */ + eProsima_user_DllExport void my_important_struct( + const ImportantStruct& _my_important_struct) + { + m_my_important_struct = _my_important_struct; + } + + /*! + * @brief This function moves the value in member my_important_struct + * @param _my_important_struct New value to be moved in member my_important_struct + */ + eProsima_user_DllExport void my_important_struct( + ImportantStruct&& _my_important_struct) + { + m_my_important_struct = std::move(_my_important_struct); + } + + /*! + * @brief This function returns a constant reference to member my_important_struct + * @return Constant reference to member my_important_struct + */ + eProsima_user_DllExport const ImportantStruct& my_important_struct() const + { + return m_my_important_struct; + } + + /*! + * @brief This function returns a reference to member my_important_struct + * @return Reference to member my_important_struct + */ + eProsima_user_DllExport ImportantStruct& my_important_struct() + { + return m_my_important_struct; + } + + + +private: + + int16_t m_my_short{0}; + int32_t m_my_long{0}; + std::string m_my_string; + ImportantStruct m_my_important_struct; + +}; + +#endif // _FAST_DDS_GENERATED_KEY_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structCdrAux.hpp new file mode 100644 index 00000000000..47a05f2d065 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structCdrAux.hpp @@ -0,0 +1,53 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file key_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__KEY_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__KEY_STRUCTCDRAUX_HPP + +#include "key_struct.hpp" + +constexpr uint32_t ImportantStruct_max_cdr_typesize {16UL}; +constexpr uint32_t ImportantStruct_max_key_cdr_typesize {8UL}; + +constexpr uint32_t KeyStruct_max_cdr_typesize {288UL}; +constexpr uint32_t KeyStruct_max_key_cdr_typesize {272UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ImportantStruct& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const KeyStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__KEY_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structCdrAux.ipp new file mode 100644 index 00000000000..d10cdaa4911 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structCdrAux.ipp @@ -0,0 +1,245 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file key_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__KEY_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__KEY_STRUCTCDRAUX_IPP + +#include "key_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const ImportantStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_first_value(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_second_value(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_third_value(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const ImportantStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_first_value() + << eprosima::fastcdr::MemberId(1) << data.my_second_value() + << eprosima::fastcdr::MemberId(2) << data.my_third_value() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + ImportantStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_first_value(); + break; + + case 1: + dcdr >> data.my_second_value(); + break; + + case 2: + dcdr >> data.my_third_value(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ImportantStruct& data) +{ + static_cast(scdr); + static_cast(data); + scdr << data.my_first_value(); + + + scdr << data.my_third_value(); + +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const KeyStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_short(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_long(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_string(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3), + data.my_important_struct(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const KeyStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_short() + << eprosima::fastcdr::MemberId(1) << data.my_long() + << eprosima::fastcdr::MemberId(2) << data.my_string() + << eprosima::fastcdr::MemberId(3) << data.my_important_struct() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + KeyStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_short(); + break; + + case 1: + dcdr >> data.my_long(); + break; + + case 2: + dcdr >> data.my_string(); + break; + + case 3: + dcdr >> data.my_important_struct(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const KeyStruct& data) +{ + static_cast(scdr); + static_cast(data); + scdr << data.my_long(); + + scdr << data.my_string(); + + serialize_key(scdr, data.my_important_struct()); + +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__KEY_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.cxx new file mode 100644 index 00000000000..4a48941b222 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.cxx @@ -0,0 +1,422 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file key_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "key_structPubSubTypes.hpp" + +#include +#include + +#include "key_structCdrAux.hpp" +#include "key_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +ImportantStructPubSubType::ImportantStructPubSubType() +{ + setName("ImportantStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(ImportantStruct::getMaxCdrSerializedSize()); +#else + ImportantStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = true; + uint32_t keyLength = ImportantStruct_max_key_cdr_typesize > 16 ? ImportantStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +ImportantStructPubSubType::~ImportantStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool ImportantStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const ImportantStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool ImportantStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + ImportantStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function ImportantStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* ImportantStructPubSubType::createData() +{ + return reinterpret_cast(new ImportantStruct()); +} + +void ImportantStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool ImportantStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const ImportantStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + ImportantStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || ImportantStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void ImportantStructPubSubType::register_type_object_representation() +{ + register_ImportantStruct_type_identifier(type_identifiers_); +} + +KeyStructPubSubType::KeyStructPubSubType() +{ + setName("KeyStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(KeyStruct::getMaxCdrSerializedSize()); +#else + KeyStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = true; + uint32_t keyLength = KeyStruct_max_key_cdr_typesize > 16 ? KeyStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +KeyStructPubSubType::~KeyStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool KeyStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const KeyStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool KeyStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + KeyStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function KeyStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* KeyStructPubSubType::createData() +{ + return reinterpret_cast(new KeyStruct()); +} + +void KeyStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool KeyStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const KeyStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + KeyStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || KeyStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void KeyStructPubSubType::register_type_object_representation() +{ + register_KeyStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "key_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.hpp new file mode 100644 index 00000000000..bb3d4678554 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structPubSubTypes.hpp @@ -0,0 +1,224 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file key_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__KEY_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__KEY_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "key_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated key_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type ImportantStruct defined by the user in the IDL file. + * @ingroup key_struct + */ +class ImportantStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef ImportantStruct type; + + eProsima_user_DllExport ImportantStructPubSubType(); + + eProsima_user_DllExport ~ImportantStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +/*! + * @brief This class represents the TopicDataType of the type KeyStruct defined by the user in the IDL file. + * @ingroup key_struct + */ +class KeyStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef KeyStruct type; + + eProsima_user_DllExport KeyStructPubSubType(); + + eProsima_user_DllExport ~KeyStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__KEY_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..8b72a3d175c --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structTypeObjectSupport.cxx @@ -0,0 +1,380 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file key_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "key_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "key_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_ImportantStruct_type_identifier( + TypeIdentifierPair& type_ids_ImportantStruct) +{ + + ReturnCode_t return_code_ImportantStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_ImportantStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ImportantStruct", type_ids_ImportantStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ImportantStruct) + { + StructTypeFlag struct_flags_ImportantStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_ImportantStruct = "ImportantStruct"; + eprosima::fastcdr::optional type_ann_builtin_ImportantStruct; + eprosima::fastcdr::optional ann_custom_ImportantStruct; + CompleteTypeDetail detail_ImportantStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ImportantStruct, ann_custom_ImportantStruct, type_name_ImportantStruct.to_string()); + CompleteStructHeader header_ImportantStruct; + header_ImportantStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_ImportantStruct); + CompleteStructMemberSeq member_seq_ImportantStruct; + { + TypeIdentifierPair type_ids_my_first_value; + ReturnCode_t return_code_my_first_value {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_first_value = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_my_first_value); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_first_value) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_first_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_first_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, true, false); + MemberId member_id_my_first_value = 0x00000000; + bool common_my_first_value_ec {false}; + CommonStructMember common_my_first_value {TypeObjectUtils::build_common_struct_member(member_id_my_first_value, member_flags_my_first_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_first_value, common_my_first_value_ec))}; + if (!common_my_first_value_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_first_value member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_first_value = "my_first_value"; + eprosima::fastcdr::optional member_ann_builtin_my_first_value; + ann_custom_ImportantStruct.reset(); + AppliedAnnotationSeq tmp_ann_custom_my_first_value; + eprosima::fastcdr::optional unit_my_first_value; + eprosima::fastcdr::optional min_my_first_value; + eprosima::fastcdr::optional max_my_first_value; + eprosima::fastcdr::optional hash_id_my_first_value; + if (unit_my_first_value.has_value() || min_my_first_value.has_value() || max_my_first_value.has_value() || hash_id_my_first_value.has_value()) + { + member_ann_builtin_my_first_value = TypeObjectUtils::build_applied_builtin_member_annotations(unit_my_first_value, min_my_first_value, max_my_first_value, hash_id_my_first_value); + } + if (!tmp_ann_custom_my_first_value.empty()) + { + ann_custom_ImportantStruct = tmp_ann_custom_my_first_value; + } + CompleteMemberDetail detail_my_first_value = TypeObjectUtils::build_complete_member_detail(name_my_first_value, member_ann_builtin_my_first_value, ann_custom_ImportantStruct); + CompleteStructMember member_my_first_value = TypeObjectUtils::build_complete_struct_member(common_my_first_value, detail_my_first_value); + TypeObjectUtils::add_complete_struct_member(member_seq_ImportantStruct, member_my_first_value); + } + { + TypeIdentifierPair type_ids_my_second_value; + ReturnCode_t return_code_my_second_value {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_second_value = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_my_second_value); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_second_value) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_second_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_second_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_second_value = 0x00000001; + bool common_my_second_value_ec {false}; + CommonStructMember common_my_second_value {TypeObjectUtils::build_common_struct_member(member_id_my_second_value, member_flags_my_second_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_second_value, common_my_second_value_ec))}; + if (!common_my_second_value_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_second_value member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_second_value = "my_second_value"; + eprosima::fastcdr::optional member_ann_builtin_my_second_value; + ann_custom_ImportantStruct.reset(); + CompleteMemberDetail detail_my_second_value = TypeObjectUtils::build_complete_member_detail(name_my_second_value, member_ann_builtin_my_second_value, ann_custom_ImportantStruct); + CompleteStructMember member_my_second_value = TypeObjectUtils::build_complete_struct_member(common_my_second_value, detail_my_second_value); + TypeObjectUtils::add_complete_struct_member(member_seq_ImportantStruct, member_my_second_value); + } + { + TypeIdentifierPair type_ids_my_third_value; + ReturnCode_t return_code_my_third_value {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_third_value = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_my_third_value); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_third_value) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_third_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_third_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, true, false); + MemberId member_id_my_third_value = 0x00000002; + bool common_my_third_value_ec {false}; + CommonStructMember common_my_third_value {TypeObjectUtils::build_common_struct_member(member_id_my_third_value, member_flags_my_third_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_third_value, common_my_third_value_ec))}; + if (!common_my_third_value_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_third_value member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_third_value = "my_third_value"; + eprosima::fastcdr::optional member_ann_builtin_my_third_value; + ann_custom_ImportantStruct.reset(); + AppliedAnnotationSeq tmp_ann_custom_my_third_value; + eprosima::fastcdr::optional unit_my_third_value; + eprosima::fastcdr::optional min_my_third_value; + eprosima::fastcdr::optional max_my_third_value; + eprosima::fastcdr::optional hash_id_my_third_value; + if (unit_my_third_value.has_value() || min_my_third_value.has_value() || max_my_third_value.has_value() || hash_id_my_third_value.has_value()) + { + member_ann_builtin_my_third_value = TypeObjectUtils::build_applied_builtin_member_annotations(unit_my_third_value, min_my_third_value, max_my_third_value, hash_id_my_third_value); + } + if (!tmp_ann_custom_my_third_value.empty()) + { + ann_custom_ImportantStruct = tmp_ann_custom_my_third_value; + } + CompleteMemberDetail detail_my_third_value = TypeObjectUtils::build_complete_member_detail(name_my_third_value, member_ann_builtin_my_third_value, ann_custom_ImportantStruct); + CompleteStructMember member_my_third_value = TypeObjectUtils::build_complete_struct_member(common_my_third_value, detail_my_third_value); + TypeObjectUtils::add_complete_struct_member(member_seq_ImportantStruct, member_my_third_value); + } + CompleteStructType struct_type_ImportantStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_ImportantStruct, header_ImportantStruct, member_seq_ImportantStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_ImportantStruct, type_name_ImportantStruct.to_string(), type_ids_ImportantStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ImportantStruct already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_KeyStruct_type_identifier( + TypeIdentifierPair& type_ids_KeyStruct) +{ + + ReturnCode_t return_code_KeyStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_KeyStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "KeyStruct", type_ids_KeyStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_KeyStruct) + { + StructTypeFlag struct_flags_KeyStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_KeyStruct = "KeyStruct"; + eprosima::fastcdr::optional type_ann_builtin_KeyStruct; + eprosima::fastcdr::optional ann_custom_KeyStruct; + CompleteTypeDetail detail_KeyStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_KeyStruct, ann_custom_KeyStruct, type_name_KeyStruct.to_string()); + CompleteStructHeader header_KeyStruct; + header_KeyStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_KeyStruct); + CompleteStructMemberSeq member_seq_KeyStruct; + { + TypeIdentifierPair type_ids_my_short; + ReturnCode_t return_code_my_short {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_short = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int16_t", type_ids_my_short); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_short) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_short Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_short = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_short = 0x00000000; + bool common_my_short_ec {false}; + CommonStructMember common_my_short {TypeObjectUtils::build_common_struct_member(member_id_my_short, member_flags_my_short, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_short, common_my_short_ec))}; + if (!common_my_short_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_short member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_short = "my_short"; + eprosima::fastcdr::optional member_ann_builtin_my_short; + ann_custom_KeyStruct.reset(); + CompleteMemberDetail detail_my_short = TypeObjectUtils::build_complete_member_detail(name_my_short, member_ann_builtin_my_short, ann_custom_KeyStruct); + CompleteStructMember member_my_short = TypeObjectUtils::build_complete_struct_member(common_my_short, detail_my_short); + TypeObjectUtils::add_complete_struct_member(member_seq_KeyStruct, member_my_short); + } + { + TypeIdentifierPair type_ids_my_long; + ReturnCode_t return_code_my_long {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_long = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_my_long); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_long) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_long Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_long = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, true, false); + MemberId member_id_my_long = 0x00000001; + bool common_my_long_ec {false}; + CommonStructMember common_my_long {TypeObjectUtils::build_common_struct_member(member_id_my_long, member_flags_my_long, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_long, common_my_long_ec))}; + if (!common_my_long_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_long member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_long = "my_long"; + eprosima::fastcdr::optional member_ann_builtin_my_long; + ann_custom_KeyStruct.reset(); + AppliedAnnotationSeq tmp_ann_custom_my_long; + eprosima::fastcdr::optional unit_my_long; + eprosima::fastcdr::optional min_my_long; + eprosima::fastcdr::optional max_my_long; + eprosima::fastcdr::optional hash_id_my_long; + if (unit_my_long.has_value() || min_my_long.has_value() || max_my_long.has_value() || hash_id_my_long.has_value()) + { + member_ann_builtin_my_long = TypeObjectUtils::build_applied_builtin_member_annotations(unit_my_long, min_my_long, max_my_long, hash_id_my_long); + } + if (!tmp_ann_custom_my_long.empty()) + { + ann_custom_KeyStruct = tmp_ann_custom_my_long; + } + CompleteMemberDetail detail_my_long = TypeObjectUtils::build_complete_member_detail(name_my_long, member_ann_builtin_my_long, ann_custom_KeyStruct); + CompleteStructMember member_my_long = TypeObjectUtils::build_complete_struct_member(common_my_long, detail_my_long); + TypeObjectUtils::add_complete_struct_member(member_seq_KeyStruct, member_my_long); + } + { + TypeIdentifierPair type_ids_my_string; + ReturnCode_t return_code_my_string {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_string = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_my_string); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_string) + { + { + SBound bound = 0; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "anonymous_string_unbounded", type_ids_my_string)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_string = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, true, false); + MemberId member_id_my_string = 0x00000002; + bool common_my_string_ec {false}; + CommonStructMember common_my_string {TypeObjectUtils::build_common_struct_member(member_id_my_string, member_flags_my_string, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_string, common_my_string_ec))}; + if (!common_my_string_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_string member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_string = "my_string"; + eprosima::fastcdr::optional member_ann_builtin_my_string; + ann_custom_KeyStruct.reset(); + AppliedAnnotationSeq tmp_ann_custom_my_string; + eprosima::fastcdr::optional unit_my_string; + eprosima::fastcdr::optional min_my_string; + eprosima::fastcdr::optional max_my_string; + eprosima::fastcdr::optional hash_id_my_string; + if (unit_my_string.has_value() || min_my_string.has_value() || max_my_string.has_value() || hash_id_my_string.has_value()) + { + member_ann_builtin_my_string = TypeObjectUtils::build_applied_builtin_member_annotations(unit_my_string, min_my_string, max_my_string, hash_id_my_string); + } + if (!tmp_ann_custom_my_string.empty()) + { + ann_custom_KeyStruct = tmp_ann_custom_my_string; + } + CompleteMemberDetail detail_my_string = TypeObjectUtils::build_complete_member_detail(name_my_string, member_ann_builtin_my_string, ann_custom_KeyStruct); + CompleteStructMember member_my_string = TypeObjectUtils::build_complete_struct_member(common_my_string, detail_my_string); + TypeObjectUtils::add_complete_struct_member(member_seq_KeyStruct, member_my_string); + } + { + TypeIdentifierPair type_ids_my_important_struct; + ReturnCode_t return_code_my_important_struct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_important_struct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ImportantStruct", type_ids_my_important_struct); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_important_struct) + { + ::register_ImportantStruct_type_identifier(type_ids_my_important_struct); + } + StructMemberFlag member_flags_my_important_struct = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, true, false); + MemberId member_id_my_important_struct = 0x00000003; + bool common_my_important_struct_ec {false}; + CommonStructMember common_my_important_struct {TypeObjectUtils::build_common_struct_member(member_id_my_important_struct, member_flags_my_important_struct, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_important_struct, common_my_important_struct_ec))}; + if (!common_my_important_struct_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_important_struct member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_important_struct = "my_important_struct"; + eprosima::fastcdr::optional member_ann_builtin_my_important_struct; + ann_custom_KeyStruct.reset(); + AppliedAnnotationSeq tmp_ann_custom_my_important_struct; + eprosima::fastcdr::optional unit_my_important_struct; + eprosima::fastcdr::optional min_my_important_struct; + eprosima::fastcdr::optional max_my_important_struct; + eprosima::fastcdr::optional hash_id_my_important_struct; + if (unit_my_important_struct.has_value() || min_my_important_struct.has_value() || max_my_important_struct.has_value() || hash_id_my_important_struct.has_value()) + { + member_ann_builtin_my_important_struct = TypeObjectUtils::build_applied_builtin_member_annotations(unit_my_important_struct, min_my_important_struct, max_my_important_struct, hash_id_my_important_struct); + } + if (!tmp_ann_custom_my_important_struct.empty()) + { + ann_custom_KeyStruct = tmp_ann_custom_my_important_struct; + } + CompleteMemberDetail detail_my_important_struct = TypeObjectUtils::build_complete_member_detail(name_my_important_struct, member_ann_builtin_my_important_struct, ann_custom_KeyStruct); + CompleteStructMember member_my_important_struct = TypeObjectUtils::build_complete_struct_member(common_my_important_struct, detail_my_important_struct); + TypeObjectUtils::add_complete_struct_member(member_seq_KeyStruct, member_my_important_struct); + } + CompleteStructType struct_type_KeyStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_KeyStruct, header_KeyStruct, member_seq_KeyStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_KeyStruct, type_name_KeyStruct.to_string(), type_ids_KeyStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "KeyStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..4c201bb072c --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/gen/key_structTypeObjectSupport.hpp @@ -0,0 +1,68 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file key_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__KEY_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__KEY_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register ImportantStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_ImportantStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register KeyStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_KeyStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__KEY_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/key_struct/key_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/key_struct.idl new file mode 100644 index 00000000000..b2ce10062f4 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/key_struct/key_struct.idl @@ -0,0 +1,14 @@ +struct ImportantStruct +{ + @key long my_first_value; + long my_second_value; + @key long my_third_value; +}; + +struct KeyStruct +{ + short my_short; + @key long my_long; + @key string my_string; + @key ImportantStruct my_important_struct; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_struct.hpp new file mode 100644 index 00000000000..7481625166a --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_struct.hpp @@ -0,0 +1,455 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file map_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__MAP_STRUCT_HPP +#define FAST_DDS_GENERATED__MAP_STRUCT_HPP + +#include +#include +#include +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(MAP_STRUCT_SOURCE) +#define MAP_STRUCT_DllAPI __declspec( dllexport ) +#else +#define MAP_STRUCT_DllAPI __declspec( dllimport ) +#endif // MAP_STRUCT_SOURCE +#else +#define MAP_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define MAP_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure ValueStruct defined by the user in the IDL file. + * @ingroup map_struct + */ +class ValueStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport ValueStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~ValueStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object ValueStruct that will be copied. + */ + eProsima_user_DllExport ValueStruct( + const ValueStruct& x) + { + m_value = x.m_value; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object ValueStruct that will be copied. + */ + eProsima_user_DllExport ValueStruct( + ValueStruct&& x) noexcept + { + m_value = x.m_value; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object ValueStruct that will be copied. + */ + eProsima_user_DllExport ValueStruct& operator =( + const ValueStruct& x) + { + + m_value = x.m_value; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object ValueStruct that will be copied. + */ + eProsima_user_DllExport ValueStruct& operator =( + ValueStruct&& x) noexcept + { + + m_value = x.m_value; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x ValueStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const ValueStruct& x) const + { + return (m_value == x.m_value); + } + + /*! + * @brief Comparison operator. + * @param x ValueStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const ValueStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member value + * @param _value New value for member value + */ + eProsima_user_DllExport void value( + bool _value) + { + m_value = _value; + } + + /*! + * @brief This function returns the value of member value + * @return Value of member value + */ + eProsima_user_DllExport bool value() const + { + return m_value; + } + + /*! + * @brief This function returns a reference to member value + * @return Reference to member value + */ + eProsima_user_DllExport bool& value() + { + return m_value; + } + + + +private: + + bool m_value{false}; + +}; +/*! + * @brief This class represents the structure MapStruct defined by the user in the IDL file. + * @ingroup map_struct + */ +class MapStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport MapStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~MapStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object MapStruct that will be copied. + */ + eProsima_user_DllExport MapStruct( + const MapStruct& x) + { + m_my_basic_map = x.m_my_basic_map; + + m_my_complex_map = x.m_my_complex_map; + + m_my_basic_bounded_map = x.m_my_basic_bounded_map; + + m_my_complex_bounded_map = x.m_my_complex_bounded_map; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object MapStruct that will be copied. + */ + eProsima_user_DllExport MapStruct( + MapStruct&& x) noexcept + { + m_my_basic_map = std::move(x.m_my_basic_map); + m_my_complex_map = std::move(x.m_my_complex_map); + m_my_basic_bounded_map = std::move(x.m_my_basic_bounded_map); + m_my_complex_bounded_map = std::move(x.m_my_complex_bounded_map); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object MapStruct that will be copied. + */ + eProsima_user_DllExport MapStruct& operator =( + const MapStruct& x) + { + + m_my_basic_map = x.m_my_basic_map; + + m_my_complex_map = x.m_my_complex_map; + + m_my_basic_bounded_map = x.m_my_basic_bounded_map; + + m_my_complex_bounded_map = x.m_my_complex_bounded_map; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object MapStruct that will be copied. + */ + eProsima_user_DllExport MapStruct& operator =( + MapStruct&& x) noexcept + { + + m_my_basic_map = std::move(x.m_my_basic_map); + m_my_complex_map = std::move(x.m_my_complex_map); + m_my_basic_bounded_map = std::move(x.m_my_basic_bounded_map); + m_my_complex_bounded_map = std::move(x.m_my_complex_bounded_map); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x MapStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const MapStruct& x) const + { + return (m_my_basic_map == x.m_my_basic_map && + m_my_complex_map == x.m_my_complex_map && + m_my_basic_bounded_map == x.m_my_basic_bounded_map && + m_my_complex_bounded_map == x.m_my_complex_bounded_map); + } + + /*! + * @brief Comparison operator. + * @param x MapStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const MapStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member my_basic_map + * @param _my_basic_map New value to be copied in member my_basic_map + */ + eProsima_user_DllExport void my_basic_map( + const std::map& _my_basic_map) + { + m_my_basic_map = _my_basic_map; + } + + /*! + * @brief This function moves the value in member my_basic_map + * @param _my_basic_map New value to be moved in member my_basic_map + */ + eProsima_user_DllExport void my_basic_map( + std::map&& _my_basic_map) + { + m_my_basic_map = std::move(_my_basic_map); + } + + /*! + * @brief This function returns a constant reference to member my_basic_map + * @return Constant reference to member my_basic_map + */ + eProsima_user_DllExport const std::map& my_basic_map() const + { + return m_my_basic_map; + } + + /*! + * @brief This function returns a reference to member my_basic_map + * @return Reference to member my_basic_map + */ + eProsima_user_DllExport std::map& my_basic_map() + { + return m_my_basic_map; + } + + + /*! + * @brief This function copies the value in member my_complex_map + * @param _my_complex_map New value to be copied in member my_complex_map + */ + eProsima_user_DllExport void my_complex_map( + const std::map& _my_complex_map) + { + m_my_complex_map = _my_complex_map; + } + + /*! + * @brief This function moves the value in member my_complex_map + * @param _my_complex_map New value to be moved in member my_complex_map + */ + eProsima_user_DllExport void my_complex_map( + std::map&& _my_complex_map) + { + m_my_complex_map = std::move(_my_complex_map); + } + + /*! + * @brief This function returns a constant reference to member my_complex_map + * @return Constant reference to member my_complex_map + */ + eProsima_user_DllExport const std::map& my_complex_map() const + { + return m_my_complex_map; + } + + /*! + * @brief This function returns a reference to member my_complex_map + * @return Reference to member my_complex_map + */ + eProsima_user_DllExport std::map& my_complex_map() + { + return m_my_complex_map; + } + + + /*! + * @brief This function copies the value in member my_basic_bounded_map + * @param _my_basic_bounded_map New value to be copied in member my_basic_bounded_map + */ + eProsima_user_DllExport void my_basic_bounded_map( + const std::map& _my_basic_bounded_map) + { + m_my_basic_bounded_map = _my_basic_bounded_map; + } + + /*! + * @brief This function moves the value in member my_basic_bounded_map + * @param _my_basic_bounded_map New value to be moved in member my_basic_bounded_map + */ + eProsima_user_DllExport void my_basic_bounded_map( + std::map&& _my_basic_bounded_map) + { + m_my_basic_bounded_map = std::move(_my_basic_bounded_map); + } + + /*! + * @brief This function returns a constant reference to member my_basic_bounded_map + * @return Constant reference to member my_basic_bounded_map + */ + eProsima_user_DllExport const std::map& my_basic_bounded_map() const + { + return m_my_basic_bounded_map; + } + + /*! + * @brief This function returns a reference to member my_basic_bounded_map + * @return Reference to member my_basic_bounded_map + */ + eProsima_user_DllExport std::map& my_basic_bounded_map() + { + return m_my_basic_bounded_map; + } + + + /*! + * @brief This function copies the value in member my_complex_bounded_map + * @param _my_complex_bounded_map New value to be copied in member my_complex_bounded_map + */ + eProsima_user_DllExport void my_complex_bounded_map( + const std::map& _my_complex_bounded_map) + { + m_my_complex_bounded_map = _my_complex_bounded_map; + } + + /*! + * @brief This function moves the value in member my_complex_bounded_map + * @param _my_complex_bounded_map New value to be moved in member my_complex_bounded_map + */ + eProsima_user_DllExport void my_complex_bounded_map( + std::map&& _my_complex_bounded_map) + { + m_my_complex_bounded_map = std::move(_my_complex_bounded_map); + } + + /*! + * @brief This function returns a constant reference to member my_complex_bounded_map + * @return Constant reference to member my_complex_bounded_map + */ + eProsima_user_DllExport const std::map& my_complex_bounded_map() const + { + return m_my_complex_bounded_map; + } + + /*! + * @brief This function returns a reference to member my_complex_bounded_map + * @return Reference to member my_complex_bounded_map + */ + eProsima_user_DllExport std::map& my_complex_bounded_map() + { + return m_my_complex_bounded_map; + } + + + +private: + + std::map m_my_basic_map; + std::map m_my_complex_map; + std::map m_my_basic_bounded_map; + std::map m_my_complex_bounded_map; + +}; + +#endif // _FAST_DDS_GENERATED_MAP_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structCdrAux.hpp new file mode 100644 index 00000000000..4a3c9711ef9 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structCdrAux.hpp @@ -0,0 +1,53 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file map_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__MAP_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__MAP_STRUCTCDRAUX_HPP + +#include "map_struct.hpp" + +constexpr uint32_t ValueStruct_max_cdr_typesize {5UL}; +constexpr uint32_t ValueStruct_max_key_cdr_typesize {0UL}; + +constexpr uint32_t MapStruct_max_cdr_typesize {3657UL}; +constexpr uint32_t MapStruct_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ValueStruct& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const MapStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__MAP_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structCdrAux.ipp new file mode 100644 index 00000000000..3ae14997cf2 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structCdrAux.ipp @@ -0,0 +1,218 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file map_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__MAP_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__MAP_STRUCTCDRAUX_IPP + +#include "map_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const ValueStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.value(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const ValueStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.value() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + ValueStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.value(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ValueStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const MapStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_basic_map(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_complex_map(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_basic_bounded_map(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3), + data.my_complex_bounded_map(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const MapStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_basic_map() + << eprosima::fastcdr::MemberId(1) << data.my_complex_map() + << eprosima::fastcdr::MemberId(2) << data.my_basic_bounded_map() + << eprosima::fastcdr::MemberId(3) << data.my_complex_bounded_map() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + MapStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_basic_map(); + break; + + case 1: + dcdr >> data.my_complex_map(); + break; + + case 2: + dcdr >> data.my_basic_bounded_map(); + break; + + case 3: + dcdr >> data.my_complex_bounded_map(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const MapStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__MAP_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.cxx new file mode 100644 index 00000000000..8c30463bdcc --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.cxx @@ -0,0 +1,422 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file map_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "map_structPubSubTypes.hpp" + +#include +#include + +#include "map_structCdrAux.hpp" +#include "map_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +ValueStructPubSubType::ValueStructPubSubType() +{ + setName("ValueStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(ValueStruct::getMaxCdrSerializedSize()); +#else + ValueStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = ValueStruct_max_key_cdr_typesize > 16 ? ValueStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +ValueStructPubSubType::~ValueStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool ValueStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const ValueStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool ValueStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + ValueStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function ValueStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* ValueStructPubSubType::createData() +{ + return reinterpret_cast(new ValueStruct()); +} + +void ValueStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool ValueStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const ValueStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + ValueStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || ValueStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void ValueStructPubSubType::register_type_object_representation() +{ + register_ValueStruct_type_identifier(type_identifiers_); +} + +MapStructPubSubType::MapStructPubSubType() +{ + setName("MapStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(MapStruct::getMaxCdrSerializedSize()); +#else + MapStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = MapStruct_max_key_cdr_typesize > 16 ? MapStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +MapStructPubSubType::~MapStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool MapStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const MapStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool MapStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + MapStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function MapStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* MapStructPubSubType::createData() +{ + return reinterpret_cast(new MapStruct()); +} + +void MapStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool MapStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const MapStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + MapStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || MapStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void MapStructPubSubType::register_type_object_representation() +{ + register_MapStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "map_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.hpp new file mode 100644 index 00000000000..6cffc72f9e0 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structPubSubTypes.hpp @@ -0,0 +1,224 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file map_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__MAP_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__MAP_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "map_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated map_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type ValueStruct defined by the user in the IDL file. + * @ingroup map_struct + */ +class ValueStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef ValueStruct type; + + eProsima_user_DllExport ValueStructPubSubType(); + + eProsima_user_DllExport ~ValueStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +/*! + * @brief This class represents the TopicDataType of the type MapStruct defined by the user in the IDL file. + * @ingroup map_struct + */ +class MapStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef MapStruct type; + + eProsima_user_DllExport MapStructPubSubType(); + + eProsima_user_DllExport ~MapStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__MAP_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..eb7eab79b7c --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structTypeObjectSupport.cxx @@ -0,0 +1,505 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file map_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "map_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "map_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_ValueStruct_type_identifier( + TypeIdentifierPair& type_ids_ValueStruct) +{ + + ReturnCode_t return_code_ValueStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_ValueStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ValueStruct", type_ids_ValueStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ValueStruct) + { + StructTypeFlag struct_flags_ValueStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_ValueStruct = "ValueStruct"; + eprosima::fastcdr::optional type_ann_builtin_ValueStruct; + eprosima::fastcdr::optional ann_custom_ValueStruct; + CompleteTypeDetail detail_ValueStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ValueStruct, ann_custom_ValueStruct, type_name_ValueStruct.to_string()); + CompleteStructHeader header_ValueStruct; + header_ValueStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_ValueStruct); + CompleteStructMemberSeq member_seq_ValueStruct; + { + TypeIdentifierPair type_ids_value; + ReturnCode_t return_code_value {eprosima::fastdds::dds::RETCODE_OK}; + return_code_value = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_bool", type_ids_value); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_value) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "value Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_value = 0x00000000; + bool common_value_ec {false}; + CommonStructMember common_value {TypeObjectUtils::build_common_struct_member(member_id_value, member_flags_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_value, common_value_ec))}; + if (!common_value_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure value member TypeIdentifier inconsistent."); + return; + } + MemberName name_value = "value"; + eprosima::fastcdr::optional member_ann_builtin_value; + ann_custom_ValueStruct.reset(); + CompleteMemberDetail detail_value = TypeObjectUtils::build_complete_member_detail(name_value, member_ann_builtin_value, ann_custom_ValueStruct); + CompleteStructMember member_value = TypeObjectUtils::build_complete_struct_member(common_value, detail_value); + TypeObjectUtils::add_complete_struct_member(member_seq_ValueStruct, member_value); + } + CompleteStructType struct_type_ValueStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_ValueStruct, header_ValueStruct, member_seq_ValueStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_ValueStruct, type_name_ValueStruct.to_string(), type_ids_ValueStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ValueStruct already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_MapStruct_type_identifier( + TypeIdentifierPair& type_ids_MapStruct) +{ + + ReturnCode_t return_code_MapStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_MapStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "MapStruct", type_ids_MapStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_MapStruct) + { + StructTypeFlag struct_flags_MapStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_MapStruct = "MapStruct"; + eprosima::fastcdr::optional type_ann_builtin_MapStruct; + eprosima::fastcdr::optional ann_custom_MapStruct; + CompleteTypeDetail detail_MapStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_MapStruct, ann_custom_MapStruct, type_name_MapStruct.to_string()); + CompleteStructHeader header_MapStruct; + header_MapStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_MapStruct); + CompleteStructMemberSeq member_seq_MapStruct; + { + TypeIdentifierPair type_ids_my_basic_map; + ReturnCode_t return_code_my_basic_map {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_basic_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_map_anonymous_string_unbounded_bool_unbounded", type_ids_my_basic_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_basic_map) + { + return_code_my_basic_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_bool", type_ids_my_basic_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_basic_map) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Map element TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded_ec {false}; + TypeIdentifier* element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_basic_map, element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded_ec))}; + if (!element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_anonymous_string_unbounded_bool_unbounded inconsistent element TypeIdentifier."); + return; + } + return_code_my_basic_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_my_basic_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_basic_map) + { + { + SBound bound = 0; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "anonymous_string_unbounded", type_ids_my_basic_map)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + bool key_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded_ec {false}; + TypeIdentifier* key_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_basic_map, key_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded_ec))}; + if (!key_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_anonymous_string_unbounded_bool_unbounded inconsistent key TypeIdentifier."); + return; + } + EquivalenceKind equiv_kind_anonymous_map_anonymous_string_unbounded_bool_unbounded = EK_BOTH; + if ((EK_COMPLETE == key_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->_d()) || + (TI_PLAIN_SEQUENCE_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->seq_sdefn().header().equiv_kind()) || + (TI_PLAIN_SEQUENCE_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->seq_ldefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->array_sdefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->array_ldefn().header().equiv_kind()) || + (TI_PLAIN_MAP_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->map_sdefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->map_sdefn().header().equiv_kind())) || + (TI_PLAIN_MAP_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->map_ldefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded->map_ldefn().header().equiv_kind()))) + { + equiv_kind_anonymous_map_anonymous_string_unbounded_bool_unbounded = EK_COMPLETE; + } + CollectionElementFlag element_flags_anonymous_map_anonymous_string_unbounded_bool_unbounded = 0; + CollectionElementFlag key_flags_anonymous_map_anonymous_string_unbounded_bool_unbounded = 0; + PlainCollectionHeader header_anonymous_map_anonymous_string_unbounded_bool_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_map_anonymous_string_unbounded_bool_unbounded, element_flags_anonymous_map_anonymous_string_unbounded_bool_unbounded); + { + SBound bound = 0; + PlainMapSTypeDefn map_sdefn = TypeObjectUtils::build_plain_map_s_type_defn(header_anonymous_map_anonymous_string_unbounded_bool_unbounded, bound, + eprosima::fastcdr::external(element_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded), key_flags_anonymous_map_anonymous_string_unbounded_bool_unbounded, + eprosima::fastcdr::external(key_identifier_anonymous_map_anonymous_string_unbounded_bool_unbounded)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_map_type_identifier(map_sdefn, "anonymous_map_anonymous_string_unbounded_bool_unbounded", type_ids_my_basic_map)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_anonymous_string_unbounded_bool_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_basic_map = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_basic_map = 0x00000000; + bool common_my_basic_map_ec {false}; + CommonStructMember common_my_basic_map {TypeObjectUtils::build_common_struct_member(member_id_my_basic_map, member_flags_my_basic_map, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_basic_map, common_my_basic_map_ec))}; + if (!common_my_basic_map_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_basic_map member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_basic_map = "my_basic_map"; + eprosima::fastcdr::optional member_ann_builtin_my_basic_map; + ann_custom_MapStruct.reset(); + CompleteMemberDetail detail_my_basic_map = TypeObjectUtils::build_complete_member_detail(name_my_basic_map, member_ann_builtin_my_basic_map, ann_custom_MapStruct); + CompleteStructMember member_my_basic_map = TypeObjectUtils::build_complete_struct_member(common_my_basic_map, detail_my_basic_map); + TypeObjectUtils::add_complete_struct_member(member_seq_MapStruct, member_my_basic_map); + } + { + TypeIdentifierPair type_ids_my_complex_map; + ReturnCode_t return_code_my_complex_map {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_complex_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded", type_ids_my_complex_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_map) + { + return_code_my_complex_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ValueStruct", type_ids_my_complex_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_map) + { + ::register_ValueStruct_type_identifier(type_ids_my_complex_map); + } + bool element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded_ec {false}; + TypeIdentifier* element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_map, element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded_ec))}; + if (!element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded inconsistent element TypeIdentifier."); + return; + } + return_code_my_complex_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_my_complex_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_map) + { + { + SBound bound = 0; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "anonymous_string_unbounded", type_ids_my_complex_map)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + bool key_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded_ec {false}; + TypeIdentifier* key_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_map, key_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded_ec))}; + if (!key_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded inconsistent key TypeIdentifier."); + return; + } + EquivalenceKind equiv_kind_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded = EK_BOTH; + if ((EK_COMPLETE == key_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->_d()) || + (TI_PLAIN_SEQUENCE_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->seq_sdefn().header().equiv_kind()) || + (TI_PLAIN_SEQUENCE_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->seq_ldefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->array_sdefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->array_ldefn().header().equiv_kind()) || + (TI_PLAIN_MAP_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->map_sdefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->map_sdefn().header().equiv_kind())) || + (TI_PLAIN_MAP_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->map_ldefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded->map_ldefn().header().equiv_kind()))) + { + equiv_kind_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded = EK_COMPLETE; + } + CollectionElementFlag element_flags_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded = 0; + CollectionElementFlag key_flags_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded = 0; + PlainCollectionHeader header_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded, element_flags_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded); + { + SBound bound = 0; + PlainMapSTypeDefn map_sdefn = TypeObjectUtils::build_plain_map_s_type_defn(header_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded, bound, + eprosima::fastcdr::external(element_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded), key_flags_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded, + eprosima::fastcdr::external(key_identifier_anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_map_type_identifier(map_sdefn, "anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded", type_ids_my_complex_map)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_anonymous_string_unbounded_ValueStruct_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_complex_map = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_complex_map = 0x00000001; + bool common_my_complex_map_ec {false}; + CommonStructMember common_my_complex_map {TypeObjectUtils::build_common_struct_member(member_id_my_complex_map, member_flags_my_complex_map, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_map, common_my_complex_map_ec))}; + if (!common_my_complex_map_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_complex_map member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_complex_map = "my_complex_map"; + eprosima::fastcdr::optional member_ann_builtin_my_complex_map; + ann_custom_MapStruct.reset(); + CompleteMemberDetail detail_my_complex_map = TypeObjectUtils::build_complete_member_detail(name_my_complex_map, member_ann_builtin_my_complex_map, ann_custom_MapStruct); + CompleteStructMember member_my_complex_map = TypeObjectUtils::build_complete_struct_member(common_my_complex_map, detail_my_complex_map); + TypeObjectUtils::add_complete_struct_member(member_seq_MapStruct, member_my_complex_map); + } + { + TypeIdentifierPair type_ids_my_basic_bounded_map; + ReturnCode_t return_code_my_basic_bounded_map {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_basic_bounded_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_map_int32_t_anonymous_string_unbounded_10", type_ids_my_basic_bounded_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_basic_bounded_map) + { + return_code_my_basic_bounded_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_my_basic_bounded_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_basic_bounded_map) + { + { + SBound bound = 0; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "anonymous_string_unbounded", type_ids_my_basic_bounded_map)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + bool element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10_ec {false}; + TypeIdentifier* element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_basic_bounded_map, element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10_ec))}; + if (!element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_int32_t_anonymous_string_unbounded_10 inconsistent element TypeIdentifier."); + return; + } + return_code_my_basic_bounded_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_my_basic_bounded_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_basic_bounded_map) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Map key TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool key_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10_ec {false}; + TypeIdentifier* key_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_basic_bounded_map, key_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10_ec))}; + if (!key_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_int32_t_anonymous_string_unbounded_10 inconsistent key TypeIdentifier."); + return; + } + EquivalenceKind equiv_kind_anonymous_map_int32_t_anonymous_string_unbounded_10 = EK_BOTH; + if ((EK_COMPLETE == key_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->_d() || EK_COMPLETE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->_d()) || + (TI_PLAIN_SEQUENCE_SMALL == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->_d() && EK_COMPLETE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->seq_sdefn().header().equiv_kind()) || + (TI_PLAIN_SEQUENCE_LARGE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->_d() && EK_COMPLETE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->seq_ldefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_SMALL == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->_d() && EK_COMPLETE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->array_sdefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_LARGE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->_d() && EK_COMPLETE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->array_ldefn().header().equiv_kind()) || + (TI_PLAIN_MAP_SMALL == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->_d() && (EK_COMPLETE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->map_sdefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->map_sdefn().header().equiv_kind())) || + (TI_PLAIN_MAP_LARGE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->_d() && (EK_COMPLETE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->map_ldefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10->map_ldefn().header().equiv_kind()))) + { + equiv_kind_anonymous_map_int32_t_anonymous_string_unbounded_10 = EK_COMPLETE; + } + CollectionElementFlag element_flags_anonymous_map_int32_t_anonymous_string_unbounded_10 = 0; + CollectionElementFlag key_flags_anonymous_map_int32_t_anonymous_string_unbounded_10 = 0; + PlainCollectionHeader header_anonymous_map_int32_t_anonymous_string_unbounded_10 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_map_int32_t_anonymous_string_unbounded_10, element_flags_anonymous_map_int32_t_anonymous_string_unbounded_10); + { + SBound bound = static_cast(10); + PlainMapSTypeDefn map_sdefn = TypeObjectUtils::build_plain_map_s_type_defn(header_anonymous_map_int32_t_anonymous_string_unbounded_10, bound, + eprosima::fastcdr::external(element_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10), key_flags_anonymous_map_int32_t_anonymous_string_unbounded_10, + eprosima::fastcdr::external(key_identifier_anonymous_map_int32_t_anonymous_string_unbounded_10)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_map_type_identifier(map_sdefn, "anonymous_map_int32_t_anonymous_string_unbounded_10", type_ids_my_basic_bounded_map)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_int32_t_anonymous_string_unbounded_10 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_basic_bounded_map = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_basic_bounded_map = 0x00000002; + bool common_my_basic_bounded_map_ec {false}; + CommonStructMember common_my_basic_bounded_map {TypeObjectUtils::build_common_struct_member(member_id_my_basic_bounded_map, member_flags_my_basic_bounded_map, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_basic_bounded_map, common_my_basic_bounded_map_ec))}; + if (!common_my_basic_bounded_map_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_basic_bounded_map member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_basic_bounded_map = "my_basic_bounded_map"; + eprosima::fastcdr::optional member_ann_builtin_my_basic_bounded_map; + ann_custom_MapStruct.reset(); + CompleteMemberDetail detail_my_basic_bounded_map = TypeObjectUtils::build_complete_member_detail(name_my_basic_bounded_map, member_ann_builtin_my_basic_bounded_map, ann_custom_MapStruct); + CompleteStructMember member_my_basic_bounded_map = TypeObjectUtils::build_complete_struct_member(common_my_basic_bounded_map, detail_my_basic_bounded_map); + TypeObjectUtils::add_complete_struct_member(member_seq_MapStruct, member_my_basic_bounded_map); + } + { + TypeIdentifierPair type_ids_my_complex_bounded_map; + ReturnCode_t return_code_my_complex_bounded_map {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_complex_bounded_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_map_int16_t_ValueStruct_123", type_ids_my_complex_bounded_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_bounded_map) + { + return_code_my_complex_bounded_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ValueStruct", type_ids_my_complex_bounded_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_bounded_map) + { + ::register_ValueStruct_type_identifier(type_ids_my_complex_bounded_map); + } + bool element_identifier_anonymous_map_int16_t_ValueStruct_123_ec {false}; + TypeIdentifier* element_identifier_anonymous_map_int16_t_ValueStruct_123 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_bounded_map, element_identifier_anonymous_map_int16_t_ValueStruct_123_ec))}; + if (!element_identifier_anonymous_map_int16_t_ValueStruct_123_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_int16_t_ValueStruct_123 inconsistent element TypeIdentifier."); + return; + } + return_code_my_complex_bounded_map = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int16_t", type_ids_my_complex_bounded_map); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_bounded_map) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Map key TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool key_identifier_anonymous_map_int16_t_ValueStruct_123_ec {false}; + TypeIdentifier* key_identifier_anonymous_map_int16_t_ValueStruct_123 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_bounded_map, key_identifier_anonymous_map_int16_t_ValueStruct_123_ec))}; + if (!key_identifier_anonymous_map_int16_t_ValueStruct_123_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_int16_t_ValueStruct_123 inconsistent key TypeIdentifier."); + return; + } + EquivalenceKind equiv_kind_anonymous_map_int16_t_ValueStruct_123 = EK_BOTH; + if ((EK_COMPLETE == key_identifier_anonymous_map_int16_t_ValueStruct_123->_d() || EK_COMPLETE == element_identifier_anonymous_map_int16_t_ValueStruct_123->_d()) || + (TI_PLAIN_SEQUENCE_SMALL == element_identifier_anonymous_map_int16_t_ValueStruct_123->_d() && EK_COMPLETE == element_identifier_anonymous_map_int16_t_ValueStruct_123->seq_sdefn().header().equiv_kind()) || + (TI_PLAIN_SEQUENCE_LARGE == element_identifier_anonymous_map_int16_t_ValueStruct_123->_d() && EK_COMPLETE == element_identifier_anonymous_map_int16_t_ValueStruct_123->seq_ldefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_SMALL == element_identifier_anonymous_map_int16_t_ValueStruct_123->_d() && EK_COMPLETE == element_identifier_anonymous_map_int16_t_ValueStruct_123->array_sdefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_LARGE == element_identifier_anonymous_map_int16_t_ValueStruct_123->_d() && EK_COMPLETE == element_identifier_anonymous_map_int16_t_ValueStruct_123->array_ldefn().header().equiv_kind()) || + (TI_PLAIN_MAP_SMALL == element_identifier_anonymous_map_int16_t_ValueStruct_123->_d() && (EK_COMPLETE == element_identifier_anonymous_map_int16_t_ValueStruct_123->map_sdefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_int16_t_ValueStruct_123->map_sdefn().header().equiv_kind())) || + (TI_PLAIN_MAP_LARGE == element_identifier_anonymous_map_int16_t_ValueStruct_123->_d() && (EK_COMPLETE == element_identifier_anonymous_map_int16_t_ValueStruct_123->map_ldefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_int16_t_ValueStruct_123->map_ldefn().header().equiv_kind()))) + { + equiv_kind_anonymous_map_int16_t_ValueStruct_123 = EK_COMPLETE; + } + CollectionElementFlag element_flags_anonymous_map_int16_t_ValueStruct_123 = 0; + CollectionElementFlag key_flags_anonymous_map_int16_t_ValueStruct_123 = 0; + PlainCollectionHeader header_anonymous_map_int16_t_ValueStruct_123 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_map_int16_t_ValueStruct_123, element_flags_anonymous_map_int16_t_ValueStruct_123); + { + SBound bound = static_cast(123); + PlainMapSTypeDefn map_sdefn = TypeObjectUtils::build_plain_map_s_type_defn(header_anonymous_map_int16_t_ValueStruct_123, bound, + eprosima::fastcdr::external(element_identifier_anonymous_map_int16_t_ValueStruct_123), key_flags_anonymous_map_int16_t_ValueStruct_123, + eprosima::fastcdr::external(key_identifier_anonymous_map_int16_t_ValueStruct_123)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_map_type_identifier(map_sdefn, "anonymous_map_int16_t_ValueStruct_123", type_ids_my_complex_bounded_map)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_int16_t_ValueStruct_123 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_complex_bounded_map = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_complex_bounded_map = 0x00000003; + bool common_my_complex_bounded_map_ec {false}; + CommonStructMember common_my_complex_bounded_map {TypeObjectUtils::build_common_struct_member(member_id_my_complex_bounded_map, member_flags_my_complex_bounded_map, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_bounded_map, common_my_complex_bounded_map_ec))}; + if (!common_my_complex_bounded_map_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_complex_bounded_map member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_complex_bounded_map = "my_complex_bounded_map"; + eprosima::fastcdr::optional member_ann_builtin_my_complex_bounded_map; + ann_custom_MapStruct.reset(); + CompleteMemberDetail detail_my_complex_bounded_map = TypeObjectUtils::build_complete_member_detail(name_my_complex_bounded_map, member_ann_builtin_my_complex_bounded_map, ann_custom_MapStruct); + CompleteStructMember member_my_complex_bounded_map = TypeObjectUtils::build_complete_struct_member(common_my_complex_bounded_map, detail_my_complex_bounded_map); + TypeObjectUtils::add_complete_struct_member(member_seq_MapStruct, member_my_complex_bounded_map); + } + CompleteStructType struct_type_MapStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_MapStruct, header_MapStruct, member_seq_MapStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_MapStruct, type_name_MapStruct.to_string(), type_ids_MapStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "MapStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..3cadcab9a55 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/gen/map_structTypeObjectSupport.hpp @@ -0,0 +1,68 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file map_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__MAP_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__MAP_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register ValueStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_ValueStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register MapStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_MapStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__MAP_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/map_struct/map_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/map_struct.idl new file mode 100644 index 00000000000..b0f70f92594 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/map_struct/map_struct.idl @@ -0,0 +1,12 @@ +struct ValueStruct +{ + boolean value; +}; + +struct MapStruct +{ + map my_basic_map; + map my_complex_map; + map my_basic_bounded_map; + map my_complex_bounded_map; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_struct.hpp new file mode 100644 index 00000000000..1b3f51f6b68 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_struct.hpp @@ -0,0 +1,696 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file primitives_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__PRIMITIVES_STRUCT_HPP +#define FAST_DDS_GENERATED__PRIMITIVES_STRUCT_HPP + +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(PRIMITIVES_STRUCT_SOURCE) +#define PRIMITIVES_STRUCT_DllAPI __declspec( dllexport ) +#else +#define PRIMITIVES_STRUCT_DllAPI __declspec( dllimport ) +#endif // PRIMITIVES_STRUCT_SOURCE +#else +#define PRIMITIVES_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define PRIMITIVES_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure PrimitivesStruct defined by the user in the IDL file. + * @ingroup primitives_struct + */ +class PrimitivesStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport PrimitivesStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~PrimitivesStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object PrimitivesStruct that will be copied. + */ + eProsima_user_DllExport PrimitivesStruct( + const PrimitivesStruct& x) + { + m_my_bool = x.m_my_bool; + + m_my_octet = x.m_my_octet; + + m_my_char = x.m_my_char; + + m_my_wchar = x.m_my_wchar; + + m_my_long = x.m_my_long; + + m_my_ulong = x.m_my_ulong; + + m_my_int8 = x.m_my_int8; + + m_my_uint8 = x.m_my_uint8; + + m_my_short = x.m_my_short; + + m_my_ushort = x.m_my_ushort; + + m_my_longlong = x.m_my_longlong; + + m_my_ulonglong = x.m_my_ulonglong; + + m_my_float = x.m_my_float; + + m_my_double = x.m_my_double; + + m_my_longdouble = x.m_my_longdouble; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object PrimitivesStruct that will be copied. + */ + eProsima_user_DllExport PrimitivesStruct( + PrimitivesStruct&& x) noexcept + { + m_my_bool = x.m_my_bool; + m_my_octet = x.m_my_octet; + m_my_char = x.m_my_char; + m_my_wchar = x.m_my_wchar; + m_my_long = x.m_my_long; + m_my_ulong = x.m_my_ulong; + m_my_int8 = x.m_my_int8; + m_my_uint8 = x.m_my_uint8; + m_my_short = x.m_my_short; + m_my_ushort = x.m_my_ushort; + m_my_longlong = x.m_my_longlong; + m_my_ulonglong = x.m_my_ulonglong; + m_my_float = x.m_my_float; + m_my_double = x.m_my_double; + m_my_longdouble = x.m_my_longdouble; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object PrimitivesStruct that will be copied. + */ + eProsima_user_DllExport PrimitivesStruct& operator =( + const PrimitivesStruct& x) + { + + m_my_bool = x.m_my_bool; + + m_my_octet = x.m_my_octet; + + m_my_char = x.m_my_char; + + m_my_wchar = x.m_my_wchar; + + m_my_long = x.m_my_long; + + m_my_ulong = x.m_my_ulong; + + m_my_int8 = x.m_my_int8; + + m_my_uint8 = x.m_my_uint8; + + m_my_short = x.m_my_short; + + m_my_ushort = x.m_my_ushort; + + m_my_longlong = x.m_my_longlong; + + m_my_ulonglong = x.m_my_ulonglong; + + m_my_float = x.m_my_float; + + m_my_double = x.m_my_double; + + m_my_longdouble = x.m_my_longdouble; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object PrimitivesStruct that will be copied. + */ + eProsima_user_DllExport PrimitivesStruct& operator =( + PrimitivesStruct&& x) noexcept + { + + m_my_bool = x.m_my_bool; + m_my_octet = x.m_my_octet; + m_my_char = x.m_my_char; + m_my_wchar = x.m_my_wchar; + m_my_long = x.m_my_long; + m_my_ulong = x.m_my_ulong; + m_my_int8 = x.m_my_int8; + m_my_uint8 = x.m_my_uint8; + m_my_short = x.m_my_short; + m_my_ushort = x.m_my_ushort; + m_my_longlong = x.m_my_longlong; + m_my_ulonglong = x.m_my_ulonglong; + m_my_float = x.m_my_float; + m_my_double = x.m_my_double; + m_my_longdouble = x.m_my_longdouble; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x PrimitivesStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const PrimitivesStruct& x) const + { + return (m_my_bool == x.m_my_bool && + m_my_octet == x.m_my_octet && + m_my_char == x.m_my_char && + m_my_wchar == x.m_my_wchar && + m_my_long == x.m_my_long && + m_my_ulong == x.m_my_ulong && + m_my_int8 == x.m_my_int8 && + m_my_uint8 == x.m_my_uint8 && + m_my_short == x.m_my_short && + m_my_ushort == x.m_my_ushort && + m_my_longlong == x.m_my_longlong && + m_my_ulonglong == x.m_my_ulonglong && + m_my_float == x.m_my_float && + m_my_double == x.m_my_double && + m_my_longdouble == x.m_my_longdouble); + } + + /*! + * @brief Comparison operator. + * @param x PrimitivesStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const PrimitivesStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_bool + * @param _my_bool New value for member my_bool + */ + eProsima_user_DllExport void my_bool( + bool _my_bool) + { + m_my_bool = _my_bool; + } + + /*! + * @brief This function returns the value of member my_bool + * @return Value of member my_bool + */ + eProsima_user_DllExport bool my_bool() const + { + return m_my_bool; + } + + /*! + * @brief This function returns a reference to member my_bool + * @return Reference to member my_bool + */ + eProsima_user_DllExport bool& my_bool() + { + return m_my_bool; + } + + + /*! + * @brief This function sets a value in member my_octet + * @param _my_octet New value for member my_octet + */ + eProsima_user_DllExport void my_octet( + uint8_t _my_octet) + { + m_my_octet = _my_octet; + } + + /*! + * @brief This function returns the value of member my_octet + * @return Value of member my_octet + */ + eProsima_user_DllExport uint8_t my_octet() const + { + return m_my_octet; + } + + /*! + * @brief This function returns a reference to member my_octet + * @return Reference to member my_octet + */ + eProsima_user_DllExport uint8_t& my_octet() + { + return m_my_octet; + } + + + /*! + * @brief This function sets a value in member my_char + * @param _my_char New value for member my_char + */ + eProsima_user_DllExport void my_char( + char _my_char) + { + m_my_char = _my_char; + } + + /*! + * @brief This function returns the value of member my_char + * @return Value of member my_char + */ + eProsima_user_DllExport char my_char() const + { + return m_my_char; + } + + /*! + * @brief This function returns a reference to member my_char + * @return Reference to member my_char + */ + eProsima_user_DllExport char& my_char() + { + return m_my_char; + } + + + /*! + * @brief This function sets a value in member my_wchar + * @param _my_wchar New value for member my_wchar + */ + eProsima_user_DllExport void my_wchar( + wchar_t _my_wchar) + { + m_my_wchar = _my_wchar; + } + + /*! + * @brief This function returns the value of member my_wchar + * @return Value of member my_wchar + */ + eProsima_user_DllExport wchar_t my_wchar() const + { + return m_my_wchar; + } + + /*! + * @brief This function returns a reference to member my_wchar + * @return Reference to member my_wchar + */ + eProsima_user_DllExport wchar_t& my_wchar() + { + return m_my_wchar; + } + + + /*! + * @brief This function sets a value in member my_long + * @param _my_long New value for member my_long + */ + eProsima_user_DllExport void my_long( + int32_t _my_long) + { + m_my_long = _my_long; + } + + /*! + * @brief This function returns the value of member my_long + * @return Value of member my_long + */ + eProsima_user_DllExport int32_t my_long() const + { + return m_my_long; + } + + /*! + * @brief This function returns a reference to member my_long + * @return Reference to member my_long + */ + eProsima_user_DllExport int32_t& my_long() + { + return m_my_long; + } + + + /*! + * @brief This function sets a value in member my_ulong + * @param _my_ulong New value for member my_ulong + */ + eProsima_user_DllExport void my_ulong( + uint32_t _my_ulong) + { + m_my_ulong = _my_ulong; + } + + /*! + * @brief This function returns the value of member my_ulong + * @return Value of member my_ulong + */ + eProsima_user_DllExport uint32_t my_ulong() const + { + return m_my_ulong; + } + + /*! + * @brief This function returns a reference to member my_ulong + * @return Reference to member my_ulong + */ + eProsima_user_DllExport uint32_t& my_ulong() + { + return m_my_ulong; + } + + + /*! + * @brief This function sets a value in member my_int8 + * @param _my_int8 New value for member my_int8 + */ + eProsima_user_DllExport void my_int8( + int8_t _my_int8) + { + m_my_int8 = _my_int8; + } + + /*! + * @brief This function returns the value of member my_int8 + * @return Value of member my_int8 + */ + eProsima_user_DllExport int8_t my_int8() const + { + return m_my_int8; + } + + /*! + * @brief This function returns a reference to member my_int8 + * @return Reference to member my_int8 + */ + eProsima_user_DllExport int8_t& my_int8() + { + return m_my_int8; + } + + + /*! + * @brief This function sets a value in member my_uint8 + * @param _my_uint8 New value for member my_uint8 + */ + eProsima_user_DllExport void my_uint8( + uint8_t _my_uint8) + { + m_my_uint8 = _my_uint8; + } + + /*! + * @brief This function returns the value of member my_uint8 + * @return Value of member my_uint8 + */ + eProsima_user_DllExport uint8_t my_uint8() const + { + return m_my_uint8; + } + + /*! + * @brief This function returns a reference to member my_uint8 + * @return Reference to member my_uint8 + */ + eProsima_user_DllExport uint8_t& my_uint8() + { + return m_my_uint8; + } + + + /*! + * @brief This function sets a value in member my_short + * @param _my_short New value for member my_short + */ + eProsima_user_DllExport void my_short( + int16_t _my_short) + { + m_my_short = _my_short; + } + + /*! + * @brief This function returns the value of member my_short + * @return Value of member my_short + */ + eProsima_user_DllExport int16_t my_short() const + { + return m_my_short; + } + + /*! + * @brief This function returns a reference to member my_short + * @return Reference to member my_short + */ + eProsima_user_DllExport int16_t& my_short() + { + return m_my_short; + } + + + /*! + * @brief This function sets a value in member my_ushort + * @param _my_ushort New value for member my_ushort + */ + eProsima_user_DllExport void my_ushort( + uint16_t _my_ushort) + { + m_my_ushort = _my_ushort; + } + + /*! + * @brief This function returns the value of member my_ushort + * @return Value of member my_ushort + */ + eProsima_user_DllExport uint16_t my_ushort() const + { + return m_my_ushort; + } + + /*! + * @brief This function returns a reference to member my_ushort + * @return Reference to member my_ushort + */ + eProsima_user_DllExport uint16_t& my_ushort() + { + return m_my_ushort; + } + + + /*! + * @brief This function sets a value in member my_longlong + * @param _my_longlong New value for member my_longlong + */ + eProsima_user_DllExport void my_longlong( + int64_t _my_longlong) + { + m_my_longlong = _my_longlong; + } + + /*! + * @brief This function returns the value of member my_longlong + * @return Value of member my_longlong + */ + eProsima_user_DllExport int64_t my_longlong() const + { + return m_my_longlong; + } + + /*! + * @brief This function returns a reference to member my_longlong + * @return Reference to member my_longlong + */ + eProsima_user_DllExport int64_t& my_longlong() + { + return m_my_longlong; + } + + + /*! + * @brief This function sets a value in member my_ulonglong + * @param _my_ulonglong New value for member my_ulonglong + */ + eProsima_user_DllExport void my_ulonglong( + uint64_t _my_ulonglong) + { + m_my_ulonglong = _my_ulonglong; + } + + /*! + * @brief This function returns the value of member my_ulonglong + * @return Value of member my_ulonglong + */ + eProsima_user_DllExport uint64_t my_ulonglong() const + { + return m_my_ulonglong; + } + + /*! + * @brief This function returns a reference to member my_ulonglong + * @return Reference to member my_ulonglong + */ + eProsima_user_DllExport uint64_t& my_ulonglong() + { + return m_my_ulonglong; + } + + + /*! + * @brief This function sets a value in member my_float + * @param _my_float New value for member my_float + */ + eProsima_user_DllExport void my_float( + float _my_float) + { + m_my_float = _my_float; + } + + /*! + * @brief This function returns the value of member my_float + * @return Value of member my_float + */ + eProsima_user_DllExport float my_float() const + { + return m_my_float; + } + + /*! + * @brief This function returns a reference to member my_float + * @return Reference to member my_float + */ + eProsima_user_DllExport float& my_float() + { + return m_my_float; + } + + + /*! + * @brief This function sets a value in member my_double + * @param _my_double New value for member my_double + */ + eProsima_user_DllExport void my_double( + double _my_double) + { + m_my_double = _my_double; + } + + /*! + * @brief This function returns the value of member my_double + * @return Value of member my_double + */ + eProsima_user_DllExport double my_double() const + { + return m_my_double; + } + + /*! + * @brief This function returns a reference to member my_double + * @return Reference to member my_double + */ + eProsima_user_DllExport double& my_double() + { + return m_my_double; + } + + + /*! + * @brief This function sets a value in member my_longdouble + * @param _my_longdouble New value for member my_longdouble + */ + eProsima_user_DllExport void my_longdouble( + long double _my_longdouble) + { + m_my_longdouble = _my_longdouble; + } + + /*! + * @brief This function returns the value of member my_longdouble + * @return Value of member my_longdouble + */ + eProsima_user_DllExport long double my_longdouble() const + { + return m_my_longdouble; + } + + /*! + * @brief This function returns a reference to member my_longdouble + * @return Reference to member my_longdouble + */ + eProsima_user_DllExport long double& my_longdouble() + { + return m_my_longdouble; + } + + + +private: + + bool m_my_bool{false}; + uint8_t m_my_octet{0}; + char m_my_char{0}; + wchar_t m_my_wchar{0}; + int32_t m_my_long{0}; + uint32_t m_my_ulong{0}; + int8_t m_my_int8{0}; + uint8_t m_my_uint8{0}; + int16_t m_my_short{0}; + uint16_t m_my_ushort{0}; + int64_t m_my_longlong{0}; + uint64_t m_my_ulonglong{0}; + float m_my_float{0.0}; + double m_my_double{0.0}; + long double m_my_longdouble{0.0}; + +}; + +#endif // _FAST_DDS_GENERATED_PRIMITIVES_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structCdrAux.hpp new file mode 100644 index 00000000000..db4d8cb0b8d --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structCdrAux.hpp @@ -0,0 +1,46 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file primitives_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__PRIMITIVES_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__PRIMITIVES_STRUCTCDRAUX_HPP + +#include "primitives_struct.hpp" + +constexpr uint32_t PrimitivesStruct_max_cdr_typesize {80UL}; +constexpr uint32_t PrimitivesStruct_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const PrimitivesStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__PRIMITIVES_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structCdrAux.ipp new file mode 100644 index 00000000000..3e15e487d00 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structCdrAux.ipp @@ -0,0 +1,230 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file primitives_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__PRIMITIVES_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__PRIMITIVES_STRUCTCDRAUX_IPP + +#include "primitives_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const PrimitivesStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_bool(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_octet(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_char(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3), + data.my_wchar(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(4), + data.my_long(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(5), + data.my_ulong(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(6), + data.my_int8(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(7), + data.my_uint8(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(8), + data.my_short(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(9), + data.my_ushort(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(10), + data.my_longlong(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(11), + data.my_ulonglong(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(12), + data.my_float(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(13), + data.my_double(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(14), + data.my_longdouble(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const PrimitivesStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_bool() + << eprosima::fastcdr::MemberId(1) << data.my_octet() + << eprosima::fastcdr::MemberId(2) << data.my_char() + << eprosima::fastcdr::MemberId(3) << data.my_wchar() + << eprosima::fastcdr::MemberId(4) << data.my_long() + << eprosima::fastcdr::MemberId(5) << data.my_ulong() + << eprosima::fastcdr::MemberId(6) << data.my_int8() + << eprosima::fastcdr::MemberId(7) << data.my_uint8() + << eprosima::fastcdr::MemberId(8) << data.my_short() + << eprosima::fastcdr::MemberId(9) << data.my_ushort() + << eprosima::fastcdr::MemberId(10) << data.my_longlong() + << eprosima::fastcdr::MemberId(11) << data.my_ulonglong() + << eprosima::fastcdr::MemberId(12) << data.my_float() + << eprosima::fastcdr::MemberId(13) << data.my_double() + << eprosima::fastcdr::MemberId(14) << data.my_longdouble() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + PrimitivesStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_bool(); + break; + + case 1: + dcdr >> data.my_octet(); + break; + + case 2: + dcdr >> data.my_char(); + break; + + case 3: + dcdr >> data.my_wchar(); + break; + + case 4: + dcdr >> data.my_long(); + break; + + case 5: + dcdr >> data.my_ulong(); + break; + + case 6: + dcdr >> data.my_int8(); + break; + + case 7: + dcdr >> data.my_uint8(); + break; + + case 8: + dcdr >> data.my_short(); + break; + + case 9: + dcdr >> data.my_ushort(); + break; + + case 10: + dcdr >> data.my_longlong(); + break; + + case 11: + dcdr >> data.my_ulonglong(); + break; + + case 12: + dcdr >> data.my_float(); + break; + + case 13: + dcdr >> data.my_double(); + break; + + case 14: + dcdr >> data.my_longdouble(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const PrimitivesStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__PRIMITIVES_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.cxx new file mode 100644 index 00000000000..3434ba975ca --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.cxx @@ -0,0 +1,229 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file primitives_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "primitives_structPubSubTypes.hpp" + +#include +#include + +#include "primitives_structCdrAux.hpp" +#include "primitives_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +PrimitivesStructPubSubType::PrimitivesStructPubSubType() +{ + setName("PrimitivesStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(PrimitivesStruct::getMaxCdrSerializedSize()); +#else + PrimitivesStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = PrimitivesStruct_max_key_cdr_typesize > 16 ? PrimitivesStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +PrimitivesStructPubSubType::~PrimitivesStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool PrimitivesStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const PrimitivesStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool PrimitivesStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + PrimitivesStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function PrimitivesStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* PrimitivesStructPubSubType::createData() +{ + return reinterpret_cast(new PrimitivesStruct()); +} + +void PrimitivesStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool PrimitivesStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const PrimitivesStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + PrimitivesStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || PrimitivesStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void PrimitivesStructPubSubType::register_type_object_representation() +{ + register_PrimitivesStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "primitives_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.hpp new file mode 100644 index 00000000000..afcc3758609 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structPubSubTypes.hpp @@ -0,0 +1,133 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file primitives_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__PRIMITIVES_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__PRIMITIVES_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "primitives_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated primitives_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type PrimitivesStruct defined by the user in the IDL file. + * @ingroup primitives_struct + */ +class PrimitivesStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef PrimitivesStruct type; + + eProsima_user_DllExport PrimitivesStructPubSubType(); + + eProsima_user_DllExport ~PrimitivesStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__PRIMITIVES_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..dbafd4778da --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structTypeObjectSupport.cxx @@ -0,0 +1,520 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file primitives_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "primitives_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "primitives_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_PrimitivesStruct_type_identifier( + TypeIdentifierPair& type_ids_PrimitivesStruct) +{ + + ReturnCode_t return_code_PrimitivesStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_PrimitivesStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "PrimitivesStruct", type_ids_PrimitivesStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_PrimitivesStruct) + { + StructTypeFlag struct_flags_PrimitivesStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_PrimitivesStruct = "PrimitivesStruct"; + eprosima::fastcdr::optional type_ann_builtin_PrimitivesStruct; + eprosima::fastcdr::optional ann_custom_PrimitivesStruct; + CompleteTypeDetail detail_PrimitivesStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_PrimitivesStruct, ann_custom_PrimitivesStruct, type_name_PrimitivesStruct.to_string()); + CompleteStructHeader header_PrimitivesStruct; + header_PrimitivesStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_PrimitivesStruct); + CompleteStructMemberSeq member_seq_PrimitivesStruct; + { + TypeIdentifierPair type_ids_my_bool; + ReturnCode_t return_code_my_bool {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_bool = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_bool", type_ids_my_bool); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_bool) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_bool Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_bool = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_bool = 0x00000000; + bool common_my_bool_ec {false}; + CommonStructMember common_my_bool {TypeObjectUtils::build_common_struct_member(member_id_my_bool, member_flags_my_bool, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_bool, common_my_bool_ec))}; + if (!common_my_bool_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_bool member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_bool = "my_bool"; + eprosima::fastcdr::optional member_ann_builtin_my_bool; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_bool = TypeObjectUtils::build_complete_member_detail(name_my_bool, member_ann_builtin_my_bool, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_bool = TypeObjectUtils::build_complete_struct_member(common_my_bool, detail_my_bool); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_bool); + } + { + TypeIdentifierPair type_ids_my_octet; + ReturnCode_t return_code_my_octet {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_octet = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_byte", type_ids_my_octet); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_octet) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_octet Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_octet = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_octet = 0x00000001; + bool common_my_octet_ec {false}; + CommonStructMember common_my_octet {TypeObjectUtils::build_common_struct_member(member_id_my_octet, member_flags_my_octet, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_octet, common_my_octet_ec))}; + if (!common_my_octet_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_octet member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_octet = "my_octet"; + eprosima::fastcdr::optional member_ann_builtin_my_octet; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_octet = TypeObjectUtils::build_complete_member_detail(name_my_octet, member_ann_builtin_my_octet, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_octet = TypeObjectUtils::build_complete_struct_member(common_my_octet, detail_my_octet); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_octet); + } + { + TypeIdentifierPair type_ids_my_char; + ReturnCode_t return_code_my_char {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_char = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_char", type_ids_my_char); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_char) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_char Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_char = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_char = 0x00000002; + bool common_my_char_ec {false}; + CommonStructMember common_my_char {TypeObjectUtils::build_common_struct_member(member_id_my_char, member_flags_my_char, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_char, common_my_char_ec))}; + if (!common_my_char_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_char member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_char = "my_char"; + eprosima::fastcdr::optional member_ann_builtin_my_char; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_char = TypeObjectUtils::build_complete_member_detail(name_my_char, member_ann_builtin_my_char, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_char = TypeObjectUtils::build_complete_struct_member(common_my_char, detail_my_char); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_char); + } + { + TypeIdentifierPair type_ids_my_wchar; + ReturnCode_t return_code_my_wchar {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_wchar = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_wchar_t", type_ids_my_wchar); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_wchar) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_wchar Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_wchar = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_wchar = 0x00000003; + bool common_my_wchar_ec {false}; + CommonStructMember common_my_wchar {TypeObjectUtils::build_common_struct_member(member_id_my_wchar, member_flags_my_wchar, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_wchar, common_my_wchar_ec))}; + if (!common_my_wchar_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_wchar member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_wchar = "my_wchar"; + eprosima::fastcdr::optional member_ann_builtin_my_wchar; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_wchar = TypeObjectUtils::build_complete_member_detail(name_my_wchar, member_ann_builtin_my_wchar, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_wchar = TypeObjectUtils::build_complete_struct_member(common_my_wchar, detail_my_wchar); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_wchar); + } + { + TypeIdentifierPair type_ids_my_long; + ReturnCode_t return_code_my_long {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_long = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_my_long); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_long) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_long Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_long = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_long = 0x00000004; + bool common_my_long_ec {false}; + CommonStructMember common_my_long {TypeObjectUtils::build_common_struct_member(member_id_my_long, member_flags_my_long, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_long, common_my_long_ec))}; + if (!common_my_long_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_long member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_long = "my_long"; + eprosima::fastcdr::optional member_ann_builtin_my_long; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_long = TypeObjectUtils::build_complete_member_detail(name_my_long, member_ann_builtin_my_long, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_long = TypeObjectUtils::build_complete_struct_member(common_my_long, detail_my_long); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_long); + } + { + TypeIdentifierPair type_ids_my_ulong; + ReturnCode_t return_code_my_ulong {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_ulong = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_uint32_t", type_ids_my_ulong); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_ulong) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_ulong Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_ulong = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_ulong = 0x00000005; + bool common_my_ulong_ec {false}; + CommonStructMember common_my_ulong {TypeObjectUtils::build_common_struct_member(member_id_my_ulong, member_flags_my_ulong, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_ulong, common_my_ulong_ec))}; + if (!common_my_ulong_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_ulong member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_ulong = "my_ulong"; + eprosima::fastcdr::optional member_ann_builtin_my_ulong; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_ulong = TypeObjectUtils::build_complete_member_detail(name_my_ulong, member_ann_builtin_my_ulong, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_ulong = TypeObjectUtils::build_complete_struct_member(common_my_ulong, detail_my_ulong); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_ulong); + } + { + TypeIdentifierPair type_ids_my_int8; + ReturnCode_t return_code_my_int8 {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_int8 = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int8_t", type_ids_my_int8); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_int8) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_int8 Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_int8 = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_int8 = 0x00000006; + bool common_my_int8_ec {false}; + CommonStructMember common_my_int8 {TypeObjectUtils::build_common_struct_member(member_id_my_int8, member_flags_my_int8, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_int8, common_my_int8_ec))}; + if (!common_my_int8_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_int8 member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_int8 = "my_int8"; + eprosima::fastcdr::optional member_ann_builtin_my_int8; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_int8 = TypeObjectUtils::build_complete_member_detail(name_my_int8, member_ann_builtin_my_int8, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_int8 = TypeObjectUtils::build_complete_struct_member(common_my_int8, detail_my_int8); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_int8); + } + { + TypeIdentifierPair type_ids_my_uint8; + ReturnCode_t return_code_my_uint8 {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_uint8 = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_uint8_t", type_ids_my_uint8); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_uint8) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_uint8 Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_uint8 = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_uint8 = 0x00000007; + bool common_my_uint8_ec {false}; + CommonStructMember common_my_uint8 {TypeObjectUtils::build_common_struct_member(member_id_my_uint8, member_flags_my_uint8, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_uint8, common_my_uint8_ec))}; + if (!common_my_uint8_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_uint8 member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_uint8 = "my_uint8"; + eprosima::fastcdr::optional member_ann_builtin_my_uint8; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_uint8 = TypeObjectUtils::build_complete_member_detail(name_my_uint8, member_ann_builtin_my_uint8, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_uint8 = TypeObjectUtils::build_complete_struct_member(common_my_uint8, detail_my_uint8); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_uint8); + } + { + TypeIdentifierPair type_ids_my_short; + ReturnCode_t return_code_my_short {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_short = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int16_t", type_ids_my_short); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_short) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_short Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_short = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_short = 0x00000008; + bool common_my_short_ec {false}; + CommonStructMember common_my_short {TypeObjectUtils::build_common_struct_member(member_id_my_short, member_flags_my_short, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_short, common_my_short_ec))}; + if (!common_my_short_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_short member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_short = "my_short"; + eprosima::fastcdr::optional member_ann_builtin_my_short; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_short = TypeObjectUtils::build_complete_member_detail(name_my_short, member_ann_builtin_my_short, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_short = TypeObjectUtils::build_complete_struct_member(common_my_short, detail_my_short); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_short); + } + { + TypeIdentifierPair type_ids_my_ushort; + ReturnCode_t return_code_my_ushort {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_ushort = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_uint16_t", type_ids_my_ushort); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_ushort) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_ushort Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_ushort = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_ushort = 0x00000009; + bool common_my_ushort_ec {false}; + CommonStructMember common_my_ushort {TypeObjectUtils::build_common_struct_member(member_id_my_ushort, member_flags_my_ushort, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_ushort, common_my_ushort_ec))}; + if (!common_my_ushort_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_ushort member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_ushort = "my_ushort"; + eprosima::fastcdr::optional member_ann_builtin_my_ushort; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_ushort = TypeObjectUtils::build_complete_member_detail(name_my_ushort, member_ann_builtin_my_ushort, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_ushort = TypeObjectUtils::build_complete_struct_member(common_my_ushort, detail_my_ushort); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_ushort); + } + { + TypeIdentifierPair type_ids_my_longlong; + ReturnCode_t return_code_my_longlong {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_longlong = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int64_t", type_ids_my_longlong); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_longlong) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_longlong Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_longlong = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_longlong = 0x0000000a; + bool common_my_longlong_ec {false}; + CommonStructMember common_my_longlong {TypeObjectUtils::build_common_struct_member(member_id_my_longlong, member_flags_my_longlong, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_longlong, common_my_longlong_ec))}; + if (!common_my_longlong_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_longlong member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_longlong = "my_longlong"; + eprosima::fastcdr::optional member_ann_builtin_my_longlong; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_longlong = TypeObjectUtils::build_complete_member_detail(name_my_longlong, member_ann_builtin_my_longlong, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_longlong = TypeObjectUtils::build_complete_struct_member(common_my_longlong, detail_my_longlong); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_longlong); + } + { + TypeIdentifierPair type_ids_my_ulonglong; + ReturnCode_t return_code_my_ulonglong {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_ulonglong = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_uint64_t", type_ids_my_ulonglong); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_ulonglong) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_ulonglong Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_ulonglong = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_ulonglong = 0x0000000b; + bool common_my_ulonglong_ec {false}; + CommonStructMember common_my_ulonglong {TypeObjectUtils::build_common_struct_member(member_id_my_ulonglong, member_flags_my_ulonglong, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_ulonglong, common_my_ulonglong_ec))}; + if (!common_my_ulonglong_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_ulonglong member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_ulonglong = "my_ulonglong"; + eprosima::fastcdr::optional member_ann_builtin_my_ulonglong; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_ulonglong = TypeObjectUtils::build_complete_member_detail(name_my_ulonglong, member_ann_builtin_my_ulonglong, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_ulonglong = TypeObjectUtils::build_complete_struct_member(common_my_ulonglong, detail_my_ulonglong); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_ulonglong); + } + { + TypeIdentifierPair type_ids_my_float; + ReturnCode_t return_code_my_float {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_float = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_float", type_ids_my_float); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_float) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_float Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_float = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_float = 0x0000000c; + bool common_my_float_ec {false}; + CommonStructMember common_my_float {TypeObjectUtils::build_common_struct_member(member_id_my_float, member_flags_my_float, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_float, common_my_float_ec))}; + if (!common_my_float_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_float member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_float = "my_float"; + eprosima::fastcdr::optional member_ann_builtin_my_float; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_float = TypeObjectUtils::build_complete_member_detail(name_my_float, member_ann_builtin_my_float, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_float = TypeObjectUtils::build_complete_struct_member(common_my_float, detail_my_float); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_float); + } + { + TypeIdentifierPair type_ids_my_double; + ReturnCode_t return_code_my_double {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_double = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_double", type_ids_my_double); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_double) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_double Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_double = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_double = 0x0000000d; + bool common_my_double_ec {false}; + CommonStructMember common_my_double {TypeObjectUtils::build_common_struct_member(member_id_my_double, member_flags_my_double, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_double, common_my_double_ec))}; + if (!common_my_double_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_double member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_double = "my_double"; + eprosima::fastcdr::optional member_ann_builtin_my_double; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_double = TypeObjectUtils::build_complete_member_detail(name_my_double, member_ann_builtin_my_double, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_double = TypeObjectUtils::build_complete_struct_member(common_my_double, detail_my_double); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_double); + } + { + TypeIdentifierPair type_ids_my_longdouble; + ReturnCode_t return_code_my_longdouble {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_longdouble = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_longdouble", type_ids_my_longdouble); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_longdouble) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_longdouble Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_longdouble = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_longdouble = 0x0000000e; + bool common_my_longdouble_ec {false}; + CommonStructMember common_my_longdouble {TypeObjectUtils::build_common_struct_member(member_id_my_longdouble, member_flags_my_longdouble, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_longdouble, common_my_longdouble_ec))}; + if (!common_my_longdouble_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_longdouble member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_longdouble = "my_longdouble"; + eprosima::fastcdr::optional member_ann_builtin_my_longdouble; + ann_custom_PrimitivesStruct.reset(); + CompleteMemberDetail detail_my_longdouble = TypeObjectUtils::build_complete_member_detail(name_my_longdouble, member_ann_builtin_my_longdouble, ann_custom_PrimitivesStruct); + CompleteStructMember member_my_longdouble = TypeObjectUtils::build_complete_struct_member(common_my_longdouble, detail_my_longdouble); + TypeObjectUtils::add_complete_struct_member(member_seq_PrimitivesStruct, member_my_longdouble); + } + CompleteStructType struct_type_PrimitivesStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_PrimitivesStruct, header_PrimitivesStruct, member_seq_PrimitivesStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_PrimitivesStruct, type_name_PrimitivesStruct.to_string(), type_ids_PrimitivesStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "PrimitivesStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..bcd2330e7f7 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/gen/primitives_structTypeObjectSupport.hpp @@ -0,0 +1,56 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file primitives_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__PRIMITIVES_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__PRIMITIVES_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register PrimitivesStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_PrimitivesStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__PRIMITIVES_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/primitives_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/primitives_struct.idl new file mode 100644 index 00000000000..eb6191cf7ea --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/primitives_struct.idl @@ -0,0 +1,18 @@ +struct PrimitivesStruct +{ + boolean my_bool; + octet my_octet; + char my_char; + wchar my_wchar; + long my_long; + unsigned long my_ulong; + int8 my_int8; + uint8 my_uint8; + short my_short; + unsigned short my_ushort; + long long my_longlong; + unsigned long long my_ulonglong; + float my_float; + double my_double; + long double my_longdouble; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_struct.hpp new file mode 100644 index 00000000000..ca3e3ae5439 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_struct.hpp @@ -0,0 +1,673 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file sequence_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__SEQUENCE_STRUCT_HPP +#define FAST_DDS_GENERATED__SEQUENCE_STRUCT_HPP + +#include +#include +#include +#include + +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(SEQUENCE_STRUCT_SOURCE) +#define SEQUENCE_STRUCT_DllAPI __declspec( dllexport ) +#else +#define SEQUENCE_STRUCT_DllAPI __declspec( dllimport ) +#endif // SEQUENCE_STRUCT_SOURCE +#else +#define SEQUENCE_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define SEQUENCE_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure NestedSequenceElement defined by the user in the IDL file. + * @ingroup sequence_struct + */ +class NestedSequenceElement +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport NestedSequenceElement() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~NestedSequenceElement() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object NestedSequenceElement that will be copied. + */ + eProsima_user_DllExport NestedSequenceElement( + const NestedSequenceElement& x) + { + m_my_string = x.m_my_string; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object NestedSequenceElement that will be copied. + */ + eProsima_user_DllExport NestedSequenceElement( + NestedSequenceElement&& x) noexcept + { + m_my_string = std::move(x.m_my_string); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object NestedSequenceElement that will be copied. + */ + eProsima_user_DllExport NestedSequenceElement& operator =( + const NestedSequenceElement& x) + { + + m_my_string = x.m_my_string; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object NestedSequenceElement that will be copied. + */ + eProsima_user_DllExport NestedSequenceElement& operator =( + NestedSequenceElement&& x) noexcept + { + + m_my_string = std::move(x.m_my_string); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x NestedSequenceElement object to compare. + */ + eProsima_user_DllExport bool operator ==( + const NestedSequenceElement& x) const + { + return (m_my_string == x.m_my_string); + } + + /*! + * @brief Comparison operator. + * @param x NestedSequenceElement object to compare. + */ + eProsima_user_DllExport bool operator !=( + const NestedSequenceElement& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member my_string + * @param _my_string New value to be copied in member my_string + */ + eProsima_user_DllExport void my_string( + const std::string& _my_string) + { + m_my_string = _my_string; + } + + /*! + * @brief This function moves the value in member my_string + * @param _my_string New value to be moved in member my_string + */ + eProsima_user_DllExport void my_string( + std::string&& _my_string) + { + m_my_string = std::move(_my_string); + } + + /*! + * @brief This function returns a constant reference to member my_string + * @return Constant reference to member my_string + */ + eProsima_user_DllExport const std::string& my_string() const + { + return m_my_string; + } + + /*! + * @brief This function returns a reference to member my_string + * @return Reference to member my_string + */ + eProsima_user_DllExport std::string& my_string() + { + return m_my_string; + } + + + +private: + + std::string m_my_string; + +}; +/*! + * @brief This class represents the structure ComplexSequenceElement defined by the user in the IDL file. + * @ingroup sequence_struct + */ +class ComplexSequenceElement +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport ComplexSequenceElement() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~ComplexSequenceElement() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object ComplexSequenceElement that will be copied. + */ + eProsima_user_DllExport ComplexSequenceElement( + const ComplexSequenceElement& x) + { + m_my_short = x.m_my_short; + + m_my_long = x.m_my_long; + + m_my_complex_element = x.m_my_complex_element; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object ComplexSequenceElement that will be copied. + */ + eProsima_user_DllExport ComplexSequenceElement( + ComplexSequenceElement&& x) noexcept + { + m_my_short = x.m_my_short; + m_my_long = x.m_my_long; + m_my_complex_element = std::move(x.m_my_complex_element); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object ComplexSequenceElement that will be copied. + */ + eProsima_user_DllExport ComplexSequenceElement& operator =( + const ComplexSequenceElement& x) + { + + m_my_short = x.m_my_short; + + m_my_long = x.m_my_long; + + m_my_complex_element = x.m_my_complex_element; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object ComplexSequenceElement that will be copied. + */ + eProsima_user_DllExport ComplexSequenceElement& operator =( + ComplexSequenceElement&& x) noexcept + { + + m_my_short = x.m_my_short; + m_my_long = x.m_my_long; + m_my_complex_element = std::move(x.m_my_complex_element); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x ComplexSequenceElement object to compare. + */ + eProsima_user_DllExport bool operator ==( + const ComplexSequenceElement& x) const + { + return (m_my_short == x.m_my_short && + m_my_long == x.m_my_long && + m_my_complex_element == x.m_my_complex_element); + } + + /*! + * @brief Comparison operator. + * @param x ComplexSequenceElement object to compare. + */ + eProsima_user_DllExport bool operator !=( + const ComplexSequenceElement& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_short + * @param _my_short New value for member my_short + */ + eProsima_user_DllExport void my_short( + int16_t _my_short) + { + m_my_short = _my_short; + } + + /*! + * @brief This function returns the value of member my_short + * @return Value of member my_short + */ + eProsima_user_DllExport int16_t my_short() const + { + return m_my_short; + } + + /*! + * @brief This function returns a reference to member my_short + * @return Reference to member my_short + */ + eProsima_user_DllExport int16_t& my_short() + { + return m_my_short; + } + + + /*! + * @brief This function sets a value in member my_long + * @param _my_long New value for member my_long + */ + eProsima_user_DllExport void my_long( + int32_t _my_long) + { + m_my_long = _my_long; + } + + /*! + * @brief This function returns the value of member my_long + * @return Value of member my_long + */ + eProsima_user_DllExport int32_t my_long() const + { + return m_my_long; + } + + /*! + * @brief This function returns a reference to member my_long + * @return Reference to member my_long + */ + eProsima_user_DllExport int32_t& my_long() + { + return m_my_long; + } + + + /*! + * @brief This function copies the value in member my_complex_element + * @param _my_complex_element New value to be copied in member my_complex_element + */ + eProsima_user_DllExport void my_complex_element( + const NestedSequenceElement& _my_complex_element) + { + m_my_complex_element = _my_complex_element; + } + + /*! + * @brief This function moves the value in member my_complex_element + * @param _my_complex_element New value to be moved in member my_complex_element + */ + eProsima_user_DllExport void my_complex_element( + NestedSequenceElement&& _my_complex_element) + { + m_my_complex_element = std::move(_my_complex_element); + } + + /*! + * @brief This function returns a constant reference to member my_complex_element + * @return Constant reference to member my_complex_element + */ + eProsima_user_DllExport const NestedSequenceElement& my_complex_element() const + { + return m_my_complex_element; + } + + /*! + * @brief This function returns a reference to member my_complex_element + * @return Reference to member my_complex_element + */ + eProsima_user_DllExport NestedSequenceElement& my_complex_element() + { + return m_my_complex_element; + } + + + +private: + + int16_t m_my_short{0}; + int32_t m_my_long{0}; + NestedSequenceElement m_my_complex_element; + +}; +/*! + * @brief This class represents the structure SequenceStruct defined by the user in the IDL file. + * @ingroup sequence_struct + */ +class SequenceStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport SequenceStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~SequenceStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object SequenceStruct that will be copied. + */ + eProsima_user_DllExport SequenceStruct( + const SequenceStruct& x) + { + m_my_basic_sequence = x.m_my_basic_sequence; + + m_my_bounded_sequence = x.m_my_bounded_sequence; + + m_my_complex_sequence = x.m_my_complex_sequence; + + m_my_complex_bounded_sequence = x.m_my_complex_bounded_sequence; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object SequenceStruct that will be copied. + */ + eProsima_user_DllExport SequenceStruct( + SequenceStruct&& x) noexcept + { + m_my_basic_sequence = std::move(x.m_my_basic_sequence); + m_my_bounded_sequence = std::move(x.m_my_bounded_sequence); + m_my_complex_sequence = std::move(x.m_my_complex_sequence); + m_my_complex_bounded_sequence = std::move(x.m_my_complex_bounded_sequence); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object SequenceStruct that will be copied. + */ + eProsima_user_DllExport SequenceStruct& operator =( + const SequenceStruct& x) + { + + m_my_basic_sequence = x.m_my_basic_sequence; + + m_my_bounded_sequence = x.m_my_bounded_sequence; + + m_my_complex_sequence = x.m_my_complex_sequence; + + m_my_complex_bounded_sequence = x.m_my_complex_bounded_sequence; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object SequenceStruct that will be copied. + */ + eProsima_user_DllExport SequenceStruct& operator =( + SequenceStruct&& x) noexcept + { + + m_my_basic_sequence = std::move(x.m_my_basic_sequence); + m_my_bounded_sequence = std::move(x.m_my_bounded_sequence); + m_my_complex_sequence = std::move(x.m_my_complex_sequence); + m_my_complex_bounded_sequence = std::move(x.m_my_complex_bounded_sequence); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x SequenceStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const SequenceStruct& x) const + { + return (m_my_basic_sequence == x.m_my_basic_sequence && + m_my_bounded_sequence == x.m_my_bounded_sequence && + m_my_complex_sequence == x.m_my_complex_sequence && + m_my_complex_bounded_sequence == x.m_my_complex_bounded_sequence); + } + + /*! + * @brief Comparison operator. + * @param x SequenceStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const SequenceStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member my_basic_sequence + * @param _my_basic_sequence New value to be copied in member my_basic_sequence + */ + eProsima_user_DllExport void my_basic_sequence( + const std::vector& _my_basic_sequence) + { + m_my_basic_sequence = _my_basic_sequence; + } + + /*! + * @brief This function moves the value in member my_basic_sequence + * @param _my_basic_sequence New value to be moved in member my_basic_sequence + */ + eProsima_user_DllExport void my_basic_sequence( + std::vector&& _my_basic_sequence) + { + m_my_basic_sequence = std::move(_my_basic_sequence); + } + + /*! + * @brief This function returns a constant reference to member my_basic_sequence + * @return Constant reference to member my_basic_sequence + */ + eProsima_user_DllExport const std::vector& my_basic_sequence() const + { + return m_my_basic_sequence; + } + + /*! + * @brief This function returns a reference to member my_basic_sequence + * @return Reference to member my_basic_sequence + */ + eProsima_user_DllExport std::vector& my_basic_sequence() + { + return m_my_basic_sequence; + } + + + /*! + * @brief This function copies the value in member my_bounded_sequence + * @param _my_bounded_sequence New value to be copied in member my_bounded_sequence + */ + eProsima_user_DllExport void my_bounded_sequence( + const std::vector& _my_bounded_sequence) + { + m_my_bounded_sequence = _my_bounded_sequence; + } + + /*! + * @brief This function moves the value in member my_bounded_sequence + * @param _my_bounded_sequence New value to be moved in member my_bounded_sequence + */ + eProsima_user_DllExport void my_bounded_sequence( + std::vector&& _my_bounded_sequence) + { + m_my_bounded_sequence = std::move(_my_bounded_sequence); + } + + /*! + * @brief This function returns a constant reference to member my_bounded_sequence + * @return Constant reference to member my_bounded_sequence + */ + eProsima_user_DllExport const std::vector& my_bounded_sequence() const + { + return m_my_bounded_sequence; + } + + /*! + * @brief This function returns a reference to member my_bounded_sequence + * @return Reference to member my_bounded_sequence + */ + eProsima_user_DllExport std::vector& my_bounded_sequence() + { + return m_my_bounded_sequence; + } + + + /*! + * @brief This function copies the value in member my_complex_sequence + * @param _my_complex_sequence New value to be copied in member my_complex_sequence + */ + eProsima_user_DllExport void my_complex_sequence( + const std::vector& _my_complex_sequence) + { + m_my_complex_sequence = _my_complex_sequence; + } + + /*! + * @brief This function moves the value in member my_complex_sequence + * @param _my_complex_sequence New value to be moved in member my_complex_sequence + */ + eProsima_user_DllExport void my_complex_sequence( + std::vector&& _my_complex_sequence) + { + m_my_complex_sequence = std::move(_my_complex_sequence); + } + + /*! + * @brief This function returns a constant reference to member my_complex_sequence + * @return Constant reference to member my_complex_sequence + */ + eProsima_user_DllExport const std::vector& my_complex_sequence() const + { + return m_my_complex_sequence; + } + + /*! + * @brief This function returns a reference to member my_complex_sequence + * @return Reference to member my_complex_sequence + */ + eProsima_user_DllExport std::vector& my_complex_sequence() + { + return m_my_complex_sequence; + } + + + /*! + * @brief This function copies the value in member my_complex_bounded_sequence + * @param _my_complex_bounded_sequence New value to be copied in member my_complex_bounded_sequence + */ + eProsima_user_DllExport void my_complex_bounded_sequence( + const std::vector& _my_complex_bounded_sequence) + { + m_my_complex_bounded_sequence = _my_complex_bounded_sequence; + } + + /*! + * @brief This function moves the value in member my_complex_bounded_sequence + * @param _my_complex_bounded_sequence New value to be moved in member my_complex_bounded_sequence + */ + eProsima_user_DllExport void my_complex_bounded_sequence( + std::vector&& _my_complex_bounded_sequence) + { + m_my_complex_bounded_sequence = std::move(_my_complex_bounded_sequence); + } + + /*! + * @brief This function returns a constant reference to member my_complex_bounded_sequence + * @return Constant reference to member my_complex_bounded_sequence + */ + eProsima_user_DllExport const std::vector& my_complex_bounded_sequence() const + { + return m_my_complex_bounded_sequence; + } + + /*! + * @brief This function returns a reference to member my_complex_bounded_sequence + * @return Reference to member my_complex_bounded_sequence + */ + eProsima_user_DllExport std::vector& my_complex_bounded_sequence() + { + return m_my_complex_bounded_sequence; + } + + + +private: + + std::vector m_my_basic_sequence; + std::vector m_my_bounded_sequence; + std::vector m_my_complex_sequence; + std::vector m_my_complex_bounded_sequence; + +}; + +#endif // _FAST_DDS_GENERATED_SEQUENCE_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structCdrAux.hpp new file mode 100644 index 00000000000..0d16d1bd995 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structCdrAux.hpp @@ -0,0 +1,60 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file sequence_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__SEQUENCE_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__SEQUENCE_STRUCTCDRAUX_HPP + +#include "sequence_struct.hpp" + +constexpr uint32_t NestedSequenceElement_max_cdr_typesize {264UL}; +constexpr uint32_t NestedSequenceElement_max_key_cdr_typesize {0UL}; + +constexpr uint32_t ComplexSequenceElement_max_cdr_typesize {276UL}; +constexpr uint32_t ComplexSequenceElement_max_key_cdr_typesize {0UL}; + +constexpr uint32_t SequenceStruct_max_cdr_typesize {34028UL}; +constexpr uint32_t SequenceStruct_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const NestedSequenceElement& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ComplexSequenceElement& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const SequenceStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__SEQUENCE_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structCdrAux.ipp new file mode 100644 index 00000000000..4e06b7efdee --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structCdrAux.ipp @@ -0,0 +1,310 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file sequence_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__SEQUENCE_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__SEQUENCE_STRUCTCDRAUX_IPP + +#include "sequence_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const NestedSequenceElement& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_string(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const NestedSequenceElement& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_string() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + NestedSequenceElement& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_string(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const NestedSequenceElement& data) +{ + static_cast(scdr); + static_cast(data); +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const ComplexSequenceElement& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_short(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_long(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_complex_element(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const ComplexSequenceElement& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_short() + << eprosima::fastcdr::MemberId(1) << data.my_long() + << eprosima::fastcdr::MemberId(2) << data.my_complex_element() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + ComplexSequenceElement& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_short(); + break; + + case 1: + dcdr >> data.my_long(); + break; + + case 2: + dcdr >> data.my_complex_element(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ComplexSequenceElement& data) +{ + static_cast(scdr); + static_cast(data); +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const SequenceStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_basic_sequence(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_bounded_sequence(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_complex_sequence(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3), + data.my_complex_bounded_sequence(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const SequenceStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_basic_sequence() + << eprosima::fastcdr::MemberId(1) << data.my_bounded_sequence() + << eprosima::fastcdr::MemberId(2) << data.my_complex_sequence() + << eprosima::fastcdr::MemberId(3) << data.my_complex_bounded_sequence() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + SequenceStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_basic_sequence(); + break; + + case 1: + dcdr >> data.my_bounded_sequence(); + break; + + case 2: + dcdr >> data.my_complex_sequence(); + break; + + case 3: + dcdr >> data.my_complex_bounded_sequence(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const SequenceStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__SEQUENCE_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.cxx new file mode 100644 index 00000000000..406a1041ea5 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.cxx @@ -0,0 +1,615 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file sequence_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "sequence_structPubSubTypes.hpp" + +#include +#include + +#include "sequence_structCdrAux.hpp" +#include "sequence_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +NestedSequenceElementPubSubType::NestedSequenceElementPubSubType() +{ + setName("NestedSequenceElement"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(NestedSequenceElement::getMaxCdrSerializedSize()); +#else + NestedSequenceElement_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = NestedSequenceElement_max_key_cdr_typesize > 16 ? NestedSequenceElement_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +NestedSequenceElementPubSubType::~NestedSequenceElementPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool NestedSequenceElementPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const NestedSequenceElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool NestedSequenceElementPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + NestedSequenceElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function NestedSequenceElementPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* NestedSequenceElementPubSubType::createData() +{ + return reinterpret_cast(new NestedSequenceElement()); +} + +void NestedSequenceElementPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool NestedSequenceElementPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const NestedSequenceElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + NestedSequenceElement_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || NestedSequenceElement_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void NestedSequenceElementPubSubType::register_type_object_representation() +{ + register_NestedSequenceElement_type_identifier(type_identifiers_); +} + +ComplexSequenceElementPubSubType::ComplexSequenceElementPubSubType() +{ + setName("ComplexSequenceElement"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(ComplexSequenceElement::getMaxCdrSerializedSize()); +#else + ComplexSequenceElement_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = ComplexSequenceElement_max_key_cdr_typesize > 16 ? ComplexSequenceElement_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +ComplexSequenceElementPubSubType::~ComplexSequenceElementPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool ComplexSequenceElementPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const ComplexSequenceElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool ComplexSequenceElementPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + ComplexSequenceElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function ComplexSequenceElementPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* ComplexSequenceElementPubSubType::createData() +{ + return reinterpret_cast(new ComplexSequenceElement()); +} + +void ComplexSequenceElementPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool ComplexSequenceElementPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const ComplexSequenceElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + ComplexSequenceElement_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || ComplexSequenceElement_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void ComplexSequenceElementPubSubType::register_type_object_representation() +{ + register_ComplexSequenceElement_type_identifier(type_identifiers_); +} + +SequenceStructPubSubType::SequenceStructPubSubType() +{ + setName("SequenceStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(SequenceStruct::getMaxCdrSerializedSize()); +#else + SequenceStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = SequenceStruct_max_key_cdr_typesize > 16 ? SequenceStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +SequenceStructPubSubType::~SequenceStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool SequenceStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const SequenceStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool SequenceStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + SequenceStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function SequenceStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* SequenceStructPubSubType::createData() +{ + return reinterpret_cast(new SequenceStruct()); +} + +void SequenceStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool SequenceStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const SequenceStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + SequenceStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || SequenceStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void SequenceStructPubSubType::register_type_object_representation() +{ + register_SequenceStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "sequence_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.hpp new file mode 100644 index 00000000000..d0c2498530d --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structPubSubTypes.hpp @@ -0,0 +1,315 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file sequence_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__SEQUENCE_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__SEQUENCE_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "sequence_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated sequence_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type NestedSequenceElement defined by the user in the IDL file. + * @ingroup sequence_struct + */ +class NestedSequenceElementPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef NestedSequenceElement type; + + eProsima_user_DllExport NestedSequenceElementPubSubType(); + + eProsima_user_DllExport ~NestedSequenceElementPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +/*! + * @brief This class represents the TopicDataType of the type ComplexSequenceElement defined by the user in the IDL file. + * @ingroup sequence_struct + */ +class ComplexSequenceElementPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef ComplexSequenceElement type; + + eProsima_user_DllExport ComplexSequenceElementPubSubType(); + + eProsima_user_DllExport ~ComplexSequenceElementPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +/*! + * @brief This class represents the TopicDataType of the type SequenceStruct defined by the user in the IDL file. + * @ingroup sequence_struct + */ +class SequenceStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef SequenceStruct type; + + eProsima_user_DllExport SequenceStructPubSubType(); + + eProsima_user_DllExport ~SequenceStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__SEQUENCE_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..3a9201f6dbe --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structTypeObjectSupport.cxx @@ -0,0 +1,498 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file sequence_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "sequence_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "sequence_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_NestedSequenceElement_type_identifier( + TypeIdentifierPair& type_ids_NestedSequenceElement) +{ + + ReturnCode_t return_code_NestedSequenceElement {eprosima::fastdds::dds::RETCODE_OK}; + return_code_NestedSequenceElement = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "NestedSequenceElement", type_ids_NestedSequenceElement); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_NestedSequenceElement) + { + StructTypeFlag struct_flags_NestedSequenceElement = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_NestedSequenceElement = "NestedSequenceElement"; + eprosima::fastcdr::optional type_ann_builtin_NestedSequenceElement; + eprosima::fastcdr::optional ann_custom_NestedSequenceElement; + CompleteTypeDetail detail_NestedSequenceElement = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_NestedSequenceElement, ann_custom_NestedSequenceElement, type_name_NestedSequenceElement.to_string()); + CompleteStructHeader header_NestedSequenceElement; + header_NestedSequenceElement = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_NestedSequenceElement); + CompleteStructMemberSeq member_seq_NestedSequenceElement; + { + TypeIdentifierPair type_ids_my_string; + ReturnCode_t return_code_my_string {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_string = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_my_string); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_string) + { + { + SBound bound = 0; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "anonymous_string_unbounded", type_ids_my_string)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_string = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_string = 0x00000000; + bool common_my_string_ec {false}; + CommonStructMember common_my_string {TypeObjectUtils::build_common_struct_member(member_id_my_string, member_flags_my_string, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_string, common_my_string_ec))}; + if (!common_my_string_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_string member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_string = "my_string"; + eprosima::fastcdr::optional member_ann_builtin_my_string; + ann_custom_NestedSequenceElement.reset(); + CompleteMemberDetail detail_my_string = TypeObjectUtils::build_complete_member_detail(name_my_string, member_ann_builtin_my_string, ann_custom_NestedSequenceElement); + CompleteStructMember member_my_string = TypeObjectUtils::build_complete_struct_member(common_my_string, detail_my_string); + TypeObjectUtils::add_complete_struct_member(member_seq_NestedSequenceElement, member_my_string); + } + CompleteStructType struct_type_NestedSequenceElement = TypeObjectUtils::build_complete_struct_type(struct_flags_NestedSequenceElement, header_NestedSequenceElement, member_seq_NestedSequenceElement); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_NestedSequenceElement, type_name_NestedSequenceElement.to_string(), type_ids_NestedSequenceElement)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "NestedSequenceElement already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_ComplexSequenceElement_type_identifier( + TypeIdentifierPair& type_ids_ComplexSequenceElement) +{ + + ReturnCode_t return_code_ComplexSequenceElement {eprosima::fastdds::dds::RETCODE_OK}; + return_code_ComplexSequenceElement = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ComplexSequenceElement", type_ids_ComplexSequenceElement); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ComplexSequenceElement) + { + StructTypeFlag struct_flags_ComplexSequenceElement = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_ComplexSequenceElement = "ComplexSequenceElement"; + eprosima::fastcdr::optional type_ann_builtin_ComplexSequenceElement; + eprosima::fastcdr::optional ann_custom_ComplexSequenceElement; + CompleteTypeDetail detail_ComplexSequenceElement = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ComplexSequenceElement, ann_custom_ComplexSequenceElement, type_name_ComplexSequenceElement.to_string()); + CompleteStructHeader header_ComplexSequenceElement; + header_ComplexSequenceElement = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_ComplexSequenceElement); + CompleteStructMemberSeq member_seq_ComplexSequenceElement; + { + TypeIdentifierPair type_ids_my_short; + ReturnCode_t return_code_my_short {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_short = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int16_t", type_ids_my_short); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_short) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_short Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_short = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_short = 0x00000000; + bool common_my_short_ec {false}; + CommonStructMember common_my_short {TypeObjectUtils::build_common_struct_member(member_id_my_short, member_flags_my_short, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_short, common_my_short_ec))}; + if (!common_my_short_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_short member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_short = "my_short"; + eprosima::fastcdr::optional member_ann_builtin_my_short; + ann_custom_ComplexSequenceElement.reset(); + CompleteMemberDetail detail_my_short = TypeObjectUtils::build_complete_member_detail(name_my_short, member_ann_builtin_my_short, ann_custom_ComplexSequenceElement); + CompleteStructMember member_my_short = TypeObjectUtils::build_complete_struct_member(common_my_short, detail_my_short); + TypeObjectUtils::add_complete_struct_member(member_seq_ComplexSequenceElement, member_my_short); + } + { + TypeIdentifierPair type_ids_my_long; + ReturnCode_t return_code_my_long {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_long = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_my_long); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_long) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_long Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_long = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_long = 0x00000001; + bool common_my_long_ec {false}; + CommonStructMember common_my_long {TypeObjectUtils::build_common_struct_member(member_id_my_long, member_flags_my_long, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_long, common_my_long_ec))}; + if (!common_my_long_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_long member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_long = "my_long"; + eprosima::fastcdr::optional member_ann_builtin_my_long; + ann_custom_ComplexSequenceElement.reset(); + CompleteMemberDetail detail_my_long = TypeObjectUtils::build_complete_member_detail(name_my_long, member_ann_builtin_my_long, ann_custom_ComplexSequenceElement); + CompleteStructMember member_my_long = TypeObjectUtils::build_complete_struct_member(common_my_long, detail_my_long); + TypeObjectUtils::add_complete_struct_member(member_seq_ComplexSequenceElement, member_my_long); + } + { + TypeIdentifierPair type_ids_my_complex_element; + ReturnCode_t return_code_my_complex_element {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_complex_element = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "NestedSequenceElement", type_ids_my_complex_element); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_element) + { + ::register_NestedSequenceElement_type_identifier(type_ids_my_complex_element); + } + StructMemberFlag member_flags_my_complex_element = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_complex_element = 0x00000002; + bool common_my_complex_element_ec {false}; + CommonStructMember common_my_complex_element {TypeObjectUtils::build_common_struct_member(member_id_my_complex_element, member_flags_my_complex_element, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_element, common_my_complex_element_ec))}; + if (!common_my_complex_element_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_complex_element member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_complex_element = "my_complex_element"; + eprosima::fastcdr::optional member_ann_builtin_my_complex_element; + ann_custom_ComplexSequenceElement.reset(); + CompleteMemberDetail detail_my_complex_element = TypeObjectUtils::build_complete_member_detail(name_my_complex_element, member_ann_builtin_my_complex_element, ann_custom_ComplexSequenceElement); + CompleteStructMember member_my_complex_element = TypeObjectUtils::build_complete_struct_member(common_my_complex_element, detail_my_complex_element); + TypeObjectUtils::add_complete_struct_member(member_seq_ComplexSequenceElement, member_my_complex_element); + } + CompleteStructType struct_type_ComplexSequenceElement = TypeObjectUtils::build_complete_struct_type(struct_flags_ComplexSequenceElement, header_ComplexSequenceElement, member_seq_ComplexSequenceElement); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_ComplexSequenceElement, type_name_ComplexSequenceElement.to_string(), type_ids_ComplexSequenceElement)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ComplexSequenceElement already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_SequenceStruct_type_identifier( + TypeIdentifierPair& type_ids_SequenceStruct) +{ + + ReturnCode_t return_code_SequenceStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_SequenceStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "SequenceStruct", type_ids_SequenceStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_SequenceStruct) + { + StructTypeFlag struct_flags_SequenceStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_SequenceStruct = "SequenceStruct"; + eprosima::fastcdr::optional type_ann_builtin_SequenceStruct; + eprosima::fastcdr::optional ann_custom_SequenceStruct; + CompleteTypeDetail detail_SequenceStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_SequenceStruct, ann_custom_SequenceStruct, type_name_SequenceStruct.to_string()); + CompleteStructHeader header_SequenceStruct; + header_SequenceStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_SequenceStruct); + CompleteStructMemberSeq member_seq_SequenceStruct; + { + TypeIdentifierPair type_ids_my_basic_sequence; + ReturnCode_t return_code_my_basic_sequence {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_basic_sequence = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_sequence_char_unbounded", type_ids_my_basic_sequence); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_basic_sequence) + { + return_code_my_basic_sequence = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_char", type_ids_my_basic_sequence); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_basic_sequence) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Sequence element TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool element_identifier_anonymous_sequence_char_unbounded_ec {false}; + TypeIdentifier* element_identifier_anonymous_sequence_char_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_basic_sequence, element_identifier_anonymous_sequence_char_unbounded_ec))}; + if (!element_identifier_anonymous_sequence_char_unbounded_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Sequence element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_sequence_char_unbounded = EK_COMPLETE; + if (TK_NONE == type_ids_my_basic_sequence.type_identifier2()._d()) + { + equiv_kind_anonymous_sequence_char_unbounded = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_sequence_char_unbounded = 0; + PlainCollectionHeader header_anonymous_sequence_char_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_sequence_char_unbounded, element_flags_anonymous_sequence_char_unbounded); + { + SBound bound = 0; + PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_anonymous_sequence_char_unbounded, bound, + eprosima::fastcdr::external(element_identifier_anonymous_sequence_char_unbounded)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "anonymous_sequence_char_unbounded", type_ids_my_basic_sequence)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_sequence_char_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_basic_sequence = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_basic_sequence = 0x00000000; + bool common_my_basic_sequence_ec {false}; + CommonStructMember common_my_basic_sequence {TypeObjectUtils::build_common_struct_member(member_id_my_basic_sequence, member_flags_my_basic_sequence, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_basic_sequence, common_my_basic_sequence_ec))}; + if (!common_my_basic_sequence_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_basic_sequence member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_basic_sequence = "my_basic_sequence"; + eprosima::fastcdr::optional member_ann_builtin_my_basic_sequence; + ann_custom_SequenceStruct.reset(); + CompleteMemberDetail detail_my_basic_sequence = TypeObjectUtils::build_complete_member_detail(name_my_basic_sequence, member_ann_builtin_my_basic_sequence, ann_custom_SequenceStruct); + CompleteStructMember member_my_basic_sequence = TypeObjectUtils::build_complete_struct_member(common_my_basic_sequence, detail_my_basic_sequence); + TypeObjectUtils::add_complete_struct_member(member_seq_SequenceStruct, member_my_basic_sequence); + } + { + TypeIdentifierPair type_ids_my_bounded_sequence; + ReturnCode_t return_code_my_bounded_sequence {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_bounded_sequence = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_sequence_float_13", type_ids_my_bounded_sequence); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_bounded_sequence) + { + return_code_my_bounded_sequence = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_float", type_ids_my_bounded_sequence); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_bounded_sequence) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Sequence element TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool element_identifier_anonymous_sequence_float_13_ec {false}; + TypeIdentifier* element_identifier_anonymous_sequence_float_13 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_bounded_sequence, element_identifier_anonymous_sequence_float_13_ec))}; + if (!element_identifier_anonymous_sequence_float_13_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Sequence element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_sequence_float_13 = EK_COMPLETE; + if (TK_NONE == type_ids_my_bounded_sequence.type_identifier2()._d()) + { + equiv_kind_anonymous_sequence_float_13 = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_sequence_float_13 = 0; + PlainCollectionHeader header_anonymous_sequence_float_13 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_sequence_float_13, element_flags_anonymous_sequence_float_13); + { + SBound bound = static_cast(13); + PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_anonymous_sequence_float_13, bound, + eprosima::fastcdr::external(element_identifier_anonymous_sequence_float_13)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "anonymous_sequence_float_13", type_ids_my_bounded_sequence)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_sequence_float_13 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_bounded_sequence = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_bounded_sequence = 0x00000001; + bool common_my_bounded_sequence_ec {false}; + CommonStructMember common_my_bounded_sequence {TypeObjectUtils::build_common_struct_member(member_id_my_bounded_sequence, member_flags_my_bounded_sequence, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_bounded_sequence, common_my_bounded_sequence_ec))}; + if (!common_my_bounded_sequence_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_bounded_sequence member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_bounded_sequence = "my_bounded_sequence"; + eprosima::fastcdr::optional member_ann_builtin_my_bounded_sequence; + ann_custom_SequenceStruct.reset(); + CompleteMemberDetail detail_my_bounded_sequence = TypeObjectUtils::build_complete_member_detail(name_my_bounded_sequence, member_ann_builtin_my_bounded_sequence, ann_custom_SequenceStruct); + CompleteStructMember member_my_bounded_sequence = TypeObjectUtils::build_complete_struct_member(common_my_bounded_sequence, detail_my_bounded_sequence); + TypeObjectUtils::add_complete_struct_member(member_seq_SequenceStruct, member_my_bounded_sequence); + } + { + TypeIdentifierPair type_ids_my_complex_sequence; + ReturnCode_t return_code_my_complex_sequence {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_complex_sequence = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_sequence_ComplexSequenceElement_unbounded", type_ids_my_complex_sequence); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_sequence) + { + return_code_my_complex_sequence = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ComplexSequenceElement", type_ids_my_complex_sequence); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_sequence) + { + ::register_ComplexSequenceElement_type_identifier(type_ids_my_complex_sequence); + } + bool element_identifier_anonymous_sequence_ComplexSequenceElement_unbounded_ec {false}; + TypeIdentifier* element_identifier_anonymous_sequence_ComplexSequenceElement_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_sequence, element_identifier_anonymous_sequence_ComplexSequenceElement_unbounded_ec))}; + if (!element_identifier_anonymous_sequence_ComplexSequenceElement_unbounded_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Sequence element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_sequence_ComplexSequenceElement_unbounded = EK_COMPLETE; + if (TK_NONE == type_ids_my_complex_sequence.type_identifier2()._d()) + { + equiv_kind_anonymous_sequence_ComplexSequenceElement_unbounded = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_sequence_ComplexSequenceElement_unbounded = 0; + PlainCollectionHeader header_anonymous_sequence_ComplexSequenceElement_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_sequence_ComplexSequenceElement_unbounded, element_flags_anonymous_sequence_ComplexSequenceElement_unbounded); + { + SBound bound = 0; + PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_anonymous_sequence_ComplexSequenceElement_unbounded, bound, + eprosima::fastcdr::external(element_identifier_anonymous_sequence_ComplexSequenceElement_unbounded)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "anonymous_sequence_ComplexSequenceElement_unbounded", type_ids_my_complex_sequence)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_sequence_ComplexSequenceElement_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_complex_sequence = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_complex_sequence = 0x00000002; + bool common_my_complex_sequence_ec {false}; + CommonStructMember common_my_complex_sequence {TypeObjectUtils::build_common_struct_member(member_id_my_complex_sequence, member_flags_my_complex_sequence, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_sequence, common_my_complex_sequence_ec))}; + if (!common_my_complex_sequence_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_complex_sequence member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_complex_sequence = "my_complex_sequence"; + eprosima::fastcdr::optional member_ann_builtin_my_complex_sequence; + ann_custom_SequenceStruct.reset(); + CompleteMemberDetail detail_my_complex_sequence = TypeObjectUtils::build_complete_member_detail(name_my_complex_sequence, member_ann_builtin_my_complex_sequence, ann_custom_SequenceStruct); + CompleteStructMember member_my_complex_sequence = TypeObjectUtils::build_complete_struct_member(common_my_complex_sequence, detail_my_complex_sequence); + TypeObjectUtils::add_complete_struct_member(member_seq_SequenceStruct, member_my_complex_sequence); + } + { + TypeIdentifierPair type_ids_my_complex_bounded_sequence; + ReturnCode_t return_code_my_complex_bounded_sequence {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_complex_bounded_sequence = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_sequence_ComplexSequenceElement_123", type_ids_my_complex_bounded_sequence); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_bounded_sequence) + { + return_code_my_complex_bounded_sequence = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ComplexSequenceElement", type_ids_my_complex_bounded_sequence); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_bounded_sequence) + { + ::register_ComplexSequenceElement_type_identifier(type_ids_my_complex_bounded_sequence); + } + bool element_identifier_anonymous_sequence_ComplexSequenceElement_123_ec {false}; + TypeIdentifier* element_identifier_anonymous_sequence_ComplexSequenceElement_123 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_bounded_sequence, element_identifier_anonymous_sequence_ComplexSequenceElement_123_ec))}; + if (!element_identifier_anonymous_sequence_ComplexSequenceElement_123_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Sequence element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_sequence_ComplexSequenceElement_123 = EK_COMPLETE; + if (TK_NONE == type_ids_my_complex_bounded_sequence.type_identifier2()._d()) + { + equiv_kind_anonymous_sequence_ComplexSequenceElement_123 = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_sequence_ComplexSequenceElement_123 = 0; + PlainCollectionHeader header_anonymous_sequence_ComplexSequenceElement_123 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_sequence_ComplexSequenceElement_123, element_flags_anonymous_sequence_ComplexSequenceElement_123); + { + SBound bound = static_cast(123); + PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_anonymous_sequence_ComplexSequenceElement_123, bound, + eprosima::fastcdr::external(element_identifier_anonymous_sequence_ComplexSequenceElement_123)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "anonymous_sequence_ComplexSequenceElement_123", type_ids_my_complex_bounded_sequence)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_sequence_ComplexSequenceElement_123 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_complex_bounded_sequence = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_complex_bounded_sequence = 0x00000003; + bool common_my_complex_bounded_sequence_ec {false}; + CommonStructMember common_my_complex_bounded_sequence {TypeObjectUtils::build_common_struct_member(member_id_my_complex_bounded_sequence, member_flags_my_complex_bounded_sequence, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_bounded_sequence, common_my_complex_bounded_sequence_ec))}; + if (!common_my_complex_bounded_sequence_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_complex_bounded_sequence member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_complex_bounded_sequence = "my_complex_bounded_sequence"; + eprosima::fastcdr::optional member_ann_builtin_my_complex_bounded_sequence; + ann_custom_SequenceStruct.reset(); + CompleteMemberDetail detail_my_complex_bounded_sequence = TypeObjectUtils::build_complete_member_detail(name_my_complex_bounded_sequence, member_ann_builtin_my_complex_bounded_sequence, ann_custom_SequenceStruct); + CompleteStructMember member_my_complex_bounded_sequence = TypeObjectUtils::build_complete_struct_member(common_my_complex_bounded_sequence, detail_my_complex_bounded_sequence); + TypeObjectUtils::add_complete_struct_member(member_seq_SequenceStruct, member_my_complex_bounded_sequence); + } + CompleteStructType struct_type_SequenceStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_SequenceStruct, header_SequenceStruct, member_seq_SequenceStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_SequenceStruct, type_name_SequenceStruct.to_string(), type_ids_SequenceStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "SequenceStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..aa34019b7ea --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/gen/sequence_structTypeObjectSupport.hpp @@ -0,0 +1,80 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file sequence_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__SEQUENCE_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__SEQUENCE_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register NestedSequenceElement related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_NestedSequenceElement_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register ComplexSequenceElement related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_ComplexSequenceElement_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register SequenceStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_SequenceStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__SEQUENCE_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/sequence_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/sequence_struct.idl new file mode 100644 index 00000000000..9a776855590 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/sequence_struct.idl @@ -0,0 +1,19 @@ +struct NestedSequenceElement +{ + string my_string; +}; + +struct ComplexSequenceElement +{ + short my_short; + long my_long; + NestedSequenceElement my_complex_element; +}; + +struct SequenceStruct +{ + sequence my_basic_sequence; + sequence my_bounded_sequence; + sequence my_complex_sequence; + sequence my_complex_bounded_sequence; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_struct.hpp new file mode 100644 index 00000000000..fb5664b8732 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_struct.hpp @@ -0,0 +1,331 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file string_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__STRING_STRUCT_HPP +#define FAST_DDS_GENERATED__STRING_STRUCT_HPP + +#include +#include +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(STRING_STRUCT_SOURCE) +#define STRING_STRUCT_DllAPI __declspec( dllexport ) +#else +#define STRING_STRUCT_DllAPI __declspec( dllimport ) +#endif // STRING_STRUCT_SOURCE +#else +#define STRING_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define STRING_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure StringStruct defined by the user in the IDL file. + * @ingroup string_struct + */ +class StringStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport StringStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~StringStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object StringStruct that will be copied. + */ + eProsima_user_DllExport StringStruct( + const StringStruct& x) + { + m_my_string = x.m_my_string; + + m_my_wstring = x.m_my_wstring; + + m_my_bounded_string = x.m_my_bounded_string; + + m_my_bounded_wstring = x.m_my_bounded_wstring; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object StringStruct that will be copied. + */ + eProsima_user_DllExport StringStruct( + StringStruct&& x) noexcept + { + m_my_string = std::move(x.m_my_string); + m_my_wstring = std::move(x.m_my_wstring); + m_my_bounded_string = std::move(x.m_my_bounded_string); + m_my_bounded_wstring = std::move(x.m_my_bounded_wstring); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object StringStruct that will be copied. + */ + eProsima_user_DllExport StringStruct& operator =( + const StringStruct& x) + { + + m_my_string = x.m_my_string; + + m_my_wstring = x.m_my_wstring; + + m_my_bounded_string = x.m_my_bounded_string; + + m_my_bounded_wstring = x.m_my_bounded_wstring; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object StringStruct that will be copied. + */ + eProsima_user_DllExport StringStruct& operator =( + StringStruct&& x) noexcept + { + + m_my_string = std::move(x.m_my_string); + m_my_wstring = std::move(x.m_my_wstring); + m_my_bounded_string = std::move(x.m_my_bounded_string); + m_my_bounded_wstring = std::move(x.m_my_bounded_wstring); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x StringStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const StringStruct& x) const + { + return (m_my_string == x.m_my_string && + m_my_wstring == x.m_my_wstring && + m_my_bounded_string == x.m_my_bounded_string && + m_my_bounded_wstring == x.m_my_bounded_wstring); + } + + /*! + * @brief Comparison operator. + * @param x StringStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const StringStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member my_string + * @param _my_string New value to be copied in member my_string + */ + eProsima_user_DllExport void my_string( + const std::string& _my_string) + { + m_my_string = _my_string; + } + + /*! + * @brief This function moves the value in member my_string + * @param _my_string New value to be moved in member my_string + */ + eProsima_user_DllExport void my_string( + std::string&& _my_string) + { + m_my_string = std::move(_my_string); + } + + /*! + * @brief This function returns a constant reference to member my_string + * @return Constant reference to member my_string + */ + eProsima_user_DllExport const std::string& my_string() const + { + return m_my_string; + } + + /*! + * @brief This function returns a reference to member my_string + * @return Reference to member my_string + */ + eProsima_user_DllExport std::string& my_string() + { + return m_my_string; + } + + + /*! + * @brief This function copies the value in member my_wstring + * @param _my_wstring New value to be copied in member my_wstring + */ + eProsima_user_DllExport void my_wstring( + const std::wstring& _my_wstring) + { + m_my_wstring = _my_wstring; + } + + /*! + * @brief This function moves the value in member my_wstring + * @param _my_wstring New value to be moved in member my_wstring + */ + eProsima_user_DllExport void my_wstring( + std::wstring&& _my_wstring) + { + m_my_wstring = std::move(_my_wstring); + } + + /*! + * @brief This function returns a constant reference to member my_wstring + * @return Constant reference to member my_wstring + */ + eProsima_user_DllExport const std::wstring& my_wstring() const + { + return m_my_wstring; + } + + /*! + * @brief This function returns a reference to member my_wstring + * @return Reference to member my_wstring + */ + eProsima_user_DllExport std::wstring& my_wstring() + { + return m_my_wstring; + } + + + /*! + * @brief This function copies the value in member my_bounded_string + * @param _my_bounded_string New value to be copied in member my_bounded_string + */ + eProsima_user_DllExport void my_bounded_string( + const eprosima::fastcdr::fixed_string<41925>& _my_bounded_string) + { + m_my_bounded_string = _my_bounded_string; + } + + /*! + * @brief This function moves the value in member my_bounded_string + * @param _my_bounded_string New value to be moved in member my_bounded_string + */ + eProsima_user_DllExport void my_bounded_string( + eprosima::fastcdr::fixed_string<41925>&& _my_bounded_string) + { + m_my_bounded_string = std::move(_my_bounded_string); + } + + /*! + * @brief This function returns a constant reference to member my_bounded_string + * @return Constant reference to member my_bounded_string + */ + eProsima_user_DllExport const eprosima::fastcdr::fixed_string<41925>& my_bounded_string() const + { + return m_my_bounded_string; + } + + /*! + * @brief This function returns a reference to member my_bounded_string + * @return Reference to member my_bounded_string + */ + eProsima_user_DllExport eprosima::fastcdr::fixed_string<41925>& my_bounded_string() + { + return m_my_bounded_string; + } + + + /*! + * @brief This function copies the value in member my_bounded_wstring + * @param _my_bounded_wstring New value to be copied in member my_bounded_wstring + */ + eProsima_user_DllExport void my_bounded_wstring( + const std::wstring& _my_bounded_wstring) + { + m_my_bounded_wstring = _my_bounded_wstring; + } + + /*! + * @brief This function moves the value in member my_bounded_wstring + * @param _my_bounded_wstring New value to be moved in member my_bounded_wstring + */ + eProsima_user_DllExport void my_bounded_wstring( + std::wstring&& _my_bounded_wstring) + { + m_my_bounded_wstring = std::move(_my_bounded_wstring); + } + + /*! + * @brief This function returns a constant reference to member my_bounded_wstring + * @return Constant reference to member my_bounded_wstring + */ + eProsima_user_DllExport const std::wstring& my_bounded_wstring() const + { + return m_my_bounded_wstring; + } + + /*! + * @brief This function returns a reference to member my_bounded_wstring + * @return Reference to member my_bounded_wstring + */ + eProsima_user_DllExport std::wstring& my_bounded_wstring() + { + return m_my_bounded_wstring; + } + + + +private: + + std::string m_my_string; + std::wstring m_my_wstring; + eprosima::fastcdr::fixed_string<41925> m_my_bounded_string; + std::wstring m_my_bounded_wstring; + +}; + +#endif // _FAST_DDS_GENERATED_STRING_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structCdrAux.hpp new file mode 100644 index 00000000000..1d5e43a5a5a --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structCdrAux.hpp @@ -0,0 +1,46 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file string_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__STRING_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__STRING_STRUCTCDRAUX_HPP + +#include "string_struct.hpp" + +constexpr uint32_t StringStruct_max_cdr_typesize {84566UL}; +constexpr uint32_t StringStruct_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const StringStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__STRING_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structCdrAux.ipp new file mode 100644 index 00000000000..732a933e09a --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structCdrAux.ipp @@ -0,0 +1,142 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file string_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__STRING_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__STRING_STRUCTCDRAUX_IPP + +#include "string_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const StringStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_string(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_wstring(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_bounded_string(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3), + data.my_bounded_wstring(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const StringStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_string() + << eprosima::fastcdr::MemberId(1) << data.my_wstring() + << eprosima::fastcdr::MemberId(2) << data.my_bounded_string() + << eprosima::fastcdr::MemberId(3) << data.my_bounded_wstring() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + StringStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_string(); + break; + + case 1: + dcdr >> data.my_wstring(); + break; + + case 2: + dcdr >> data.my_bounded_string(); + break; + + case 3: + dcdr >> data.my_bounded_wstring(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const StringStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__STRING_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.cxx new file mode 100644 index 00000000000..68f1132a3dc --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.cxx @@ -0,0 +1,229 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file string_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "string_structPubSubTypes.hpp" + +#include +#include + +#include "string_structCdrAux.hpp" +#include "string_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +StringStructPubSubType::StringStructPubSubType() +{ + setName("StringStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(StringStruct::getMaxCdrSerializedSize()); +#else + StringStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = StringStruct_max_key_cdr_typesize > 16 ? StringStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +StringStructPubSubType::~StringStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool StringStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const StringStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool StringStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + StringStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function StringStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* StringStructPubSubType::createData() +{ + return reinterpret_cast(new StringStruct()); +} + +void StringStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool StringStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const StringStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + StringStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || StringStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void StringStructPubSubType::register_type_object_representation() +{ + register_StringStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "string_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.hpp new file mode 100644 index 00000000000..e8e375b8b10 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structPubSubTypes.hpp @@ -0,0 +1,133 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file string_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__STRING_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__STRING_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "string_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated string_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type StringStruct defined by the user in the IDL file. + * @ingroup string_struct + */ +class StringStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef StringStruct type; + + eProsima_user_DllExport StringStructPubSubType(); + + eProsima_user_DllExport ~StringStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__STRING_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..c598b5d2b0c --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structTypeObjectSupport.cxx @@ -0,0 +1,222 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file string_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "string_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "string_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_StringStruct_type_identifier( + TypeIdentifierPair& type_ids_StringStruct) +{ + + ReturnCode_t return_code_StringStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_StringStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "StringStruct", type_ids_StringStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_StringStruct) + { + StructTypeFlag struct_flags_StringStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_StringStruct = "StringStruct"; + eprosima::fastcdr::optional type_ann_builtin_StringStruct; + eprosima::fastcdr::optional ann_custom_StringStruct; + CompleteTypeDetail detail_StringStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_StringStruct, ann_custom_StringStruct, type_name_StringStruct.to_string()); + CompleteStructHeader header_StringStruct; + header_StringStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_StringStruct); + CompleteStructMemberSeq member_seq_StringStruct; + { + TypeIdentifierPair type_ids_my_string; + ReturnCode_t return_code_my_string {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_string = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_my_string); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_string) + { + { + SBound bound = 0; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "anonymous_string_unbounded", type_ids_my_string)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_string = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_string = 0x00000000; + bool common_my_string_ec {false}; + CommonStructMember common_my_string {TypeObjectUtils::build_common_struct_member(member_id_my_string, member_flags_my_string, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_string, common_my_string_ec))}; + if (!common_my_string_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_string member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_string = "my_string"; + eprosima::fastcdr::optional member_ann_builtin_my_string; + ann_custom_StringStruct.reset(); + CompleteMemberDetail detail_my_string = TypeObjectUtils::build_complete_member_detail(name_my_string, member_ann_builtin_my_string, ann_custom_StringStruct); + CompleteStructMember member_my_string = TypeObjectUtils::build_complete_struct_member(common_my_string, detail_my_string); + TypeObjectUtils::add_complete_struct_member(member_seq_StringStruct, member_my_string); + } + { + TypeIdentifierPair type_ids_my_wstring; + ReturnCode_t return_code_my_wstring {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_wstring = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_wstring_unbounded", type_ids_my_wstring); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_wstring) + { + { + SBound bound = 0; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "anonymous_wstring_unbounded", type_ids_my_wstring, true)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_wstring_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_wstring = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_wstring = 0x00000001; + bool common_my_wstring_ec {false}; + CommonStructMember common_my_wstring {TypeObjectUtils::build_common_struct_member(member_id_my_wstring, member_flags_my_wstring, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_wstring, common_my_wstring_ec))}; + if (!common_my_wstring_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_wstring member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_wstring = "my_wstring"; + eprosima::fastcdr::optional member_ann_builtin_my_wstring; + ann_custom_StringStruct.reset(); + CompleteMemberDetail detail_my_wstring = TypeObjectUtils::build_complete_member_detail(name_my_wstring, member_ann_builtin_my_wstring, ann_custom_StringStruct); + CompleteStructMember member_my_wstring = TypeObjectUtils::build_complete_struct_member(common_my_wstring, detail_my_wstring); + TypeObjectUtils::add_complete_struct_member(member_seq_StringStruct, member_my_wstring); + } + { + TypeIdentifierPair type_ids_my_bounded_string; + ReturnCode_t return_code_my_bounded_string {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_bounded_string = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_41925", type_ids_my_bounded_string); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_bounded_string) + { + { + LBound bound = 41925; + StringLTypeDefn string_ldefn = TypeObjectUtils::build_string_l_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_l_string_type_identifier(string_ldefn, + "anonymous_string_41925", type_ids_my_bounded_string)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_41925 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_bounded_string = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_bounded_string = 0x00000002; + bool common_my_bounded_string_ec {false}; + CommonStructMember common_my_bounded_string {TypeObjectUtils::build_common_struct_member(member_id_my_bounded_string, member_flags_my_bounded_string, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_bounded_string, common_my_bounded_string_ec))}; + if (!common_my_bounded_string_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_bounded_string member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_bounded_string = "my_bounded_string"; + eprosima::fastcdr::optional member_ann_builtin_my_bounded_string; + ann_custom_StringStruct.reset(); + CompleteMemberDetail detail_my_bounded_string = TypeObjectUtils::build_complete_member_detail(name_my_bounded_string, member_ann_builtin_my_bounded_string, ann_custom_StringStruct); + CompleteStructMember member_my_bounded_string = TypeObjectUtils::build_complete_struct_member(common_my_bounded_string, detail_my_bounded_string); + TypeObjectUtils::add_complete_struct_member(member_seq_StringStruct, member_my_bounded_string); + } + { + TypeIdentifierPair type_ids_my_bounded_wstring; + ReturnCode_t return_code_my_bounded_wstring {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_bounded_wstring = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_wstring_20925", type_ids_my_bounded_wstring); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_bounded_wstring) + { + { + LBound bound = 20925; + StringLTypeDefn string_ldefn = TypeObjectUtils::build_string_l_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_l_string_type_identifier(string_ldefn, + "anonymous_wstring_20925", type_ids_my_bounded_wstring, true)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_wstring_20925 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_bounded_wstring = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_bounded_wstring = 0x00000003; + bool common_my_bounded_wstring_ec {false}; + CommonStructMember common_my_bounded_wstring {TypeObjectUtils::build_common_struct_member(member_id_my_bounded_wstring, member_flags_my_bounded_wstring, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_bounded_wstring, common_my_bounded_wstring_ec))}; + if (!common_my_bounded_wstring_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_bounded_wstring member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_bounded_wstring = "my_bounded_wstring"; + eprosima::fastcdr::optional member_ann_builtin_my_bounded_wstring; + ann_custom_StringStruct.reset(); + CompleteMemberDetail detail_my_bounded_wstring = TypeObjectUtils::build_complete_member_detail(name_my_bounded_wstring, member_ann_builtin_my_bounded_wstring, ann_custom_StringStruct); + CompleteStructMember member_my_bounded_wstring = TypeObjectUtils::build_complete_struct_member(common_my_bounded_wstring, detail_my_bounded_wstring); + TypeObjectUtils::add_complete_struct_member(member_seq_StringStruct, member_my_bounded_wstring); + } + CompleteStructType struct_type_StringStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_StringStruct, header_StringStruct, member_seq_StringStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_StringStruct, type_name_StringStruct.to_string(), type_ids_StringStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "StringStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..d62ad4c887c --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/gen/string_structTypeObjectSupport.hpp @@ -0,0 +1,56 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file string_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__STRING_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__STRING_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register StringStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_StringStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__STRING_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/string_struct/string_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/string_struct.idl new file mode 100644 index 00000000000..58043c722f2 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/string_struct/string_struct.idl @@ -0,0 +1,7 @@ +struct StringStruct +{ + string my_string; + wstring my_wstring; + string<41925> my_bounded_string; + wstring<20925> my_bounded_wstring; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_struct.hpp new file mode 100644 index 00000000000..b6a0f41d9de --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_struct.hpp @@ -0,0 +1,710 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file struct_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__STRUCT_STRUCT_HPP +#define FAST_DDS_GENERATED__STRUCT_STRUCT_HPP + +#include +#include +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(STRUCT_STRUCT_SOURCE) +#define STRUCT_STRUCT_DllAPI __declspec( dllexport ) +#else +#define STRUCT_STRUCT_DllAPI __declspec( dllimport ) +#endif // STRUCT_STRUCT_SOURCE +#else +#define STRUCT_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define STRUCT_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure GrandparentStruct defined by the user in the IDL file. + * @ingroup struct_struct + */ +class GrandparentStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport GrandparentStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~GrandparentStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object GrandparentStruct that will be copied. + */ + eProsima_user_DllExport GrandparentStruct( + const GrandparentStruct& x) + { + m_my_long = x.m_my_long; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object GrandparentStruct that will be copied. + */ + eProsima_user_DllExport GrandparentStruct( + GrandparentStruct&& x) noexcept + { + m_my_long = x.m_my_long; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object GrandparentStruct that will be copied. + */ + eProsima_user_DllExport GrandparentStruct& operator =( + const GrandparentStruct& x) + { + + m_my_long = x.m_my_long; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object GrandparentStruct that will be copied. + */ + eProsima_user_DllExport GrandparentStruct& operator =( + GrandparentStruct&& x) noexcept + { + + m_my_long = x.m_my_long; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x GrandparentStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const GrandparentStruct& x) const + { + return (m_my_long == x.m_my_long); + } + + /*! + * @brief Comparison operator. + * @param x GrandparentStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const GrandparentStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_long + * @param _my_long New value for member my_long + */ + eProsima_user_DllExport void my_long( + int32_t _my_long) + { + m_my_long = _my_long; + } + + /*! + * @brief This function returns the value of member my_long + * @return Value of member my_long + */ + eProsima_user_DllExport int32_t my_long() const + { + return m_my_long; + } + + /*! + * @brief This function returns a reference to member my_long + * @return Reference to member my_long + */ + eProsima_user_DllExport int32_t& my_long() + { + return m_my_long; + } + + + +private: + + int32_t m_my_long{0}; + +}; +/*! + * @brief This class represents the structure ParentStruct defined by the user in the IDL file. + * @ingroup struct_struct + */ +class ParentStruct : public GrandparentStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport ParentStruct() + : GrandparentStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~ParentStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object ParentStruct that will be copied. + */ + eProsima_user_DllExport ParentStruct( + const ParentStruct& x) + : GrandparentStruct(x) + { + m_my_short = x.m_my_short; + + m_my_string = x.m_my_string; + + m_my_grandparent = x.m_my_grandparent; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object ParentStruct that will be copied. + */ + eProsima_user_DllExport ParentStruct( + ParentStruct&& x) noexcept + : GrandparentStruct(std::move(x)) + + { + m_my_short = x.m_my_short; + m_my_string = std::move(x.m_my_string); + m_my_grandparent = std::move(x.m_my_grandparent); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object ParentStruct that will be copied. + */ + eProsima_user_DllExport ParentStruct& operator =( + const ParentStruct& x) + { + GrandparentStruct::operator =(x); + + m_my_short = x.m_my_short; + + m_my_string = x.m_my_string; + + m_my_grandparent = x.m_my_grandparent; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object ParentStruct that will be copied. + */ + eProsima_user_DllExport ParentStruct& operator =( + ParentStruct&& x) noexcept + { + GrandparentStruct::operator =(std::move(x)); + + m_my_short = x.m_my_short; + m_my_string = std::move(x.m_my_string); + m_my_grandparent = std::move(x.m_my_grandparent); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x ParentStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const ParentStruct& x) const + { + if (GrandparentStruct::operator !=(x)) + { + return false; + } + return (m_my_short == x.m_my_short && + m_my_string == x.m_my_string && + m_my_grandparent == x.m_my_grandparent); + } + + /*! + * @brief Comparison operator. + * @param x ParentStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const ParentStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_short + * @param _my_short New value for member my_short + */ + eProsima_user_DllExport void my_short( + int16_t _my_short) + { + m_my_short = _my_short; + } + + /*! + * @brief This function returns the value of member my_short + * @return Value of member my_short + */ + eProsima_user_DllExport int16_t my_short() const + { + return m_my_short; + } + + /*! + * @brief This function returns a reference to member my_short + * @return Reference to member my_short + */ + eProsima_user_DllExport int16_t& my_short() + { + return m_my_short; + } + + + /*! + * @brief This function copies the value in member my_string + * @param _my_string New value to be copied in member my_string + */ + eProsima_user_DllExport void my_string( + const std::string& _my_string) + { + m_my_string = _my_string; + } + + /*! + * @brief This function moves the value in member my_string + * @param _my_string New value to be moved in member my_string + */ + eProsima_user_DllExport void my_string( + std::string&& _my_string) + { + m_my_string = std::move(_my_string); + } + + /*! + * @brief This function returns a constant reference to member my_string + * @return Constant reference to member my_string + */ + eProsima_user_DllExport const std::string& my_string() const + { + return m_my_string; + } + + /*! + * @brief This function returns a reference to member my_string + * @return Reference to member my_string + */ + eProsima_user_DllExport std::string& my_string() + { + return m_my_string; + } + + + /*! + * @brief This function copies the value in member my_grandparent + * @param _my_grandparent New value to be copied in member my_grandparent + */ + eProsima_user_DllExport void my_grandparent( + const GrandparentStruct& _my_grandparent) + { + m_my_grandparent = _my_grandparent; + } + + /*! + * @brief This function moves the value in member my_grandparent + * @param _my_grandparent New value to be moved in member my_grandparent + */ + eProsima_user_DllExport void my_grandparent( + GrandparentStruct&& _my_grandparent) + { + m_my_grandparent = std::move(_my_grandparent); + } + + /*! + * @brief This function returns a constant reference to member my_grandparent + * @return Constant reference to member my_grandparent + */ + eProsima_user_DllExport const GrandparentStruct& my_grandparent() const + { + return m_my_grandparent; + } + + /*! + * @brief This function returns a reference to member my_grandparent + * @return Reference to member my_grandparent + */ + eProsima_user_DllExport GrandparentStruct& my_grandparent() + { + return m_my_grandparent; + } + + + +private: + + int16_t m_my_short{0}; + std::string m_my_string; + GrandparentStruct m_my_grandparent; + +}; +/*! + * @brief This class represents the structure NestedStructElement defined by the user in the IDL file. + * @ingroup struct_struct + */ +class NestedStructElement +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport NestedStructElement() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~NestedStructElement() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object NestedStructElement that will be copied. + */ + eProsima_user_DllExport NestedStructElement( + const NestedStructElement& x) + { + m_my_boolean = x.m_my_boolean; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object NestedStructElement that will be copied. + */ + eProsima_user_DllExport NestedStructElement( + NestedStructElement&& x) noexcept + { + m_my_boolean = x.m_my_boolean; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object NestedStructElement that will be copied. + */ + eProsima_user_DllExport NestedStructElement& operator =( + const NestedStructElement& x) + { + + m_my_boolean = x.m_my_boolean; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object NestedStructElement that will be copied. + */ + eProsima_user_DllExport NestedStructElement& operator =( + NestedStructElement&& x) noexcept + { + + m_my_boolean = x.m_my_boolean; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x NestedStructElement object to compare. + */ + eProsima_user_DllExport bool operator ==( + const NestedStructElement& x) const + { + return (m_my_boolean == x.m_my_boolean); + } + + /*! + * @brief Comparison operator. + * @param x NestedStructElement object to compare. + */ + eProsima_user_DllExport bool operator !=( + const NestedStructElement& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member my_boolean + * @param _my_boolean New value for member my_boolean + */ + eProsima_user_DllExport void my_boolean( + bool _my_boolean) + { + m_my_boolean = _my_boolean; + } + + /*! + * @brief This function returns the value of member my_boolean + * @return Value of member my_boolean + */ + eProsima_user_DllExport bool my_boolean() const + { + return m_my_boolean; + } + + /*! + * @brief This function returns a reference to member my_boolean + * @return Reference to member my_boolean + */ + eProsima_user_DllExport bool& my_boolean() + { + return m_my_boolean; + } + + + +private: + + bool m_my_boolean{false}; + +}; +/*! + * @brief This class represents the structure StructStruct defined by the user in the IDL file. + * @ingroup struct_struct + */ +class StructStruct : public ParentStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport StructStruct() + : ParentStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~StructStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object StructStruct that will be copied. + */ + eProsima_user_DllExport StructStruct( + const StructStruct& x) + : ParentStruct(x) + { + m_my_nested_element = x.m_my_nested_element; + + m_my_char = x.m_my_char; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object StructStruct that will be copied. + */ + eProsima_user_DllExport StructStruct( + StructStruct&& x) noexcept + : ParentStruct(std::move(x)) + + { + m_my_nested_element = std::move(x.m_my_nested_element); + m_my_char = x.m_my_char; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object StructStruct that will be copied. + */ + eProsima_user_DllExport StructStruct& operator =( + const StructStruct& x) + { + ParentStruct::operator =(x); + + m_my_nested_element = x.m_my_nested_element; + + m_my_char = x.m_my_char; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object StructStruct that will be copied. + */ + eProsima_user_DllExport StructStruct& operator =( + StructStruct&& x) noexcept + { + ParentStruct::operator =(std::move(x)); + + m_my_nested_element = std::move(x.m_my_nested_element); + m_my_char = x.m_my_char; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x StructStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const StructStruct& x) const + { + if (ParentStruct::operator !=(x)) + { + return false; + } + return (m_my_nested_element == x.m_my_nested_element && + m_my_char == x.m_my_char); + } + + /*! + * @brief Comparison operator. + * @param x StructStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const StructStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member my_nested_element + * @param _my_nested_element New value to be copied in member my_nested_element + */ + eProsima_user_DllExport void my_nested_element( + const NestedStructElement& _my_nested_element) + { + m_my_nested_element = _my_nested_element; + } + + /*! + * @brief This function moves the value in member my_nested_element + * @param _my_nested_element New value to be moved in member my_nested_element + */ + eProsima_user_DllExport void my_nested_element( + NestedStructElement&& _my_nested_element) + { + m_my_nested_element = std::move(_my_nested_element); + } + + /*! + * @brief This function returns a constant reference to member my_nested_element + * @return Constant reference to member my_nested_element + */ + eProsima_user_DllExport const NestedStructElement& my_nested_element() const + { + return m_my_nested_element; + } + + /*! + * @brief This function returns a reference to member my_nested_element + * @return Reference to member my_nested_element + */ + eProsima_user_DllExport NestedStructElement& my_nested_element() + { + return m_my_nested_element; + } + + + /*! + * @brief This function sets a value in member my_char + * @param _my_char New value for member my_char + */ + eProsima_user_DllExport void my_char( + char _my_char) + { + m_my_char = _my_char; + } + + /*! + * @brief This function returns the value of member my_char + * @return Value of member my_char + */ + eProsima_user_DllExport char my_char() const + { + return m_my_char; + } + + /*! + * @brief This function returns a reference to member my_char + * @return Reference to member my_char + */ + eProsima_user_DllExport char& my_char() + { + return m_my_char; + } + + + +private: + + NestedStructElement m_my_nested_element; + char m_my_char{0}; + +}; + +#endif // _FAST_DDS_GENERATED_STRUCT_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structCdrAux.hpp new file mode 100644 index 00000000000..9d875c61cf0 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structCdrAux.hpp @@ -0,0 +1,67 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file struct_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__STRUCT_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__STRUCT_STRUCTCDRAUX_HPP + +#include "struct_struct.hpp" + +constexpr uint32_t NestedStructElement_max_cdr_typesize {5UL}; +constexpr uint32_t NestedStructElement_max_key_cdr_typesize {0UL}; + +constexpr uint32_t ParentStruct_max_cdr_typesize {280UL}; +constexpr uint32_t ParentStruct_max_key_cdr_typesize {0UL}; + +constexpr uint32_t GrandparentStruct_max_cdr_typesize {8UL}; +constexpr uint32_t GrandparentStruct_max_key_cdr_typesize {0UL}; + +constexpr uint32_t StructStruct_max_cdr_typesize {286UL}; +constexpr uint32_t StructStruct_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const GrandparentStruct& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ParentStruct& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const NestedStructElement& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const StructStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__STRUCT_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structCdrAux.ipp new file mode 100644 index 00000000000..33dc9b42416 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structCdrAux.ipp @@ -0,0 +1,410 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file struct_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__STRUCT_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__STRUCT_STRUCTCDRAUX_IPP + +#include "struct_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const GrandparentStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_long(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const GrandparentStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_long() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + GrandparentStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_long(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const GrandparentStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const ParentStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_long(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_short(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_string(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3), + data.my_grandparent(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const ParentStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_long() + << eprosima::fastcdr::MemberId(1) << data.my_short() + << eprosima::fastcdr::MemberId(2) << data.my_string() + << eprosima::fastcdr::MemberId(3) << data.my_grandparent() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + ParentStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_long(); + break; + + case 1: + dcdr >> data.my_short(); + break; + + case 2: + dcdr >> data.my_string(); + break; + + case 3: + dcdr >> data.my_grandparent(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const ParentStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const NestedStructElement& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_boolean(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const NestedStructElement& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_boolean() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + NestedStructElement& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_boolean(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const NestedStructElement& data) +{ + static_cast(scdr); + static_cast(data); +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const StructStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_long(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.my_short(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.my_string(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3), + data.my_grandparent(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(4), + data.my_nested_element(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(5), + data.my_char(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const StructStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_long() + << eprosima::fastcdr::MemberId(1) << data.my_short() + << eprosima::fastcdr::MemberId(2) << data.my_string() + << eprosima::fastcdr::MemberId(3) << data.my_grandparent() + << eprosima::fastcdr::MemberId(4) << data.my_nested_element() + << eprosima::fastcdr::MemberId(5) << data.my_char() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + StructStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_long(); + break; + + case 1: + dcdr >> data.my_short(); + break; + + case 2: + dcdr >> data.my_string(); + break; + + case 3: + dcdr >> data.my_grandparent(); + break; + + case 4: + dcdr >> data.my_nested_element(); + break; + + case 5: + dcdr >> data.my_char(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const StructStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__STRUCT_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.cxx new file mode 100644 index 00000000000..90e507519ec --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.cxx @@ -0,0 +1,808 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file struct_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "struct_structPubSubTypes.hpp" + +#include +#include + +#include "struct_structCdrAux.hpp" +#include "struct_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +GrandparentStructPubSubType::GrandparentStructPubSubType() +{ + setName("GrandparentStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(GrandparentStruct::getMaxCdrSerializedSize()); +#else + GrandparentStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = GrandparentStruct_max_key_cdr_typesize > 16 ? GrandparentStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +GrandparentStructPubSubType::~GrandparentStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool GrandparentStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const GrandparentStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool GrandparentStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + GrandparentStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function GrandparentStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* GrandparentStructPubSubType::createData() +{ + return reinterpret_cast(new GrandparentStruct()); +} + +void GrandparentStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool GrandparentStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const GrandparentStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + GrandparentStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || GrandparentStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void GrandparentStructPubSubType::register_type_object_representation() +{ + register_GrandparentStruct_type_identifier(type_identifiers_); +} + +ParentStructPubSubType::ParentStructPubSubType() +{ + setName("ParentStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(ParentStruct::getMaxCdrSerializedSize()); +#else + ParentStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = ParentStruct_max_key_cdr_typesize > 16 ? ParentStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +ParentStructPubSubType::~ParentStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool ParentStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const ParentStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool ParentStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + ParentStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function ParentStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* ParentStructPubSubType::createData() +{ + return reinterpret_cast(new ParentStruct()); +} + +void ParentStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool ParentStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const ParentStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + ParentStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || ParentStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void ParentStructPubSubType::register_type_object_representation() +{ + register_ParentStruct_type_identifier(type_identifiers_); +} + +NestedStructElementPubSubType::NestedStructElementPubSubType() +{ + setName("NestedStructElement"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(NestedStructElement::getMaxCdrSerializedSize()); +#else + NestedStructElement_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = NestedStructElement_max_key_cdr_typesize > 16 ? NestedStructElement_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +NestedStructElementPubSubType::~NestedStructElementPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool NestedStructElementPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const NestedStructElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool NestedStructElementPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + NestedStructElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function NestedStructElementPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* NestedStructElementPubSubType::createData() +{ + return reinterpret_cast(new NestedStructElement()); +} + +void NestedStructElementPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool NestedStructElementPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const NestedStructElement* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + NestedStructElement_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || NestedStructElement_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void NestedStructElementPubSubType::register_type_object_representation() +{ + register_NestedStructElement_type_identifier(type_identifiers_); +} + +StructStructPubSubType::StructStructPubSubType() +{ + setName("StructStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(StructStruct::getMaxCdrSerializedSize()); +#else + StructStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = StructStruct_max_key_cdr_typesize > 16 ? StructStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +StructStructPubSubType::~StructStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool StructStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const StructStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool StructStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + StructStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function StructStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* StructStructPubSubType::createData() +{ + return reinterpret_cast(new StructStruct()); +} + +void StructStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool StructStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const StructStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + StructStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || StructStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void StructStructPubSubType::register_type_object_representation() +{ + register_StructStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "struct_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.hpp new file mode 100644 index 00000000000..5a87fd6aa30 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structPubSubTypes.hpp @@ -0,0 +1,406 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file struct_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__STRUCT_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__STRUCT_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "struct_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated struct_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type GrandparentStruct defined by the user in the IDL file. + * @ingroup struct_struct + */ +class GrandparentStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef GrandparentStruct type; + + eProsima_user_DllExport GrandparentStructPubSubType(); + + eProsima_user_DllExport ~GrandparentStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +/*! + * @brief This class represents the TopicDataType of the type ParentStruct defined by the user in the IDL file. + * @ingroup struct_struct + */ +class ParentStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef ParentStruct type; + + eProsima_user_DllExport ParentStructPubSubType(); + + eProsima_user_DllExport ~ParentStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +/*! + * @brief This class represents the TopicDataType of the type NestedStructElement defined by the user in the IDL file. + * @ingroup struct_struct + */ +class NestedStructElementPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef NestedStructElement type; + + eProsima_user_DllExport NestedStructElementPubSubType(); + + eProsima_user_DllExport ~NestedStructElementPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +/*! + * @brief This class represents the TopicDataType of the type StructStruct defined by the user in the IDL file. + * @ingroup struct_struct + */ +class StructStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef StructStruct type; + + eProsima_user_DllExport StructStructPubSubType(); + + eProsima_user_DllExport ~StructStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__STRUCT_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..c1b79de458b --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structTypeObjectSupport.cxx @@ -0,0 +1,413 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file struct_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "struct_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "struct_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_GrandparentStruct_type_identifier( + TypeIdentifierPair& type_ids_GrandparentStruct) +{ + + ReturnCode_t return_code_GrandparentStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_GrandparentStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "GrandparentStruct", type_ids_GrandparentStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_GrandparentStruct) + { + StructTypeFlag struct_flags_GrandparentStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_GrandparentStruct = "GrandparentStruct"; + eprosima::fastcdr::optional type_ann_builtin_GrandparentStruct; + eprosima::fastcdr::optional ann_custom_GrandparentStruct; + CompleteTypeDetail detail_GrandparentStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_GrandparentStruct, ann_custom_GrandparentStruct, type_name_GrandparentStruct.to_string()); + CompleteStructHeader header_GrandparentStruct; + header_GrandparentStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_GrandparentStruct); + CompleteStructMemberSeq member_seq_GrandparentStruct; + { + TypeIdentifierPair type_ids_my_long; + ReturnCode_t return_code_my_long {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_long = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_my_long); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_long) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_long Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_long = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_long = 0x00000000; + bool common_my_long_ec {false}; + CommonStructMember common_my_long {TypeObjectUtils::build_common_struct_member(member_id_my_long, member_flags_my_long, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_long, common_my_long_ec))}; + if (!common_my_long_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_long member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_long = "my_long"; + eprosima::fastcdr::optional member_ann_builtin_my_long; + ann_custom_GrandparentStruct.reset(); + CompleteMemberDetail detail_my_long = TypeObjectUtils::build_complete_member_detail(name_my_long, member_ann_builtin_my_long, ann_custom_GrandparentStruct); + CompleteStructMember member_my_long = TypeObjectUtils::build_complete_struct_member(common_my_long, detail_my_long); + TypeObjectUtils::add_complete_struct_member(member_seq_GrandparentStruct, member_my_long); + } + CompleteStructType struct_type_GrandparentStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_GrandparentStruct, header_GrandparentStruct, member_seq_GrandparentStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_GrandparentStruct, type_name_GrandparentStruct.to_string(), type_ids_GrandparentStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "GrandparentStruct already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_ParentStruct_type_identifier( + TypeIdentifierPair& type_ids_ParentStruct) +{ + + ReturnCode_t return_code_ParentStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_ParentStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ParentStruct", type_ids_ParentStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ParentStruct) + { + StructTypeFlag struct_flags_ParentStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + return_code_ParentStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "GrandparentStruct", type_ids_ParentStruct); + + if (return_code_ParentStruct != eprosima::fastdds::dds::RETCODE_OK) + { +::register_GrandparentStruct_type_identifier(type_ids_ParentStruct); + } + QualifiedTypeName type_name_ParentStruct = "ParentStruct"; + eprosima::fastcdr::optional type_ann_builtin_ParentStruct; + eprosima::fastcdr::optional ann_custom_ParentStruct; + CompleteTypeDetail detail_ParentStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ParentStruct, ann_custom_ParentStruct, type_name_ParentStruct.to_string()); + CompleteStructHeader header_ParentStruct; + if (EK_COMPLETE == type_ids_ParentStruct.type_identifier1()._d()) + { + header_ParentStruct = TypeObjectUtils::build_complete_struct_header(type_ids_ParentStruct.type_identifier1(), detail_ParentStruct); + } + else if (EK_COMPLETE == type_ids_ParentStruct.type_identifier2()._d()) + { + header_ParentStruct = TypeObjectUtils::build_complete_struct_header(type_ids_ParentStruct.type_identifier2(), detail_ParentStruct); + } + else + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ParentStruct Structure: base_type TypeIdentifier registered in TypeObjectRegistry is inconsistent."); + return; + } + CompleteStructMemberSeq member_seq_ParentStruct; + { + TypeIdentifierPair type_ids_my_short; + ReturnCode_t return_code_my_short {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_short = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int16_t", type_ids_my_short); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_short) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_short Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_short = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_short = 0x00000001; + bool common_my_short_ec {false}; + CommonStructMember common_my_short {TypeObjectUtils::build_common_struct_member(member_id_my_short, member_flags_my_short, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_short, common_my_short_ec))}; + if (!common_my_short_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_short member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_short = "my_short"; + eprosima::fastcdr::optional member_ann_builtin_my_short; + ann_custom_ParentStruct.reset(); + CompleteMemberDetail detail_my_short = TypeObjectUtils::build_complete_member_detail(name_my_short, member_ann_builtin_my_short, ann_custom_ParentStruct); + CompleteStructMember member_my_short = TypeObjectUtils::build_complete_struct_member(common_my_short, detail_my_short); + TypeObjectUtils::add_complete_struct_member(member_seq_ParentStruct, member_my_short); + } + { + TypeIdentifierPair type_ids_my_string; + ReturnCode_t return_code_my_string {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_string = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_my_string); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_string) + { + { + SBound bound = 0; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "anonymous_string_unbounded", type_ids_my_string)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_my_string = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_string = 0x00000002; + bool common_my_string_ec {false}; + CommonStructMember common_my_string {TypeObjectUtils::build_common_struct_member(member_id_my_string, member_flags_my_string, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_string, common_my_string_ec))}; + if (!common_my_string_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_string member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_string = "my_string"; + eprosima::fastcdr::optional member_ann_builtin_my_string; + ann_custom_ParentStruct.reset(); + CompleteMemberDetail detail_my_string = TypeObjectUtils::build_complete_member_detail(name_my_string, member_ann_builtin_my_string, ann_custom_ParentStruct); + CompleteStructMember member_my_string = TypeObjectUtils::build_complete_struct_member(common_my_string, detail_my_string); + TypeObjectUtils::add_complete_struct_member(member_seq_ParentStruct, member_my_string); + } + { + TypeIdentifierPair type_ids_my_grandparent; + ReturnCode_t return_code_my_grandparent {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_grandparent = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "GrandparentStruct", type_ids_my_grandparent); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_grandparent) + { + ::register_GrandparentStruct_type_identifier(type_ids_my_grandparent); + } + StructMemberFlag member_flags_my_grandparent = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_grandparent = 0x00000003; + bool common_my_grandparent_ec {false}; + CommonStructMember common_my_grandparent {TypeObjectUtils::build_common_struct_member(member_id_my_grandparent, member_flags_my_grandparent, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_grandparent, common_my_grandparent_ec))}; + if (!common_my_grandparent_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_grandparent member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_grandparent = "my_grandparent"; + eprosima::fastcdr::optional member_ann_builtin_my_grandparent; + ann_custom_ParentStruct.reset(); + CompleteMemberDetail detail_my_grandparent = TypeObjectUtils::build_complete_member_detail(name_my_grandparent, member_ann_builtin_my_grandparent, ann_custom_ParentStruct); + CompleteStructMember member_my_grandparent = TypeObjectUtils::build_complete_struct_member(common_my_grandparent, detail_my_grandparent); + TypeObjectUtils::add_complete_struct_member(member_seq_ParentStruct, member_my_grandparent); + } + CompleteStructType struct_type_ParentStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_ParentStruct, header_ParentStruct, member_seq_ParentStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_ParentStruct, type_name_ParentStruct.to_string(), type_ids_ParentStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ParentStruct already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_NestedStructElement_type_identifier( + TypeIdentifierPair& type_ids_NestedStructElement) +{ + + ReturnCode_t return_code_NestedStructElement {eprosima::fastdds::dds::RETCODE_OK}; + return_code_NestedStructElement = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "NestedStructElement", type_ids_NestedStructElement); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_NestedStructElement) + { + StructTypeFlag struct_flags_NestedStructElement = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_NestedStructElement = "NestedStructElement"; + eprosima::fastcdr::optional type_ann_builtin_NestedStructElement; + eprosima::fastcdr::optional ann_custom_NestedStructElement; + CompleteTypeDetail detail_NestedStructElement = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_NestedStructElement, ann_custom_NestedStructElement, type_name_NestedStructElement.to_string()); + CompleteStructHeader header_NestedStructElement; + header_NestedStructElement = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_NestedStructElement); + CompleteStructMemberSeq member_seq_NestedStructElement; + { + TypeIdentifierPair type_ids_my_boolean; + ReturnCode_t return_code_my_boolean {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_boolean = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_bool", type_ids_my_boolean); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_boolean) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_boolean Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_boolean = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_boolean = 0x00000000; + bool common_my_boolean_ec {false}; + CommonStructMember common_my_boolean {TypeObjectUtils::build_common_struct_member(member_id_my_boolean, member_flags_my_boolean, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_boolean, common_my_boolean_ec))}; + if (!common_my_boolean_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_boolean member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_boolean = "my_boolean"; + eprosima::fastcdr::optional member_ann_builtin_my_boolean; + ann_custom_NestedStructElement.reset(); + CompleteMemberDetail detail_my_boolean = TypeObjectUtils::build_complete_member_detail(name_my_boolean, member_ann_builtin_my_boolean, ann_custom_NestedStructElement); + CompleteStructMember member_my_boolean = TypeObjectUtils::build_complete_struct_member(common_my_boolean, detail_my_boolean); + TypeObjectUtils::add_complete_struct_member(member_seq_NestedStructElement, member_my_boolean); + } + CompleteStructType struct_type_NestedStructElement = TypeObjectUtils::build_complete_struct_type(struct_flags_NestedStructElement, header_NestedStructElement, member_seq_NestedStructElement); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_NestedStructElement, type_name_NestedStructElement.to_string(), type_ids_NestedStructElement)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "NestedStructElement already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_StructStruct_type_identifier( + TypeIdentifierPair& type_ids_StructStruct) +{ + + ReturnCode_t return_code_StructStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_StructStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "StructStruct", type_ids_StructStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_StructStruct) + { + StructTypeFlag struct_flags_StructStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + return_code_StructStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ParentStruct", type_ids_StructStruct); + + if (return_code_StructStruct != eprosima::fastdds::dds::RETCODE_OK) + { +::register_ParentStruct_type_identifier(type_ids_StructStruct); + } + QualifiedTypeName type_name_StructStruct = "StructStruct"; + eprosima::fastcdr::optional type_ann_builtin_StructStruct; + eprosima::fastcdr::optional ann_custom_StructStruct; + CompleteTypeDetail detail_StructStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_StructStruct, ann_custom_StructStruct, type_name_StructStruct.to_string()); + CompleteStructHeader header_StructStruct; + if (EK_COMPLETE == type_ids_StructStruct.type_identifier1()._d()) + { + header_StructStruct = TypeObjectUtils::build_complete_struct_header(type_ids_StructStruct.type_identifier1(), detail_StructStruct); + } + else if (EK_COMPLETE == type_ids_StructStruct.type_identifier2()._d()) + { + header_StructStruct = TypeObjectUtils::build_complete_struct_header(type_ids_StructStruct.type_identifier2(), detail_StructStruct); + } + else + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "StructStruct Structure: base_type TypeIdentifier registered in TypeObjectRegistry is inconsistent."); + return; + } + CompleteStructMemberSeq member_seq_StructStruct; + { + TypeIdentifierPair type_ids_my_nested_element; + ReturnCode_t return_code_my_nested_element {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_nested_element = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "NestedStructElement", type_ids_my_nested_element); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_nested_element) + { + ::register_NestedStructElement_type_identifier(type_ids_my_nested_element); + } + StructMemberFlag member_flags_my_nested_element = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_nested_element = 0x00000004; + bool common_my_nested_element_ec {false}; + CommonStructMember common_my_nested_element {TypeObjectUtils::build_common_struct_member(member_id_my_nested_element, member_flags_my_nested_element, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_nested_element, common_my_nested_element_ec))}; + if (!common_my_nested_element_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_nested_element member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_nested_element = "my_nested_element"; + eprosima::fastcdr::optional member_ann_builtin_my_nested_element; + ann_custom_StructStruct.reset(); + CompleteMemberDetail detail_my_nested_element = TypeObjectUtils::build_complete_member_detail(name_my_nested_element, member_ann_builtin_my_nested_element, ann_custom_StructStruct); + CompleteStructMember member_my_nested_element = TypeObjectUtils::build_complete_struct_member(common_my_nested_element, detail_my_nested_element); + TypeObjectUtils::add_complete_struct_member(member_seq_StructStruct, member_my_nested_element); + } + { + TypeIdentifierPair type_ids_my_char; + ReturnCode_t return_code_my_char {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_char = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_char", type_ids_my_char); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_char) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "my_char Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_my_char = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_char = 0x00000005; + bool common_my_char_ec {false}; + CommonStructMember common_my_char {TypeObjectUtils::build_common_struct_member(member_id_my_char, member_flags_my_char, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_char, common_my_char_ec))}; + if (!common_my_char_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_char member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_char = "my_char"; + eprosima::fastcdr::optional member_ann_builtin_my_char; + ann_custom_StructStruct.reset(); + CompleteMemberDetail detail_my_char = TypeObjectUtils::build_complete_member_detail(name_my_char, member_ann_builtin_my_char, ann_custom_StructStruct); + CompleteStructMember member_my_char = TypeObjectUtils::build_complete_struct_member(common_my_char, detail_my_char); + TypeObjectUtils::add_complete_struct_member(member_seq_StructStruct, member_my_char); + } + CompleteStructType struct_type_StructStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_StructStruct, header_StructStruct, member_seq_StructStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_StructStruct, type_name_StructStruct.to_string(), type_ids_StructStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "StructStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..b7f57b7fe3d --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structTypeObjectSupport.hpp @@ -0,0 +1,92 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file struct_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__STRUCT_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__STRUCT_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register GrandparentStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_GrandparentStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register ParentStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_ParentStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register NestedStructElement related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_NestedStructElement_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register StructStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_StructStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__STRUCT_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/struct_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/struct_struct.idl new file mode 100644 index 00000000000..908d293f22e --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/struct_struct.idl @@ -0,0 +1,22 @@ +struct GrandparentStruct +{ + long my_long; +}; + +struct ParentStruct : GrandparentStruct +{ + short my_short; + string my_string; + GrandparentStruct my_grandparent; +}; + +struct NestedStructElement +{ + boolean my_boolean; +}; + +struct StructStruct : ParentStruct +{ + NestedStructElement my_nested_element; + char my_char; +}; diff --git a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_struct.hpp b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_struct.hpp new file mode 100644 index 00000000000..f8edadff464 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_struct.hpp @@ -0,0 +1,893 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file union_struct.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__UNION_STRUCT_HPP +#define FAST_DDS_GENERATED__UNION_STRUCT_HPP + +#include +#include +#include +#include +#include +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(UNION_STRUCT_SOURCE) +#define UNION_STRUCT_DllAPI __declspec( dllexport ) +#else +#define UNION_STRUCT_DllAPI __declspec( dllimport ) +#endif // UNION_STRUCT_SOURCE +#else +#define UNION_STRUCT_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define UNION_STRUCT_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the union BasicUnion defined by the user in the IDL file. + * @ingroup union_struct + */ +class BasicUnion +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport BasicUnion() + { + second_(); + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~BasicUnion() + { + if (member_destructor_) + { + member_destructor_(); + } + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object BasicUnion that will be copied. + */ + eProsima_user_DllExport BasicUnion( + const BasicUnion& x) + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + first_() = x.m_first; + break; + + case 0x00000002: + second_() = x.m_second; + break; + + } + } + + /*! + * @brief Move constructor. + * @param x Reference to the object BasicUnion that will be copied. + */ + eProsima_user_DllExport BasicUnion( + BasicUnion&& x) noexcept + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + first_() = std::move(x.m_first); + break; + + case 0x00000002: + second_() = std::move(x.m_second); + break; + + } + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object BasicUnion that will be copied. + */ + eProsima_user_DllExport BasicUnion& operator =( + const BasicUnion& x) + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + first_() = x.m_first; + break; + + case 0x00000002: + second_() = x.m_second; + break; + + } + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object BasicUnion that will be copied. + */ + eProsima_user_DllExport BasicUnion& operator =( + BasicUnion&& x) noexcept + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + first_() = std::move(x.m_first); + break; + + case 0x00000002: + second_() = std::move(x.m_second); + break; + + } + + return *this; + } + + /*! + * @brief Comparison operator. + * @param x BasicUnion object to compare. + */ + eProsima_user_DllExport bool operator ==( + const BasicUnion& x) const + { + bool ret_value {false}; + + if (m__d == x.m__d && + selected_member_ == x.selected_member_) + { + switch (selected_member_) + { + case 0x00000001: + ret_value = (m_first == x.m_first); + break; + + case 0x00000002: + ret_value = (m_second == x.m_second); + break; + + } + } + + return ret_value; + } + + /*! + * @brief Comparison operator. + * @param x BasicUnion object to compare. + */ + eProsima_user_DllExport bool operator !=( + const BasicUnion& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets the discriminator value. + * @param __d New value for the discriminator. + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the new value doesn't correspond to the selected union member. + */ + eProsima_user_DllExport void _d( + int16_t __d) + { + bool valid_discriminator = false; + + switch (__d) + { + case 0: + if (0x00000001 == selected_member_) + { + valid_discriminator = true; + } + break; + + case 1: + default: + if (0x00000002 == selected_member_) + { + valid_discriminator = true; + } + break; + + } + + if (!valid_discriminator) + { + throw eprosima::fastcdr::exception::BadParamException("Discriminator doesn't correspond with the selected union member"); + } + + m__d = __d; + } + + /*! + * @brief This function returns the value of the discriminator. + * @return Value of the discriminator + */ + eProsima_user_DllExport int16_t _d() const + { + return m__d; + } + + /*! + * @brief This function copies the value in member first + * @param _first New value to be copied in member first + */ + eProsima_user_DllExport void first( + const std::string& _first) + { + first_() = _first; + m__d = 0; + } + + /*! + * @brief This function moves the value in member first + * @param _first New value to be moved in member first + */ + eProsima_user_DllExport void first( + std::string&& _first) + { + first_() = _first; + m__d = 0; + } + + /*! + * @brief This function returns a constant reference to member first + * @return Constant reference to member first + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport const std::string& first() const + { + if (0x00000001 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_first; + } + + /*! + * @brief This function returns a reference to member first + * @return Reference to member first + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport std::string& first() + { + if (0x00000001 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_first; + } + + + /*! + * @brief This function sets a value in member second + * @param _second New value for member second + */ + eProsima_user_DllExport void second( + int64_t _second) + { + second_() = _second; + m__d = 32767; + } + + /*! + * @brief This function returns the value of member second + * @return Value of member second + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport int64_t second() const + { + if (0x00000002 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_second; + } + + /*! + * @brief This function returns a reference to member second + * @return Reference to member second + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport int64_t& second() + { + if (0x00000002 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_second; + } + + + +private: + + std::string& first_() + { + if (0x00000001 != selected_member_) + { + if (member_destructor_) + { + member_destructor_(); + } + + selected_member_ = 0x00000001; + member_destructor_ = [&]() {m_first.~basic_string();}; + new(&m_first) std::string(); + ; + } + + return m_first; + } + + int64_t& second_() + { + if (0x00000002 != selected_member_) + { + if (member_destructor_) + { + member_destructor_(); + } + + selected_member_ = 0x00000002; + member_destructor_ = nullptr; + m_second = {0}; + ; + } + + return m_second; + } + + + int16_t m__d {32767}; + + union + { + std::string m_first; + int64_t m_second; + }; + + uint32_t selected_member_ {0x0FFFFFFFu}; + + std::function member_destructor_; +}; +/*! + * @brief This class represents the union ComplexUnion defined by the user in the IDL file. + * @ingroup union_struct + */ +class ComplexUnion +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport ComplexUnion() + { + fourth_(); + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~ComplexUnion() + { + if (member_destructor_) + { + member_destructor_(); + } + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object ComplexUnion that will be copied. + */ + eProsima_user_DllExport ComplexUnion( + const ComplexUnion& x) + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + third_() = x.m_third; + break; + + case 0x00000002: + fourth_() = x.m_fourth; + break; + + } + } + + /*! + * @brief Move constructor. + * @param x Reference to the object ComplexUnion that will be copied. + */ + eProsima_user_DllExport ComplexUnion( + ComplexUnion&& x) noexcept + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + third_() = std::move(x.m_third); + break; + + case 0x00000002: + fourth_() = std::move(x.m_fourth); + break; + + } + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object ComplexUnion that will be copied. + */ + eProsima_user_DllExport ComplexUnion& operator =( + const ComplexUnion& x) + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + third_() = x.m_third; + break; + + case 0x00000002: + fourth_() = x.m_fourth; + break; + + } + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object ComplexUnion that will be copied. + */ + eProsima_user_DllExport ComplexUnion& operator =( + ComplexUnion&& x) noexcept + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + third_() = std::move(x.m_third); + break; + + case 0x00000002: + fourth_() = std::move(x.m_fourth); + break; + + } + + return *this; + } + + /*! + * @brief Comparison operator. + * @param x ComplexUnion object to compare. + */ + eProsima_user_DllExport bool operator ==( + const ComplexUnion& x) const + { + bool ret_value {false}; + + if (m__d == x.m__d && + selected_member_ == x.selected_member_) + { + switch (selected_member_) + { + case 0x00000001: + ret_value = (m_third == x.m_third); + break; + + case 0x00000002: + ret_value = (m_fourth == x.m_fourth); + break; + + } + } + + return ret_value; + } + + /*! + * @brief Comparison operator. + * @param x ComplexUnion object to compare. + */ + eProsima_user_DllExport bool operator !=( + const ComplexUnion& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets the discriminator value. + * @param __d New value for the discriminator. + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the new value doesn't correspond to the selected union member. + */ + eProsima_user_DllExport void _d( + int32_t __d) + { + bool valid_discriminator = false; + + switch (__d) + { + case 0: + case 1: + if (0x00000001 == selected_member_) + { + valid_discriminator = true; + } + break; + + default: + if (0x00000002 == selected_member_) + { + valid_discriminator = true; + } + break; + + } + + if (!valid_discriminator) + { + throw eprosima::fastcdr::exception::BadParamException("Discriminator doesn't correspond with the selected union member"); + } + + m__d = __d; + } + + /*! + * @brief This function returns the value of the discriminator. + * @return Value of the discriminator + */ + eProsima_user_DllExport int32_t _d() const + { + return m__d; + } + + /*! + * @brief This function sets a value in member third + * @param _third New value for member third + */ + eProsima_user_DllExport void third( + int32_t _third) + { + third_() = _third; + m__d = 0; + } + + /*! + * @brief This function returns the value of member third + * @return Value of member third + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport int32_t third() const + { + if (0x00000001 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_third; + } + + /*! + * @brief This function returns a reference to member third + * @return Reference to member third + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport int32_t& third() + { + if (0x00000001 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_third; + } + + + /*! + * @brief This function copies the value in member fourth + * @param _fourth New value to be copied in member fourth + */ + eProsima_user_DllExport void fourth( + const BasicUnion& _fourth) + { + fourth_() = _fourth; + m__d = 2147483647; + } + + /*! + * @brief This function moves the value in member fourth + * @param _fourth New value to be moved in member fourth + */ + eProsima_user_DllExport void fourth( + BasicUnion&& _fourth) + { + fourth_() = _fourth; + m__d = 2147483647; + } + + /*! + * @brief This function returns a constant reference to member fourth + * @return Constant reference to member fourth + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport const BasicUnion& fourth() const + { + if (0x00000002 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_fourth; + } + + /*! + * @brief This function returns a reference to member fourth + * @return Reference to member fourth + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport BasicUnion& fourth() + { + if (0x00000002 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_fourth; + } + + + +private: + + int32_t& third_() + { + if (0x00000001 != selected_member_) + { + if (member_destructor_) + { + member_destructor_(); + } + + selected_member_ = 0x00000001; + member_destructor_ = nullptr; + m_third = {0}; + ; + } + + return m_third; + } + + BasicUnion& fourth_() + { + if (0x00000002 != selected_member_) + { + if (member_destructor_) + { + member_destructor_(); + } + + selected_member_ = 0x00000002; + member_destructor_ = [&]() {m_fourth.~BasicUnion();}; + new(&m_fourth) BasicUnion(); + ; + } + + return m_fourth; + } + + + int32_t m__d {2147483647}; + + union + { + int32_t m_third; + BasicUnion m_fourth; + }; + + uint32_t selected_member_ {0x0FFFFFFFu}; + + std::function member_destructor_; +}; +/*! + * @brief This class represents the structure UnionStruct defined by the user in the IDL file. + * @ingroup union_struct + */ +class UnionStruct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport UnionStruct() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~UnionStruct() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object UnionStruct that will be copied. + */ + eProsima_user_DllExport UnionStruct( + const UnionStruct& x) + { + m_my_complex_union = x.m_my_complex_union; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object UnionStruct that will be copied. + */ + eProsima_user_DllExport UnionStruct( + UnionStruct&& x) noexcept + { + m_my_complex_union = std::move(x.m_my_complex_union); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object UnionStruct that will be copied. + */ + eProsima_user_DllExport UnionStruct& operator =( + const UnionStruct& x) + { + + m_my_complex_union = x.m_my_complex_union; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object UnionStruct that will be copied. + */ + eProsima_user_DllExport UnionStruct& operator =( + UnionStruct&& x) noexcept + { + + m_my_complex_union = std::move(x.m_my_complex_union); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x UnionStruct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const UnionStruct& x) const + { + return (m_my_complex_union == x.m_my_complex_union); + } + + /*! + * @brief Comparison operator. + * @param x UnionStruct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const UnionStruct& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member my_complex_union + * @param _my_complex_union New value to be copied in member my_complex_union + */ + eProsima_user_DllExport void my_complex_union( + const ComplexUnion& _my_complex_union) + { + m_my_complex_union = _my_complex_union; + } + + /*! + * @brief This function moves the value in member my_complex_union + * @param _my_complex_union New value to be moved in member my_complex_union + */ + eProsima_user_DllExport void my_complex_union( + ComplexUnion&& _my_complex_union) + { + m_my_complex_union = std::move(_my_complex_union); + } + + /*! + * @brief This function returns a constant reference to member my_complex_union + * @return Constant reference to member my_complex_union + */ + eProsima_user_DllExport const ComplexUnion& my_complex_union() const + { + return m_my_complex_union; + } + + /*! + * @brief This function returns a reference to member my_complex_union + * @return Reference to member my_complex_union + */ + eProsima_user_DllExport ComplexUnion& my_complex_union() + { + return m_my_complex_union; + } + + + +private: + + ComplexUnion m_my_complex_union; + +}; + +#endif // _FAST_DDS_GENERATED_UNION_STRUCT_HPP_ + + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structCdrAux.hpp b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structCdrAux.hpp new file mode 100644 index 00000000000..8f0a33c4712 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structCdrAux.hpp @@ -0,0 +1,46 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file union_structCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__UNION_STRUCTCDRAUX_HPP +#define FAST_DDS_GENERATED__UNION_STRUCTCDRAUX_HPP + +#include "union_struct.hpp" + +constexpr uint32_t UnionStruct_max_cdr_typesize {280UL}; +constexpr uint32_t UnionStruct_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const UnionStruct& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__UNION_STRUCTCDRAUX_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structCdrAux.ipp new file mode 100644 index 00000000000..61102777754 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structCdrAux.ipp @@ -0,0 +1,368 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file union_structCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__UNION_STRUCTCDRAUX_IPP +#define FAST_DDS_GENERATED__UNION_STRUCTCDRAUX_IPP + +#include "union_structCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const BasicUnion& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), data._d(), + current_alignment); + + switch (data._d()) + { + case 0: + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.first(), current_alignment); + break; + + case 1: + default: + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.second(), current_alignment); + break; + + } + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const BasicUnion& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr << eprosima::fastcdr::MemberId(0) << data._d(); + + switch (data._d()) + { + case 0: + scdr << eprosima::fastcdr::MemberId(1) << data.first(); + break; + + case 1: + default: + scdr << eprosima::fastcdr::MemberId(2) << data.second(); + break; + + } + + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + BasicUnion& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + if (0 == mid.id) + { + int16_t discriminator; + dcdr >> discriminator; + + switch (discriminator) + { + case 0: + { + std::string first_value; + data.first(std::move(first_value)); + data._d(discriminator); + break; + } + + case 1: + default: + { + int64_t second_value{0}; + data.second(std::move(second_value)); + data._d(discriminator); + break; + } + + } + } + else + { + switch (data._d()) + { + case 0: + dcdr >> data.first(); + break; + + case 1: + default: + dcdr >> data.second(); + break; + + } + ret_value = false; + } + return ret_value; + }); +} + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const ComplexUnion& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), data._d(), + current_alignment); + + switch (data._d()) + { + case 0: + case 1: + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.third(), current_alignment); + break; + + default: + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.fourth(), current_alignment); + break; + + } + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const ComplexUnion& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr << eprosima::fastcdr::MemberId(0) << data._d(); + + switch (data._d()) + { + case 0: + case 1: + scdr << eprosima::fastcdr::MemberId(1) << data.third(); + break; + + default: + scdr << eprosima::fastcdr::MemberId(2) << data.fourth(); + break; + + } + + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + ComplexUnion& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + if (0 == mid.id) + { + int32_t discriminator; + dcdr >> discriminator; + + switch (discriminator) + { + case 0: + case 1: + { + int32_t third_value{0}; + data.third(std::move(third_value)); + data._d(discriminator); + break; + } + + default: + { + BasicUnion fourth_value; + data.fourth(std::move(fourth_value)); + data._d(discriminator); + break; + } + + } + } + else + { + switch (data._d()) + { + case 0: + case 1: + dcdr >> data.third(); + break; + + default: + dcdr >> data.fourth(); + break; + + } + ret_value = false; + } + return ret_value; + }); +} + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const UnionStruct& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.my_complex_union(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const UnionStruct& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.my_complex_union() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + UnionStruct& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.my_complex_union(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const UnionStruct& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__UNION_STRUCTCDRAUX_IPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.cxx b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.cxx new file mode 100644 index 00000000000..22ad76ec79b --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.cxx @@ -0,0 +1,229 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file union_structPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "union_structPubSubTypes.hpp" + +#include +#include + +#include "union_structCdrAux.hpp" +#include "union_structTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +UnionStructPubSubType::UnionStructPubSubType() +{ + setName("UnionStruct"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(UnionStruct::getMaxCdrSerializedSize()); +#else + UnionStruct_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = UnionStruct_max_key_cdr_typesize > 16 ? UnionStruct_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +UnionStructPubSubType::~UnionStructPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool UnionStructPubSubType::serialize( + const void* const data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + const UnionStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool UnionStructPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + UnionStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function UnionStructPubSubType::getSerializedSizeProvider( + const void* const data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* UnionStructPubSubType::createData() +{ + return reinterpret_cast(new UnionStruct()); +} + +void UnionStructPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool UnionStructPubSubType::getKey( + const void* const data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + const UnionStruct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + UnionStruct_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || UnionStruct_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void UnionStructPubSubType::register_type_object_representation() +{ + register_UnionStruct_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "union_structCdrAux.ipp" diff --git a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.hpp b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.hpp new file mode 100644 index 00000000000..bbd1b9e3986 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structPubSubTypes.hpp @@ -0,0 +1,133 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file union_structPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__UNION_STRUCT_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__UNION_STRUCT_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "union_struct.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated union_struct is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type UnionStruct defined by the user in the IDL file. + * @ingroup union_struct + */ +class UnionStructPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef UnionStruct type; + + eProsima_user_DllExport UnionStructPubSubType(); + + eProsima_user_DllExport ~UnionStructPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__UNION_STRUCT_PUBSUBTYPES_HPP + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structTypeObjectSupport.cxx b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structTypeObjectSupport.cxx new file mode 100644 index 00000000000..7ec28283a60 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structTypeObjectSupport.cxx @@ -0,0 +1,350 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file union_structTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "union_structTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "union_struct.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_BasicUnion_type_identifier( + TypeIdentifierPair& type_ids_BasicUnion) +{ + ReturnCode_t return_code_BasicUnion {eprosima::fastdds::dds::RETCODE_OK}; + return_code_BasicUnion = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "BasicUnion", type_ids_BasicUnion); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_BasicUnion) + { + UnionTypeFlag union_flags_BasicUnion = TypeObjectUtils::build_union_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_BasicUnion = "BasicUnion"; + eprosima::fastcdr::optional type_ann_builtin_BasicUnion; + eprosima::fastcdr::optional ann_custom_BasicUnion; + CompleteTypeDetail detail_BasicUnion = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_BasicUnion, ann_custom_BasicUnion, type_name_BasicUnion.to_string()); + CompleteUnionHeader header_BasicUnion = TypeObjectUtils::build_complete_union_header(detail_BasicUnion); + UnionDiscriminatorFlag member_flags_BasicUnion = TypeObjectUtils::build_union_discriminator_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false); + return_code_BasicUnion = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int16_t", type_ids_BasicUnion); + + if (return_code_BasicUnion != eprosima::fastdds::dds::RETCODE_OK) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Union discriminator TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + CommonDiscriminatorMember common_BasicUnion; + if (EK_COMPLETE == type_ids_BasicUnion.type_identifier1()._d() || TK_NONE == type_ids_BasicUnion.type_identifier2()._d()) + { + common_BasicUnion = TypeObjectUtils::build_common_discriminator_member(member_flags_BasicUnion, type_ids_BasicUnion.type_identifier1()); + } + else if (EK_COMPLETE == type_ids_BasicUnion.type_identifier2()._d()) + { + common_BasicUnion = TypeObjectUtils::build_common_discriminator_member(member_flags_BasicUnion, type_ids_BasicUnion.type_identifier2()); + } + else + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "BasicUnion discriminator TypeIdentifier inconsistent."); + return; + } + type_ann_builtin_BasicUnion.reset(); + ann_custom_BasicUnion.reset(); + CompleteDiscriminatorMember discriminator_BasicUnion = TypeObjectUtils::build_complete_discriminator_member(common_BasicUnion, + type_ann_builtin_BasicUnion, ann_custom_BasicUnion); + CompleteUnionMemberSeq member_seq_BasicUnion; + { + return_code_BasicUnion = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_BasicUnion); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_BasicUnion) + { + { + SBound bound = 0; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "anonymous_string_unbounded", type_ids_BasicUnion)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + UnionMemberFlag member_flags_first = TypeObjectUtils::build_union_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false); + UnionCaseLabelSeq label_seq_first; + TypeObjectUtils::add_union_case_label(label_seq_first, static_cast(0)); + MemberId member_id_first = 0x00000001; + bool common_first_ec {false}; + CommonUnionMember common_first {TypeObjectUtils::build_common_union_member(member_id_first, + member_flags_first, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_BasicUnion, + common_first_ec), label_seq_first)}; + if (!common_first_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Union first member TypeIdentifier inconsistent."); + return; + } + MemberName name_first = "first"; + eprosima::fastcdr::optional member_ann_builtin_first; + ann_custom_BasicUnion.reset(); + CompleteMemberDetail detail_first = TypeObjectUtils::build_complete_member_detail(name_first, member_ann_builtin_first, ann_custom_BasicUnion); + CompleteUnionMember member_first = TypeObjectUtils::build_complete_union_member(common_first, detail_first); + TypeObjectUtils::add_complete_union_member(member_seq_BasicUnion, member_first); + } + { + return_code_BasicUnion = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int64_t", type_ids_BasicUnion); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_BasicUnion) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "second Union member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + UnionMemberFlag member_flags_second = TypeObjectUtils::build_union_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + true, false); + UnionCaseLabelSeq label_seq_second; + TypeObjectUtils::add_union_case_label(label_seq_second, static_cast(1)); + MemberId member_id_second = 0x00000002; + bool common_second_ec {false}; + CommonUnionMember common_second {TypeObjectUtils::build_common_union_member(member_id_second, + member_flags_second, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_BasicUnion, + common_second_ec), label_seq_second)}; + if (!common_second_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Union second member TypeIdentifier inconsistent."); + return; + } + MemberName name_second = "second"; + eprosima::fastcdr::optional member_ann_builtin_second; + ann_custom_BasicUnion.reset(); + CompleteMemberDetail detail_second = TypeObjectUtils::build_complete_member_detail(name_second, member_ann_builtin_second, ann_custom_BasicUnion); + CompleteUnionMember member_second = TypeObjectUtils::build_complete_union_member(common_second, detail_second); + TypeObjectUtils::add_complete_union_member(member_seq_BasicUnion, member_second); + } + CompleteUnionType union_type_BasicUnion = TypeObjectUtils::build_complete_union_type(union_flags_BasicUnion, header_BasicUnion, discriminator_BasicUnion, + member_seq_BasicUnion); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_union_type_object(union_type_BasicUnion, type_name_BasicUnion.to_string(), type_ids_BasicUnion)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "BasicUnion already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_ComplexUnion_type_identifier( + TypeIdentifierPair& type_ids_ComplexUnion) +{ + ReturnCode_t return_code_ComplexUnion {eprosima::fastdds::dds::RETCODE_OK}; + return_code_ComplexUnion = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ComplexUnion", type_ids_ComplexUnion); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ComplexUnion) + { + UnionTypeFlag union_flags_ComplexUnion = TypeObjectUtils::build_union_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_ComplexUnion = "ComplexUnion"; + eprosima::fastcdr::optional type_ann_builtin_ComplexUnion; + eprosima::fastcdr::optional ann_custom_ComplexUnion; + CompleteTypeDetail detail_ComplexUnion = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ComplexUnion, ann_custom_ComplexUnion, type_name_ComplexUnion.to_string()); + CompleteUnionHeader header_ComplexUnion = TypeObjectUtils::build_complete_union_header(detail_ComplexUnion); + UnionDiscriminatorFlag member_flags_ComplexUnion = TypeObjectUtils::build_union_discriminator_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false); + return_code_ComplexUnion = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_ComplexUnion); + + if (return_code_ComplexUnion != eprosima::fastdds::dds::RETCODE_OK) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Union discriminator TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + CommonDiscriminatorMember common_ComplexUnion; + if (EK_COMPLETE == type_ids_ComplexUnion.type_identifier1()._d() || TK_NONE == type_ids_ComplexUnion.type_identifier2()._d()) + { + common_ComplexUnion = TypeObjectUtils::build_common_discriminator_member(member_flags_ComplexUnion, type_ids_ComplexUnion.type_identifier1()); + } + else if (EK_COMPLETE == type_ids_ComplexUnion.type_identifier2()._d()) + { + common_ComplexUnion = TypeObjectUtils::build_common_discriminator_member(member_flags_ComplexUnion, type_ids_ComplexUnion.type_identifier2()); + } + else + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ComplexUnion discriminator TypeIdentifier inconsistent."); + return; + } + type_ann_builtin_ComplexUnion.reset(); + ann_custom_ComplexUnion.reset(); + CompleteDiscriminatorMember discriminator_ComplexUnion = TypeObjectUtils::build_complete_discriminator_member(common_ComplexUnion, + type_ann_builtin_ComplexUnion, ann_custom_ComplexUnion); + CompleteUnionMemberSeq member_seq_ComplexUnion; + { + return_code_ComplexUnion = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_ComplexUnion); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ComplexUnion) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "third Union member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + UnionMemberFlag member_flags_third = TypeObjectUtils::build_union_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false); + UnionCaseLabelSeq label_seq_third; + TypeObjectUtils::add_union_case_label(label_seq_third, static_cast(0)); + TypeObjectUtils::add_union_case_label(label_seq_third, static_cast(1)); + MemberId member_id_third = 0x00000001; + bool common_third_ec {false}; + CommonUnionMember common_third {TypeObjectUtils::build_common_union_member(member_id_third, + member_flags_third, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_ComplexUnion, + common_third_ec), label_seq_third)}; + if (!common_third_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Union third member TypeIdentifier inconsistent."); + return; + } + MemberName name_third = "third"; + eprosima::fastcdr::optional member_ann_builtin_third; + ann_custom_ComplexUnion.reset(); + CompleteMemberDetail detail_third = TypeObjectUtils::build_complete_member_detail(name_third, member_ann_builtin_third, ann_custom_ComplexUnion); + CompleteUnionMember member_third = TypeObjectUtils::build_complete_union_member(common_third, detail_third); + TypeObjectUtils::add_complete_union_member(member_seq_ComplexUnion, member_third); + } + { + return_code_ComplexUnion = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "BasicUnion", type_ids_ComplexUnion); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_ComplexUnion) + { + ::register_BasicUnion_type_identifier(type_ids_ComplexUnion); + } + UnionMemberFlag member_flags_fourth = TypeObjectUtils::build_union_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + true, false); + UnionCaseLabelSeq label_seq_fourth; + MemberId member_id_fourth = 0x00000002; + bool common_fourth_ec {false}; + CommonUnionMember common_fourth {TypeObjectUtils::build_common_union_member(member_id_fourth, + member_flags_fourth, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_ComplexUnion, + common_fourth_ec), label_seq_fourth)}; + if (!common_fourth_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Union fourth member TypeIdentifier inconsistent."); + return; + } + MemberName name_fourth = "fourth"; + eprosima::fastcdr::optional member_ann_builtin_fourth; + ann_custom_ComplexUnion.reset(); + CompleteMemberDetail detail_fourth = TypeObjectUtils::build_complete_member_detail(name_fourth, member_ann_builtin_fourth, ann_custom_ComplexUnion); + CompleteUnionMember member_fourth = TypeObjectUtils::build_complete_union_member(common_fourth, detail_fourth); + TypeObjectUtils::add_complete_union_member(member_seq_ComplexUnion, member_fourth); + } + CompleteUnionType union_type_ComplexUnion = TypeObjectUtils::build_complete_union_type(union_flags_ComplexUnion, header_ComplexUnion, discriminator_ComplexUnion, + member_seq_ComplexUnion); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_union_type_object(union_type_ComplexUnion, type_name_ComplexUnion.to_string(), type_ids_ComplexUnion)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "ComplexUnion already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_UnionStruct_type_identifier( + TypeIdentifierPair& type_ids_UnionStruct) +{ + + ReturnCode_t return_code_UnionStruct {eprosima::fastdds::dds::RETCODE_OK}; + return_code_UnionStruct = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "UnionStruct", type_ids_UnionStruct); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_UnionStruct) + { + StructTypeFlag struct_flags_UnionStruct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_UnionStruct = "UnionStruct"; + eprosima::fastcdr::optional type_ann_builtin_UnionStruct; + eprosima::fastcdr::optional ann_custom_UnionStruct; + CompleteTypeDetail detail_UnionStruct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_UnionStruct, ann_custom_UnionStruct, type_name_UnionStruct.to_string()); + CompleteStructHeader header_UnionStruct; + header_UnionStruct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_UnionStruct); + CompleteStructMemberSeq member_seq_UnionStruct; + { + TypeIdentifierPair type_ids_my_complex_union; + ReturnCode_t return_code_my_complex_union {eprosima::fastdds::dds::RETCODE_OK}; + return_code_my_complex_union = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "ComplexUnion", type_ids_my_complex_union); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_my_complex_union) + { + ::register_ComplexUnion_type_identifier(type_ids_my_complex_union); + } + StructMemberFlag member_flags_my_complex_union = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_my_complex_union = 0x00000000; + bool common_my_complex_union_ec {false}; + CommonStructMember common_my_complex_union {TypeObjectUtils::build_common_struct_member(member_id_my_complex_union, member_flags_my_complex_union, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_my_complex_union, common_my_complex_union_ec))}; + if (!common_my_complex_union_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure my_complex_union member TypeIdentifier inconsistent."); + return; + } + MemberName name_my_complex_union = "my_complex_union"; + eprosima::fastcdr::optional member_ann_builtin_my_complex_union; + ann_custom_UnionStruct.reset(); + CompleteMemberDetail detail_my_complex_union = TypeObjectUtils::build_complete_member_detail(name_my_complex_union, member_ann_builtin_my_complex_union, ann_custom_UnionStruct); + CompleteStructMember member_my_complex_union = TypeObjectUtils::build_complete_struct_member(common_my_complex_union, detail_my_complex_union); + TypeObjectUtils::add_complete_struct_member(member_seq_UnionStruct, member_my_complex_union); + } + CompleteStructType struct_type_UnionStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_UnionStruct, header_UnionStruct, member_seq_UnionStruct); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_UnionStruct, type_name_UnionStruct.to_string(), type_ids_UnionStruct)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "UnionStruct already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structTypeObjectSupport.hpp b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structTypeObjectSupport.hpp new file mode 100644 index 00000000000..aad34849a6f --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/gen/union_structTypeObjectSupport.hpp @@ -0,0 +1,80 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file union_structTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__UNION_STRUCT_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__UNION_STRUCT_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register BasicUnion related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_BasicUnion_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register ComplexUnion related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_ComplexUnion_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register UnionStruct related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_UnionStruct_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__UNION_STRUCT_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/unittest/dds/xtypes/serializers/idl/types/union_struct/union_struct.idl b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/union_struct.idl new file mode 100644 index 00000000000..d2d6bbefff6 --- /dev/null +++ b/test/unittest/dds/xtypes/serializers/idl/types/union_struct/union_struct.idl @@ -0,0 +1,22 @@ +union BasicUnion switch (short) +{ + case 0: + string first; + case 1: + default: + long long second; +}; + +union ComplexUnion switch (long) +{ + case 0: + case 1: + long third; + default: + BasicUnion fourth; +}; + +struct UnionStruct +{ + ComplexUnion my_complex_union; +}; diff --git a/test/unittest/dds/xtypes/serializers/json/CMakeLists.txt b/test/unittest/dds/xtypes/serializers/json/CMakeLists.txt index ea0092052f8..7638d5b1d1d 100644 --- a/test/unittest/dds/xtypes/serializers/json/CMakeLists.txt +++ b/test/unittest/dds/xtypes/serializers/json/CMakeLists.txt @@ -12,38 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/types/comprehensive_type/json/ComprehensiveType_Unfilled_EPROSIMA.json - ${CMAKE_CURRENT_BINARY_DIR}/types/comprehensive_type/json/ComprehensiveType_Unfilled_EPROSIMA.json - COPYONLY) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_EPROSIMA_1.json - ${CMAKE_CURRENT_BINARY_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_EPROSIMA_1.json - COPYONLY) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_EPROSIMA_2.json - ${CMAKE_CURRENT_BINARY_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_EPROSIMA_2.json - COPYONLY) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_EPROSIMA_3.json - ${CMAKE_CURRENT_BINARY_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_EPROSIMA_3.json - COPYONLY) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/types/comprehensive_type/json/ComprehensiveType_Unfilled_OMG.json - ${CMAKE_CURRENT_BINARY_DIR}/types/comprehensive_type/json/ComprehensiveType_Unfilled_OMG.json - COPYONLY) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_OMG_1.json - ${CMAKE_CURRENT_BINARY_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_OMG_1.json - COPYONLY) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_OMG_2.json - ${CMAKE_CURRENT_BINARY_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_OMG_2.json - COPYONLY) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_OMG_3.json - ${CMAKE_CURRENT_BINARY_DIR}/types/comprehensive_type/json/ComprehensiveType_Filled_OMG_3.json - COPYONLY) +# Recursively find all .json files in the types directory +file(GLOB_RECURSE JSON_FILES ${CMAKE_CURRENT_SOURCE_DIR}/types/*.json) + +# Iterate over each .json file found +foreach(JSON_FILE ${JSON_FILES}) + # Get the relative path of the .json file + file(RELATIVE_PATH RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${JSON_FILE}) + + # Determine the destination directory + set(DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/${RELATIVE_PATH}) + get_filename_component(DEST_DIR ${DEST_DIR} DIRECTORY) + + # Ensure the destination directory exists + file(MAKE_DIRECTORY ${DEST_DIR}) + + # Copy the .json file to the destination directory + configure_file(${JSON_FILE} ${DEST_DIR} COPYONLY) +endforeach() set(SERIALIZE_JSON_SOURCE DynDataJSONTests.cpp) diff --git a/test/unittest/utils/CMakeLists.txt b/test/unittest/utils/CMakeLists.txt index 881b79ded67..3c8da0c6c10 100644 --- a/test/unittest/utils/CMakeLists.txt +++ b/test/unittest/utils/CMakeLists.txt @@ -65,6 +65,9 @@ set(SYSTEMINFOTESTS_SOURCE ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp) +set(TREETESTS_SOURCE + TreeNodeTests.cpp) + include_directories(mock/) add_executable(StringMatchingTests ${STRINGMATCHINGTESTS_SOURCE}) @@ -167,6 +170,11 @@ target_include_directories(SharedMutexTests PRIVATE ${PROJECT_SOURCE_DIR}/src/cp target_link_libraries(SharedMutexTests PUBLIC GTest::gtest) gtest_discover_tests(SharedMutexTests) +add_executable(TreeNodeTests ${TREETESTS_SOURCE}) +target_include_directories(TreeNodeTests PRIVATE ${PROJECT_SOURCE_DIR}/src/cpp) +target_link_libraries(TreeNodeTests PUBLIC GTest::gtest) +gtest_discover_tests(TreeNodeTests) + ############################################################################### # Necessary files ############################################################################### diff --git a/test/unittest/utils/TreeNodeTests.cpp b/test/unittest/utils/TreeNodeTests.cpp new file mode 100644 index 00000000000..a1a12cbcebb --- /dev/null +++ b/test/unittest/utils/TreeNodeTests.cpp @@ -0,0 +1,299 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +#include + +#include + +using namespace eprosima; + + +struct TreeNodeTestType +{ + TreeNodeTestType( + const std::string& name) + : name(name) + { + } + + const std::string name; +}; + +/** + * @brief Test that a tree can support one shallow branch. + * + * 0 + * │ + * ▼ + * 1 + */ +TEST(TreeNodeTests, one_shallow_branch) +{ + constexpr auto DEPTH = 1U; + constexpr auto NODE_COUNT = 2U; + constexpr auto BRANCH_COUNT = 1U; + + std::vector nodes; + std::vector> trees; + + // Create the nodes and the trees + for (unsigned int i = 0; i < NODE_COUNT; i++) + { + nodes.emplace_back(std::to_string(i)); + trees.emplace_back(nodes[i]); + } + + // Build the tree + auto& root = trees[0]; + + root.add_branch(trees[1]); + + // Verify the depth + const auto tree_depth = root.depth(); + ASSERT_EQ(tree_depth, DEPTH); + + // Verify the nodes are correct + const auto tree_nodes = root.all_nodes(); + ASSERT_EQ(tree_nodes.size(), NODE_COUNT - 1); + + // Verify the branch count + const auto tree_branches = root.branches(); + ASSERT_EQ(tree_branches.size(), BRANCH_COUNT); + + // Verify that the branch is a leaf + ASSERT_TRUE(tree_branches.front().leaf()); +} + +/** + * @brief Test that a tree can support one deep branch. + * + * 0 + * │ + * ▼ + * 1 + * │ + * ▼ + * 2 + * │ + * ▼ + * 3 + * │ + * ▼ + * 4 + * │ + * ▼ + * 5 + */ +TEST(TreeNodeTests, one_deep_branch) +{ + constexpr auto DEPTH = 5U; + constexpr auto NODE_COUNT = 6U; + constexpr auto BRANCH_COUNT = 1U; + + std::vector nodes; + std::vector> trees; + + // Create the nodes and the trees + for (unsigned int i = 0; i < NODE_COUNT; i++) + { + nodes.emplace_back(std::to_string(i)); + trees.emplace_back(nodes[i]); + } + + // Build the tree + for (int i = NODE_COUNT - 1; i >= 1; i--) + { + trees[i - 1].add_branch(trees[i]); + } + + const auto& root = trees[0]; + + // Verify the depth + const auto tree_depth = root.depth(); + ASSERT_EQ(tree_depth, DEPTH); + + // Verify the nodes are correct + const auto tree_nodes = root.all_nodes(); + ASSERT_EQ(tree_nodes.size(), NODE_COUNT - 1); + + // Verify the branch count + const auto tree_branches = root.branches(); + ASSERT_EQ(tree_branches.size(), BRANCH_COUNT); + + // Verify that the branch is not a leaf + ASSERT_FALSE(tree_branches.front().leaf()); +} + +/** + * @brief Test that a tree can support many shallow branches. + * + * ┌───┬───0───┬───┐ + * │ │ │ │ │ + * ▼ ▼ ▼ ▼ ▼ + * 1 2 3 4 5 + */ +TEST(TreeNodeTests, many_shallow_branches) +{ + constexpr auto DEPTH = 1U; + constexpr auto NODE_COUNT = 6U; + constexpr auto BRANCH_COUNT = 5U; + + std::vector nodes; + std::vector> trees; + + // Create the nodes and the trees + for (unsigned int i = 0; i < NODE_COUNT; i++) + { + nodes.emplace_back(std::to_string(i)); + trees.emplace_back(nodes[i]); + } + + // Build the tree + auto& root = trees[0]; + + for (unsigned int i = 1; i < NODE_COUNT; i++) + { + root.add_branch(nodes[i]); + } + + // Verify the depth + const auto tree_depth = root.depth(); + ASSERT_EQ(tree_depth, DEPTH); + + // Verify the node count + const auto tree_nodes = root.all_nodes(); + ASSERT_EQ(tree_nodes.size(), NODE_COUNT - 1); + + // Verify the node order + static const std::array NODES_ORDER{"1", "2", "3", "4", "5"}; + int i = 0; + + for (const auto& node : tree_nodes) + { + ASSERT_EQ(node.info.name, NODES_ORDER[i]); + i++; + } + + // Verify the branch count + const auto tree_branches = root.branches(); + ASSERT_EQ(tree_branches.size(), BRANCH_COUNT); + + // Verify the branch order + i = 0; + + for (const auto& child : tree_branches) + { + ASSERT_EQ(child.info.name, NODES_ORDER[i]); + i++; + } + + // Verify that every branch is a leaf + for (const auto& branch : tree_branches) + { + ASSERT_TRUE(branch.leaf()); + } +} + +/** + * @brief Test that a tree can support a binary tree. + * + * ┌───0───┐ + * │ │ + * ▼ ▼ + * ┌──1──┐ ┌──2──┐ + * │ │ │ │ + * ▼ ▼ ▼ ▼ + * 3 4 5 6 + */ +TEST(TreeNodeTests, binary_tree) +{ + constexpr auto DEPTH = 2U; + constexpr auto NODE_COUNT = 7U; + constexpr auto BRANCH_COUNT = 2U; + + std::vector nodes; + std::vector> trees; + + // Create the nodes and the trees + for (unsigned int i = 0; i < NODE_COUNT; i++) + { + nodes.emplace_back(std::to_string(i)); + trees.emplace_back(nodes[i]); + } + + // Build the tree + trees[1].add_branch(trees[3]); + trees[1].add_branch(trees[4]); + + trees[2].add_branch(trees[5]); + trees[2].add_branch(trees[6]); + + trees[0].add_branch(trees[1]); + trees[0].add_branch(trees[2]); + + const auto& root = trees[0]; + + // Verify the depth + const auto tree_depth = root.depth(); + ASSERT_EQ(tree_depth, DEPTH); + + // Verify the node count + const auto tree_nodes = root.all_nodes(); + ASSERT_EQ(tree_nodes.size(), NODE_COUNT - 1); + + // Verify the node order + const std::array NODES_ORDER{"3", "4", "1", "5", "6", "2"}; + int i = 0; + + for (const auto& node : tree_nodes) + { + ASSERT_EQ(node.info.name, NODES_ORDER[i]); + i++; + } + + // Verify the branch count + const auto tree_branches = root.branches(); + ASSERT_EQ(tree_branches.size(), BRANCH_COUNT); + + // Verify the branch order + ASSERT_EQ(tree_branches.front().info.name, "1"); + ASSERT_EQ(tree_branches.back().info.name, "2"); + + // Verify that every branch is not a leaf + for (const auto& branch : tree_branches) + { + // Verify the branch count + const auto branch_branches = branch.branches(); + ASSERT_EQ(branch_branches.size(), BRANCH_COUNT); + + // Verify that every branch is a leaf + for (const auto& branch_branch : branch_branches) + { + ASSERT_TRUE(branch_branch.leaf()); + } + } +} + + +int main( + int argc, + char** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/utils/scripts/update_generated_code_from_idl.sh b/utils/scripts/update_generated_code_from_idl.sh index ad7ceff9264..c83ef652f09 100755 --- a/utils/scripts/update_generated_code_from_idl.sh +++ b/utils/scripts/update_generated_code_from_idl.sh @@ -21,6 +21,19 @@ files_needing_output_dir=( './include/fastdds/statistics/monitorservice_types.idl|../../../src/cpp/statistics/types|../../../test/blackbox/types/statistics' './include/fastdds/statistics/types.idl|../../../src/cpp/statistics/types|../../../test/blackbox/types/statistics' './test/blackbox/types/core/core_types.idl|.' + './test/unittest/dds/xtypes/serializers/idl/types/alias_struct/alias_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/array_struct/array_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/bitmask_struct/bitmask_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/bitset_struct/bitset_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/enum_struct/enum_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/extensibility_struct/extensibility_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/key_struct/key_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/map_struct/map_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/primitives_struct/primitives_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/sequence_struct/sequence_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/string_struct/string_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/struct_struct/struct_struct.idl|./gen' + './test/unittest/dds/xtypes/serializers/idl/types/union_struct/union_struct.idl|./gen' './test/unittest/dds/xtypes/serializers/json/types/comprehensive_type/ComprehensiveType.idl|./gen' './thirdparty/dds-types-test/IDL/aliases.idl|../../../test/dds-types-test' './thirdparty/dds-types-test/IDL/annotations.idl|../../../test/dds-types-test' diff --git a/versions.md b/versions.md index 0e089ecde11..f9a03651782 100644 --- a/versions.md +++ b/versions.md @@ -83,6 +83,7 @@ Forthcoming * Refactor in XML Parser to return DynamicTypeBuilder instead of DynamicType * Setting vendor_id in the received CacheChange_t for Data and DataFrag. * Added new DynamicData to JSON serializer (`json_serialize`). +* Added new DynamicType to IDL serializer (`idl_serialize`). Version 2.14.0 --------------