Skip to content

Commit

Permalink
Merge pull request #402 from jwillemsen/jwi-bitmaskidl4
Browse files Browse the repository at this point in the history
Update bitmask prototype to IDL4 to C++ mapping proposal, fixed CDR insertion, test extensions
  • Loading branch information
jwillemsen authored Oct 18, 2024
2 parents 2845dd7 + 6b20def commit 77a9c74
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 39 deletions.
33 changes: 23 additions & 10 deletions ridlbe/c++11/templates/cli/hdr/bitmask.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@

// generated from <%= ridl_template_path %>
/// @copydoc <%= doc_scoped_name %>
enum class <%= cxxname %> : <%= bitbound.cxx_type %>
class <%= cxxname %>
{
<%= bitvalues.collect {|e| "/// @copydoc #{doc_scoped_name}::#{e.name}\n #{e.cxxname} = 0x01 << #{e.position}" }.join(",\n ") %>
};// <%= cxxname %>
public:
enum _flags : <%= bitbound.cxx_type %>
{
<%= bitvalues.collect {|e| "/// @copydoc #{doc_scoped_name}::#{e.name}\n #{e.cxxname} = 0x01 << #{e.position}" }.join(",\n ") %>
};
<%= cxxname %> () = default;
<%= cxxname %> (<%= bitbound.cxx_in_type %> _v) : _value(_v) {}
operator <%= bitbound.cxx_type %>() const { return _value; }
%# <%= cxx_return_type %> operator~ () { return ~_value; }
%# <%= cxx_return_type %> operator| () { return _value | _taox11_y; }
%# <%= cxx_return_type %> operator^ () { return _value ^ _taox11_y; }
%# <%= cxx_return_type %> operator& () { return _value & _taox11_y; }
<%= cxx_return_type %>& operator |= (<%= bitbound.cxx_in_type %> _taox11_rhs) { _value |= _taox11_rhs; return *this; }
<%= cxx_return_type %>& operator &= (<%= bitbound.cxx_in_type %> _taox11_rhs) { _value &= _taox11_rhs; return *this; }
<%= cxx_return_type %>& operator ^= (<%= bitbound.cxx_in_type %> _taox11_rhs) { _value ^= _taox11_rhs; return *this; }
<%= cxx_out_type %> operator= (<%= cxx_in_type %>) = default;
<%= cxx_out_type %> operator= (<%= cxx_move_type %>) = default;
<%= cxxname %> (<%= cxx_in_type %>) = default;
<%= cxxname %> (<%= cxx_move_type %>) = default;
private:
<%= bitbound.cxx_member_type %> _value <%= bitbound.value_initializer %>;
}; // <%= cxxname %>

