Skip to content

Commit

Permalink
Merge pull request #351 from jwillemsen/jwi-enumvalueannotation
Browse files Browse the repository at this point in the history
Support and test value annotation for enum
  • Loading branch information
jwillemsen authored Jan 24, 2024
2 parents 582f46a + a44e2c3 commit a0b82a7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ridlbe/c++11/templates/cli/hdr/enum.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
/// @copydoc <%= doc_scoped_name %>
enum class <%= cxxname %> : <%= bitbound.cxx_type %>
{
<%= enumerators.collect {|e| "/// @copydoc #{doc_scoped_name}::#{e.name}\n #{e.cxxname}" }.join(",\n ") %>
% enumerators.each do |e|
% valueann = e.annotations[:value].first
% unless valueann.nil?
% value = ' = ' + valueann.fields[:value].to_s
% end
/// @copydoc <%= doc_scoped_name %>::<%= e.name %>
<%= e.cxxname %><%= value %><% unless e.equal?(enumerators.last)%>,<% end %>
% end
};// <%= cxxname %>

% visit_template('typecode') if generate_typecode_support?
18 changes: 18 additions & 0 deletions tests/idl4/enum/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,23 @@ int main (int /*argc*/, char* /*argv*/[])
TAOX11_TEST_ERROR << "bit_bound traits MyEnum is 32" << std::endl;
}

if (static_cast<int32_t>(MyValueEnum::myv4) != 4)
{
++retval;
TAOX11_TEST_ERROR << "myValueEnum::myv4 is not 4 but " << static_cast<int32_t>(MyValueEnum::myv4) << std::endl;
}

if (static_cast<int32_t>(MyValueEnum::myv5) != 5)
{
++retval;
TAOX11_TEST_ERROR << "myValueEnum::myv5 is not 5 but " << static_cast<int32_t>(MyValueEnum::myv5) << std::endl;
}

if (static_cast<int32_t>(MyValueEnum::myv6) != 6)
{
++retval;
TAOX11_TEST_ERROR << "myValueEnum::myv6 is not 6 but " << static_cast<int32_t>(MyValueEnum::myv6) << std::endl;
}

return retval;
}
6 changes: 6 additions & 0 deletions tests/idl4/enum/test.idl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ enum MyEnumBound32 {
flag32_2,
flag32_3
};

enum MyValueEnum {
@value(4) myv4,
@value(5) myv5,
@value(6) myv6
};

0 comments on commit a0b82a7

Please sign in to comment.