Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[21424] Add test for support of enumeration literal @value annotation #5109

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2140,9 +2140,10 @@ ReturnCode_t TypeObjectRegistry::register_typeobject_w_enum_dynamic_type(
MemberDescriptorImpl& member_descriptor {literal->get_descriptor()};
EnumeratedLiteralFlag flags {TypeObjectUtils::build_enumerated_literal_flag(
member_descriptor.is_default_label())};
// TODO(richi): Literal value might be automatically assigned or taken from default_value (@value annotation)
// Literal value might be automatically assigned or taken from default_value (@value annotation)
CommonEnumeratedLiteral common_literal {TypeObjectUtils::build_common_enumerated_literal(
member_descriptor.index(), flags)};
member_descriptor.default_value().empty() ? member_descriptor.index() :
std::stol(member_descriptor.default_value()), flags)};
CompleteMemberDetail member_detail;
complete_member_detail(literal, member_detail);
CompleteEnumeratedLiteral literal_member {TypeObjectUtils::build_complete_enumerated_literal(
Expand Down
133 changes: 133 additions & 0 deletions test/dds-types-test/enumerations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_
Expand Down
8 changes: 8 additions & 0 deletions test/dds-types-test/enumerationsCdrAux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down
79 changes: 79 additions & 0 deletions test/dds-types-test/enumerationsCdrAux.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,85 @@ 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<void>(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<void>(scdr);
static_cast<void>(data);
scdr << data.var_enumwithvalues();

}



} // namespace fastcdr
} // namespace eprosima
Expand Down
Loading
Loading