inline <%= cxx_return_type %> operator~ (<%= cxx_in_type %> _taox11_t) { return static_cast<<%= cxxname %>>(~static_cast<<%= bitbound.cxx_type %>>(_taox11_t)); }
inline <%= cxx_return_type %> operator| (<%= cxx_in_type %> _taox11_t, <%= cxx_in_type %> _taox11_y) { return static_cast<<%= cxxname %>>(static_cast<<%= bitbound.cxx_type %>>(_taox11_t) | static_cast<<%= bitbound.cxx_type %>>(_taox11_y)); }
inline <%= cxx_return_type %> operator^ (<%= cxx_in_type %> _taox11_t, <%= cxx_in_type %> _taox11_y) { return static_cast<<%= cxxname %>>(static_cast<<%= bitbound.cxx_type %>>(_taox11_t) ^ static_cast<<%= bitbound.cxx_type %>>(_taox11_y)); }
inline <%= cxx_return_type %> operator& (<%= cxx_in_type %> _taox11_t, <%= cxx_in_type %> _taox11_y) { return static_cast<<%= cxxname %>>(static_cast<<%= bitbound.cxx_type %>>(_taox11_t) & static_cast<<%= bitbound.cxx_type %>>(_taox11_y)); }
inline <%= cxx_return_type %> operator |= (<%= cxx_inout_type %> _taox11_lhs, <%= cxx_in_type %> _taox11_rhs) { _taox11_lhs = _taox11_lhs | _taox11_rhs; return _taox11_lhs; }
inline <%= cxx_return_type %> operator &= (<%= cxx_inout_type %> _taox11_lhs, <%= cxx_in_type %> _taox11_rhs) { _taox11_lhs = _taox11_lhs & _taox11_rhs; return _taox11_lhs; }
inline <%= cxx_return_type %> operator ^= (<%= cxx_inout_type %> _taox11_lhs, <%= cxx_in_type %> _taox11_rhs) { _taox11_lhs = _taox11_lhs ^ _taox11_rhs; return _taox11_lhs; }
2 changes: 1 addition & 1 deletion ridlbe/c++11/templates/cli/hdr/bitmask_idl_traits.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_>
{
bool first_ {true};
%bitvalues.each do |e|
if (static_cast<bool>(val_ & <%= scoped_cxxtype %>::<%=e.cxxname %>))
if (val_ & <%= scoped_cxxtype %>::<%=e.cxxname %>)
{
if (!first_) os_ << "|";
os_ << "<%= formatted_cxxname %>::<%=e.cxxname %>";
Expand Down
9 changes: 3 additions & 6 deletions ridlbe/c++11/templates/cli/src/bitmask_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
// generated from <%= ridl_template_path %>
TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> &_tao_bitmask)
{
#if defined (ACE_HAS_CPP23)
return strm << std::to_underlying (_tao_bitmask);
#else
return strm << static_cast<<%= bitbound.cxx_type %>> (_tao_bitmask);
#endif
std::underlying_type_t<<%= scoped_cxxname %>::_flags> const _tao_temp { _tao_bitmask };
return strm << <%= bitbound.cdr_from_fmt % "_tao_temp" %>;
}

TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_bitmask)
{
std::underlying_type_t<<%= scoped_cxxname %>> _tao_temp <%= bitbound.value_initializer %>;
std::underlying_type_t<<%= scoped_cxxname %>::_flags> _tao_temp <%= bitbound.value_initializer %>;
bool const _tao_success = strm >> <%= bitbound.cdr_to_fmt % "_tao_temp" %>;

if (_tao_success)
Expand Down
2 changes: 1 addition & 1 deletion ridlbe/c++11/templates/srv/src/enum_sarg_traits.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// Argument traits specializations for <%= name %>
template<>
class SArg_Traits<<%= scoped_cxxtype %>>
: public Basic_SArg_Traits_T<<%= scoped_cxxtype %>,<% if generate_any_support? %>Any_Insert_Policy_Stream<% else %>Any_Insert_Policy_Noop<% end %>>
: public Basic_SArg_Traits_T<<%= scoped_cxxtype %>, <% if generate_any_support? %>Any_Insert_Policy_Stream<% else %>Any_Insert_Policy_Noop<% end %>>
{
};
# endif // !_<%= _traits_incl_guard_ %>_SARG_TRAITS_
2 changes: 1 addition & 1 deletion ridlbe/c++11/writers/servantsource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def check_idl_type(idl_type)
when IDL::Type::BitSet
visitor(BitsetVisitor).visit_sarg_traits(res_idl_type.node)# unless is_tracked?(res_idl_type.node)
when IDL::Type::BitMask
visitor(BitmaskVisitor).visit_sarg_traits(res_idl_type.node)# unless is_tracked?(res_idl_type.node)
visitor(BitmaskVisitor).visit_sarg_traits(res_idl_type.node) unless is_tracked?(res_idl_type.node)
when IDL::Type::Union
visitor(UnionVisitor).visit_sarg_traits(res_idl_type.node) unless is_tracked?(res_idl_type.node)
when IDL::Type::Sequence
Expand Down
72 changes: 54 additions & 18 deletions tests/idl4/bitmask/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,71 @@

int main (int argc, char* argv[])
{
// Just compilation test
int error_count = 0;

MyBitMask my_bitmask1 = MyBitMask::flag0;

// static_cast is necessary when we map to an `enum class`, when we map to an `enum` the static_cast
// is not necessary but that puts the enum members into the containing namespace. The IDL4 specification
// does put IDL enums in the containing namespace, but doesn't do that for bitmask members
if (static_cast<bool>(my_bitmask1 & MyBitMask::flag0))
if (my_bitmask1 & MyBitMask::flag0)
{
TAOX11_TEST_INFO << "Flag my_bitmask1 correctly set: " << my_bitmask1 << std::endl;
}
else
{
TAOX11_TEST_ERROR << "Flag my_bitmask1 NOT set" << my_bitmask1 << std::endl;
++error_count;
}
my_bitmask1 = my_bitmask1 | MyBitMask::flag1;
if (static_cast<bool>(my_bitmask1 & MyBitMask::flag0) && static_cast<bool>(my_bitmask1 & MyBitMask::flag1))
if ((my_bitmask1 & MyBitMask::flag0) && (my_bitmask1 & MyBitMask::flag1))
{
TAOX11_TEST_INFO << "Flag my_bitmask1 correctly set: " << my_bitmask1 << std::endl;
}
else
{
TAOX11_TEST_ERROR << "Flag my_bitmask1 NOT set: " << static_cast<uint16_t>(my_bitmask1) << std::endl;
++error_count;
}

if (static_cast<std::underlying_type_t<MyBitMask>>(MyBitMask::flag1) != (0x01 << 1))
if (static_cast<std::underlying_type_t<MyBitMask::_flags>>(MyBitMask::flag1) != (0x01 << 1))
{
TAOX11_TEST_ERROR << "MyBitMask::flag1 has wrong value" << std::endl;
++error_count;
}
if (static_cast<std::underlying_type_t<MyBitMaskBound8_position>>(MyBitMaskBound8_position::flag64_3) != (0x01 << 3))
if (static_cast<std::underlying_type_t<MyBitMaskBound8_position::_flags>>(MyBitMaskBound8_position::flag64_3) != (0x01 << 3))
{
TAOX11_TEST_ERROR << "MyBitMaskBound8_position::flag64_3 has wrong value, position annotation not correctly handled" << std::endl;
++error_count;
}
if (static_cast<std::underlying_type_t<MyBitMaskBound8_position>>(MyBitMaskBound8_position::flag64_4) != (0x01 << 4))
if (static_cast<std::underlying_type_t<MyBitMaskBound8_position::_flags>>(MyBitMaskBound8_position::flag64_4) != (0x01 << 4))
{
TAOX11_TEST_ERROR << "MyBitMaskBound8_position::flag64_4 has wrong value, position annotation not correctly handled" << std::endl;
++error_count;
}
if (static_cast<std::underlying_type_t<MyBitMaskBound8_position>>(MyBitMaskBound8_position::flag64_7) != (0x01 << 7))
if (static_cast<std::underlying_type_t<MyBitMaskBound8_position::_flags>>(MyBitMaskBound8_position::flag64_7) != (0x01 << 7))
{
TAOX11_TEST_ERROR << "MyBitMaskBound8_position::flag64_7 has wrong value, position annotation not correctly handled" << std::endl;
++error_count;
}
if (!std::is_same<std::underlying_type_t<MyBitMaskBound8>, uint8_t>::value)
if (!std::is_same<std::underlying_type_t<MyBitMaskBound8::_flags>, uint8_t>::value)
{
TAOX11_TEST_ERROR << "Type of MyBitMaskBound8 is not uint8_t" << std::endl;
++error_count;
}
if (!std::is_same<std::underlying_type_t<MyBitMaskBound16>, uint16_t>::value)
if (!std::is_same<std::underlying_type_t<MyBitMaskBound16::_flags>, uint16_t>::value)
{
TAOX11_TEST_ERROR << "Type of MyBitMaskBound16 is not uint16_t" << std::endl;
++error_count;
}
if (!std::is_same<std::underlying_type_t<MyBitMaskBound32>, uint32_t>::value)
if (!std::is_same<std::underlying_type_t<MyBitMaskBound32::_flags>, uint32_t>::value)
{
TAOX11_TEST_ERROR << "Type of MyBitMaskBound32 is not uint32_t" << std::endl;
++error_count;
}
if (!std::is_same<std::underlying_type_t<MyBitMaskBound64>, uint64_t>::value)
if (!std::is_same<std::underlying_type_t<MyBitMaskBound64::_flags>, uint64_t>::value)
{
TAOX11_TEST_ERROR << "Type of MyBitMaskBound64 is not uint64_t" << std::endl;
++error_count;
}

int error_count = 0;
try
{
IDL::traits<CORBA::ORB>::ref_type _orb = CORBA::ORB_init (argc, argv);
Expand Down Expand Up @@ -102,20 +108,50 @@ int main (int argc, char* argv[])
TAOX11_TEST_DEBUG << "narrowed Foo interface" << std::endl;

MyBitMask sin {MyBitMask::flag0};
MyBitMask sinout {};
MyBitMask sinout {MyBitMask::flag1};
MyBitMask sout {};

TAOX11_TEST_DEBUG << "Sending MyBitMask sin: " << sin << " sinout: " << sinout << std::endl;
MyBitMask sret = foo->test_mybitmask (sin, sinout, sout);
MyBitMask const sret = foo->test_mybitmask (sin, sinout, sout);
if (sret != MyBitMask::flag2)
{
TAOX11_TEST_ERROR << "ERROR: sret<" << sret << "> != sin<" << sin << ">" << std::endl;
++error_count;
}
if (sout != sin)
{
TAOX11_TEST_ERROR << "ERROR: sout<" << sout << "> != sin<" << sin << ">" << std::endl;
++error_count;
}
if (sinout != sin)
{
TAOX11_TEST_ERROR << "ERROR: sinout<" << sinout << "> != sin<" << sin << ">" << std::endl;
++error_count;
}
TAOX11_TEST_DEBUG << "Received MyBitMask sret: " << sret << " sinout: " << sinout << " sout: " << sout << std::endl;

MyBitMaskBound8 sin5 {MyBitMaskBound8::flag8_2};
MyBitMaskBound8 sinout5 {};
MyBitMaskBound8 sout5 {};

TAOX11_TEST_DEBUG << "Sending MyBitMaskBound8 sin: " << sin5 << " sinout: " << sinout5 << std::endl;
MyBitMaskBound8 sret5 = foo->test_mybitmaskbound8 (sin5, sinout5, sout5);
MyBitMaskBound8 const sret5 = foo->test_mybitmaskbound8 (sin5, sinout5, sout5);
TAOX11_TEST_DEBUG << "Received MyBitMaskBound8 sret: " << sret5 << " sinout: " << sinout5 << " sout: " << sout5 << std::endl;
if (sret5 != sin5)
{
TAOX11_TEST_ERROR << "ERROR: sret5<" << sret5 << "> != sin5<" << sin5 << ">" << std::endl;
++error_count;
}
if (sout5 != sin5)
{
TAOX11_TEST_ERROR << "ERROR: sout<" << sout << "> != sin5<" << sin5 << ">" << std::endl;
++error_count;
}
if (sinout5 != sin5)
{
TAOX11_TEST_ERROR << "ERROR: sinout5<" << sinout5 << "> != sin5<" << sin5 << ">" << std::endl;
++error_count;
}

TAOX11_TEST_DEBUG << "shutting down..." << std::endl;
foo->shutdown ();
Expand Down
27 changes: 25 additions & 2 deletions tests/idl4/bitmask/foo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,40 @@ Foo::test_mybitmask (const MyBitMask & sin,
MyBitMask & sinout,
MyBitMask & sout)
{
if (!(sin & MyBitMask::flag0))
{
TAOX11_TEST_ERROR << "ERROR: test_mybitmask: Received incorrect sin<" << sin << ">" << std::endl;
}
else
{
TAOX11_TEST_DEBUG << "test_mybitmask: Received sin<" << sin << ">" << std::endl;
}
if (!(sinout & MyBitMask::flag1))
{
TAOX11_TEST_ERROR << "ERROR: test_mybitmask: Received incorrect sinout<" << sinout << ">" << std::endl;
}
else
{
TAOX11_TEST_DEBUG << "test_mybitmask: Received sinout<" << sinout << ">" << std::endl;
}
sout = sin;
if (!(sout & MyBitMask::flag0))
{
TAOX11_TEST_ERROR << "ERROR: test_mybitmask: Setting sout failed <" << sout << ">" << std::endl;
}
sinout = sin;
MyBitMask sret = sin;
return sret;
return MyBitMask::flag2;
}

MyBitMaskBound8
Foo::test_mybitmaskbound8 (const MyBitMaskBound8 & sin,
MyBitMaskBound8 & sinout,
MyBitMaskBound8 & sout)
{
if (!(sin & MyBitMaskBound8::flag8_2))
{
TAOX11_TEST_ERROR << "ERROR: MyBitMaskBound8: Received incorrect sin<" << sin << ">" << std::endl;
}
sout = sin;
sinout = sin;
MyBitMaskBound8 sret = sin;
Expand Down

0 comments on commit 77a9c74

Please sign in to comment.