diff --git a/ddspipe_core/include/ddspipe_core/types/dynamic_types/schema.hpp b/ddspipe_core/include/ddspipe_core/types/dynamic_types/schema.hpp index 33f05a30..91f115e4 100644 --- a/ddspipe_core/include/ddspipe_core/types/dynamic_types/schema.hpp +++ b/ddspipe_core/include/ddspipe_core/types/dynamic_types/schema.hpp @@ -28,7 +28,7 @@ namespace core { namespace types { DDSPIPE_CORE_DllAPI -std::string generate_ros2_schema( +std::string generate_idl_schema( const fastrtps::types::DynamicType_ptr& dynamic_type); } /* namespace types */ diff --git a/ddspipe_core/src/cpp/types/dynamic_types/schema.cpp b/ddspipe_core/src/cpp/types/dynamic_types/schema.cpp index 59e6818f..33394386 100644 --- a/ddspipe_core/src/cpp/types/dynamic_types/schema.cpp +++ b/ddspipe_core/src/cpp/types/dynamic_types/schema.cpp @@ -36,24 +36,30 @@ namespace ddspipe { namespace core { namespace types { -constexpr const char* TYPE_SEPARATOR = - "================================================================================\n"; +constexpr const char* TYPE_OPENING = + "\n{\n"; + +constexpr const char* TYPE_CLOSURE = + "};\n"; + +constexpr const char* TAB_SEPARATOR = + " "; struct TreeNodeType { TreeNodeType( std::string member_name, std::string type_kind_name, - bool is_struct = false) + fastrtps::types::DynamicType_ptr dynamic_type) : member_name(member_name) , type_kind_name(type_kind_name) - , is_struct(is_struct) + , dynamic_type(dynamic_type) { } std::string member_name; std::string type_kind_name; - bool is_struct; + fastrtps::types::DynamicType_ptr dynamic_type; }; // Forward declaration @@ -66,7 +72,7 @@ fastrtps::types::DynamicType_ptr container_internal_type( return dyn_type->get_descriptor()->get_element_type(); } -std::vector array_size( +std::vector container_size( const fastrtps::types::DynamicType_ptr& dyn_type, bool unidimensional = true) { @@ -103,34 +109,52 @@ std::vector> get_member return result; } -std::string container_kind_to_str( - const fastrtps::types::DynamicType_ptr& dyn_type, - bool allow_bounded = false) +std::string array_kind_to_str( + const fastrtps::types::DynamicType_ptr& dyn_type) { auto internal_type = container_internal_type(dyn_type); - auto this_array_size = array_size(dyn_type); + auto this_array_size = container_size(dyn_type); std::stringstream ss; ss << type_kind_to_str(internal_type); for (const auto& bound : this_array_size) + { + ss << "[" << bound << "]"; + } + + return ss.str(); +} + +std::string sequence_kind_to_str( + const fastrtps::types::DynamicType_ptr& dyn_type) +{ + auto internal_type = container_internal_type(dyn_type); + auto this_sequence_size = container_size(dyn_type); + + std::stringstream ss; + ss << "sequence<" << type_kind_to_str(internal_type); + + for (const auto& bound : this_sequence_size) { if (bound != fastrtps::types::BOUND_UNLIMITED) { - if (allow_bounded) - { - ss << "[<=" << bound << "]"; - } - else - { - ss << "[" << bound << "]"; - } - } - else - { - ss << "[]"; + ss << ", " << bound; } } + ss << ">"; + + return ss.str(); +} + +std::string map_kind_to_str( + const fastrtps::types::DynamicType_ptr& dyn_type) +{ + std::stringstream ss; + + auto key_type = dyn_type->get_descriptor()->get_key_element_type(); + auto value_type = dyn_type->get_descriptor()->get_element_type(); + ss << "map<" << type_kind_to_str(key_type) << ", " << type_kind_to_str(value_type) << ">"; return ss.str(); } @@ -141,60 +165,69 @@ std::string type_kind_to_str( switch (dyn_type->get_kind()) { case fastrtps::types::TK_BOOLEAN: - return "bool"; + return "boolean"; case fastrtps::types::TK_BYTE: - return "uint8"; + return "octet"; case fastrtps::types::TK_INT16: - return "int16"; + return "short"; case fastrtps::types::TK_INT32: - return "int32"; + return "long"; case fastrtps::types::TK_INT64: - return "int64"; + return "long long"; case fastrtps::types::TK_UINT16: - return "uint16"; + return "unsigned short"; case fastrtps::types::TK_UINT32: - return "uint32"; + return "unsigned long"; case fastrtps::types::TK_UINT64: - return "uint64"; + return "unsigned long long"; case fastrtps::types::TK_FLOAT32: - return "float32"; + return "float"; case fastrtps::types::TK_FLOAT64: - return "float64"; + return "double"; + + case fastrtps::types::TK_FLOAT128: + return "long double"; case fastrtps::types::TK_CHAR8: - return "int8"; + return "char"; + + case fastrtps::types::TK_CHAR16: + return "wchar"; case fastrtps::types::TK_STRING8: return "string"; + case fastrtps::types::TK_STRING16: + return "wstring"; + case fastrtps::types::TK_ARRAY: - return container_kind_to_str(dyn_type); + return array_kind_to_str(dyn_type); case fastrtps::types::TK_SEQUENCE: - return container_kind_to_str(dyn_type, true); + return sequence_kind_to_str(dyn_type); + + case fastrtps::types::TK_MAP: + return map_kind_to_str(dyn_type); case fastrtps::types::TK_STRUCTURE: + case fastrtps::types::TK_ENUM: + case fastrtps::types::TK_UNION: return dyn_type->get_name(); - case fastrtps::types::TK_FLOAT128: - case fastrtps::types::TK_CHAR16: - case fastrtps::types::TK_STRING16: - case fastrtps::types::TK_ENUM: case fastrtps::types::TK_BITSET: - case fastrtps::types::TK_MAP: - case fastrtps::types::TK_UNION: + case fastrtps::types::TK_BITMASK: case fastrtps::types::TK_NONE: throw utils::UnsupportedException( - STR_ENTRY << "Type " << dyn_type->get_name() << " is not supported in ROS2 msg."); + STR_ENTRY << "Type " << dyn_type->get_name() << " is not supported."); default: throw utils::InconsistencyException( @@ -202,18 +235,6 @@ std::string type_kind_to_str( } } -bool struct_kind( - const fastrtps::types::TypeKind& kind) -{ - return kind == fastrtps::types::TK_STRUCTURE; -} - -bool container_kind( - const fastrtps::types::TypeKind& kind) -{ - return kind == fastrtps::types::TK_ARRAY || kind == fastrtps::types::TK_SEQUENCE; -} - utils::TreeNode generate_dyn_type_tree( const fastrtps::types::DynamicType_ptr& type, const std::string& member_name = "PARENT") @@ -221,62 +242,152 @@ utils::TreeNode generate_dyn_type_tree( // Get kind fastrtps::types::TypeKind kind = type->get_kind(); - if (container_kind(kind)) + switch (kind) { - // If container (array or struct) has exactly one branch - // Calculate child branch - auto internal_type = container_internal_type(type); - - // Create this node - utils::TreeNode container(member_name, type_kind_to_str(type)); - // Add branch - container.add_branch(generate_dyn_type_tree(internal_type, "CONTAINER_MEMBER")); + case fastrtps::types::TK_STRUCTURE: + { + // If is struct, the call is recursive. + // Create new tree node + utils::TreeNode parent(member_name, type->get_name(), type); - return container; - } - else if (struct_kind(kind)) - { - // If is struct, the call is recursive. - // Create new tree node - utils::TreeNode parent(member_name, type->get_name(), true); + // Get all members of this struct + std::vector> members_by_name = get_members_sorted(type); - // Get all members of this struct - std::vector> members_by_name = get_members_sorted(type); + for (const auto& member : members_by_name) + { + // Add each member with its name as a new node in a branch (recursion) + parent.add_branch( + generate_dyn_type_tree(member.second, member.first)); + } + return parent; + } + break; - for (const auto& member : members_by_name) + case fastrtps::types::TK_ARRAY: + case fastrtps::types::TK_SEQUENCE: { - // Add each member with its name as a new node in a branch (recursion) - parent.add_branch( - generate_dyn_type_tree(member.second, member.first)); + // If container (array or struct) has exactly one branch + // Calculate child branch + auto internal_type = container_internal_type(type); + + // Create this node + utils::TreeNode container(member_name, type_kind_to_str(type), type); + // Add branch + container.add_branch(generate_dyn_type_tree(internal_type, "CONTAINER_MEMBER")); + + return container; } - return parent; - } - else - { - // It is primitive type, thus add type name and return - return utils::TreeNode(member_name, type_kind_to_str(type)); + break; + + default: + return utils::TreeNode(member_name, type_kind_to_str(type), type); + break; } } std::ostream& node_to_str( std::ostream& os, - const TreeNodeType& node) + const utils::TreeNode& node) { - os << node.type_kind_name << " " << node.member_name; + os << TAB_SEPARATOR; + + if (node.info.dynamic_type->get_kind() == fastrtps::types::TK_ARRAY) + { + auto dim_pos = node.info.type_kind_name.find("["); + auto kind_name_str = node.info.type_kind_name.substr(0, dim_pos); + auto dim_str = node.info.type_kind_name.substr(dim_pos, std::string::npos); + + os << kind_name_str << " " << node.info.member_name << dim_str; + } + else + { + os << node.info.type_kind_name << " " << node.info.member_name; + } + return os; } -std::ostream& generate_schema_from_node( +std::ostream& struct_to_str( std::ostream& os, const utils::TreeNode& node) { - // We know for sure this is called from structs + // Add types name + os << "struct " << node.info.type_kind_name << TYPE_OPENING; + + // Add struct attributes for (auto const& child : node.branches()) { node_to_str(os, child.info); - os << "\n"; + os << ";\n"; + } + + // Close definition + os << TYPE_CLOSURE; + + return os; +} + +std::ostream& enum_to_str( + std::ostream& os, + const utils::TreeNode& node) +{ + os << "enum " << node.info.type_kind_name << TYPE_OPENING << TAB_SEPARATOR; + + std::map members; + node.info.dynamic_type->get_all_members(members); + bool first_iter = true; + for (const auto& member : members) + { + if (!first_iter) + { + os << ",\n" << TAB_SEPARATOR; + } + first_iter = false; + + os << member.second->get_name(); } + + // Close definition + os << "\n" << TYPE_CLOSURE; + + return os; +} + +std::ostream& union_to_str( + std::ostream& os, + const utils::TreeNode& node) +{ + os << "union " << node.info.type_kind_name << " switch (" << type_kind_to_str( + node.info.dynamic_type->get_descriptor()->get_discriminator_type()) << ")" << TYPE_OPENING; + + std::map members; + node.info.dynamic_type->get_all_members(members); // WARNING: Default case not included in this collection, and currently not available + for (const auto& member : members) + { + auto labels = member.second->get_union_labels(); // WARNING: There might be casting issues as discriminant type is currently not taken into consideration + bool first_iter = true; + for (const auto& label : labels) + { + if (first_iter) + { + os << TAB_SEPARATOR; + } + else + { + os << " "; + } + first_iter = false; + + os << "case " << std::to_string(label) << ":"; + } + os << "\n" << TAB_SEPARATOR << TAB_SEPARATOR << type_kind_to_str(member.second->get_descriptor()->get_type()) << + " " << member.second->get_name() << ";\n"; + } + + // Close definition + os << TYPE_CLOSURE; + return os; } @@ -287,33 +398,44 @@ std::string generate_dyn_type_schema_from_tree( std::stringstream ss; - // Write down main node - generate_schema_from_node(ss, parent_node); - types_written.insert(parent_node.info.type_kind_name); - - // For every Node, check if it is a struct. + // For every Node, check if it is of a "writable" type (i.e. struct, enum or union). // If it is, check if it is not yet written // If it is not, write it down for (const auto& node : parent_node.all_nodes()) { - if (node.info.is_struct && types_written.find(node.info.type_kind_name) == types_written.end()) + auto kind = node.info.dynamic_type->get_kind(); + if (types_written.find(node.info.type_kind_name) == types_written.end()) { - // Add types separator - ss << TYPE_SEPARATOR; + switch (kind) + { + case fastrtps::types::TK_STRUCTURE: + struct_to_str(ss, node); + break; - // Add types name - ss << "MSG: fastdds/" << node.info.type_kind_name << "\n"; + case fastrtps::types::TK_ENUM: + enum_to_str(ss, node); + break; - // Add next type - generate_schema_from_node(ss, node); + case fastrtps::types::TK_UNION: + union_to_str(ss, node); + break; + + default: + continue; + } + ss << "\n"; // Introduce blank line between type definitions types_written.insert(node.info.type_kind_name); } } + // Write struct parent node at last, after all its dependencies + // NOTE: not a requirement for Foxglove IDL Parser, dependencies can be placed after parent + struct_to_str(ss, parent_node); + return ss.str(); } -std::string generate_ros2_schema( +std::string generate_idl_schema( const fastrtps::types::DynamicType_ptr& dynamic_type) { // Generate type tree diff --git a/ddspipe_core/test/unittest/types/dynamic_types/CMakeLists.txt b/ddspipe_core/test/unittest/types/dynamic_types/CMakeLists.txt index 1675ad62..d968e0f3 100644 --- a/ddspipe_core/test/unittest/types/dynamic_types/CMakeLists.txt +++ b/ddspipe_core/test/unittest/types/dynamic_types/CMakeLists.txt @@ -38,7 +38,7 @@ file( RESULT_SOURCES_MSG RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" - "resources/*.msg") + "types/idls/*.idl") set(TEST_NEEDED_SOURCES ${RESULT_SOURCES_MSG} diff --git a/ddspipe_core/test/unittest/types/dynamic_types/dtypes_tests.cpp b/ddspipe_core/test/unittest/types/dynamic_types/dtypes_tests.cpp index 47fdc3b8..34c008fa 100644 --- a/ddspipe_core/test/unittest/types/dynamic_types/dtypes_tests.cpp +++ b/ddspipe_core/test/unittest/types/dynamic_types/dtypes_tests.cpp @@ -30,7 +30,7 @@ using namespace eprosima; namespace test { -std::string read_msg_from_file_( +std::string read_idl_from_file_( const std::string& file_name) { return utils::file_to_string(file_name.c_str()); @@ -39,7 +39,7 @@ std::string read_msg_from_file_( std::string file_name_by_type( SupportedType type) { - return std::string("resources/") + to_string(type) + ".msg"; + return std::string("types/idls/") + to_string(type) + ".idl"; } void compare_schemas( @@ -52,17 +52,17 @@ void compare_schemas( void execute_test_by_type( SupportedType type) { - // Get msg file in string with the value expected to be generated in the schema - std::string msg_file = read_msg_from_file_(file_name_by_type(type)); + // Get IDL file in string with the value expected to be generated in the schema + std::string idl_file = read_idl_from_file_(file_name_by_type(type)); // Get Dynamic type fastrtps::types::DynamicType_ptr dyn_type = get_dynamic_type(type); // Get schema generated - std::string schema = ddspipe::core::types::generate_ros2_schema(dyn_type); + std::string schema = ddspipe::core::types::generate_idl_schema(dyn_type); // Compare schemas - compare_schemas(msg_file, schema); + compare_schemas(idl_file, schema); } } // namespace test @@ -95,7 +95,10 @@ INSTANTIATE_TEST_SUITE_P(dtypes_tests, ParametrizedTests, ::testing::Values( test::SupportedType::basic_array_struct, test::SupportedType::float_bounded_sequence, test::SupportedType::arrays_and_sequences, - test::SupportedType::complex_nested_arrays + test::SupportedType::complex_nested_arrays, + test::SupportedType::enum_struct, + test::SupportedType::union_struct, + test::SupportedType::map_struct )); int main( diff --git a/ddspipe_core/test/unittest/types/dynamic_types/resources/arrays_and_sequences.msg b/ddspipe_core/test/unittest/types/dynamic_types/resources/arrays_and_sequences.msg deleted file mode 100644 index 1942bc58..00000000 --- a/ddspipe_core/test/unittest/types/dynamic_types/resources/arrays_and_sequences.msg +++ /dev/null @@ -1,7 +0,0 @@ -AnInternalObject[] unlimited_vector -AnInternalObject[<=10] limited_vector -AnInternalObject[10] limited_array -================================================================================ -MSG: fastdds/AnInternalObject -float32 x -bool positive diff --git a/ddspipe_core/test/unittest/types/dynamic_types/resources/basic_array_struct.msg b/ddspipe_core/test/unittest/types/dynamic_types/resources/basic_array_struct.msg deleted file mode 100644 index a012398a..00000000 --- a/ddspipe_core/test/unittest/types/dynamic_types/resources/basic_array_struct.msg +++ /dev/null @@ -1,6 +0,0 @@ -uint32 index -TheOtherObjectInArray[5] sub_structs -================================================================================ -MSG: fastdds/TheOtherObjectInArray -int32 some_num -bool positive diff --git a/ddspipe_core/test/unittest/types/dynamic_types/resources/basic_struct.msg b/ddspipe_core/test/unittest/types/dynamic_types/resources/basic_struct.msg deleted file mode 100644 index eb9814cb..00000000 --- a/ddspipe_core/test/unittest/types/dynamic_types/resources/basic_struct.msg +++ /dev/null @@ -1,4 +0,0 @@ -TheOtherObject sub_struct -================================================================================ -MSG: fastdds/TheOtherObject -int32 some_num diff --git a/ddspipe_core/test/unittest/types/dynamic_types/resources/char_sequence.msg b/ddspipe_core/test/unittest/types/dynamic_types/resources/char_sequence.msg deleted file mode 100644 index bf4b2456..00000000 --- a/ddspipe_core/test/unittest/types/dynamic_types/resources/char_sequence.msg +++ /dev/null @@ -1 +0,0 @@ -int8[] chars diff --git a/ddspipe_core/test/unittest/types/dynamic_types/resources/complex_nested_arrays.msg b/ddspipe_core/test/unittest/types/dynamic_types/resources/complex_nested_arrays.msg deleted file mode 100644 index 0369ad8f..00000000 --- a/ddspipe_core/test/unittest/types/dynamic_types/resources/complex_nested_arrays.msg +++ /dev/null @@ -1,14 +0,0 @@ -FirstLevelElement[3] array_of_elements -================================================================================ -MSG: fastdds/FirstLevelElement -string useless_name -SecondLevelElement[] sub -ThirdLevelElement an_element_alone -================================================================================ -MSG: fastdds/ThirdLevelElement -float64 x -float64 y -================================================================================ -MSG: fastdds/SecondLevelElement -ThirdLevelElement an_element_alone -ThirdLevelElement[<=1] a_limited_other_value diff --git a/ddspipe_core/test/unittest/types/dynamic_types/resources/float_bounded_sequence.msg b/ddspipe_core/test/unittest/types/dynamic_types/resources/float_bounded_sequence.msg deleted file mode 100644 index 77503c2e..00000000 --- a/ddspipe_core/test/unittest/types/dynamic_types/resources/float_bounded_sequence.msg +++ /dev/null @@ -1 +0,0 @@ -float32[<=13] numbers diff --git a/ddspipe_core/test/unittest/types/dynamic_types/resources/hello_world.msg b/ddspipe_core/test/unittest/types/dynamic_types/resources/hello_world.msg deleted file mode 100644 index 63e3fbcb..00000000 --- a/ddspipe_core/test/unittest/types/dynamic_types/resources/hello_world.msg +++ /dev/null @@ -1,2 +0,0 @@ -uint32 index -string message diff --git a/ddspipe_core/test/unittest/types/dynamic_types/resources/numeric_array.msg b/ddspipe_core/test/unittest/types/dynamic_types/resources/numeric_array.msg deleted file mode 100644 index d391c85d..00000000 --- a/ddspipe_core/test/unittest/types/dynamic_types/resources/numeric_array.msg +++ /dev/null @@ -1 +0,0 @@ -int32[3] points diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/all_types.hpp b/ddspipe_core/test/unittest/types/dynamic_types/types/all_types.hpp index 1f34fce2..65fa0566 100644 --- a/ddspipe_core/test/unittest/types/dynamic_types/types/all_types.hpp +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/all_types.hpp @@ -40,6 +40,9 @@ #include "type_objects/float_bounded_sequenceTypeObject.h" #include "type_objects/arrays_and_sequencesTypeObject.h" #include "type_objects/complex_nested_arraysTypeObject.h" +#include "type_objects/enum_structTypeObject.h" +#include "type_objects/union_structTypeObject.h" +#include "type_objects/map_structTypeObject.h" namespace test { @@ -52,7 +55,10 @@ ENUMERATION_BUILDER( basic_array_struct, float_bounded_sequence, arrays_and_sequences, - complex_nested_arrays + complex_nested_arrays, + enum_struct, + union_struct, // NOTE: default case currently not supported in dynamic types + map_struct ); eprosima::fastrtps::types::DynamicType_ptr get_dynamic_type( @@ -66,6 +72,9 @@ eprosima::fastrtps::types::DynamicType_ptr get_dynamic_type( registerfloat_bounded_sequenceTypes(); registerarrays_and_sequencesTypes(); registercomplex_nested_arraysTypes(); + registerenum_structTypes(); + registerunion_structTypes(); + registermap_structTypes(); auto type_name = to_string(type); diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/idls/arrays_and_sequences.idl b/ddspipe_core/test/unittest/types/dynamic_types/types/idls/arrays_and_sequences.idl index 5fcdd54f..5d9f9819 100644 --- a/ddspipe_core/test/unittest/types/dynamic_types/types/idls/arrays_and_sequences.idl +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/idls/arrays_and_sequences.idl @@ -1,7 +1,7 @@ struct AnInternalObject { float x; - bool positive; + boolean positive; }; struct arrays_and_sequences diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/idls/basic_array_struct.idl b/ddspipe_core/test/unittest/types/dynamic_types/types/idls/basic_array_struct.idl index 6a5fe61b..b81e5956 100644 --- a/ddspipe_core/test/unittest/types/dynamic_types/types/idls/basic_array_struct.idl +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/idls/basic_array_struct.idl @@ -1,7 +1,7 @@ struct TheOtherObjectInArray { long some_num; - bool positive; + boolean positive; }; struct basic_array_struct diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/idls/enum_struct.idl b/ddspipe_core/test/unittest/types/dynamic_types/types/idls/enum_struct.idl new file mode 100644 index 00000000..c40eae6e --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/idls/enum_struct.idl @@ -0,0 +1,12 @@ +enum ColorEnum +{ + RED, + GREEN, + BLUE +}; + +struct enum_struct +{ + unsigned long index; + ColorEnum enum_value; +}; diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/idls/map_struct.idl b/ddspipe_core/test/unittest/types/dynamic_types/types/idls/map_struct.idl new file mode 100644 index 00000000..d4d19acb --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/idls/map_struct.idl @@ -0,0 +1,4 @@ +struct map_struct +{ + map my_map; +}; diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/idls/union_struct.idl b/ddspipe_core/test/unittest/types/dynamic_types/types/idls/union_struct.idl new file mode 100644 index 00000000..3967f961 --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/idls/union_struct.idl @@ -0,0 +1,15 @@ +union MyUnion switch (long) +{ + case 1: + octet octet_value; + case 2: + long long_value; + case 3: + string string_value; +}; + +struct union_struct +{ + unsigned long index; + MyUnion union_value; +}; diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_struct.cxx b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_struct.cxx new file mode 100644 index 00000000..908a7a0e --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_struct.cxx @@ -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 enum_struct.cpp + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifdef _WIN32 +// Remove linker warning LNK4221 on Visual Studio +namespace { +char dummy; +} // namespace +#endif // _WIN32 + +#include "enum_struct.h" +#include "enum_structTypeObject.h" +#include + +#include +using namespace eprosima::fastcdr::exception; + +#include + +#define enum_struct_max_cdr_typesize 8ULL; + +#define enum_struct_max_key_cdr_typesize 0ULL; + + + +enum_struct::enum_struct() +{ + // unsigned long m_index + m_index = 0; + // ColorEnum m_enum_value + m_enum_value = ::RED; + + // Just to register all known types + registerenum_structTypes(); +} + +enum_struct::~enum_struct() +{ + + +} + +enum_struct::enum_struct( + const enum_struct& x) +{ + m_index = x.m_index; + m_enum_value = x.m_enum_value; +} + +enum_struct::enum_struct( + enum_struct&& x) noexcept +{ + m_index = x.m_index; + m_enum_value = x.m_enum_value; +} + +enum_struct& enum_struct::operator =( + const enum_struct& x) +{ + + m_index = x.m_index; + m_enum_value = x.m_enum_value; + + return *this; +} + +enum_struct& enum_struct::operator =( + enum_struct&& x) noexcept +{ + + m_index = x.m_index; + m_enum_value = x.m_enum_value; + + return *this; +} + +bool enum_struct::operator ==( + const enum_struct& x) const +{ + + return (m_index == x.m_index && m_enum_value == x.m_enum_value); +} + +bool enum_struct::operator !=( + const enum_struct& x) const +{ + return !(*this == x); +} + +size_t enum_struct::getMaxCdrSerializedSize( + size_t current_alignment) +{ + static_cast(current_alignment); + return enum_struct_max_cdr_typesize; +} + +size_t enum_struct::getCdrSerializedSize( + const enum_struct& data, + size_t current_alignment) +{ + (void)data; + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + + return current_alignment - initial_alignment; +} + +void enum_struct::serialize( + eprosima::fastcdr::Cdr& scdr) const +{ + + scdr << m_index; + scdr << (uint32_t)m_enum_value; + +} + +void enum_struct::deserialize( + eprosima::fastcdr::Cdr& dcdr) +{ + + dcdr >> m_index; + { + uint32_t enum_value = 0; + dcdr >> enum_value; + m_enum_value = (ColorEnum)enum_value; + } + +} + +/*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ +void enum_struct::index( + uint32_t _index) +{ + m_index = _index; +} + +/*! + * @brief This function returns the value of member index + * @return Value of member index + */ +uint32_t enum_struct::index() const +{ + return m_index; +} + +/*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ +uint32_t& enum_struct::index() +{ + return m_index; +} + +/*! + * @brief This function sets a value in member enum_value + * @param _enum_value New value for member enum_value + */ +void enum_struct::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 + */ +ColorEnum enum_struct::enum_value() const +{ + return m_enum_value; +} + +/*! + * @brief This function returns a reference to member enum_value + * @return Reference to member enum_value + */ +ColorEnum& enum_struct::enum_value() +{ + return m_enum_value; +} + + + +size_t enum_struct::getKeyMaxCdrSerializedSize( + size_t current_alignment) +{ + static_cast(current_alignment); + return enum_struct_max_key_cdr_typesize; +} + +bool enum_struct::isKeyDefined() +{ + return false; +} + +void enum_struct::serializeKey( + eprosima::fastcdr::Cdr& scdr) const +{ + (void) scdr; +} + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_struct.h b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_struct.h new file mode 100644 index 00000000..13c10e1e --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_struct.h @@ -0,0 +1,240 @@ +// 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.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _FAST_DDS_GENERATED_ENUM_STRUCT_H_ +#define _FAST_DDS_GENERATED_ENUM_STRUCT_H_ + + +#include + +#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(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 + +namespace eprosima { +namespace fastcdr { +class Cdr; +} // namespace fastcdr +} // namespace eprosima + + +/*! + * @brief This class represents the enumeration ColorEnum defined by the user in the IDL file. + * @ingroup enum_struct + */ +enum ColorEnum : uint32_t +{ + RED, + GREEN, + BLUE +}; +/*! + * @brief This class represents the structure enum_struct defined by the user in the IDL file. + * @ingroup enum_struct + */ +class enum_struct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport enum_struct(); + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~enum_struct(); + + /*! + * @brief Copy constructor. + * @param x Reference to the object enum_struct that will be copied. + */ + eProsima_user_DllExport enum_struct( + const enum_struct& x); + + /*! + * @brief Move constructor. + * @param x Reference to the object enum_struct that will be copied. + */ + eProsima_user_DllExport enum_struct( + enum_struct&& x) noexcept; + + /*! + * @brief Copy assignment. + * @param x Reference to the object enum_struct that will be copied. + */ + eProsima_user_DllExport enum_struct& operator =( + const enum_struct& x); + + /*! + * @brief Move assignment. + * @param x Reference to the object enum_struct that will be copied. + */ + eProsima_user_DllExport enum_struct& operator =( + enum_struct&& x) noexcept; + + /*! + * @brief Comparison operator. + * @param x enum_struct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const enum_struct& x) const; + + /*! + * @brief Comparison operator. + * @param x enum_struct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const enum_struct& x) const; + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index); + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const; + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index(); + + /*! + * @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); + + /*! + * @brief This function returns the value of member enum_value + * @return Value of member enum_value + */ + eProsima_user_DllExport ColorEnum enum_value() const; + + /*! + * @brief This function returns a reference to member enum_value + * @return Reference to member enum_value + */ + eProsima_user_DllExport ColorEnum& enum_value(); + + + /*! + * @brief This function returns the maximum serialized size of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function returns the serialized size of a data depending on the buffer alignment. + * @param data Data which is calculated its serialized size. + * @param current_alignment Buffer alignment. + * @return Serialized size. + */ + eProsima_user_DllExport static size_t getCdrSerializedSize( + const enum_struct& data, + size_t current_alignment = 0); + + + /*! + * @brief This function serializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& cdr) const; + + /*! + * @brief This function deserializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr); + + + + /*! + * @brief This function returns the maximum serialized size of the Key of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function tells you if the Key has been defined for this type + */ + eProsima_user_DllExport static bool isKeyDefined(); + + /*! + * @brief This function serializes the key members of an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serializeKey( + eprosima::fastcdr::Cdr& cdr) const; + +private: + + uint32_t m_index; + ColorEnum m_enum_value; + +}; + +#endif // _FAST_DDS_GENERATED_ENUM_STRUCT_H_ + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structPubSubTypes.cxx b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structPubSubTypes.cxx new file mode 100644 index 00000000..f03142d6 --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structPubSubTypes.cxx @@ -0,0 +1,171 @@ +// 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 fastcdrgen. + */ + + +#include +#include + +#include "enum_structPubSubTypes.h" + +using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; + + +enum_structPubSubType::enum_structPubSubType() +{ + setName("enum_struct"); + auto type_size = enum_struct::getMaxCdrSerializedSize(); + type_size += eprosima::fastcdr::Cdr::alignment(type_size, 4); /* possible submessage alignment */ + m_typeSize = static_cast(type_size) + 4; /*encapsulation*/ + m_isGetKeyDefined = enum_struct::isKeyDefined(); + size_t keyLength = enum_struct::getKeyMaxCdrSerializedSize() > 16 ? + enum_struct::getKeyMaxCdrSerializedSize() : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +enum_structPubSubType::~enum_structPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool enum_structPubSubType::serialize( + void* data, + SerializedPayload_t* payload) +{ + enum_struct* 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, eprosima::fastcdr::Cdr::DDS_CDR); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + p_type->serialize(ser); + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length + payload->length = static_cast(ser.getSerializedDataLength()); + return true; +} + +bool enum_structPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + enum_struct* 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, eprosima::fastcdr::Cdr::DDS_CDR); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + p_type->deserialize(deser); + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function enum_structPubSubType::getSerializedSizeProvider( + void* data) +{ + return [data]() -> uint32_t + { + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; + }; +} + +void* enum_structPubSubType::createData() +{ + return reinterpret_cast(new enum_struct()); +} + +void enum_structPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool enum_structPubSubType::getKey( + void* data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + enum_struct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + enum_struct::getKeyMaxCdrSerializedSize()); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); + p_type->serializeKey(ser); + if (force_md5 || enum_struct::getKeyMaxCdrSerializedSize() > 16) + { + m_md5.init(); + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); + 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; +} + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structPubSubTypes.h b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structPubSubTypes.h new file mode 100644 index 00000000..21694418 --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structPubSubTypes.h @@ -0,0 +1,106 @@ +// 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.h + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ + + +#ifndef _FAST_DDS_GENERATED_ENUM_STRUCT_PUBSUBTYPES_H_ +#define _FAST_DDS_GENERATED_ENUM_STRUCT_PUBSUBTYPES_H_ + +#include +#include + +#include "enum_struct.h" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 1) +#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 enum_struct defined by the user in the IDL file. + * @ingroup enum_struct + */ +class enum_structPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef enum_struct type; + + eProsima_user_DllExport enum_structPubSubType(); + + eProsima_user_DllExport virtual ~enum_structPubSubType() override; + + eProsima_user_DllExport virtual bool serialize( + void* data, + eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; + + eProsima_user_DllExport virtual bool deserialize( + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport virtual std::function getSerializedSizeProvider( + void* data) override; + + eProsima_user_DllExport virtual bool getKey( + void* data, + eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport virtual void* createData() override; + + eProsima_user_DllExport virtual void deleteData( + void* data) 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; + } + +#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 + { + (void)memory; + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // _FAST_DDS_GENERATED_ENUM_STRUCT_PUBSUBTYPES_H_ + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structTypeObject.cxx b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structTypeObject.cxx new file mode 100644 index 00000000..109026e6 --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structTypeObject.cxx @@ -0,0 +1,470 @@ +// 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_structTypeObject.cpp + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifdef _WIN32 +// Remove linker warning LNK4221 on Visual Studio +namespace { char dummy; } +#endif + +#include "enum_struct.h" +#include "enum_structTypeObject.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace eprosima::fastrtps::rtps; + +void registerenum_structTypes() +{ + static std::once_flag once_flag; + std::call_once(once_flag, []() + { + TypeObjectFactory *factory = TypeObjectFactory::get_instance(); + factory->add_type_object("ColorEnum", GetColorEnumIdentifier(true), + GetColorEnumObject(true)); + factory->add_type_object("ColorEnum", GetColorEnumIdentifier(false), + GetColorEnumObject(false)); + + factory->add_type_object("enum_struct", Getenum_structIdentifier(true), + Getenum_structObject(true)); + factory->add_type_object("enum_struct", Getenum_structIdentifier(false), + Getenum_structObject(false)); + + }); +} + +const TypeIdentifier* GetColorEnumIdentifier(bool complete) +{ + const TypeIdentifier* c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("ColorEnum", complete); + if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) + { + return c_identifier; + } + + GetColorEnumObject(complete); // Generated inside + return TypeObjectFactory::get_instance()->get_type_identifier("ColorEnum", complete); +} + +const TypeObject* GetColorEnumObject(bool complete) +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("ColorEnum", complete); + if (c_type_object != nullptr) + { + return c_type_object; + } + else if (complete) + { + return GetCompleteColorEnumObject(); + } + // else + return GetMinimalColorEnumObject(); +} + +const TypeObject* GetMinimalColorEnumObject() +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("ColorEnum", false); + if (c_type_object != nullptr) + { + return c_type_object; + } + + TypeObject *type_object = new TypeObject(); + type_object->_d(EK_MINIMAL); + type_object->minimal()._d(TK_ENUM); + + // No flags apply + //type_object->minimal().enumerated_type().enum_flags().IS_FINAL(false); + //type_object->minimal().enumerated_type().enum_flags().IS_APPENDABLE(false); + //type_object->minimal().enumerated_type().enum_flags().IS_MUTABLE(false); + //type_object->minimal().enumerated_type().enum_flags().IS_NESTED(false); + //type_object->minimal().enumerated_type().enum_flags().IS_AUTOID_HASH(false); + + type_object->minimal().enumerated_type().header().common().bit_bound(32); // TODO fixed by IDL, isn't? + + uint32_t value = 0; + MinimalEnumeratedLiteral mel_RED; + mel_RED.common().flags().TRY_CONSTRUCT1(false); // Doesn't apply + mel_RED.common().flags().TRY_CONSTRUCT2(false); // Doesn't apply + mel_RED.common().flags().IS_EXTERNAL(false); // Doesn't apply + mel_RED.common().flags().IS_OPTIONAL(false); // Doesn't apply + mel_RED.common().flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + mel_RED.common().flags().IS_KEY(false); // Doesn't apply + mel_RED.common().flags().IS_DEFAULT(false); + mel_RED.common().value(value++); + MD5 RED_hash("RED"); + for(int i = 0; i < 4; ++i) + { + mel_RED.detail().name_hash()[i] = RED_hash.digest[i]; + } + type_object->minimal().enumerated_type().literal_seq().emplace_back(mel_RED); + + MinimalEnumeratedLiteral mel_GREEN; + mel_GREEN.common().flags().TRY_CONSTRUCT1(false); // Doesn't apply + mel_GREEN.common().flags().TRY_CONSTRUCT2(false); // Doesn't apply + mel_GREEN.common().flags().IS_EXTERNAL(false); // Doesn't apply + mel_GREEN.common().flags().IS_OPTIONAL(false); // Doesn't apply + mel_GREEN.common().flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + mel_GREEN.common().flags().IS_KEY(false); // Doesn't apply + mel_GREEN.common().flags().IS_DEFAULT(false); + mel_GREEN.common().value(value++); + MD5 GREEN_hash("GREEN"); + for(int i = 0; i < 4; ++i) + { + mel_GREEN.detail().name_hash()[i] = GREEN_hash.digest[i]; + } + type_object->minimal().enumerated_type().literal_seq().emplace_back(mel_GREEN); + + MinimalEnumeratedLiteral mel_BLUE; + mel_BLUE.common().flags().TRY_CONSTRUCT1(false); // Doesn't apply + mel_BLUE.common().flags().TRY_CONSTRUCT2(false); // Doesn't apply + mel_BLUE.common().flags().IS_EXTERNAL(false); // Doesn't apply + mel_BLUE.common().flags().IS_OPTIONAL(false); // Doesn't apply + mel_BLUE.common().flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + mel_BLUE.common().flags().IS_KEY(false); // Doesn't apply + mel_BLUE.common().flags().IS_DEFAULT(false); + mel_BLUE.common().value(value++); + MD5 BLUE_hash("BLUE"); + for(int i = 0; i < 4; ++i) + { + mel_BLUE.detail().name_hash()[i] = BLUE_hash.digest[i]; + } + type_object->minimal().enumerated_type().literal_seq().emplace_back(mel_BLUE); + + + TypeIdentifier identifier; + identifier._d(EK_MINIMAL); + + SerializedPayload_t payload(static_cast( + MinimalEnumeratedType::getCdrSerializedSize(type_object->minimal().enumerated_type()) + 4)); + eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); + // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) + eprosima::fastcdr::Cdr ser( + fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload.encapsulation = CDR_LE; + + type_object->serialize(ser); + payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + MD5 objectHash; + objectHash.update((char*)payload.data, payload.length); + objectHash.finalize(); + for(int i = 0; i < 14; ++i) + { + identifier.equivalence_hash()[i] = objectHash.digest[i]; + } + + TypeObjectFactory::get_instance()->add_type_object("ColorEnum", &identifier, type_object); + delete type_object; + return TypeObjectFactory::get_instance()->get_type_object("ColorEnum", false); +} + +const TypeObject* GetCompleteColorEnumObject() +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("ColorEnum", true); + if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) + { + return c_type_object; + } + + TypeObject *type_object = new TypeObject(); + type_object->_d(EK_COMPLETE); + type_object->complete()._d(TK_ENUM); + + // No flags apply + //type_object->complete().enumerated_type().enum_flags().IS_FINAL(false); + //type_object->complete().enumerated_type().enum_flags().IS_APPENDABLE(false); + //type_object->complete().enumerated_type().enum_flags().IS_MUTABLE(false); + //type_object->complete().enumerated_type().enum_flags().IS_NESTED(false); + //type_object->complete().enumerated_type().enum_flags().IS_AUTOID_HASH(false); + + type_object->complete().enumerated_type().header().common().bit_bound(32); // TODO fixed by IDL, isn't? + type_object->complete().enumerated_type().header().detail().type_name("ColorEnum"); + + + uint32_t value = 0; + CompleteEnumeratedLiteral cel_RED; + cel_RED.common().flags().TRY_CONSTRUCT1(false); // Doesn't apply + cel_RED.common().flags().TRY_CONSTRUCT2(false); // Doesn't apply + cel_RED.common().flags().IS_EXTERNAL(false); // Doesn't apply + cel_RED.common().flags().IS_OPTIONAL(false); // Doesn't apply + cel_RED.common().flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + cel_RED.common().flags().IS_KEY(false); // Doesn't apply + cel_RED.common().flags().IS_DEFAULT(false); + cel_RED.common().value(value++); + cel_RED.detail().name("RED"); + + type_object->complete().enumerated_type().literal_seq().emplace_back(cel_RED); + + CompleteEnumeratedLiteral cel_GREEN; + cel_GREEN.common().flags().TRY_CONSTRUCT1(false); // Doesn't apply + cel_GREEN.common().flags().TRY_CONSTRUCT2(false); // Doesn't apply + cel_GREEN.common().flags().IS_EXTERNAL(false); // Doesn't apply + cel_GREEN.common().flags().IS_OPTIONAL(false); // Doesn't apply + cel_GREEN.common().flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + cel_GREEN.common().flags().IS_KEY(false); // Doesn't apply + cel_GREEN.common().flags().IS_DEFAULT(false); + cel_GREEN.common().value(value++); + cel_GREEN.detail().name("GREEN"); + + type_object->complete().enumerated_type().literal_seq().emplace_back(cel_GREEN); + + CompleteEnumeratedLiteral cel_BLUE; + cel_BLUE.common().flags().TRY_CONSTRUCT1(false); // Doesn't apply + cel_BLUE.common().flags().TRY_CONSTRUCT2(false); // Doesn't apply + cel_BLUE.common().flags().IS_EXTERNAL(false); // Doesn't apply + cel_BLUE.common().flags().IS_OPTIONAL(false); // Doesn't apply + cel_BLUE.common().flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + cel_BLUE.common().flags().IS_KEY(false); // Doesn't apply + cel_BLUE.common().flags().IS_DEFAULT(false); + cel_BLUE.common().value(value++); + cel_BLUE.detail().name("BLUE"); + + type_object->complete().enumerated_type().literal_seq().emplace_back(cel_BLUE); + + + TypeIdentifier identifier; + identifier._d(EK_COMPLETE); + + SerializedPayload_t payload(static_cast( + CompleteEnumeratedType::getCdrSerializedSize(type_object->complete().enumerated_type()) + 4)); + eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); + // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) + eprosima::fastcdr::Cdr ser( + fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload.encapsulation = CDR_LE; + + type_object->serialize(ser); + payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + MD5 objectHash; + objectHash.update((char*)payload.data, payload.length); + objectHash.finalize(); + for(int i = 0; i < 14; ++i) + { + identifier.equivalence_hash()[i] = objectHash.digest[i]; + } + + TypeObjectFactory::get_instance()->add_type_object("ColorEnum", &identifier, type_object); + delete type_object; + return TypeObjectFactory::get_instance()->get_type_object("ColorEnum", true); +} + +const TypeIdentifier* Getenum_structIdentifier(bool complete) +{ + const TypeIdentifier * c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("enum_struct", complete); + if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) + { + return c_identifier; + } + + Getenum_structObject(complete); // Generated inside + return TypeObjectFactory::get_instance()->get_type_identifier("enum_struct", complete); +} + +const TypeObject* Getenum_structObject(bool complete) +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("enum_struct", complete); + if (c_type_object != nullptr) + { + return c_type_object; + } + else if (complete) + { + return GetCompleteenum_structObject(); + } + //else + return GetMinimalenum_structObject(); +} + +const TypeObject* GetMinimalenum_structObject() +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("enum_struct", false); + if (c_type_object != nullptr) + { + return c_type_object; + } + + TypeObject *type_object = new TypeObject(); + type_object->_d(EK_MINIMAL); + type_object->minimal()._d(TK_STRUCTURE); + + type_object->minimal().struct_type().struct_flags().IS_FINAL(false); + type_object->minimal().struct_type().struct_flags().IS_APPENDABLE(false); + type_object->minimal().struct_type().struct_flags().IS_MUTABLE(false); + type_object->minimal().struct_type().struct_flags().IS_NESTED(false); + type_object->minimal().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported + + MemberId memberId = 0; + MinimalStructMember mst_index; + mst_index.common().member_id(memberId++); + mst_index.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + mst_index.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + mst_index.common().member_flags().IS_EXTERNAL(false); // Unsupported + mst_index.common().member_flags().IS_OPTIONAL(false); + mst_index.common().member_flags().IS_MUST_UNDERSTAND(false); + mst_index.common().member_flags().IS_KEY(false); + mst_index.common().member_flags().IS_DEFAULT(false); // Doesn't apply + mst_index.common().member_type_id(*TypeObjectFactory::get_instance()->get_type_identifier("uint32_t", false)); + + MD5 index_hash("index"); + for(int i = 0; i < 4; ++i) + { + mst_index.detail().name_hash()[i] = index_hash.digest[i]; + } + type_object->minimal().struct_type().member_seq().emplace_back(mst_index); + + MinimalStructMember mst_enum_value; + mst_enum_value.common().member_id(memberId++); + mst_enum_value.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + mst_enum_value.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + mst_enum_value.common().member_flags().IS_EXTERNAL(false); // Unsupported + mst_enum_value.common().member_flags().IS_OPTIONAL(false); + mst_enum_value.common().member_flags().IS_MUST_UNDERSTAND(false); + mst_enum_value.common().member_flags().IS_KEY(false); + mst_enum_value.common().member_flags().IS_DEFAULT(false); // Doesn't apply + mst_enum_value.common().member_type_id(*GetColorEnumIdentifier(false)); + MD5 enum_value_hash("enum_value"); + for(int i = 0; i < 4; ++i) + { + mst_enum_value.detail().name_hash()[i] = enum_value_hash.digest[i]; + } + type_object->minimal().struct_type().member_seq().emplace_back(mst_enum_value); + + + // Header + // TODO Inheritance + //type_object->minimal().struct_type().header().base_type()._d(EK_MINIMAL); + //type_object->minimal().struct_type().header().base_type().equivalence_hash()[0..13]; + + TypeIdentifier identifier; + identifier._d(EK_MINIMAL); + + SerializedPayload_t payload(static_cast( + MinimalStructType::getCdrSerializedSize(type_object->minimal().struct_type()) + 4)); + eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); + // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) + eprosima::fastcdr::Cdr ser( + fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload.encapsulation = CDR_LE; + + type_object->serialize(ser); + payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + MD5 objectHash; + objectHash.update((char*)payload.data, payload.length); + objectHash.finalize(); + for(int i = 0; i < 14; ++i) + { + identifier.equivalence_hash()[i] = objectHash.digest[i]; + } + + TypeObjectFactory::get_instance()->add_type_object("enum_struct", &identifier, type_object); + delete type_object; + return TypeObjectFactory::get_instance()->get_type_object("enum_struct", false); +} + +const TypeObject* GetCompleteenum_structObject() +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("enum_struct", true); + if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) + { + return c_type_object; + } + + TypeObject *type_object = new TypeObject(); + type_object->_d(EK_COMPLETE); + type_object->complete()._d(TK_STRUCTURE); + + type_object->complete().struct_type().struct_flags().IS_FINAL(false); + type_object->complete().struct_type().struct_flags().IS_APPENDABLE(false); + type_object->complete().struct_type().struct_flags().IS_MUTABLE(false); + type_object->complete().struct_type().struct_flags().IS_NESTED(false); + type_object->complete().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported + + MemberId memberId = 0; + CompleteStructMember cst_index; + cst_index.common().member_id(memberId++); + cst_index.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + cst_index.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + cst_index.common().member_flags().IS_EXTERNAL(false); // Unsupported + cst_index.common().member_flags().IS_OPTIONAL(false); + cst_index.common().member_flags().IS_MUST_UNDERSTAND(false); + cst_index.common().member_flags().IS_KEY(false); + cst_index.common().member_flags().IS_DEFAULT(false); // Doesn't apply + cst_index.common().member_type_id(*TypeObjectFactory::get_instance()->get_type_identifier("uint32_t", false)); + + cst_index.detail().name("index"); + + type_object->complete().struct_type().member_seq().emplace_back(cst_index); + + CompleteStructMember cst_enum_value; + cst_enum_value.common().member_id(memberId++); + cst_enum_value.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + cst_enum_value.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + cst_enum_value.common().member_flags().IS_EXTERNAL(false); // Unsupported + cst_enum_value.common().member_flags().IS_OPTIONAL(false); + cst_enum_value.common().member_flags().IS_MUST_UNDERSTAND(false); + cst_enum_value.common().member_flags().IS_KEY(false); + cst_enum_value.common().member_flags().IS_DEFAULT(false); // Doesn't apply + cst_enum_value.common().member_type_id(*GetColorEnumIdentifier(true)); + cst_enum_value.detail().name("enum_value"); + + type_object->complete().struct_type().member_seq().emplace_back(cst_enum_value); + + + // Header + type_object->complete().struct_type().header().detail().type_name("enum_struct"); + // TODO inheritance + + + TypeIdentifier identifier; + identifier._d(EK_COMPLETE); + + SerializedPayload_t payload(static_cast( + CompleteStructType::getCdrSerializedSize(type_object->complete().struct_type()) + 4)); + eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); + // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) + eprosima::fastcdr::Cdr ser( + fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload.encapsulation = CDR_LE; + + type_object->serialize(ser); + payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + MD5 objectHash; + objectHash.update((char*)payload.data, payload.length); + objectHash.finalize(); + for(int i = 0; i < 14; ++i) + { + identifier.equivalence_hash()[i] = objectHash.digest[i]; + } + + TypeObjectFactory::get_instance()->add_type_object("enum_struct", &identifier, type_object); + delete type_object; + return TypeObjectFactory::get_instance()->get_type_object("enum_struct", true); +} diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structTypeObject.h b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structTypeObject.h new file mode 100644 index 00000000..ba3c63a0 --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/enum_structTypeObject.h @@ -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_structTypeObject.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _FAST_DDS_GENERATED_ENUM_STRUCT_TYPE_OBJECT_H_ +#define _FAST_DDS_GENERATED_ENUM_STRUCT_TYPE_OBJECT_H_ + + +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif +#else +#define eProsima_user_DllExport +#endif + +#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 +#else +#define enum_struct_DllAPI +#endif // _WIN32 + +using namespace eprosima::fastrtps::types; + +eProsima_user_DllExport void registerenum_structTypes(); + +eProsima_user_DllExport const TypeIdentifier* GetColorEnumIdentifier(bool complete = false); +eProsima_user_DllExport const TypeObject* GetColorEnumObject(bool complete = false); +eProsima_user_DllExport const TypeObject* GetMinimalColorEnumObject(); +eProsima_user_DllExport const TypeObject* GetCompleteColorEnumObject(); + +eProsima_user_DllExport const TypeIdentifier* Getenum_structIdentifier(bool complete = false); +eProsima_user_DllExport const TypeObject* Getenum_structObject(bool complete = false); +eProsima_user_DllExport const TypeObject* GetMinimalenum_structObject(); +eProsima_user_DllExport const TypeObject* GetCompleteenum_structObject(); + + +#endif // _FAST_DDS_GENERATED_ENUM_STRUCT_TYPE_OBJECT_H_ \ No newline at end of file diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_struct.cxx b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_struct.cxx new file mode 100644 index 00000000..412bd689 --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_struct.cxx @@ -0,0 +1,195 @@ +// 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.cpp + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifdef _WIN32 +// Remove linker warning LNK4221 on Visual Studio +namespace { +char dummy; +} // namespace +#endif // _WIN32 + +#include "map_struct.h" +#include "map_structTypeObject.h" +#include + +#include +using namespace eprosima::fastcdr::exception; + +#include + +#define map_struct_max_cdr_typesize 26401ULL; +#define map_struct_max_key_cdr_typesize 0ULL; + +map_struct::map_struct() +{ + // map m_my_map + + + // Just to register all known types + registermap_structTypes(); +} + +map_struct::~map_struct() +{ +} + +map_struct::map_struct( + const map_struct& x) +{ + m_my_map = x.m_my_map; +} + +map_struct::map_struct( + map_struct&& x) noexcept +{ + m_my_map = std::move(x.m_my_map); +} + +map_struct& map_struct::operator =( + const map_struct& x) +{ + + m_my_map = x.m_my_map; + + return *this; +} + +map_struct& map_struct::operator =( + map_struct&& x) noexcept +{ + + m_my_map = std::move(x.m_my_map); + + return *this; +} + +bool map_struct::operator ==( + const map_struct& x) const +{ + + return (m_my_map == x.m_my_map); +} + +bool map_struct::operator !=( + const map_struct& x) const +{ + return !(*this == x); +} + +size_t map_struct::getMaxCdrSerializedSize( + size_t current_alignment) +{ + static_cast(current_alignment); + return map_struct_max_cdr_typesize; +} + +size_t map_struct::getCdrSerializedSize( + const map_struct& data, + size_t current_alignment) +{ + (void)data; + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + for(auto a : data.my_map()) + { + (void)a; + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + a.first.size() + 1; + current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1); + + } + + return current_alignment - initial_alignment; +} + +void map_struct::serialize( + eprosima::fastcdr::Cdr& scdr) const +{ + + scdr << m_my_map; +} + +void map_struct::deserialize( + eprosima::fastcdr::Cdr& dcdr) +{ + + dcdr >> m_my_map;} + +/*! + * @brief This function copies the value in member my_map + * @param _my_map New value to be copied in member my_map + */ +void map_struct::my_map( + const std::map& _my_map) +{ + m_my_map = _my_map; +} + +/*! + * @brief This function moves the value in member my_map + * @param _my_map New value to be moved in member my_map + */ +void map_struct::my_map( + std::map&& _my_map) +{ + m_my_map = std::move(_my_map); +} + +/*! + * @brief This function returns a constant reference to member my_map + * @return Constant reference to member my_map + */ +const std::map& map_struct::my_map() const +{ + return m_my_map; +} + +/*! + * @brief This function returns a reference to member my_map + * @return Reference to member my_map + */ +std::map& map_struct::my_map() +{ + return m_my_map; +} + + +size_t map_struct::getKeyMaxCdrSerializedSize( + size_t current_alignment) +{ + static_cast(current_alignment); + return map_struct_max_key_cdr_typesize; +} + +bool map_struct::isKeyDefined() +{ + return false; +} + +void map_struct::serializeKey( + eprosima::fastcdr::Cdr& scdr) const +{ + (void) scdr; +} + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_struct.h b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_struct.h new file mode 100644 index 00000000..bc84b5fa --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_struct.h @@ -0,0 +1,216 @@ +// 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.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _FAST_DDS_GENERATED_MAP_STRUCT_H_ +#define _FAST_DDS_GENERATED_MAP_STRUCT_H_ + + +#include + +#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(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 + +namespace eprosima { +namespace fastcdr { +class Cdr; +} // namespace fastcdr +} // namespace eprosima + + +/*! + * @brief This class represents the structure map_struct defined by the user in the IDL file. + * @ingroup map_struct + */ +class map_struct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport map_struct(); + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~map_struct(); + + /*! + * @brief Copy constructor. + * @param x Reference to the object map_struct that will be copied. + */ + eProsima_user_DllExport map_struct( + const map_struct& x); + + /*! + * @brief Move constructor. + * @param x Reference to the object map_struct that will be copied. + */ + eProsima_user_DllExport map_struct( + map_struct&& x) noexcept; + + /*! + * @brief Copy assignment. + * @param x Reference to the object map_struct that will be copied. + */ + eProsima_user_DllExport map_struct& operator =( + const map_struct& x); + + /*! + * @brief Move assignment. + * @param x Reference to the object map_struct that will be copied. + */ + eProsima_user_DllExport map_struct& operator =( + map_struct&& x) noexcept; + + /*! + * @brief Comparison operator. + * @param x map_struct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const map_struct& x) const; + + /*! + * @brief Comparison operator. + * @param x map_struct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const map_struct& x) const; + + /*! + * @brief This function copies the value in member my_map + * @param _my_map New value to be copied in member my_map + */ + eProsima_user_DllExport void my_map( + const std::map& _my_map); + + /*! + * @brief This function moves the value in member my_map + * @param _my_map New value to be moved in member my_map + */ + eProsima_user_DllExport void my_map( + std::map&& _my_map); + + /*! + * @brief This function returns a constant reference to member my_map + * @return Constant reference to member my_map + */ + eProsima_user_DllExport const std::map& my_map() const; + + /*! + * @brief This function returns a reference to member my_map + * @return Reference to member my_map + */ + eProsima_user_DllExport std::map& my_map(); + + /*! + * @brief This function returns the maximum serialized size of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function returns the serialized size of a data depending on the buffer alignment. + * @param data Data which is calculated its serialized size. + * @param current_alignment Buffer alignment. + * @return Serialized size. + */ + eProsima_user_DllExport static size_t getCdrSerializedSize( + const map_struct& data, + size_t current_alignment = 0); + + + /*! + * @brief This function serializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& cdr) const; + + /*! + * @brief This function deserializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr); + + + + /*! + * @brief This function returns the maximum serialized size of the Key of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function tells you if the Key has been defined for this type + */ + eProsima_user_DllExport static bool isKeyDefined(); + + /*! + * @brief This function serializes the key members of an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serializeKey( + eprosima::fastcdr::Cdr& cdr) const; + +private: + + std::map m_my_map; + +}; + +#endif // _FAST_DDS_GENERATED_MAP_STRUCT_H_ + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structPubSubTypes.cxx b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structPubSubTypes.cxx new file mode 100644 index 00000000..37bf5b07 --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structPubSubTypes.cxx @@ -0,0 +1,170 @@ +// 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 fastcdrgen. + */ + + +#include +#include + +#include "map_structPubSubTypes.h" + +using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; + +map_structPubSubType::map_structPubSubType() +{ + setName("map_struct"); + auto type_size = map_struct::getMaxCdrSerializedSize(); + type_size += eprosima::fastcdr::Cdr::alignment(type_size, 4); /* possible submessage alignment */ + m_typeSize = static_cast(type_size) + 4; /*encapsulation*/ + m_isGetKeyDefined = map_struct::isKeyDefined(); + size_t keyLength = map_struct::getKeyMaxCdrSerializedSize() > 16 ? + map_struct::getKeyMaxCdrSerializedSize() : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +map_structPubSubType::~map_structPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool map_structPubSubType::serialize( + void* data, + SerializedPayload_t* payload) +{ + map_struct* 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, eprosima::fastcdr::Cdr::DDS_CDR); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + p_type->serialize(ser); + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length + payload->length = static_cast(ser.getSerializedDataLength()); + return true; +} + +bool map_structPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + map_struct* 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, eprosima::fastcdr::Cdr::DDS_CDR); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + p_type->deserialize(deser); + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function map_structPubSubType::getSerializedSizeProvider( + void* data) +{ + return [data]() -> uint32_t + { + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; + }; +} + +void* map_structPubSubType::createData() +{ + return reinterpret_cast(new map_struct()); +} + +void map_structPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool map_structPubSubType::getKey( + void* data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + map_struct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + map_struct::getKeyMaxCdrSerializedSize()); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); + p_type->serializeKey(ser); + if (force_md5 || map_struct::getKeyMaxCdrSerializedSize() > 16) + { + m_md5.init(); + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); + 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; +} + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structPubSubTypes.h b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structPubSubTypes.h new file mode 100644 index 00000000..82e89a7f --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structPubSubTypes.h @@ -0,0 +1,105 @@ +// 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.h + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ + + +#ifndef _FAST_DDS_GENERATED_MAP_STRUCT_PUBSUBTYPES_H_ +#define _FAST_DDS_GENERATED_MAP_STRUCT_PUBSUBTYPES_H_ + +#include +#include + +#include "map_struct.h" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 1) +#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 map_struct defined by the user in the IDL file. + * @ingroup map_struct + */ +class map_structPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef map_struct type; + + eProsima_user_DllExport map_structPubSubType(); + + eProsima_user_DllExport virtual ~map_structPubSubType() override; + + eProsima_user_DllExport virtual bool serialize( + void* data, + eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; + + eProsima_user_DllExport virtual bool deserialize( + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport virtual std::function getSerializedSizeProvider( + void* data) override; + + eProsima_user_DllExport virtual bool getKey( + void* data, + eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport virtual void* createData() override; + + eProsima_user_DllExport virtual void deleteData( + void* data) 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; + } + +#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 + { + (void)memory; + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // _FAST_DDS_GENERATED_MAP_STRUCT_PUBSUBTYPES_H_ + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structTypeObject.cxx b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structTypeObject.cxx new file mode 100644 index 00000000..397ce137 --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structTypeObject.cxx @@ -0,0 +1,220 @@ +// 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_structTypeObject.cpp + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifdef _WIN32 +// Remove linker warning LNK4221 on Visual Studio +namespace { char dummy; } +#endif + +#include "map_struct.h" +#include "map_structTypeObject.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace eprosima::fastrtps::rtps; + +void registermap_structTypes() +{ + static std::once_flag once_flag; + std::call_once(once_flag, []() + { + TypeObjectFactory *factory = TypeObjectFactory::get_instance(); + factory->add_type_object("map_struct", Getmap_structIdentifier(true), + Getmap_structObject(true)); + factory->add_type_object("map_struct", Getmap_structIdentifier(false), + Getmap_structObject(false)); + + }); +} + +const TypeIdentifier* Getmap_structIdentifier(bool complete) +{ + const TypeIdentifier * c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("map_struct", complete); + if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) + { + return c_identifier; + } + + Getmap_structObject(complete); // Generated inside + return TypeObjectFactory::get_instance()->get_type_identifier("map_struct", complete); +} + +const TypeObject* Getmap_structObject(bool complete) +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("map_struct", complete); + if (c_type_object != nullptr) + { + return c_type_object; + } + else if (complete) + { + return GetCompletemap_structObject(); + } + //else + return GetMinimalmap_structObject(); +} + +const TypeObject* GetMinimalmap_structObject() +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("map_struct", false); + if (c_type_object != nullptr) + { + return c_type_object; + } + + TypeObject *type_object = new TypeObject(); + type_object->_d(EK_MINIMAL); + type_object->minimal()._d(TK_STRUCTURE); + + type_object->minimal().struct_type().struct_flags().IS_FINAL(false); + type_object->minimal().struct_type().struct_flags().IS_APPENDABLE(false); + type_object->minimal().struct_type().struct_flags().IS_MUTABLE(false); + type_object->minimal().struct_type().struct_flags().IS_NESTED(false); + type_object->minimal().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported + + MemberId memberId = 0; + MinimalStructMember mst_my_map; + mst_my_map.common().member_id(memberId++); + mst_my_map.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + mst_my_map.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + mst_my_map.common().member_flags().IS_EXTERNAL(false); // Unsupported + mst_my_map.common().member_flags().IS_OPTIONAL(false); + mst_my_map.common().member_flags().IS_MUST_UNDERSTAND(false); + mst_my_map.common().member_flags().IS_KEY(false); + mst_my_map.common().member_flags().IS_DEFAULT(false); // Doesn't apply + mst_my_map.common().member_type_id(*TypeObjectFactory::get_instance()->get_map_identifier(TypeNamesGenerator::get_string_type_name(255, false), "bool", 100, false)); + + + MD5 my_map_hash("my_map"); + for(int i = 0; i < 4; ++i) + { + mst_my_map.detail().name_hash()[i] = my_map_hash.digest[i]; + } + type_object->minimal().struct_type().member_seq().emplace_back(mst_my_map); + + + // Header + // TODO Inheritance + //type_object->minimal().struct_type().header().base_type()._d(EK_MINIMAL); + //type_object->minimal().struct_type().header().base_type().equivalence_hash()[0..13]; + + TypeIdentifier identifier; + identifier._d(EK_MINIMAL); + + SerializedPayload_t payload(static_cast( + MinimalStructType::getCdrSerializedSize(type_object->minimal().struct_type()) + 4)); + eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); + // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) + eprosima::fastcdr::Cdr ser( + fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload.encapsulation = CDR_LE; + + type_object->serialize(ser); + payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + MD5 objectHash; + objectHash.update((char*)payload.data, payload.length); + objectHash.finalize(); + for(int i = 0; i < 14; ++i) + { + identifier.equivalence_hash()[i] = objectHash.digest[i]; + } + + TypeObjectFactory::get_instance()->add_type_object("map_struct", &identifier, type_object); + delete type_object; + return TypeObjectFactory::get_instance()->get_type_object("map_struct", false); +} + +const TypeObject* GetCompletemap_structObject() +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("map_struct", true); + if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) + { + return c_type_object; + } + + TypeObject *type_object = new TypeObject(); + type_object->_d(EK_COMPLETE); + type_object->complete()._d(TK_STRUCTURE); + + type_object->complete().struct_type().struct_flags().IS_FINAL(false); + type_object->complete().struct_type().struct_flags().IS_APPENDABLE(false); + type_object->complete().struct_type().struct_flags().IS_MUTABLE(false); + type_object->complete().struct_type().struct_flags().IS_NESTED(false); + type_object->complete().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported + + MemberId memberId = 0; + CompleteStructMember cst_my_map; + cst_my_map.common().member_id(memberId++); + cst_my_map.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + cst_my_map.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + cst_my_map.common().member_flags().IS_EXTERNAL(false); // Unsupported + cst_my_map.common().member_flags().IS_OPTIONAL(false); + cst_my_map.common().member_flags().IS_MUST_UNDERSTAND(false); + cst_my_map.common().member_flags().IS_KEY(false); + cst_my_map.common().member_flags().IS_DEFAULT(false); // Doesn't apply + cst_my_map.common().member_type_id(*TypeObjectFactory::get_instance()->get_map_identifier(TypeNamesGenerator::get_string_type_name(255, false), "bool", 100, true)); + + + cst_my_map.detail().name("my_map"); + + type_object->complete().struct_type().member_seq().emplace_back(cst_my_map); + + + // Header + type_object->complete().struct_type().header().detail().type_name("map_struct"); + // TODO inheritance + + + TypeIdentifier identifier; + identifier._d(EK_COMPLETE); + + SerializedPayload_t payload(static_cast( + CompleteStructType::getCdrSerializedSize(type_object->complete().struct_type()) + 4)); + eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); + // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) + eprosima::fastcdr::Cdr ser( + fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload.encapsulation = CDR_LE; + + type_object->serialize(ser); + payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + MD5 objectHash; + objectHash.update((char*)payload.data, payload.length); + objectHash.finalize(); + for(int i = 0; i < 14; ++i) + { + identifier.equivalence_hash()[i] = objectHash.digest[i]; + } + + TypeObjectFactory::get_instance()->add_type_object("map_struct", &identifier, type_object); + delete type_object; + return TypeObjectFactory::get_instance()->get_type_object("map_struct", true); +} diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structTypeObject.h b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structTypeObject.h new file mode 100644 index 00000000..80e03173 --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/map_structTypeObject.h @@ -0,0 +1,63 @@ +// 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_structTypeObject.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _FAST_DDS_GENERATED_MAP_STRUCT_TYPE_OBJECT_H_ +#define _FAST_DDS_GENERATED_MAP_STRUCT_TYPE_OBJECT_H_ + + +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif +#else +#define eProsima_user_DllExport +#endif + +#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 +#else +#define map_struct_DllAPI +#endif // _WIN32 + +using namespace eprosima::fastrtps::types; + +eProsima_user_DllExport void registermap_structTypes(); + +eProsima_user_DllExport const TypeIdentifier* Getmap_structIdentifier(bool complete = false); +eProsima_user_DllExport const TypeObject* Getmap_structObject(bool complete = false); +eProsima_user_DllExport const TypeObject* GetMinimalmap_structObject(); +eProsima_user_DllExport const TypeObject* GetCompletemap_structObject(); + + +#endif // _FAST_DDS_GENERATED_MAP_STRUCT_TYPE_OBJECT_H_ \ No newline at end of file diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_struct.cxx b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_struct.cxx new file mode 100644 index 00000000..ab7c818a --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_struct.cxx @@ -0,0 +1,643 @@ +// 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.cpp + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifdef _WIN32 +// Remove linker warning LNK4221 on Visual Studio +namespace { +char dummy; +} // namespace +#endif // _WIN32 + +#include "union_struct.h" +#include "union_structTypeObject.h" +#include + +#include +using namespace eprosima::fastcdr::exception; + +#include + +#define union_struct_max_cdr_typesize 268ULL; + +#define union_struct_max_key_cdr_typesize 0ULL; + + +MyUnion::MyUnion() +{ + m__d = 1; + // octet m_octet_value + m_octet_value = 0; + // long m_long_value + m_long_value = 0; + // string m_string_value + m_string_value =""; +} + +MyUnion::~MyUnion() +{ +} + +MyUnion::MyUnion( + const MyUnion& x) +{ + m__d = x.m__d; + + switch(m__d) + { + case 1: + m_octet_value = x.m_octet_value; + break; + case 2: + m_long_value = x.m_long_value; + break; + case 3: + m_string_value = x.m_string_value; + break; + default: + break; + } +} + +MyUnion::MyUnion( + MyUnion&& x) noexcept +{ + m__d = x.m__d; + + switch(m__d) + { + case 1: + m_octet_value = x.m_octet_value; + break; + case 2: + m_long_value = x.m_long_value; + break; + case 3: + m_string_value = std::move(x.m_string_value); + break; + default: + break; + } +} + +MyUnion& MyUnion::operator =( + const MyUnion& x) +{ + m__d = x.m__d; + + switch(m__d) + { + case 1: + m_octet_value = x.m_octet_value; + break; + case 2: + m_long_value = x.m_long_value; + break; + case 3: + m_string_value = x.m_string_value; + break; + default: + break; + } + + return *this; +} + +MyUnion& MyUnion::operator =( + MyUnion&& x) noexcept +{ + m__d = x.m__d; + + switch(m__d) + { + case 1: + m_octet_value = x.m_octet_value; + break; + case 2: + m_long_value = x.m_long_value; + break; + case 3: + m_string_value = std::move(x.m_string_value); + break; + default: + break; + } + + return *this; +} + +bool MyUnion::operator ==( + const MyUnion& x) const +{ + if (m__d != x.m__d) + { + return false; + } + + switch(m__d) + { + case 1: + return (m_octet_value == x.m_octet_value); + break; + case 2: + return (m_long_value == x.m_long_value); + break; + case 3: + return (m_string_value == x.m_string_value); + break; + default: + break; + } + return false; +} + +bool MyUnion::operator !=( + const MyUnion& x) const +{ + return !(*this == x); +} + +void MyUnion::_d( + int32_t __d) +{ + bool b = false; + + switch(m__d) + { + case 1: + switch(__d) + { + case 1: + b = true; + break; + default: + break; + } + break; + case 2: + switch(__d) + { + case 2: + b = true; + break; + default: + break; + } + break; + case 3: + switch(__d) + { + case 3: + b = true; + break; + default: + break; + } + break; + } + + if(!b) + { + throw BadParamException("Discriminator doesn't correspond with the selected union member"); + } + + m__d = __d; +} + +int32_t MyUnion::_d() const +{ + return m__d; +} + +int32_t& MyUnion::_d() +{ + return m__d; +} + +void MyUnion::octet_value( + uint8_t _octet_value) +{ + m_octet_value = _octet_value; + m__d = 1; +} + +uint8_t MyUnion::octet_value() const +{ + bool b = false; + + switch(m__d) + { + case 1: + b = true; + break; + default: + break; + } + if(!b) + { + throw BadParamException("This member is not been selected"); + } + + return m_octet_value; +} + +uint8_t& MyUnion::octet_value() +{ + bool b = false; + + switch(m__d) + { + case 1: + b = true; + break; + default: + break; + } + if(!b) + { + throw BadParamException("This member is not been selected"); + } + + return m_octet_value; +} +void MyUnion::long_value( + int32_t _long_value) +{ + m_long_value = _long_value; + m__d = 2; +} + +int32_t MyUnion::long_value() const +{ + bool b = false; + + switch(m__d) + { + case 2: + b = true; + break; + default: + break; + } + if(!b) + { + throw BadParamException("This member is not been selected"); + } + + return m_long_value; +} + +int32_t& MyUnion::long_value() +{ + bool b = false; + + switch(m__d) + { + case 2: + b = true; + break; + default: + break; + } + if(!b) + { + throw BadParamException("This member is not been selected"); + } + + return m_long_value; +} +void MyUnion::string_value( + const std::string& _string_value) +{ + m_string_value = _string_value; + m__d = 3; +} + +void MyUnion::string_value( + std::string&& _string_value) +{ + m_string_value = std::move(_string_value); + m__d = 3; +} + +const std::string& MyUnion::string_value() const +{ + bool b = false; + + switch(m__d) + { + case 3: + b = true; + break; + default: + break; + } + if(!b) + { + throw BadParamException("This member is not been selected"); + } + + return m_string_value; +} + +std::string& MyUnion::string_value() +{ + bool b = false; + + switch(m__d) + { + case 3: + b = true; + break; + default: + break; + } + if(!b) + { + throw BadParamException("This member is not been selected"); + } + + return m_string_value; +} + +// TODO(Ricardo) Review +size_t MyUnion::getCdrSerializedSize( + const MyUnion& data, + size_t current_alignment) +{ + (void)data; + size_t initial_alignment = current_alignment; + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + switch(data.m__d) + { + case 1: + current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1); + + break; + case 2: + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + break; + case 3: + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.string_value().size() + 1; + break; + default: + break; + } + + return current_alignment - initial_alignment; +} + +void MyUnion::serialize( + eprosima::fastcdr::Cdr& scdr) const +{ + scdr << m__d; + + switch(m__d) + { + case 1: + scdr << m_octet_value; + + break; + case 2: + scdr << m_long_value; + + break; + case 3: + scdr << m_string_value.c_str(); + + break; + default: + break; + } +} + +void MyUnion::deserialize( + eprosima::fastcdr::Cdr& dcdr) +{ + dcdr >> m__d; + + switch(m__d) + { + case 1: + dcdr >> m_octet_value; + break; + case 2: + dcdr >> m_long_value; + break; + case 3: + dcdr >> m_string_value;break; + default: + break; + } +} + + +union_struct::union_struct() +{ + // unsigned long m_index + m_index = 0; + // MyUnion m_union_value + + + // Just to register all known types + registerunion_structTypes(); +} + +union_struct::~union_struct() +{ + + +} + +union_struct::union_struct( + const union_struct& x) +{ + m_index = x.m_index; + m_union_value = x.m_union_value; +} + +union_struct::union_struct( + union_struct&& x) noexcept +{ + m_index = x.m_index; + m_union_value = std::move(x.m_union_value); +} + +union_struct& union_struct::operator =( + const union_struct& x) +{ + + m_index = x.m_index; + m_union_value = x.m_union_value; + + return *this; +} + +union_struct& union_struct::operator =( + union_struct&& x) noexcept +{ + + m_index = x.m_index; + m_union_value = std::move(x.m_union_value); + + return *this; +} + +bool union_struct::operator ==( + const union_struct& x) const +{ + + return (m_index == x.m_index && m_union_value == x.m_union_value); +} + +bool union_struct::operator !=( + const union_struct& x) const +{ + return !(*this == x); +} + +size_t union_struct::getMaxCdrSerializedSize( + size_t current_alignment) +{ + static_cast(current_alignment); + return union_struct_max_cdr_typesize; +} + +size_t union_struct::getCdrSerializedSize( + const union_struct& data, + size_t current_alignment) +{ + (void)data; + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += MyUnion::getCdrSerializedSize(data.union_value(), current_alignment); + + return current_alignment - initial_alignment; +} + +void union_struct::serialize( + eprosima::fastcdr::Cdr& scdr) const +{ + + scdr << m_index; + scdr << m_union_value; + +} + +void union_struct::deserialize( + eprosima::fastcdr::Cdr& dcdr) +{ + + dcdr >> m_index; + dcdr >> m_union_value; +} + +/*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ +void union_struct::index( + uint32_t _index) +{ + m_index = _index; +} + +/*! + * @brief This function returns the value of member index + * @return Value of member index + */ +uint32_t union_struct::index() const +{ + return m_index; +} + +/*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ +uint32_t& union_struct::index() +{ + return m_index; +} + +/*! + * @brief This function copies the value in member union_value + * @param _union_value New value to be copied in member union_value + */ +void union_struct::union_value( + const MyUnion& _union_value) +{ + m_union_value = _union_value; +} + +/*! + * @brief This function moves the value in member union_value + * @param _union_value New value to be moved in member union_value + */ +void union_struct::union_value( + MyUnion&& _union_value) +{ + m_union_value = std::move(_union_value); +} + +/*! + * @brief This function returns a constant reference to member union_value + * @return Constant reference to member union_value + */ +const MyUnion& union_struct::union_value() const +{ + return m_union_value; +} + +/*! + * @brief This function returns a reference to member union_value + * @return Reference to member union_value + */ +MyUnion& union_struct::union_value() +{ + return m_union_value; +} + + +size_t union_struct::getKeyMaxCdrSerializedSize( + size_t current_alignment) +{ + static_cast(current_alignment); + return union_struct_max_key_cdr_typesize; +} + +bool union_struct::isKeyDefined() +{ + return false; +} + +void union_struct::serializeKey( + eprosima::fastcdr::Cdr& scdr) const +{ + (void) scdr; +} + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_struct.h b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_struct.h new file mode 100644 index 00000000..b722de2c --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_struct.h @@ -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 union_struct.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _FAST_DDS_GENERATED_UNION_STRUCT_H_ +#define _FAST_DDS_GENERATED_UNION_STRUCT_H_ + + +#include + +#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 + +namespace eprosima { +namespace fastcdr { +class Cdr; +} // namespace fastcdr +} // namespace eprosima + + +/*! + * @brief This class represents the union MyUnion defined by the user in the IDL file. + * @ingroup union_struct + */ +class MyUnion +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport MyUnion(); + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~MyUnion(); + + /*! + * @brief Copy constructor. + * @param x Reference to the object MyUnion that will be copied. + */ + eProsima_user_DllExport MyUnion( + const MyUnion& x); + + /*! + * @brief Move constructor. + * @param x Reference to the object MyUnion that will be copied. + */ + eProsima_user_DllExport MyUnion( + MyUnion&& x) noexcept; + + /*! + * @brief Copy assignment. + * @param x Reference to the object MyUnion that will be copied. + */ + eProsima_user_DllExport MyUnion& operator =( + const MyUnion& x); + + /*! + * @brief Move assignment. + * @param x Reference to the object MyUnion that will be copied. + */ + eProsima_user_DllExport MyUnion& operator =( + MyUnion&& x) noexcept; + + /*! + * @brief Comparison operator. + * @param x MyUnion object to compare. + */ + eProsima_user_DllExport bool operator ==( + const MyUnion& x) const; + + /*! + * @brief Comparison operator. + * @param x MyUnion object to compare. + */ + eProsima_user_DllExport bool operator !=( + const MyUnion& x) const; + + /*! + * @brief This function sets the discriminator value. + * @param __d New value for the discriminator. + * @exception eprosima::fastcdr::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); + + /*! + * @brief This function returns the value of the discriminator. + * @return Value of the discriminator + */ + eProsima_user_DllExport int32_t _d() const; + + /*! + * @brief This function returns a reference to the discriminator. + * @return Reference to the discriminator. + */ + eProsima_user_DllExport int32_t& _d(); + + /*! + * @brief This function sets a value in member octet_value + * @param _octet_value New value for member octet_value + */ + eProsima_user_DllExport void octet_value( + uint8_t _octet_value); + + /*! + * @brief This function returns the value of member octet_value + * @return Value of member octet_value + * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport uint8_t octet_value() const; + + /*! + * @brief This function returns a reference to member octet_value + * @return Reference to member octet_value + * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport uint8_t& octet_value(); + + /*! + * @brief This function sets a value in member long_value + * @param _long_value New value for member long_value + */ + eProsima_user_DllExport void long_value( + int32_t _long_value); + + /*! + * @brief This function returns the value of member long_value + * @return Value of member long_value + * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport int32_t long_value() const; + + /*! + * @brief This function returns a reference to member long_value + * @return Reference to member long_value + * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport int32_t& long_value(); + + /*! + * @brief This function copies the value in member string_value + * @param _string_value New value to be copied in member string_value + */ + eProsima_user_DllExport void string_value( + const std::string& _string_value); + + /*! + * @brief This function moves the value in member string_value + * @param _string_value New value to be moved in member string_value + */ + eProsima_user_DllExport void string_value( + std::string&& _string_value); + + /*! + * @brief This function returns a constant reference to member string_value + * @return Constant reference to member string_value + * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport const std::string& string_value() const; + + /*! + * @brief This function returns a reference to member string_value + * @return Reference to member string_value + * @exception eprosima::fastcdr::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport std::string& string_value(); + + /*! + * @brief This function returns the serialized size of a data depending on the buffer alignment. + * @param data Data which is calculated its serialized size. + * @param current_alignment Buffer alignment. + * @return Serialized size. + */ + eProsima_user_DllExport static size_t getCdrSerializedSize( + const MyUnion& data, + size_t current_alignment = 0); + + + /*! + * @brief This function serializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& cdr) const; + + /*! + * @brief This function deserializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr); + + + + +private: + + int32_t m__d; + + uint8_t m_octet_value; + int32_t m_long_value; + std::string m_string_value; +}; +/*! + * @brief This class represents the structure union_struct defined by the user in the IDL file. + * @ingroup union_struct + */ +class union_struct +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport union_struct(); + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~union_struct(); + + /*! + * @brief Copy constructor. + * @param x Reference to the object union_struct that will be copied. + */ + eProsima_user_DllExport union_struct( + const union_struct& x); + + /*! + * @brief Move constructor. + * @param x Reference to the object union_struct that will be copied. + */ + eProsima_user_DllExport union_struct( + union_struct&& x) noexcept; + + /*! + * @brief Copy assignment. + * @param x Reference to the object union_struct that will be copied. + */ + eProsima_user_DllExport union_struct& operator =( + const union_struct& x); + + /*! + * @brief Move assignment. + * @param x Reference to the object union_struct that will be copied. + */ + eProsima_user_DllExport union_struct& operator =( + union_struct&& x) noexcept; + + /*! + * @brief Comparison operator. + * @param x union_struct object to compare. + */ + eProsima_user_DllExport bool operator ==( + const union_struct& x) const; + + /*! + * @brief Comparison operator. + * @param x union_struct object to compare. + */ + eProsima_user_DllExport bool operator !=( + const union_struct& x) const; + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index); + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const; + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index(); + + /*! + * @brief This function copies the value in member union_value + * @param _union_value New value to be copied in member union_value + */ + eProsima_user_DllExport void union_value( + const MyUnion& _union_value); + + /*! + * @brief This function moves the value in member union_value + * @param _union_value New value to be moved in member union_value + */ + eProsima_user_DllExport void union_value( + MyUnion&& _union_value); + + /*! + * @brief This function returns a constant reference to member union_value + * @return Constant reference to member union_value + */ + eProsima_user_DllExport const MyUnion& union_value() const; + + /*! + * @brief This function returns a reference to member union_value + * @return Reference to member union_value + */ + eProsima_user_DllExport MyUnion& union_value(); + + /*! + * @brief This function returns the maximum serialized size of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function returns the serialized size of a data depending on the buffer alignment. + * @param data Data which is calculated its serialized size. + * @param current_alignment Buffer alignment. + * @return Serialized size. + */ + eProsima_user_DllExport static size_t getCdrSerializedSize( + const union_struct& data, + size_t current_alignment = 0); + + + /*! + * @brief This function serializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& cdr) const; + + /*! + * @brief This function deserializes an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr); + + + + /*! + * @brief This function returns the maximum serialized size of the Key of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize( + size_t current_alignment = 0); + + /*! + * @brief This function tells you if the Key has been defined for this type + */ + eProsima_user_DllExport static bool isKeyDefined(); + + /*! + * @brief This function serializes the key members of an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serializeKey( + eprosima::fastcdr::Cdr& cdr) const; + +private: + + uint32_t m_index; + MyUnion m_union_value; + +}; + +#endif // _FAST_DDS_GENERATED_UNION_STRUCT_H_ + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structPubSubTypes.cxx b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structPubSubTypes.cxx new file mode 100644 index 00000000..dd0b45cd --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structPubSubTypes.cxx @@ -0,0 +1,171 @@ +// 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 fastcdrgen. + */ + + +#include +#include + +#include "union_structPubSubTypes.h" + +using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; + + +union_structPubSubType::union_structPubSubType() +{ + setName("union_struct"); + auto type_size = union_struct::getMaxCdrSerializedSize(); + type_size += eprosima::fastcdr::Cdr::alignment(type_size, 4); /* possible submessage alignment */ + m_typeSize = static_cast(type_size) + 4; /*encapsulation*/ + m_isGetKeyDefined = union_struct::isKeyDefined(); + size_t keyLength = union_struct::getKeyMaxCdrSerializedSize() > 16 ? + union_struct::getKeyMaxCdrSerializedSize() : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +union_structPubSubType::~union_structPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool union_structPubSubType::serialize( + void* data, + SerializedPayload_t* payload) +{ + union_struct* 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, eprosima::fastcdr::Cdr::DDS_CDR); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + p_type->serialize(ser); + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length + payload->length = static_cast(ser.getSerializedDataLength()); + return true; +} + +bool union_structPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + union_struct* 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, eprosima::fastcdr::Cdr::DDS_CDR); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + p_type->deserialize(deser); + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function union_structPubSubType::getSerializedSizeProvider( + void* data) +{ + return [data]() -> uint32_t + { + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; + }; +} + +void* union_structPubSubType::createData() +{ + return reinterpret_cast(new union_struct()); +} + +void union_structPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool union_structPubSubType::getKey( + void* data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + union_struct* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + union_struct::getKeyMaxCdrSerializedSize()); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); + p_type->serializeKey(ser); + if (force_md5 || union_struct::getKeyMaxCdrSerializedSize() > 16) + { + m_md5.init(); + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); + 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; +} + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structPubSubTypes.h b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structPubSubTypes.h new file mode 100644 index 00000000..f59d70ab --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structPubSubTypes.h @@ -0,0 +1,106 @@ +// 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.h + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ + + +#ifndef _FAST_DDS_GENERATED_UNION_STRUCT_PUBSUBTYPES_H_ +#define _FAST_DDS_GENERATED_UNION_STRUCT_PUBSUBTYPES_H_ + +#include +#include + +#include "union_struct.h" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 1) +#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 union_struct defined by the user in the IDL file. + * @ingroup union_struct + */ +class union_structPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef union_struct type; + + eProsima_user_DllExport union_structPubSubType(); + + eProsima_user_DllExport virtual ~union_structPubSubType() override; + + eProsima_user_DllExport virtual bool serialize( + void* data, + eprosima::fastrtps::rtps::SerializedPayload_t* payload) override; + + eProsima_user_DllExport virtual bool deserialize( + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport virtual std::function getSerializedSizeProvider( + void* data) override; + + eProsima_user_DllExport virtual bool getKey( + void* data, + eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport virtual void* createData() override; + + eProsima_user_DllExport virtual void deleteData( + void* data) 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; + } + +#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 + { + (void)memory; + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // _FAST_DDS_GENERATED_UNION_STRUCT_PUBSUBTYPES_H_ + diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structTypeObject.cxx b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structTypeObject.cxx new file mode 100644 index 00000000..8796c646 --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structTypeObject.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 union_structTypeObject.cpp + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifdef _WIN32 +// Remove linker warning LNK4221 on Visual Studio +namespace { char dummy; } +#endif + +#include "union_struct.h" +#include "union_structTypeObject.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace eprosima::fastrtps::rtps; + +void registerunion_structTypes() +{ + static std::once_flag once_flag; + std::call_once(once_flag, []() + { + TypeObjectFactory *factory = TypeObjectFactory::get_instance(); + factory->add_type_object("MyUnion", GetMyUnionIdentifier(true), + GetMyUnionObject(true)); + factory->add_type_object("MyUnion", GetMyUnionIdentifier(false), + GetMyUnionObject(false)); + + factory->add_type_object("union_struct", Getunion_structIdentifier(true), + Getunion_structObject(true)); + factory->add_type_object("union_struct", Getunion_structIdentifier(false), + Getunion_structObject(false)); + + }); +} + +const TypeIdentifier* GetMyUnionIdentifier(bool complete) +{ + const TypeIdentifier * c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("MyUnion", complete); + if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) + { + return c_identifier; + } + + GetMyUnionObject(complete); + return TypeObjectFactory::get_instance()->get_type_identifier("MyUnion", complete); +} + +const TypeObject* GetMyUnionObject(bool complete) +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("MyUnion", complete); + if (c_type_object != nullptr) + { + return c_type_object; + } + else if (complete) + { + return GetCompleteMyUnionObject(); + } + // else + return GetMinimalMyUnionObject(); +} + +const TypeObject* GetMinimalMyUnionObject() +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("MyUnion", false); + if (c_type_object != nullptr) + { + return c_type_object; + } + + TypeObject *type_object = new TypeObject(); + type_object->_d(EK_MINIMAL); + type_object->minimal()._d(TK_UNION); + + type_object->minimal().union_type().union_flags().IS_FINAL(false); + type_object->minimal().union_type().union_flags().IS_APPENDABLE(false); + type_object->minimal().union_type().union_flags().IS_MUTABLE(false); + type_object->minimal().union_type().union_flags().IS_NESTED(false); + type_object->minimal().union_type().union_flags().IS_AUTOID_HASH(false); // Unsupported + + type_object->minimal().union_type().discriminator().common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + type_object->minimal().union_type().discriminator().common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + type_object->minimal().union_type().discriminator().common().member_flags().IS_EXTERNAL(false); // Doesn't apply + type_object->minimal().union_type().discriminator().common().member_flags().IS_OPTIONAL(false); // Doesn't apply + type_object->minimal().union_type().discriminator().common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + type_object->minimal().union_type().discriminator().common().member_flags().IS_KEY(false); // Unsupported + type_object->minimal().union_type().discriminator().common().member_flags().IS_DEFAULT(false); // Doesn't apply + + type_object->minimal().union_type().discriminator().common().type_id(*TypeObjectFactory::get_instance()->get_type_identifier("int32_t", false)); + + MemberId memberId = 0; + MinimalUnionMember mst_octet_value; + mst_octet_value.common().member_id(memberId++); + mst_octet_value.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + mst_octet_value.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + mst_octet_value.common().member_flags().IS_EXTERNAL(false); // Unsupported + mst_octet_value.common().member_flags().IS_OPTIONAL(false); // Doesn't apply + mst_octet_value.common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + mst_octet_value.common().member_flags().IS_KEY(false); // Doesn't apply + mst_octet_value.common().member_flags().IS_DEFAULT(false); + mst_octet_value.common().type_id(*TypeObjectFactory::get_instance()->get_type_identifier("uint8_t", false)); + + mst_octet_value.common().label_seq().emplace_back(1); + MD5 octet_value_hash("octet_value"); + for(int i = 0; i < 4; ++i) + { + mst_octet_value.detail().name_hash()[i] = octet_value_hash.digest[i]; + } + type_object->minimal().union_type().member_seq().emplace_back(mst_octet_value); + + MinimalUnionMember mst_long_value; + mst_long_value.common().member_id(memberId++); + mst_long_value.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + mst_long_value.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + mst_long_value.common().member_flags().IS_EXTERNAL(false); // Unsupported + mst_long_value.common().member_flags().IS_OPTIONAL(false); // Doesn't apply + mst_long_value.common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + mst_long_value.common().member_flags().IS_KEY(false); // Doesn't apply + mst_long_value.common().member_flags().IS_DEFAULT(false); + mst_long_value.common().type_id(*TypeObjectFactory::get_instance()->get_type_identifier("int32_t", false)); + + mst_long_value.common().label_seq().emplace_back(2); + MD5 long_value_hash("long_value"); + for(int i = 0; i < 4; ++i) + { + mst_long_value.detail().name_hash()[i] = long_value_hash.digest[i]; + } + type_object->minimal().union_type().member_seq().emplace_back(mst_long_value); + + MinimalUnionMember mst_string_value; + mst_string_value.common().member_id(memberId++); + mst_string_value.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + mst_string_value.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + mst_string_value.common().member_flags().IS_EXTERNAL(false); // Unsupported + mst_string_value.common().member_flags().IS_OPTIONAL(false); // Doesn't apply + mst_string_value.common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + mst_string_value.common().member_flags().IS_KEY(false); // Doesn't apply + mst_string_value.common().member_flags().IS_DEFAULT(false); + mst_string_value.common().type_id(*TypeObjectFactory::get_instance()->get_string_identifier(255, false)); + + + mst_string_value.common().label_seq().emplace_back(3); + MD5 string_value_hash("string_value"); + for(int i = 0; i < 4; ++i) + { + mst_string_value.detail().name_hash()[i] = string_value_hash.digest[i]; + } + type_object->minimal().union_type().member_seq().emplace_back(mst_string_value); + + + // Header + //type_object->minimal().union_type().header().detail()... // Empty + + TypeIdentifier* identifier = new TypeIdentifier(); + identifier->_d(EK_MINIMAL); + + SerializedPayload_t payload(static_cast( + MinimalUnionType::getCdrSerializedSize(type_object->minimal().union_type()) + 4)); + eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); + // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) + eprosima::fastcdr::Cdr ser( + fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload.encapsulation = CDR_LE; + + type_object->serialize(ser); + payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + MD5 objectHash; + objectHash.update((char*)payload.data, payload.length); + objectHash.finalize(); + for(int i = 0; i < 14; ++i) + { + identifier->equivalence_hash()[i] = objectHash.digest[i]; + } + + TypeObjectFactory::get_instance()->add_type_object("MyUnion", identifier, type_object); + delete type_object; + delete identifier; + return TypeObjectFactory::get_instance()->get_type_object("MyUnion", false); +} + +const TypeObject* GetCompleteMyUnionObject() +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("MyUnion", true); + if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) + { + return c_type_object; + } + + TypeObject *type_object = new TypeObject(); + type_object->_d(EK_COMPLETE); + type_object->complete()._d(TK_UNION); + + type_object->complete().union_type().union_flags().IS_FINAL(false); + type_object->complete().union_type().union_flags().IS_APPENDABLE(false); + type_object->complete().union_type().union_flags().IS_MUTABLE(false); + type_object->complete().union_type().union_flags().IS_NESTED(false); + type_object->complete().union_type().union_flags().IS_AUTOID_HASH(false); // Unsupported + + type_object->complete().union_type().discriminator().common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + type_object->complete().union_type().discriminator().common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + type_object->complete().union_type().discriminator().common().member_flags().IS_EXTERNAL(false); // Doesn't apply + type_object->complete().union_type().discriminator().common().member_flags().IS_OPTIONAL(false); // Doesn't apply + type_object->complete().union_type().discriminator().common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + type_object->complete().union_type().discriminator().common().member_flags().IS_KEY(false); // Unsupported + type_object->complete().union_type().discriminator().common().member_flags().IS_DEFAULT(false); // Doesn't apply + + type_object->complete().union_type().discriminator().common().type_id(*TypeObjectFactory::get_instance()->get_type_identifier("int32_t", false)); + + + MemberId memberId = 0; + CompleteUnionMember cst_octet_value; + cst_octet_value.common().member_id(memberId++); + cst_octet_value.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + cst_octet_value.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + cst_octet_value.common().member_flags().IS_EXTERNAL(false); // Unsupported + cst_octet_value.common().member_flags().IS_OPTIONAL(false); // Doesn't apply + cst_octet_value.common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + cst_octet_value.common().member_flags().IS_KEY(false); // Doesn't apply + cst_octet_value.common().member_flags().IS_DEFAULT(false); + cst_octet_value.common().type_id(*TypeObjectFactory::get_instance()->get_type_identifier("uint8_t", false)); + cst_octet_value.common().label_seq().emplace_back(1); + + cst_octet_value.detail().name("octet_value"); + + type_object->complete().union_type().member_seq().emplace_back(cst_octet_value); + + CompleteUnionMember cst_long_value; + cst_long_value.common().member_id(memberId++); + cst_long_value.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + cst_long_value.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + cst_long_value.common().member_flags().IS_EXTERNAL(false); // Unsupported + cst_long_value.common().member_flags().IS_OPTIONAL(false); // Doesn't apply + cst_long_value.common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + cst_long_value.common().member_flags().IS_KEY(false); // Doesn't apply + cst_long_value.common().member_flags().IS_DEFAULT(false); + cst_long_value.common().type_id(*TypeObjectFactory::get_instance()->get_type_identifier("int32_t", false)); + cst_long_value.common().label_seq().emplace_back(2); + + cst_long_value.detail().name("long_value"); + + type_object->complete().union_type().member_seq().emplace_back(cst_long_value); + + CompleteUnionMember cst_string_value; + cst_string_value.common().member_id(memberId++); + cst_string_value.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + cst_string_value.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + cst_string_value.common().member_flags().IS_EXTERNAL(false); // Unsupported + cst_string_value.common().member_flags().IS_OPTIONAL(false); // Doesn't apply + cst_string_value.common().member_flags().IS_MUST_UNDERSTAND(false); // Doesn't apply + cst_string_value.common().member_flags().IS_KEY(false); // Doesn't apply + cst_string_value.common().member_flags().IS_DEFAULT(false); + cst_string_value.common().type_id(*TypeObjectFactory::get_instance()->get_string_identifier(255, false)); + + cst_string_value.common().label_seq().emplace_back(3); + + cst_string_value.detail().name("string_value"); + + type_object->complete().union_type().member_seq().emplace_back(cst_string_value); + + + // Header + type_object->complete().union_type().header().detail().type_name("MyUnion"); + + + TypeIdentifier* identifier = new TypeIdentifier(); + identifier->_d(EK_COMPLETE); + + SerializedPayload_t payload(static_cast( + CompleteUnionType::getCdrSerializedSize(type_object->complete().union_type()) + 4)); + eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); + // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) + eprosima::fastcdr::Cdr ser( + fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload.encapsulation = CDR_LE; + + type_object->serialize(ser); + payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + MD5 objectHash; + objectHash.update((char*)payload.data, payload.length); + objectHash.finalize(); + for(int i = 0; i < 14; ++i) + { + identifier->equivalence_hash()[i] = objectHash.digest[i]; + } + + TypeObjectFactory::get_instance()->add_type_object("MyUnion", identifier, type_object); + delete type_object; + delete identifier; + return TypeObjectFactory::get_instance()->get_type_object("MyUnion", true); +} + +const TypeIdentifier* Getunion_structIdentifier(bool complete) +{ + const TypeIdentifier * c_identifier = TypeObjectFactory::get_instance()->get_type_identifier("union_struct", complete); + if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE)) + { + return c_identifier; + } + + Getunion_structObject(complete); // Generated inside + return TypeObjectFactory::get_instance()->get_type_identifier("union_struct", complete); +} + +const TypeObject* Getunion_structObject(bool complete) +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("union_struct", complete); + if (c_type_object != nullptr) + { + return c_type_object; + } + else if (complete) + { + return GetCompleteunion_structObject(); + } + //else + return GetMinimalunion_structObject(); +} + +const TypeObject* GetMinimalunion_structObject() +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("union_struct", false); + if (c_type_object != nullptr) + { + return c_type_object; + } + + TypeObject *type_object = new TypeObject(); + type_object->_d(EK_MINIMAL); + type_object->minimal()._d(TK_STRUCTURE); + + type_object->minimal().struct_type().struct_flags().IS_FINAL(false); + type_object->minimal().struct_type().struct_flags().IS_APPENDABLE(false); + type_object->minimal().struct_type().struct_flags().IS_MUTABLE(false); + type_object->minimal().struct_type().struct_flags().IS_NESTED(false); + type_object->minimal().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported + + MemberId memberId = 0; + MinimalStructMember mst_index; + mst_index.common().member_id(memberId++); + mst_index.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + mst_index.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + mst_index.common().member_flags().IS_EXTERNAL(false); // Unsupported + mst_index.common().member_flags().IS_OPTIONAL(false); + mst_index.common().member_flags().IS_MUST_UNDERSTAND(false); + mst_index.common().member_flags().IS_KEY(false); + mst_index.common().member_flags().IS_DEFAULT(false); // Doesn't apply + mst_index.common().member_type_id(*TypeObjectFactory::get_instance()->get_type_identifier("uint32_t", false)); + + MD5 index_hash("index"); + for(int i = 0; i < 4; ++i) + { + mst_index.detail().name_hash()[i] = index_hash.digest[i]; + } + type_object->minimal().struct_type().member_seq().emplace_back(mst_index); + + MinimalStructMember mst_union_value; + mst_union_value.common().member_id(memberId++); + mst_union_value.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + mst_union_value.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + mst_union_value.common().member_flags().IS_EXTERNAL(false); // Unsupported + mst_union_value.common().member_flags().IS_OPTIONAL(false); + mst_union_value.common().member_flags().IS_MUST_UNDERSTAND(false); + mst_union_value.common().member_flags().IS_KEY(false); + mst_union_value.common().member_flags().IS_DEFAULT(false); // Doesn't apply + mst_union_value.common().member_type_id(*GetMyUnionIdentifier(false)); + MD5 union_value_hash("union_value"); + for(int i = 0; i < 4; ++i) + { + mst_union_value.detail().name_hash()[i] = union_value_hash.digest[i]; + } + type_object->minimal().struct_type().member_seq().emplace_back(mst_union_value); + + + // Header + // TODO Inheritance + //type_object->minimal().struct_type().header().base_type()._d(EK_MINIMAL); + //type_object->minimal().struct_type().header().base_type().equivalence_hash()[0..13]; + + TypeIdentifier identifier; + identifier._d(EK_MINIMAL); + + SerializedPayload_t payload(static_cast( + MinimalStructType::getCdrSerializedSize(type_object->minimal().struct_type()) + 4)); + eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); + // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) + eprosima::fastcdr::Cdr ser( + fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload.encapsulation = CDR_LE; + + type_object->serialize(ser); + payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + MD5 objectHash; + objectHash.update((char*)payload.data, payload.length); + objectHash.finalize(); + for(int i = 0; i < 14; ++i) + { + identifier.equivalence_hash()[i] = objectHash.digest[i]; + } + + TypeObjectFactory::get_instance()->add_type_object("union_struct", &identifier, type_object); + delete type_object; + return TypeObjectFactory::get_instance()->get_type_object("union_struct", false); +} + +const TypeObject* GetCompleteunion_structObject() +{ + const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("union_struct", true); + if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE) + { + return c_type_object; + } + + TypeObject *type_object = new TypeObject(); + type_object->_d(EK_COMPLETE); + type_object->complete()._d(TK_STRUCTURE); + + type_object->complete().struct_type().struct_flags().IS_FINAL(false); + type_object->complete().struct_type().struct_flags().IS_APPENDABLE(false); + type_object->complete().struct_type().struct_flags().IS_MUTABLE(false); + type_object->complete().struct_type().struct_flags().IS_NESTED(false); + type_object->complete().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported + + MemberId memberId = 0; + CompleteStructMember cst_index; + cst_index.common().member_id(memberId++); + cst_index.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + cst_index.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + cst_index.common().member_flags().IS_EXTERNAL(false); // Unsupported + cst_index.common().member_flags().IS_OPTIONAL(false); + cst_index.common().member_flags().IS_MUST_UNDERSTAND(false); + cst_index.common().member_flags().IS_KEY(false); + cst_index.common().member_flags().IS_DEFAULT(false); // Doesn't apply + cst_index.common().member_type_id(*TypeObjectFactory::get_instance()->get_type_identifier("uint32_t", false)); + + cst_index.detail().name("index"); + + type_object->complete().struct_type().member_seq().emplace_back(cst_index); + + CompleteStructMember cst_union_value; + cst_union_value.common().member_id(memberId++); + cst_union_value.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported + cst_union_value.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported + cst_union_value.common().member_flags().IS_EXTERNAL(false); // Unsupported + cst_union_value.common().member_flags().IS_OPTIONAL(false); + cst_union_value.common().member_flags().IS_MUST_UNDERSTAND(false); + cst_union_value.common().member_flags().IS_KEY(false); + cst_union_value.common().member_flags().IS_DEFAULT(false); // Doesn't apply + cst_union_value.common().member_type_id(*GetMyUnionIdentifier(true)); + cst_union_value.detail().name("union_value"); + + type_object->complete().struct_type().member_seq().emplace_back(cst_union_value); + + + // Header + type_object->complete().struct_type().header().detail().type_name("union_struct"); + // TODO inheritance + + + TypeIdentifier identifier; + identifier._d(EK_COMPLETE); + + SerializedPayload_t payload(static_cast( + CompleteStructType::getCdrSerializedSize(type_object->complete().struct_type()) + 4)); + eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size); + // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document) + eprosima::fastcdr::Cdr ser( + fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload.encapsulation = CDR_LE; + + type_object->serialize(ser); + payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length + MD5 objectHash; + objectHash.update((char*)payload.data, payload.length); + objectHash.finalize(); + for(int i = 0; i < 14; ++i) + { + identifier.equivalence_hash()[i] = objectHash.digest[i]; + } + + TypeObjectFactory::get_instance()->add_type_object("union_struct", &identifier, type_object); + delete type_object; + return TypeObjectFactory::get_instance()->get_type_object("union_struct", true); +} diff --git a/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structTypeObject.h b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structTypeObject.h new file mode 100644 index 00000000..0abcf85c --- /dev/null +++ b/ddspipe_core/test/unittest/types/dynamic_types/types/type_objects/union_structTypeObject.h @@ -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 union_structTypeObject.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _FAST_DDS_GENERATED_UNION_STRUCT_TYPE_OBJECT_H_ +#define _FAST_DDS_GENERATED_UNION_STRUCT_TYPE_OBJECT_H_ + + +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif +#else +#define eProsima_user_DllExport +#endif + +#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 +#else +#define union_struct_DllAPI +#endif // _WIN32 + +using namespace eprosima::fastrtps::types; + +eProsima_user_DllExport void registerunion_structTypes(); + +eProsima_user_DllExport const TypeIdentifier* GetMyUnionIdentifier(bool complete = false); +eProsima_user_DllExport const TypeObject* GetMyUnionObject(bool complete = false); +eProsima_user_DllExport const TypeObject* GetMinimalMyUnionObject(); +eProsima_user_DllExport const TypeObject* GetCompleteMyUnionObject(); + +eProsima_user_DllExport const TypeIdentifier* Getunion_structIdentifier(bool complete = false); +eProsima_user_DllExport const TypeObject* Getunion_structObject(bool complete = false); +eProsima_user_DllExport const TypeObject* GetMinimalunion_structObject(); +eProsima_user_DllExport const TypeObject* GetCompleteunion_structObject(); + + +#endif // _FAST_DDS_GENERATED_UNION_STRUCT_TYPE_OBJECT_H_ \ No newline at end of file