From a44e2c33e0caf3c0a37c48b4e6330199f207ab4a Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 24 Jan 2024 10:23:50 +0100 Subject: [PATCH] Support and test value annotation for enum * ridlbe/c++11/templates/cli/hdr/enum.erb: * tests/idl4/enum/client.cpp: * tests/idl4/enum/test.idl: --- ridlbe/c++11/templates/cli/hdr/enum.erb | 9 ++++++++- tests/idl4/enum/client.cpp | 18 ++++++++++++++++++ tests/idl4/enum/test.idl | 6 ++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ridlbe/c++11/templates/cli/hdr/enum.erb b/ridlbe/c++11/templates/cli/hdr/enum.erb index f21d9e38..a8012f32 100644 --- a/ridlbe/c++11/templates/cli/hdr/enum.erb +++ b/ridlbe/c++11/templates/cli/hdr/enum.erb @@ -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? diff --git a/tests/idl4/enum/client.cpp b/tests/idl4/enum/client.cpp index e1c82db2..9446f1bd 100644 --- a/tests/idl4/enum/client.cpp +++ b/tests/idl4/enum/client.cpp @@ -60,5 +60,23 @@ int main (int /*argc*/, char* /*argv*/[]) TAOX11_TEST_ERROR << "bit_bound traits MyEnum is 32" << std::endl; } + if (static_cast(MyValueEnum::myv4) != 4) + { + ++retval; + TAOX11_TEST_ERROR << "myValueEnum::myv4 is not 4 but " << static_cast(MyValueEnum::myv4) << std::endl; + } + + if (static_cast(MyValueEnum::myv5) != 5) + { + ++retval; + TAOX11_TEST_ERROR << "myValueEnum::myv5 is not 5 but " << static_cast(MyValueEnum::myv5) << std::endl; + } + + if (static_cast(MyValueEnum::myv6) != 6) + { + ++retval; + TAOX11_TEST_ERROR << "myValueEnum::myv6 is not 6 but " << static_cast(MyValueEnum::myv6) << std::endl; + } + return retval; } diff --git a/tests/idl4/enum/test.idl b/tests/idl4/enum/test.idl index ed93f039..91d24d07 100644 --- a/tests/idl4/enum/test.idl +++ b/tests/idl4/enum/test.idl @@ -31,3 +31,9 @@ enum MyEnumBound32 { flag32_2, flag32_3 }; + +enum MyValueEnum { + @value(4) myv4, + @value(5) myv5, + @value(6) myv6 +};