diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg index abbaf1ab..060d9a62 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg @@ -418,9 +418,81 @@ bitmask_type(ctx, parent, bitmask) ::= << * @brief This class represents the bitmask $bitmask.name$ defined by the user in the IDL file. * @ingroup $ctx.trimfilename$ */ -enum $bitmask.name$$bitmask.boundType$ +class $bitmask.name$ { - $bitmask.members:{ member | $member.name$ = 0x01ull << $member.position$}; separator=",\n"$ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport $bitmask.name$(); + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~$bitmask.name$(); + + /*! + * @brief Copy constructor. + * + * @param x Reference to the object $bitmask.scopedname$ that will be copied. + */ + eProsima_user_DllExport $bitmask.name$( + const $bitmask.name$& x); + + /*! + * @brief Move constructor. + * + * @param x Reference to the object $bitmask.scopedname$ that will be copied. + */ + eProsima_user_DllExport $bitmask.name$( + $bitmask.name$&& x) noexcept; + + /*! + * @brief Copy assignment. + * + * @param x Reference to the object $bitmask.scopedname$ that will be copied. + */ + eProsima_user_DllExport $bitmask.name$& operator =( + const $bitmask.name$& x); + + /*! + * @brief Move assignment. + * + * @param x Reference to the object $bitmask.scopedname$ that will be copied. + */ + eProsima_user_DllExport $bitmask.name$& operator =( + $bitmask.name$&& x) noexcept; + + /*! + * @brief Comparison operator. + * + * @param x $bitmask.scopedname$ object to compare. + */ + eProsima_user_DllExport bool operator ==( + const $bitmask.name$& x) const; + + /*! + * @brief Comparison operator. + * + * @param x $bitmask.scopedname$ object to compare. + */ + eProsima_user_DllExport bool operator !=( + const $bitmask.name$& x) const; + + $bitmask.members:{ it | $public_bitflag_declaration(it)$}; separator="\n"$ + + eProsima_user_DllExport const std::bitset<$bitmask.bitBound$>& bitmask() const; + + eProsima_user_DllExport std::bitset<$bitmask.bitBound$>& bitmask(); + + eProsima_user_DllExport void bitmask(const std::bitset<$bitmask.bitBound$>&); + + $serialization_functions(bitmask)$ + +private: + + std::bitset<$bitmask.bitBound$> m_bitmask; }; >> @@ -619,6 +691,23 @@ eProsima_user_DllExport const $member.typecode.cppTypename$& $member.name$() con eProsima_user_DllExport $member.typecode.cppTypename$& $member.name$(); >> +public_bitflag_declaration(member) ::= << +/*! + * @brief This function sets a value in flag $member.name$ + * + * @param _$member.name$ New value for flag $member.name$ + */ +eProsima_user_DllExport void $member.name$( + bool _$member.name$); + +/*! + * @brief This function returns the value of flag $member.name$ + * + * @return Value of flag $member.name$ + */ +eProsima_user_DllExport bool $member.name$() const; +>> + member_default_init(member) ::= <% $if(!member.typecode.forwarded)$ $if(member.annotationDefault)$ diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg index da32acdd..f03e6995 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg @@ -516,7 +516,106 @@ $endif$ enum_type(ctx, parent, enum) ::= <<>> -bitmask_type(ctx, parent, bitmask) ::= <<>> +bitmask_type(ctx, parent, bitmask) ::= << +$bitmask.scopedname$::$bitmask.name$() +{ + $if(ctx.generateTypeObject)$ + // Just to register all known types + register$ctx.filename$Types(); + $endif$ +} + +$bitmask.scopedname$::~$bitmask.name$() +{ +} + +$bitmask.scopedname$::$bitmask.name$( + const $bitmask.name$& x) +{ + m_bitmask = x.m_bitmask; +} + +$bitmask.scopedname$::$bitmask.name$( + $bitmask.name$&& x) noexcept +{ + m_bitmask = x.m_bitmask; +} + +$bitmask.scopedname$& $bitmask.scopedname$::operator =( + const $bitmask.name$& x) +{ + m_bitmask = x.m_bitmask; + + return *this; +} + +$bitmask.scopedname$& $bitmask.scopedname$::operator =( + $bitmask.name$&& x) noexcept +{ + m_bitmask = x.m_bitmask; + + return *this; +} + +bool $bitmask.scopedname$::operator ==( + const $bitmask.name$& x) const +{ + return m_bitmask == x.m_bitmask; +} + +bool $bitmask.scopedname$::operator !=( + const $bitmask.name$& x) const +{ + return !(*this == x); +} + +$if(ctx.fastcdr)$ +void $bitmask.scopedname$::serialize( + eprosima::fastcdr::FastCdr& scdr) const +{ + scdr << m_bitmask; +} + +void $bitmask.scopedname$::deserialize( + eprosima::fastcdr::FastCdr& dcdr) +{ + dcdr \>> m_bitmask; +} + +$endif$ + + +$bitmask.members:{ it | $public_bitmask_definition(it)$}; separator="\n"$ + +const std::bitset<$bitmask.bitBound$>& $bitmask.scopedname$::bitmask() const +{ + return m_bitmask; +} + +std::bitset<$bitmask.bitBound$>& $bitmask.scopedname$::bitmask() +{ + return m_bitmask; +} + +void $bitmask.scopedname$::bitmask(const std::bitset<$bitmask.bitBound$>& bitmask) +{ + m_bitmask = bitmask; +} + +>> + +public_bitmask_definition(member) ::= << +void $bitmask.scopedname$::$member.name$( + bool _$member.name$) +{ + m_bitmask.set($member.position$, _$member.name$); +} + +bool $bitmask.scopedname$::$member.name$() const +{ + return m_bitmask.test($member.position$); +} +>> /***** Utils *****/ diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg index 774110f7..0db7af6b 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg @@ -70,7 +70,18 @@ enum_type(ctx, parent, enum) ::= <<>> typedef_decl(ctx, parent, typedefs) ::= <<>> -bitmask_type(ctx, parent, bitmask) ::= <<>> +bitmask_type(ctx, parent, bitmask) ::= << +void print$bitmask.name$( + $bitmask.name$* topic); + +void initialize$bitmask.name$( + $bitmask.name$* topic); + +int compare$bitmask.name$( + $bitmask.name$* a, + $bitmask.name$* b); + +>> bitset_type(ctx, parent, bitset) ::= << void print$bitset.name$( diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg index 77bae39b..f121e57c 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg @@ -148,7 +148,29 @@ int $if(union.hasScope)$$union.scope$::$endif$compare$union.name$( enum_type(ctx, parent, enum) ::= <<>> -bitmask_type(ctx, parent, bitmask) ::= <<>> +bitmask_type(ctx, parent, bitmask) ::= << +void $if(bitmask.hasScope)$$bitmask.scope$::$endif$print$bitmask.name$( + $bitmask.name$* topic) +{ + printf("$bitmask.name$: { \n"); + $bitmask.members:{ it | printf("$it.name$: %s\n", topic->$it.name$() ? "true" : "false");}; separator="\n"$ +} + +void $if(bitmask.hasScope)$$bitmask.scope$::$endif$initialize$bitmask.name$( + $bitmask.name$* topic) +{ + $bitmask.members:{ it | topic->$it.name$(static_cast(rand()%2==1));}; separator="\n"$ +} + +int $if(bitmask.hasScope)$$bitmask.scope$::$endif$compare$bitmask.name$( + $bitmask.name$* topic_a, + $bitmask.name$* topic_b) +{ + $bitmask.members:{ it | if(topic_a->$it.name$() != topic_b->$it.name$()) return 0;}; separator="\n"$ + return 1; +} + +>> typedef_decl(ctx, parent, typedefs) ::= <<>> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg b/src/main/java/com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg index 6695b44d..f0d4e81f 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg @@ -321,4 +321,35 @@ $endif$ enum_type(ctx, parent, enum) ::= <<>> -bitmask_type(ctx, parent, bitmask) ::= <<>> +bitmask_type(ctx, parent, bitmask) ::= << +$if(ctx.anyCdr)$ +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const $bitmask.scopedname$& data, + size_t& current_alignment) +{ + return calculator.calculate_serialized_size(data.bitmask(), current_alignment); +} +$endif$ + +$if(ctx.cdr)$ +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const $bitmask.scopedname$& data) +{ + scdr << data.bitmask(); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& dcdr, + $bitmask.scopedname$& data) +{ + std::bitset<$bitmask.bitBound$> bitmask; + dcdr \>> bitmask; + data.bitmask(bitmask); +} +$endif$ +>>