diff --git a/test/dds-types-test/constants.hpp b/test/dds-types-test/constants.hpp index 115272af13d..e560263e3d6 100644 --- a/test/dds-types-test/constants.hpp +++ b/test/dds-types-test/constants.hpp @@ -75,6 +75,7 @@ const uint64_t const_uint64 = 19; typedef int16_t alias_short; const alias_short alias_const = 55; +const InnerEnumHelper const_enum = InnerEnumHelper::ENUM_VALUE_1; namespace const_module1 { const int16_t const_moduled = 11; @@ -341,6 +342,7 @@ namespace const_module2 { const int16_t const_moduled = 22; const const_module1::alias_short_moduled alias_const_moduled = 2; +const int16_t const_moduled_module1 = const_module1::const_moduled; /*! * @brief This class represents the structure Module2ConstsLiteralsStruct defined by the user in the IDL file. * @ingroup constants @@ -378,6 +380,8 @@ class Module2ConstsLiteralsStruct m_module2_array_literal_module1_const_moduled = x.m_module2_array_literal_module1_const_moduled; + m_module2_array_literal_const_moduled_module1 = x.m_module2_array_literal_const_moduled_module1; + } /*! @@ -391,6 +395,7 @@ class Module2ConstsLiteralsStruct m_module2_array_literal_const_alias_const_moduled = std::move(x.m_module2_array_literal_const_alias_const_moduled); m_module2_array_literal_const_scoped_moduled = std::move(x.m_module2_array_literal_const_scoped_moduled); m_module2_array_literal_module1_const_moduled = std::move(x.m_module2_array_literal_module1_const_moduled); + m_module2_array_literal_const_moduled_module1 = std::move(x.m_module2_array_literal_const_moduled_module1); } /*! @@ -409,6 +414,8 @@ class Module2ConstsLiteralsStruct m_module2_array_literal_module1_const_moduled = x.m_module2_array_literal_module1_const_moduled; + m_module2_array_literal_const_moduled_module1 = x.m_module2_array_literal_const_moduled_module1; + return *this; } @@ -424,6 +431,7 @@ class Module2ConstsLiteralsStruct m_module2_array_literal_const_alias_const_moduled = std::move(x.m_module2_array_literal_const_alias_const_moduled); m_module2_array_literal_const_scoped_moduled = std::move(x.m_module2_array_literal_const_scoped_moduled); m_module2_array_literal_module1_const_moduled = std::move(x.m_module2_array_literal_module1_const_moduled); + m_module2_array_literal_const_moduled_module1 = std::move(x.m_module2_array_literal_const_moduled_module1); return *this; } @@ -437,7 +445,8 @@ class Module2ConstsLiteralsStruct return (m_module2_array_literal_const_moduled == x.m_module2_array_literal_const_moduled && m_module2_array_literal_const_alias_const_moduled == x.m_module2_array_literal_const_alias_const_moduled && m_module2_array_literal_const_scoped_moduled == x.m_module2_array_literal_const_scoped_moduled && - m_module2_array_literal_module1_const_moduled == x.m_module2_array_literal_module1_const_moduled); + m_module2_array_literal_module1_const_moduled == x.m_module2_array_literal_module1_const_moduled && + m_module2_array_literal_const_moduled_module1 == x.m_module2_array_literal_const_moduled_module1); } /*! @@ -606,6 +615,45 @@ class Module2ConstsLiteralsStruct } + /*! + * @brief This function copies the value in member module2_array_literal_const_moduled_module1 + * @param _module2_array_literal_const_moduled_module1 New value to be copied in member module2_array_literal_const_moduled_module1 + */ + eProsima_user_DllExport void module2_array_literal_const_moduled_module1( + const std::array& _module2_array_literal_const_moduled_module1) + { + m_module2_array_literal_const_moduled_module1 = _module2_array_literal_const_moduled_module1; + } + + /*! + * @brief This function moves the value in member module2_array_literal_const_moduled_module1 + * @param _module2_array_literal_const_moduled_module1 New value to be moved in member module2_array_literal_const_moduled_module1 + */ + eProsima_user_DllExport void module2_array_literal_const_moduled_module1( + std::array&& _module2_array_literal_const_moduled_module1) + { + m_module2_array_literal_const_moduled_module1 = std::move(_module2_array_literal_const_moduled_module1); + } + + /*! + * @brief This function returns a constant reference to member module2_array_literal_const_moduled_module1 + * @return Constant reference to member module2_array_literal_const_moduled_module1 + */ + eProsima_user_DllExport const std::array& module2_array_literal_const_moduled_module1() const + { + return m_module2_array_literal_const_moduled_module1; + } + + /*! + * @brief This function returns a reference to member module2_array_literal_const_moduled_module1 + * @return Reference to member module2_array_literal_const_moduled_module1 + */ + eProsima_user_DllExport std::array& module2_array_literal_const_moduled_module1() + { + return m_module2_array_literal_const_moduled_module1; + } + + private: @@ -613,6 +661,7 @@ class Module2ConstsLiteralsStruct std::array m_module2_array_literal_const_alias_const_moduled{0}; std::array m_module2_array_literal_const_scoped_moduled{0}; std::array m_module2_array_literal_module1_const_moduled{0}; + std::array m_module2_array_literal_const_moduled_module1{0}; }; diff --git a/test/dds-types-test/constantsCdrAux.hpp b/test/dds-types-test/constantsCdrAux.hpp index e203fb3515b..f6241db3298 100644 --- a/test/dds-types-test/constantsCdrAux.hpp +++ b/test/dds-types-test/constantsCdrAux.hpp @@ -31,7 +31,7 @@ constexpr uint32_t ConstsLiteralsStruct_max_key_cdr_typesize {0UL}; -constexpr uint32_t const_module2_Module2ConstsLiteralsStruct_max_cdr_typesize {118UL}; +constexpr uint32_t const_module2_Module2ConstsLiteralsStruct_max_cdr_typesize {140UL}; constexpr uint32_t const_module2_Module2ConstsLiteralsStruct_max_key_cdr_typesize {0UL}; constexpr uint32_t const_module1_ModuleConstsLiteralsStruct_max_cdr_typesize {50UL}; diff --git a/test/dds-types-test/constantsCdrAux.ipp b/test/dds-types-test/constantsCdrAux.ipp index 9f94fde4173..0ffd3dd60db 100644 --- a/test/dds-types-test/constantsCdrAux.ipp +++ b/test/dds-types-test/constantsCdrAux.ipp @@ -180,6 +180,9 @@ eProsima_user_DllExport size_t calculate_serialized_size( calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3), data.module2_array_literal_module1_const_moduled(), current_alignment); + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(4), + data.module2_array_literal_const_moduled_module1(), current_alignment); + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); @@ -204,6 +207,7 @@ eProsima_user_DllExport void serialize( << eprosima::fastcdr::MemberId(1) << data.module2_array_literal_const_alias_const_moduled() << eprosima::fastcdr::MemberId(2) << data.module2_array_literal_const_scoped_moduled() << eprosima::fastcdr::MemberId(3) << data.module2_array_literal_module1_const_moduled() + << eprosima::fastcdr::MemberId(4) << data.module2_array_literal_const_moduled_module1() ; scdr.end_serialize_type(current_state); } @@ -239,6 +243,10 @@ eProsima_user_DllExport void deserialize( dcdr >> data.module2_array_literal_module1_const_moduled(); break; + case 4: + dcdr >> data.module2_array_literal_const_moduled_module1(); + break; + default: ret_value = false; break; diff --git a/test/dds-types-test/constantsPubSubTypes.hpp b/test/dds-types-test/constantsPubSubTypes.hpp index f220b1da26f..c23af2163a8 100644 --- a/test/dds-types-test/constantsPubSubTypes.hpp +++ b/test/dds-types-test/constantsPubSubTypes.hpp @@ -40,6 +40,7 @@ typedef int16_t alias_short; + namespace const_module1 { typedef int16_t alias_short_moduled; diff --git a/test/dds-types-test/constantsTypeObjectSupport.cxx b/test/dds-types-test/constantsTypeObjectSupport.cxx index b1e80fc315c..09d7c4e2547 100644 --- a/test/dds-types-test/constantsTypeObjectSupport.cxx +++ b/test/dds-types-test/constantsTypeObjectSupport.cxx @@ -632,6 +632,70 @@ void register_Module2ConstsLiteralsStruct_type_identifier( CompleteStructMember member_module2_array_literal_module1_const_moduled = TypeObjectUtils::build_complete_struct_member(common_module2_array_literal_module1_const_moduled, detail_module2_array_literal_module1_const_moduled); TypeObjectUtils::add_complete_struct_member(member_seq_Module2ConstsLiteralsStruct, member_module2_array_literal_module1_const_moduled); } + { + TypeIdentifierPair type_ids_module2_array_literal_const_moduled_module1; + ReturnCode_t return_code_module2_array_literal_const_moduled_module1 {eprosima::fastdds::dds::RETCODE_OK}; + return_code_module2_array_literal_const_moduled_module1 = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_array_int16_t_11", type_ids_module2_array_literal_const_moduled_module1); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_module2_array_literal_const_moduled_module1) + { + return_code_module2_array_literal_const_moduled_module1 = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int16_t", type_ids_module2_array_literal_const_moduled_module1); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_module2_array_literal_const_moduled_module1) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Array element TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool element_identifier_anonymous_array_int16_t_11_ec {false}; + TypeIdentifier* element_identifier_anonymous_array_int16_t_11 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_module2_array_literal_const_moduled_module1, element_identifier_anonymous_array_int16_t_11_ec))}; + if (!element_identifier_anonymous_array_int16_t_11_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Array element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_array_int16_t_11 = EK_COMPLETE; + if (TK_NONE == type_ids_module2_array_literal_const_moduled_module1.type_identifier2()._d()) + { + equiv_kind_anonymous_array_int16_t_11 = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_array_int16_t_11 = 0; + PlainCollectionHeader header_anonymous_array_int16_t_11 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_array_int16_t_11, element_flags_anonymous_array_int16_t_11); + { + SBoundSeq array_bound_seq; + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(11)); + + PlainArraySElemDefn array_sdefn = TypeObjectUtils::build_plain_array_s_elem_defn(header_anonymous_array_int16_t_11, array_bound_seq, + eprosima::fastcdr::external(element_identifier_anonymous_array_int16_t_11)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_array_type_identifier(array_sdefn, "anonymous_array_int16_t_11", type_ids_module2_array_literal_const_moduled_module1)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_array_int16_t_11 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_module2_array_literal_const_moduled_module1 = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_module2_array_literal_const_moduled_module1 = 0x00000004; + bool common_module2_array_literal_const_moduled_module1_ec {false}; + CommonStructMember common_module2_array_literal_const_moduled_module1 {TypeObjectUtils::build_common_struct_member(member_id_module2_array_literal_const_moduled_module1, member_flags_module2_array_literal_const_moduled_module1, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_module2_array_literal_const_moduled_module1, common_module2_array_literal_const_moduled_module1_ec))}; + if (!common_module2_array_literal_const_moduled_module1_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure module2_array_literal_const_moduled_module1 member TypeIdentifier inconsistent."); + return; + } + MemberName name_module2_array_literal_const_moduled_module1 = "module2_array_literal_const_moduled_module1"; + eprosima::fastcdr::optional member_ann_builtin_module2_array_literal_const_moduled_module1; + ann_custom_Module2ConstsLiteralsStruct.reset(); + CompleteMemberDetail detail_module2_array_literal_const_moduled_module1 = TypeObjectUtils::build_complete_member_detail(name_module2_array_literal_const_moduled_module1, member_ann_builtin_module2_array_literal_const_moduled_module1, ann_custom_Module2ConstsLiteralsStruct); + CompleteStructMember member_module2_array_literal_const_moduled_module1 = TypeObjectUtils::build_complete_struct_member(common_module2_array_literal_const_moduled_module1, detail_module2_array_literal_const_moduled_module1); + TypeObjectUtils::add_complete_struct_member(member_seq_Module2ConstsLiteralsStruct, member_module2_array_literal_const_moduled_module1); + } CompleteStructType struct_type_Module2ConstsLiteralsStruct = TypeObjectUtils::build_complete_struct_type(struct_flags_Module2ConstsLiteralsStruct, header_Module2ConstsLiteralsStruct, member_seq_Module2ConstsLiteralsStruct); if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == TypeObjectUtils::build_and_register_struct_type_object(struct_type_Module2ConstsLiteralsStruct, type_name_Module2ConstsLiteralsStruct.to_string(), type_ids_Module2ConstsLiteralsStruct)) diff --git a/test/dds-types-test/enumerations.hpp b/test/dds-types-test/enumerations.hpp index 7308cd3a8ba..fc465a5e8df 100644 --- a/test/dds-types-test/enumerations.hpp +++ b/test/dds-types-test/enumerations.hpp @@ -64,6 +64,16 @@ enum class InnerEnumHelper : int32_t }; } // namespace Test +/*! + * @brief This class represents the enumeration EnumWithValues defined by the user in the IDL file. + * @ingroup enumerations + */ +enum class EnumWithValues : int32_t +{ + ENUM_VALUE1 = -3, + ENUM_VALUE2 = 0, + ENUM_VALUE3 = 3 +}; /*! * @brief This class represents the structure EnumStructure defined by the user in the IDL file. * @ingroup enumerations @@ -489,6 +499,129 @@ class BoundedBitMaskStructure InnerBoundedBitMaskHelper m_var_InnerBoundedBitMaskHelper{0}; +}; +/*! + * @brief This class represents the structure EnumWithValuesStructure defined by the user in the IDL file. + * @ingroup enumerations + */ +class EnumWithValuesStructure +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport EnumWithValuesStructure() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~EnumWithValuesStructure() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object EnumWithValuesStructure that will be copied. + */ + eProsima_user_DllExport EnumWithValuesStructure( + const EnumWithValuesStructure& x) + { + m_var_enumwithvalues = x.m_var_enumwithvalues; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object EnumWithValuesStructure that will be copied. + */ + eProsima_user_DllExport EnumWithValuesStructure( + EnumWithValuesStructure&& x) noexcept + { + m_var_enumwithvalues = x.m_var_enumwithvalues; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object EnumWithValuesStructure that will be copied. + */ + eProsima_user_DllExport EnumWithValuesStructure& operator =( + const EnumWithValuesStructure& x) + { + + m_var_enumwithvalues = x.m_var_enumwithvalues; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object EnumWithValuesStructure that will be copied. + */ + eProsima_user_DllExport EnumWithValuesStructure& operator =( + EnumWithValuesStructure&& x) noexcept + { + + m_var_enumwithvalues = x.m_var_enumwithvalues; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x EnumWithValuesStructure object to compare. + */ + eProsima_user_DllExport bool operator ==( + const EnumWithValuesStructure& x) const + { + return (m_var_enumwithvalues == x.m_var_enumwithvalues); + } + + /*! + * @brief Comparison operator. + * @param x EnumWithValuesStructure object to compare. + */ + eProsima_user_DllExport bool operator !=( + const EnumWithValuesStructure& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member var_enumwithvalues + * @param _var_enumwithvalues New value for member var_enumwithvalues + */ + eProsima_user_DllExport void var_enumwithvalues( + EnumWithValues _var_enumwithvalues) + { + m_var_enumwithvalues = _var_enumwithvalues; + } + + /*! + * @brief This function returns the value of member var_enumwithvalues + * @return Value of member var_enumwithvalues + */ + eProsima_user_DllExport EnumWithValues var_enumwithvalues() const + { + return m_var_enumwithvalues; + } + + /*! + * @brief This function returns a reference to member var_enumwithvalues + * @return Reference to member var_enumwithvalues + */ + eProsima_user_DllExport EnumWithValues& var_enumwithvalues() + { + return m_var_enumwithvalues; + } + + + +private: + + EnumWithValues m_var_enumwithvalues{EnumWithValues::ENUM_VALUE1}; + }; #endif // _FAST_DDS_GENERATED_ENUMERATIONS_HPP_ diff --git a/test/dds-types-test/enumerationsCdrAux.hpp b/test/dds-types-test/enumerationsCdrAux.hpp index 7dc2039594d..402e76f70dd 100644 --- a/test/dds-types-test/enumerationsCdrAux.hpp +++ b/test/dds-types-test/enumerationsCdrAux.hpp @@ -35,6 +35,10 @@ constexpr uint32_t EnumStructure_max_key_cdr_typesize {0UL}; +constexpr uint32_t EnumWithValuesStructure_max_cdr_typesize {8UL}; +constexpr uint32_t EnumWithValuesStructure_max_key_cdr_typesize {0UL}; + + constexpr uint32_t BitMaskStructure_max_cdr_typesize {8UL}; constexpr uint32_t BitMaskStructure_max_key_cdr_typesize {0UL}; @@ -64,6 +68,10 @@ eProsima_user_DllExport void serialize_key( eprosima::fastcdr::Cdr& scdr, const BoundedBitMaskStructure& data); +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const EnumWithValuesStructure& data); + } // namespace fastcdr } // namespace eprosima diff --git a/test/dds-types-test/enumerationsCdrAux.ipp b/test/dds-types-test/enumerationsCdrAux.ipp index e4096831a75..79d3f94c8fd 100644 --- a/test/dds-types-test/enumerationsCdrAux.ipp +++ b/test/dds-types-test/enumerationsCdrAux.ipp @@ -281,6 +281,82 @@ void serialize_key( } +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const EnumWithValuesStructure& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.var_enumwithvalues(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const EnumWithValuesStructure& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.var_enumwithvalues() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + EnumWithValuesStructure& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.var_enumwithvalues(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const EnumWithValuesStructure& data) +{ + static_cast(scdr); + static_cast(data); +} + + } // namespace fastcdr } // namespace eprosima diff --git a/test/dds-types-test/enumerationsPubSubTypes.cxx b/test/dds-types-test/enumerationsPubSubTypes.cxx index b381fe05527..946ed9f9dcc 100644 --- a/test/dds-types-test/enumerationsPubSubTypes.cxx +++ b/test/dds-types-test/enumerationsPubSubTypes.cxx @@ -34,6 +34,7 @@ using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; namespace Test { } // namespace Test + EnumStructurePubSubType::EnumStructurePubSubType() { set_name("EnumStructure"); @@ -577,6 +578,186 @@ void BoundedBitMaskStructurePubSubType::register_type_object_representation() register_BoundedBitMaskStructure_type_identifier(type_identifiers_); } +EnumWithValuesStructurePubSubType::EnumWithValuesStructurePubSubType() +{ + set_name("EnumWithValuesStructure"); + uint32_t type_size = EnumWithValuesStructure_max_cdr_typesize; + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = EnumWithValuesStructure_max_key_cdr_typesize > 16 ? EnumWithValuesStructure_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); +} + +EnumWithValuesStructurePubSubType::~EnumWithValuesStructurePubSubType() +{ + if (key_buffer_ != nullptr) + { + free(key_buffer_); + } +} + +bool EnumWithValuesStructurePubSubType::serialize( + const void* const data, + SerializedPayload_t& payload, + DataRepresentationId_t data_representation) +{ + const EnumWithValuesStructure* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload.data), payload.max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length + payload.length = static_cast(ser.get_serialized_data_length()); + return true; +} + +bool EnumWithValuesStructurePubSubType::deserialize( + SerializedPayload_t& payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + EnumWithValuesStructure* 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); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +uint32_t EnumWithValuesStructurePubSubType::calculate_serialized_size( + const void* const data, + DataRepresentationId_t data_representation) +{ + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +} + +void* EnumWithValuesStructurePubSubType::create_data() +{ + return reinterpret_cast(new EnumWithValuesStructure()); +} + +void EnumWithValuesStructurePubSubType::delete_data( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool EnumWithValuesStructurePubSubType::compute_key( + SerializedPayload_t& payload, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + EnumWithValuesStructure data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool EnumWithValuesStructurePubSubType::compute_key( + const void* const data, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + const EnumWithValuesStructure* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), + EnumWithValuesStructure_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); + eprosima::fastcdr::serialize_key(ser, *p_type); + if (force_md5 || EnumWithValuesStructure_max_key_cdr_typesize > 16) + { + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle.value[i] = md5_.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle.value[i] = key_buffer_[i]; + } + } + return true; +} + +void EnumWithValuesStructurePubSubType::register_type_object_representation() +{ + register_EnumWithValuesStructure_type_identifier(type_identifiers_); +} + // Include auxiliary functions like for serializing/deserializing. #include "enumerationsCdrAux.ipp" diff --git a/test/dds-types-test/enumerationsPubSubTypes.hpp b/test/dds-types-test/enumerationsPubSubTypes.hpp index bd437018d10..ac3f058018c 100644 --- a/test/dds-types-test/enumerationsPubSubTypes.hpp +++ b/test/dds-types-test/enumerationsPubSubTypes.hpp @@ -42,6 +42,7 @@ namespace Test { } // namespace Test + /*! * @brief This class represents the TopicDataType of the type EnumStructure defined by the user in the IDL file. * @ingroup enumerations @@ -285,5 +286,86 @@ class BoundedBitMaskStructurePubSubType : public eprosima::fastdds::dds::TopicDa }; +/*! + * @brief This class represents the TopicDataType of the type EnumWithValuesStructure defined by the user in the IDL file. + * @ingroup enumerations + */ +class EnumWithValuesStructurePubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef EnumWithValuesStructure type; + + eProsima_user_DllExport EnumWithValuesStructurePubSubType(); + + eProsima_user_DllExport ~EnumWithValuesStructurePubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t& payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t& payload, + void* data) override; + + eProsima_user_DllExport uint32_t calculate_serialized_size( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t& payload, + eprosima::fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* create_data() override; + + eProsima_user_DllExport void delete_data( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return true; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + +private: + + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; + +}; + #endif // FAST_DDS_GENERATED__ENUMERATIONS_PUBSUBTYPES_HPP diff --git a/test/dds-types-test/enumerationsTypeObjectSupport.cxx b/test/dds-types-test/enumerationsTypeObjectSupport.cxx index 72b0f3dd5c1..c66e3a2f397 100644 --- a/test/dds-types-test/enumerationsTypeObjectSupport.cxx +++ b/test/dds-types-test/enumerationsTypeObjectSupport.cxx @@ -99,7 +99,79 @@ void register_InnerEnumHelper_type_identifier( } } } // namespace Test -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_EnumWithValues_type_identifier( + TypeIdentifierPair& type_ids_EnumWithValues) +{ + ReturnCode_t return_code_EnumWithValues {eprosima::fastdds::dds::RETCODE_OK}; + return_code_EnumWithValues = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "EnumWithValues", type_ids_EnumWithValues); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_EnumWithValues) + { + EnumTypeFlag enum_flags_EnumWithValues = 0; + BitBound bit_bound_EnumWithValues = 32; + CommonEnumeratedHeader common_EnumWithValues = TypeObjectUtils::build_common_enumerated_header(bit_bound_EnumWithValues); + QualifiedTypeName type_name_EnumWithValues = "EnumWithValues"; + eprosima::fastcdr::optional type_ann_builtin_EnumWithValues; + eprosima::fastcdr::optional ann_custom_EnumWithValues; + CompleteTypeDetail detail_EnumWithValues = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_EnumWithValues, ann_custom_EnumWithValues, type_name_EnumWithValues.to_string()); + CompleteEnumeratedHeader header_EnumWithValues = TypeObjectUtils::build_complete_enumerated_header(common_EnumWithValues, detail_EnumWithValues); + CompleteEnumeratedLiteralSeq literal_seq_EnumWithValues; + { + EnumeratedLiteralFlag flags_ENUM_VALUE1 = TypeObjectUtils::build_enumerated_literal_flag(false); + CommonEnumeratedLiteral common_ENUM_VALUE1 = TypeObjectUtils::build_common_enumerated_literal(0, flags_ENUM_VALUE1); + eprosima::fastcdr::optional member_ann_builtin_ENUM_VALUE1; + ann_custom_EnumWithValues.reset(); + AppliedAnnotationSeq tmp_ann_custom_ENUM_VALUE1; + if (!tmp_ann_custom_ENUM_VALUE1.empty()) + { + ann_custom_EnumWithValues = tmp_ann_custom_ENUM_VALUE1; + } + MemberName name_ENUM_VALUE1 = "ENUM_VALUE1"; + CompleteMemberDetail detail_ENUM_VALUE1 = TypeObjectUtils::build_complete_member_detail(name_ENUM_VALUE1, member_ann_builtin_ENUM_VALUE1, ann_custom_EnumWithValues); + CompleteEnumeratedLiteral literal_ENUM_VALUE1 = TypeObjectUtils::build_complete_enumerated_literal(common_ENUM_VALUE1, detail_ENUM_VALUE1); + TypeObjectUtils::add_complete_enumerated_literal(literal_seq_EnumWithValues, literal_ENUM_VALUE1); + } + { + EnumeratedLiteralFlag flags_ENUM_VALUE2 = TypeObjectUtils::build_enumerated_literal_flag(false); + CommonEnumeratedLiteral common_ENUM_VALUE2 = TypeObjectUtils::build_common_enumerated_literal(1, flags_ENUM_VALUE2); + eprosima::fastcdr::optional member_ann_builtin_ENUM_VALUE2; + ann_custom_EnumWithValues.reset(); + AppliedAnnotationSeq tmp_ann_custom_ENUM_VALUE2; + if (!tmp_ann_custom_ENUM_VALUE2.empty()) + { + ann_custom_EnumWithValues = tmp_ann_custom_ENUM_VALUE2; + } + MemberName name_ENUM_VALUE2 = "ENUM_VALUE2"; + CompleteMemberDetail detail_ENUM_VALUE2 = TypeObjectUtils::build_complete_member_detail(name_ENUM_VALUE2, member_ann_builtin_ENUM_VALUE2, ann_custom_EnumWithValues); + CompleteEnumeratedLiteral literal_ENUM_VALUE2 = TypeObjectUtils::build_complete_enumerated_literal(common_ENUM_VALUE2, detail_ENUM_VALUE2); + TypeObjectUtils::add_complete_enumerated_literal(literal_seq_EnumWithValues, literal_ENUM_VALUE2); + } + { + EnumeratedLiteralFlag flags_ENUM_VALUE3 = TypeObjectUtils::build_enumerated_literal_flag(false); + CommonEnumeratedLiteral common_ENUM_VALUE3 = TypeObjectUtils::build_common_enumerated_literal(2, flags_ENUM_VALUE3); + eprosima::fastcdr::optional member_ann_builtin_ENUM_VALUE3; + ann_custom_EnumWithValues.reset(); + AppliedAnnotationSeq tmp_ann_custom_ENUM_VALUE3; + if (!tmp_ann_custom_ENUM_VALUE3.empty()) + { + ann_custom_EnumWithValues = tmp_ann_custom_ENUM_VALUE3; + } + MemberName name_ENUM_VALUE3 = "ENUM_VALUE3"; + CompleteMemberDetail detail_ENUM_VALUE3 = TypeObjectUtils::build_complete_member_detail(name_ENUM_VALUE3, member_ann_builtin_ENUM_VALUE3, ann_custom_EnumWithValues); + CompleteEnumeratedLiteral literal_ENUM_VALUE3 = TypeObjectUtils::build_complete_enumerated_literal(common_ENUM_VALUE3, detail_ENUM_VALUE3); + TypeObjectUtils::add_complete_enumerated_literal(literal_seq_EnumWithValues, literal_ENUM_VALUE3); + } + CompleteEnumeratedType enumerated_type_EnumWithValues = TypeObjectUtils::build_complete_enumerated_type(enum_flags_EnumWithValues, header_EnumWithValues, + literal_seq_EnumWithValues); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_enumerated_type_object(enumerated_type_EnumWithValues, type_name_EnumWithValues.to_string(), type_ids_EnumWithValues)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "EnumWithValues already registered in TypeObjectRegistry for a different type."); + } + } +}// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method void register_EnumStructure_type_identifier( TypeIdentifierPair& type_ids_EnumStructure) { @@ -298,4 +370,61 @@ void register_BoundedBitMaskStructure_type_identifier( } } } +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_EnumWithValuesStructure_type_identifier( + TypeIdentifierPair& type_ids_EnumWithValuesStructure) +{ + + ReturnCode_t return_code_EnumWithValuesStructure {eprosima::fastdds::dds::RETCODE_OK}; + return_code_EnumWithValuesStructure = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "EnumWithValuesStructure", type_ids_EnumWithValuesStructure); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_EnumWithValuesStructure) + { + StructTypeFlag struct_flags_EnumWithValuesStructure = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_EnumWithValuesStructure = "EnumWithValuesStructure"; + eprosima::fastcdr::optional type_ann_builtin_EnumWithValuesStructure; + eprosima::fastcdr::optional ann_custom_EnumWithValuesStructure; + CompleteTypeDetail detail_EnumWithValuesStructure = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_EnumWithValuesStructure, ann_custom_EnumWithValuesStructure, type_name_EnumWithValuesStructure.to_string()); + CompleteStructHeader header_EnumWithValuesStructure; + header_EnumWithValuesStructure = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_EnumWithValuesStructure); + CompleteStructMemberSeq member_seq_EnumWithValuesStructure; + { + TypeIdentifierPair type_ids_var_enumwithvalues; + ReturnCode_t return_code_var_enumwithvalues {eprosima::fastdds::dds::RETCODE_OK}; + return_code_var_enumwithvalues = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "EnumWithValues", type_ids_var_enumwithvalues); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_var_enumwithvalues) + { + ::register_EnumWithValues_type_identifier(type_ids_var_enumwithvalues); + } + StructMemberFlag member_flags_var_enumwithvalues = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_var_enumwithvalues = 0x00000000; + bool common_var_enumwithvalues_ec {false}; + CommonStructMember common_var_enumwithvalues {TypeObjectUtils::build_common_struct_member(member_id_var_enumwithvalues, member_flags_var_enumwithvalues, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_var_enumwithvalues, common_var_enumwithvalues_ec))}; + if (!common_var_enumwithvalues_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure var_enumwithvalues member TypeIdentifier inconsistent."); + return; + } + MemberName name_var_enumwithvalues = "var_enumwithvalues"; + eprosima::fastcdr::optional member_ann_builtin_var_enumwithvalues; + ann_custom_EnumWithValuesStructure.reset(); + CompleteMemberDetail detail_var_enumwithvalues = TypeObjectUtils::build_complete_member_detail(name_var_enumwithvalues, member_ann_builtin_var_enumwithvalues, ann_custom_EnumWithValuesStructure); + CompleteStructMember member_var_enumwithvalues = TypeObjectUtils::build_complete_struct_member(common_var_enumwithvalues, detail_var_enumwithvalues); + TypeObjectUtils::add_complete_struct_member(member_seq_EnumWithValuesStructure, member_var_enumwithvalues); + } + CompleteStructType struct_type_EnumWithValuesStructure = TypeObjectUtils::build_complete_struct_type(struct_flags_EnumWithValuesStructure, header_EnumWithValuesStructure, member_seq_EnumWithValuesStructure); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_EnumWithValuesStructure, type_name_EnumWithValuesStructure.to_string(), type_ids_EnumWithValuesStructure)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "EnumWithValuesStructure already registered in TypeObjectRegistry for a different type."); + } + } +} diff --git a/test/dds-types-test/enumerationsTypeObjectSupport.hpp b/test/dds-types-test/enumerationsTypeObjectSupport.hpp index 4920e8ed4bb..23d37c101a4 100644 --- a/test/dds-types-test/enumerationsTypeObjectSupport.hpp +++ b/test/dds-types-test/enumerationsTypeObjectSupport.hpp @@ -53,6 +53,18 @@ eProsima_user_DllExport void register_InnerEnumHelper_type_identifier( eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); } // namespace Test +/** + * @brief Register EnumWithValues related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_EnumWithValues_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); /** * @brief Register EnumStructure related TypeIdentifier. * Fully-descriptive TypeIdentifiers are directly registered. @@ -89,6 +101,18 @@ eProsima_user_DllExport void register_BitMaskStructure_type_identifier( */ eProsima_user_DllExport void register_BoundedBitMaskStructure_type_identifier( eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register EnumWithValuesStructure related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_EnumWithValuesStructure_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); #endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC diff --git a/test/dds-types-test/unions.hpp b/test/dds-types-test/unions.hpp index 73d46cc8e1a..57341ab5819 100644 --- a/test/dds-types-test/unions.hpp +++ b/test/dds-types-test/unions.hpp @@ -18795,6 +18795,353 @@ class DefaultAnnotation std::function member_destructor_; }; +/*! + * @brief This class represents the union DefaultAnnotationExternalValue defined by the user in the IDL file. + * @ingroup unions + */ +class DefaultAnnotationExternalValue +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport DefaultAnnotationExternalValue() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~DefaultAnnotationExternalValue() + { + if (member_destructor_) + { + member_destructor_(); + } + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object DefaultAnnotationExternalValue that will be copied. + */ + eProsima_user_DllExport DefaultAnnotationExternalValue( + const DefaultAnnotationExternalValue& x) + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + a_() = x.m_a; + break; + + case 0x00000002: + b_() = x.m_b; + break; + + } + } + + /*! + * @brief Move constructor. + * @param x Reference to the object DefaultAnnotationExternalValue that will be copied. + */ + eProsima_user_DllExport DefaultAnnotationExternalValue( + DefaultAnnotationExternalValue&& x) noexcept + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + a_() = std::move(x.m_a); + break; + + case 0x00000002: + b_() = std::move(x.m_b); + break; + + } + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object DefaultAnnotationExternalValue that will be copied. + */ + eProsima_user_DllExport DefaultAnnotationExternalValue& operator =( + const DefaultAnnotationExternalValue& x) + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + a_() = x.m_a; + break; + + case 0x00000002: + b_() = x.m_b; + break; + + } + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object DefaultAnnotationExternalValue that will be copied. + */ + eProsima_user_DllExport DefaultAnnotationExternalValue& operator =( + DefaultAnnotationExternalValue&& x) noexcept + { + m__d = x.m__d; + + switch (x.selected_member_) + { + case 0x00000001: + a_() = std::move(x.m_a); + break; + + case 0x00000002: + b_() = std::move(x.m_b); + break; + + } + + return *this; + } + + /*! + * @brief Comparison operator. + * @param x DefaultAnnotationExternalValue object to compare. + */ + eProsima_user_DllExport bool operator ==( + const DefaultAnnotationExternalValue& x) const + { + bool ret_value {false}; + + if (m__d == x.m__d && + selected_member_ == x.selected_member_) + { + switch (selected_member_) + { + case 0x00000001: + ret_value = (m_a == x.m_a); + break; + + case 0x00000002: + ret_value = (m_b == x.m_b); + break; + + } + } + + return ret_value; + } + + /*! + * @brief Comparison operator. + * @param x DefaultAnnotationExternalValue object to compare. + */ + eProsima_user_DllExport bool operator !=( + const DefaultAnnotationExternalValue& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets the discriminator value. + * @param __d New value for the discriminator. + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the new value doesn't correspond to the selected union member. + */ + eProsima_user_DllExport void _d( + int32_t __d) + { + bool valid_discriminator = false; + + switch (__d) + { + case 0: + if (0x00000001 == selected_member_) + { + valid_discriminator = true; + } + break; + + case 1: + if (0x00000002 == selected_member_) + { + valid_discriminator = true; + } + break; + + } + + if (!valid_discriminator) + { + throw eprosima::fastcdr::exception::BadParamException("Discriminator doesn't correspond with the selected union member"); + } + + m__d = __d; + } + + /*! + * @brief This function returns the value of the discriminator. + * @return Value of the discriminator + */ + eProsima_user_DllExport int32_t _d() const + { + return m__d; + } + + /*! + * @brief This function sets a value in member a + * @param _a New value for member a + */ + eProsima_user_DllExport void a( + uint8_t _a) + { + a_() = _a; + m__d = 0; + } + + /*! + * @brief This function returns the value of member a + * @return Value of member a + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport uint8_t a() const + { + if (0x00000001 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_a; + } + + /*! + * @brief This function returns a reference to member a + * @return Reference to member a + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport uint8_t& a() + { + if (0x00000001 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_a; + } + + + /*! + * @brief This function sets a value in member b + * @param _b New value for member b + */ + eProsima_user_DllExport void b( + int16_t _b) + { + b_() = _b; + m__d = 1; + } + + /*! + * @brief This function returns the value of member b + * @return Value of member b + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport int16_t b() const + { + if (0x00000002 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_b; + } + + /*! + * @brief This function returns a reference to member b + * @return Reference to member b + * @exception eprosima::fastcdr::exception::BadParamException This exception is thrown if the requested union member is not the current selection. + */ + eProsima_user_DllExport int16_t& b() + { + if (0x00000002 != selected_member_) + { + throw eprosima::fastcdr::exception::BadParamException("This member has not been selected"); + } + + return m_b; + } + + + void _default() + { + if (member_destructor_) + { + member_destructor_(); + } + + selected_member_ = 0x0FFFFFFFu; + } + + +private: + + uint8_t& a_() + { + if (0x00000001 != selected_member_) + { + if (member_destructor_) + { + member_destructor_(); + } + + selected_member_ = 0x00000001; + member_destructor_ = nullptr; + m_a = {0}; + ; + } + + return m_a; + } + + int16_t& b_() + { + if (0x00000002 != selected_member_) + { + if (member_destructor_) + { + member_destructor_(); + } + + selected_member_ = 0x00000002; + member_destructor_ = nullptr; + m_b = {0}; + ; + } + + return m_b; + } + + + int32_t m__d {2}; + + union + { + uint8_t m_a; + int16_t m_b; + }; + + uint32_t selected_member_ {0x0FFFFFFFu}; + + std::function member_destructor_; +}; #endif // _FAST_DDS_GENERATED_UNIONS_HPP_ diff --git a/test/dds-types-test/unionsCdrAux.hpp b/test/dds-types-test/unionsCdrAux.hpp index 9e3031cd909..b867b30d18c 100644 --- a/test/dds-types-test/unionsCdrAux.hpp +++ b/test/dds-types-test/unionsCdrAux.hpp @@ -78,6 +78,7 @@ constexpr uint32_t UnionDiscriminatorUShort_max_key_cdr_typesize {0UL}; + constexpr uint32_t UnionLong_max_cdr_typesize {16UL}; constexpr uint32_t UnionLong_max_key_cdr_typesize {0UL}; @@ -377,6 +378,7 @@ eProsima_user_DllExport void serialize_key( + } // namespace fastcdr } // namespace eprosima diff --git a/test/dds-types-test/unionsCdrAux.ipp b/test/dds-types-test/unionsCdrAux.ipp index caa3d3a725d..7d79e3d484e 100644 --- a/test/dds-types-test/unionsCdrAux.ipp +++ b/test/dds-types-test/unionsCdrAux.ipp @@ -8344,6 +8344,136 @@ eProsima_user_DllExport void deserialize( }); } +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const DefaultAnnotationExternalValue& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), data._d(), + current_alignment); + + switch (data._d()) + { + case 0: + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.a(), current_alignment); + break; + + case 1: + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.b(), current_alignment); + break; + + default: + break; + } + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const DefaultAnnotationExternalValue& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr << eprosima::fastcdr::MemberId(0) << data._d(); + + switch (data._d()) + { + case 0: + scdr << eprosima::fastcdr::MemberId(1) << data.a(); + break; + + case 1: + scdr << eprosima::fastcdr::MemberId(2) << data.b(); + break; + + default: + break; + } + + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + DefaultAnnotationExternalValue& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + if (0 == mid.id) + { + int32_t discriminator; + dcdr >> discriminator; + + switch (discriminator) + { + case 0: + { + uint8_t a_value{0}; + data.a(std::move(a_value)); + data._d(discriminator); + break; + } + + case 1: + { + int16_t b_value{0}; + data.b(std::move(b_value)); + data._d(discriminator); + break; + } + + default: + data._default(); + break; + } + } + else + { + switch (data._d()) + { + case 0: + dcdr >> data.a(); + break; + + case 1: + dcdr >> data.b(); + break; + + default: + break; + } + ret_value = false; + } + return ret_value; + }); +} + } // namespace fastcdr } // namespace eprosima diff --git a/test/dds-types-test/unionsPubSubTypes.cxx b/test/dds-types-test/unionsPubSubTypes.cxx index 331fe5bd347..76958231cfb 100644 --- a/test/dds-types-test/unionsPubSubTypes.cxx +++ b/test/dds-types-test/unionsPubSubTypes.cxx @@ -7454,5 +7454,6 @@ void UnionSeveralFieldsWithDefaultPubSubType::register_type_object_representatio + // Include auxiliary functions like for serializing/deserializing. #include "unionsCdrAux.ipp" diff --git a/test/dds-types-test/unionsPubSubTypes.hpp b/test/dds-types-test/unionsPubSubTypes.hpp index f4f03cfd3b7..66d99edd67f 100644 --- a/test/dds-types-test/unionsPubSubTypes.hpp +++ b/test/dds-types-test/unionsPubSubTypes.hpp @@ -3361,5 +3361,6 @@ class UnionSeveralFieldsWithDefaultPubSubType : public eprosima::fastdds::dds::T }; + #endif // FAST_DDS_GENERATED__UNIONS_PUBSUBTYPES_HPP diff --git a/test/dds-types-test/unionsTypeObjectSupport.cxx b/test/dds-types-test/unionsTypeObjectSupport.cxx index e7dbd2d2e24..c28ca6611fd 100644 --- a/test/dds-types-test/unionsTypeObjectSupport.cxx +++ b/test/dds-types-test/unionsTypeObjectSupport.cxx @@ -7098,4 +7098,134 @@ void register_DefaultAnnotation_type_identifier( } } } +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_DefaultAnnotationExternalValue_type_identifier( + TypeIdentifierPair& type_ids_DefaultAnnotationExternalValue) +{ + ReturnCode_t return_code_DefaultAnnotationExternalValue {eprosima::fastdds::dds::RETCODE_OK}; + return_code_DefaultAnnotationExternalValue = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "DefaultAnnotationExternalValue", type_ids_DefaultAnnotationExternalValue); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_DefaultAnnotationExternalValue) + { + UnionTypeFlag union_flags_DefaultAnnotationExternalValue = TypeObjectUtils::build_union_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_DefaultAnnotationExternalValue = "DefaultAnnotationExternalValue"; + eprosima::fastcdr::optional type_ann_builtin_DefaultAnnotationExternalValue; + eprosima::fastcdr::optional ann_custom_DefaultAnnotationExternalValue; + CompleteTypeDetail detail_DefaultAnnotationExternalValue = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_DefaultAnnotationExternalValue, ann_custom_DefaultAnnotationExternalValue, type_name_DefaultAnnotationExternalValue.to_string()); + CompleteUnionHeader header_DefaultAnnotationExternalValue = TypeObjectUtils::build_complete_union_header(detail_DefaultAnnotationExternalValue); + UnionDiscriminatorFlag member_flags_DefaultAnnotationExternalValue = TypeObjectUtils::build_union_discriminator_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false); + return_code_DefaultAnnotationExternalValue = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int32_t", type_ids_DefaultAnnotationExternalValue); + + if (return_code_DefaultAnnotationExternalValue != eprosima::fastdds::dds::RETCODE_OK) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Union discriminator TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + CommonDiscriminatorMember common_DefaultAnnotationExternalValue; + if (EK_COMPLETE == type_ids_DefaultAnnotationExternalValue.type_identifier1()._d() || TK_NONE == type_ids_DefaultAnnotationExternalValue.type_identifier2()._d()) + { + common_DefaultAnnotationExternalValue = TypeObjectUtils::build_common_discriminator_member(member_flags_DefaultAnnotationExternalValue, type_ids_DefaultAnnotationExternalValue.type_identifier1()); + } + else if (EK_COMPLETE == type_ids_DefaultAnnotationExternalValue.type_identifier2()._d()) + { + common_DefaultAnnotationExternalValue = TypeObjectUtils::build_common_discriminator_member(member_flags_DefaultAnnotationExternalValue, type_ids_DefaultAnnotationExternalValue.type_identifier2()); + } + else + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "DefaultAnnotationExternalValue discriminator TypeIdentifier inconsistent."); + return; + } + type_ann_builtin_DefaultAnnotationExternalValue.reset(); + ann_custom_DefaultAnnotationExternalValue.reset(); + AppliedAnnotationSeq tmp_ann_custom_discriminator; + eprosima::fastcdr::optional verbatim_discriminator; + if (!tmp_ann_custom_discriminator.empty()) + { + ann_custom_DefaultAnnotationExternalValue = tmp_ann_custom_discriminator; + } + + CompleteDiscriminatorMember discriminator_DefaultAnnotationExternalValue = TypeObjectUtils::build_complete_discriminator_member(common_DefaultAnnotationExternalValue, + type_ann_builtin_DefaultAnnotationExternalValue, ann_custom_DefaultAnnotationExternalValue); + CompleteUnionMemberSeq member_seq_DefaultAnnotationExternalValue; + { + return_code_DefaultAnnotationExternalValue = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_byte", type_ids_DefaultAnnotationExternalValue); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_DefaultAnnotationExternalValue) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "a Union member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + UnionMemberFlag member_flags_a = TypeObjectUtils::build_union_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false); + UnionCaseLabelSeq label_seq_a; + TypeObjectUtils::add_union_case_label(label_seq_a, static_cast(0)); + MemberId member_id_a = 0x00000001; + bool common_a_ec {false}; + CommonUnionMember common_a {TypeObjectUtils::build_common_union_member(member_id_a, + member_flags_a, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_DefaultAnnotationExternalValue, + common_a_ec), label_seq_a)}; + if (!common_a_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Union a member TypeIdentifier inconsistent."); + return; + } + MemberName name_a = "a"; + eprosima::fastcdr::optional member_ann_builtin_a; + ann_custom_DefaultAnnotationExternalValue.reset(); + CompleteMemberDetail detail_a = TypeObjectUtils::build_complete_member_detail(name_a, member_ann_builtin_a, ann_custom_DefaultAnnotationExternalValue); + CompleteUnionMember member_a = TypeObjectUtils::build_complete_union_member(common_a, detail_a); + TypeObjectUtils::add_complete_union_member(member_seq_DefaultAnnotationExternalValue, member_a); + } + { + return_code_DefaultAnnotationExternalValue = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_int16_t", type_ids_DefaultAnnotationExternalValue); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_DefaultAnnotationExternalValue) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "b Union member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + UnionMemberFlag member_flags_b = TypeObjectUtils::build_union_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false); + UnionCaseLabelSeq label_seq_b; + TypeObjectUtils::add_union_case_label(label_seq_b, static_cast(1)); + MemberId member_id_b = 0x00000002; + bool common_b_ec {false}; + CommonUnionMember common_b {TypeObjectUtils::build_common_union_member(member_id_b, + member_flags_b, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_DefaultAnnotationExternalValue, + common_b_ec), label_seq_b)}; + if (!common_b_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Union b member TypeIdentifier inconsistent."); + return; + } + MemberName name_b = "b"; + eprosima::fastcdr::optional member_ann_builtin_b; + ann_custom_DefaultAnnotationExternalValue.reset(); + CompleteMemberDetail detail_b = TypeObjectUtils::build_complete_member_detail(name_b, member_ann_builtin_b, ann_custom_DefaultAnnotationExternalValue); + CompleteUnionMember member_b = TypeObjectUtils::build_complete_union_member(common_b, detail_b); + TypeObjectUtils::add_complete_union_member(member_seq_DefaultAnnotationExternalValue, member_b); + } + CompleteUnionType union_type_DefaultAnnotationExternalValue = TypeObjectUtils::build_complete_union_type(union_flags_DefaultAnnotationExternalValue, header_DefaultAnnotationExternalValue, discriminator_DefaultAnnotationExternalValue, + member_seq_DefaultAnnotationExternalValue); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_union_type_object(union_type_DefaultAnnotationExternalValue, type_name_DefaultAnnotationExternalValue.to_string(), type_ids_DefaultAnnotationExternalValue)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "DefaultAnnotationExternalValue already registered in TypeObjectRegistry for a different type."); + } + } +} diff --git a/test/dds-types-test/unionsTypeObjectSupport.hpp b/test/dds-types-test/unionsTypeObjectSupport.hpp index 23da9c1616c..fe75d7be5fc 100644 --- a/test/dds-types-test/unionsTypeObjectSupport.hpp +++ b/test/dds-types-test/unionsTypeObjectSupport.hpp @@ -1034,6 +1034,18 @@ eProsima_user_DllExport void register_UnionSeveralFieldsWithDefault_type_identif */ eProsima_user_DllExport void register_DefaultAnnotation_type_identifier( eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register DefaultAnnotationExternalValue related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_DefaultAnnotationExternalValue_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); #endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC diff --git a/test/feature/dynamic_types/dds_types_tests/DynamicTypesEnumerationsDDSTypesTests.cpp b/test/feature/dynamic_types/dds_types_tests/DynamicTypesEnumerationsDDSTypesTests.cpp index c68064183c5..5d143dff0f7 100644 --- a/test/feature/dynamic_types/dds_types_tests/DynamicTypesEnumerationsDDSTypesTests.cpp +++ b/test/feature/dynamic_types/dds_types_tests/DynamicTypesEnumerationsDDSTypesTests.cpp @@ -31,32 +31,42 @@ namespace eprosima { namespace fastdds { namespace dds { +constexpr const char* enum_enumwithvalues_name = "EnumWithValues"; constexpr const char* struct_enumstructure_name = "EnumStructure"; constexpr const char* struct_bitmaskstructure_name = "BitMaskStructure"; constexpr const char* struct_boundedbitmaskstructure_name = "BoundedBitMaskStructure"; +constexpr const char* struct_enumwithvaluesstructure_name = "EnumWithValuesStructure"; constexpr const char* var_innerenumhelper_name = "var_InnerEnumHelper"; constexpr const char* var_scoped_innerenumhelper = "var_scoped_InnerEnumHelper"; constexpr const char* var_innerbitmaskhelper_name = "var_InnerBitMaskHelper"; constexpr const char* var_innerboundedbitmaskhelper_name = "var_InnerBoundedBitMaskHelper"; +constexpr const char* var_enumwithvalues_name = "var_enumwithvalues"; DynamicType::_ref_type create_scoped_inner_enum_helper() { TypeDescriptor::_ref_type enum_descriptor {traits::make_shared()}; enum_descriptor->kind(TK_ENUM); enum_descriptor->name(std::string("Test::") + std::string(enum_name)); - DynamicTypeBuilder::_ref_type enum_builder {DynamicTypeBuilderFactory::get_instance()->create_type(enum_descriptor)}; + DynamicTypeBuilder::_ref_type enum_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + enum_descriptor)}; MemberDescriptor::_ref_type enum_literal_descriptor {traits::make_shared()}; - enum_literal_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32)); + enum_literal_descriptor->type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type( + TK_INT32)); enum_literal_descriptor->name(enum_value_1_name); enum_builder->add_member(enum_literal_descriptor); enum_literal_descriptor = traits::make_shared(); - enum_literal_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32)); + enum_literal_descriptor->type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type( + TK_INT32)); enum_literal_descriptor->name(enum_value_2_name); enum_builder->add_member(enum_literal_descriptor); enum_literal_descriptor = traits::make_shared(); - enum_literal_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32)); + enum_literal_descriptor->type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type( + TK_INT32)); enum_literal_descriptor->name(enum_value_3_name); enum_builder->add_member(enum_literal_descriptor); @@ -68,7 +78,8 @@ TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_EnumStructure) TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; type_descriptor->kind(TK_STRUCTURE); type_descriptor->name(struct_enumstructure_name); - DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + type_descriptor)}; MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; member_descriptor->name(var_innerenumhelper_name); @@ -89,14 +100,23 @@ TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_EnumStructure) ::Test::InnerEnumHelper scoped_value = ::Test::InnerEnumHelper::ENUM_VALUE_3; int32_t test_value = 0; int32_t scoped_test_value = 0; - EXPECT_EQ(data->set_int32_value(data->get_member_id_by_name( + EXPECT_EQ( + data->set_int32_value( + data->get_member_id_by_name( var_innerenumhelper_name), static_cast(value)), RETCODE_OK); - EXPECT_EQ(data->get_int32_value(test_value, data->get_member_id_by_name(var_innerenumhelper_name)), RETCODE_OK); + EXPECT_EQ( + data->get_int32_value( + test_value, data->get_member_id_by_name( + var_innerenumhelper_name)), RETCODE_OK); EXPECT_EQ(static_cast(value), test_value); - EXPECT_EQ(data->set_int32_value(data->get_member_id_by_name( + EXPECT_EQ( + data->set_int32_value( + data->get_member_id_by_name( var_scoped_innerenumhelper), static_cast(scoped_value)), RETCODE_OK); - EXPECT_EQ(data->get_int32_value(scoped_test_value, data->get_member_id_by_name( + EXPECT_EQ( + data->get_int32_value( + scoped_test_value, data->get_member_id_by_name( var_scoped_innerenumhelper)), RETCODE_OK); EXPECT_EQ(static_cast(scoped_value), scoped_test_value); @@ -104,8 +124,9 @@ TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_EnumStructure) { EnumStructure struct_data; TypeSupport static_pubsubType {new EnumStructurePubSubType()}; - check_serialization_deserialization(struct_type, data, encoding, struct_data, - static_pubsubType); + check_serialization_deserialization( + struct_type, data, encoding, struct_data, + static_pubsubType); EXPECT_EQ(static_cast(struct_data.var_InnerEnumHelper()), test_value); EXPECT_EQ(static_cast(struct_data.var_scoped_InnerEnumHelper()), scoped_test_value); } @@ -122,7 +143,8 @@ TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_BitMaskStructure) TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; type_descriptor->kind(TK_STRUCTURE); type_descriptor->name(struct_bitmaskstructure_name); - DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + type_descriptor)}; MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; member_descriptor->name(var_innerbitmaskhelper_name); @@ -137,16 +159,23 @@ TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_BitMaskStructure) InnerBitMaskHelper value = InnerBitMaskHelperBits::flag0 | InnerBitMaskHelperBits::flag1 | InnerBitMaskHelperBits::flag4 | InnerBitMaskHelperBits::flag6; InnerBitMaskHelper test_value = 0; - EXPECT_EQ(data->set_uint32_value(data->get_member_id_by_name(var_innerbitmaskhelper_name), value), RETCODE_OK); - EXPECT_EQ(data->get_uint32_value(test_value, data->get_member_id_by_name(var_innerbitmaskhelper_name)), RETCODE_OK); + EXPECT_EQ( + data->set_uint32_value( + data->get_member_id_by_name( + var_innerbitmaskhelper_name), value), RETCODE_OK); + EXPECT_EQ( + data->get_uint32_value( + test_value, + data->get_member_id_by_name(var_innerbitmaskhelper_name)), RETCODE_OK); EXPECT_EQ(value, test_value); for (auto encoding : encodings) { BitMaskStructure struct_data; TypeSupport static_pubsubType {new BitMaskStructurePubSubType()}; - check_serialization_deserialization(struct_type, data, encoding, struct_data, - static_pubsubType); + check_serialization_deserialization( + struct_type, data, encoding, struct_data, + static_pubsubType); EXPECT_EQ(struct_data.var_InnerBitMaskHelper(), test_value); } @@ -162,7 +191,8 @@ TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_BoundedBitMaskStructure) TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; type_descriptor->kind(TK_STRUCTURE); type_descriptor->name(struct_boundedbitmaskstructure_name); - DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + type_descriptor)}; MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; member_descriptor->name(var_innerboundedbitmaskhelper_name); @@ -174,12 +204,16 @@ TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_BoundedBitMaskStructure) DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; ASSERT_TRUE(data); - InnerBoundedBitMaskHelper value = InnerBoundedBitMaskHelperBits::bflag0 | InnerBoundedBitMaskHelperBits::bflag1 | + InnerBoundedBitMaskHelper value = InnerBoundedBitMaskHelperBits::bflag0 | + InnerBoundedBitMaskHelperBits::bflag1 | InnerBoundedBitMaskHelperBits::bflag4 | InnerBoundedBitMaskHelperBits::bflag6; InnerBoundedBitMaskHelper test_value = 0; - EXPECT_EQ(data->set_uint8_value(data->get_member_id_by_name(var_innerboundedbitmaskhelper_name), value), - RETCODE_OK); - EXPECT_EQ(data->get_uint8_value(test_value, data->get_member_id_by_name( + EXPECT_EQ( + data->set_uint8_value(data->get_member_id_by_name(var_innerboundedbitmaskhelper_name), value), + RETCODE_OK); + EXPECT_EQ( + data->get_uint8_value( + test_value, data->get_member_id_by_name( var_innerboundedbitmaskhelper_name)), RETCODE_OK); EXPECT_EQ(value, test_value); @@ -187,8 +221,9 @@ TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_BoundedBitMaskStructure) { BoundedBitMaskStructure struct_data; TypeSupport static_pubsubType {new BoundedBitMaskStructurePubSubType()}; - check_serialization_deserialization(struct_type, data, encoding, struct_data, - static_pubsubType); + check_serialization_deserialization( + struct_type, data, encoding, struct_data, + static_pubsubType); EXPECT_EQ(struct_data.var_InnerBoundedBitMaskHelper(), test_value); } @@ -199,6 +234,74 @@ TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_BoundedBitMaskStructure) EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); } +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_EnumWithValuesStructure) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_enumwithvaluesstructure_name); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + type_descriptor)}; + + TypeDescriptor::_ref_type enum_descriptor {traits::make_shared()}; + enum_descriptor->kind(TK_ENUM); + enum_descriptor->name(enum_enumwithvalues_name); + DynamicTypeBuilder::_ref_type enum_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + enum_descriptor)}; + + MemberDescriptor::_ref_type enum_literal_descriptor {traits::make_shared()}; + enum_literal_descriptor->type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type( + TK_INT32)); + enum_literal_descriptor->name("ENUM_VALUE1"); + enum_builder->add_member(enum_literal_descriptor); + enum_literal_descriptor = traits::make_shared(); + enum_literal_descriptor->type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type( + TK_INT32)); + enum_literal_descriptor->name("ENUM_VALUE2"); + enum_builder->add_member(enum_literal_descriptor); + enum_literal_descriptor = traits::make_shared(); + enum_literal_descriptor->type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type( + TK_INT32)); + enum_literal_descriptor->name("ENUM_VALUE3"); + enum_builder->add_member(enum_literal_descriptor); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_enumwithvalues_name); + member_descriptor->type(enum_builder->build()); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type = type_builder->build(); + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + int32_t value = 0; + int32_t test_value = 0; + EXPECT_EQ( + data->set_int32_value( + data->get_member_id_by_name( + var_enumwithvalues_name), 1), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + EnumWithValuesStructure struct_data; + TypeSupport static_pubsubType {new EnumWithValuesStructurePubSubType()}; + check_serialization_deserialization( + struct_type, data, encoding, struct_data, + static_pubsubType); + EXPECT_EQ(static_cast(struct_data.var_enumwithvalues()), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_EnumWithValuesStructure_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + } // dds } // fastdds diff --git a/thirdparty/dds-types-test b/thirdparty/dds-types-test index 9e3ff55e392..5209b354e68 160000 --- a/thirdparty/dds-types-test +++ b/thirdparty/dds-types-test @@ -1 +1 @@ -Subproject commit 9e3ff55e392cafcf6246ba13055c1472eb37e46d +Subproject commit 5209b354e68940fc72515cec9fb65e890b1fdc94 diff --git a/thirdparty/fastcdr b/thirdparty/fastcdr index 455a4e7e626..e17fdc426eb 160000 --- a/thirdparty/fastcdr +++ b/thirdparty/fastcdr @@ -1 +1 @@ -Subproject commit 455a4e7e6267631bc1313203ebed489b72c48009 +Subproject commit e17fdc426eb878c963cf3b9002709bc407643fbf