From fc85a8d79f19e897b281588cbfddd99cc20d9763 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 7 Aug 2024 16:14:31 +0200 Subject: [PATCH 01/15] Add optional CDR test * tests/idl4/optional/foo.cpp: * tests/idl4/optional/foo.h: * tests/idl4/optional/server.cpp: Added. * tests/idl4/optional/client.cpp: * tests/idl4/optional/test.idl: * tests/idl4/optional/test.mpc: --- tests/idl4/optional/client.cpp | 61 +++++++++++++++--- tests/idl4/optional/foo.cpp | 32 ++++++++++ tests/idl4/optional/foo.h | 33 ++++++++++ tests/idl4/optional/server.cpp | 110 +++++++++++++++++++++++++++++++++ tests/idl4/optional/test.idl | 13 ++++ tests/idl4/optional/test.mpc | 12 ++++ 6 files changed, 254 insertions(+), 7 deletions(-) create mode 100644 tests/idl4/optional/foo.cpp create mode 100644 tests/idl4/optional/foo.h create mode 100644 tests/idl4/optional/server.cpp diff --git a/tests/idl4/optional/client.cpp b/tests/idl4/optional/client.cpp index 6638c975..eb281d45 100644 --- a/tests/idl4/optional/client.cpp +++ b/tests/idl4/optional/client.cpp @@ -10,14 +10,61 @@ #include "testC.h" #include "testlib/taox11_testlog.h" -int main (int /*argc*/, char* /*argv*/[]) +int main (int argc, char* argv[]) { - int retval {}; - bar mybar; + int error_count = 0; - TAOX11_TEST_INFO << "mybar: " << mybar << std::endl; - mybar.z(6); - TAOX11_TEST_INFO << "mybar: " << mybar << std::endl; + try + { + IDL::traits::ref_type _orb = CORBA::ORB_init (argc, argv); - return retval; + if (!_orb) + { + TAOX11_TEST_ERROR << "ERROR: CORBA::ORB_init (argc, argv) returned null ORB." << std::endl; + return 1; + } + + IDL::traits::ref_type obj = _orb->string_to_object ("file://test.ior"); + + if (!obj) + { + TAOX11_TEST_ERROR << "ERROR: string_to_object() returned null reference." << std::endl; + return 1; + } + + TAOX11_TEST_DEBUG << "retrieved object reference" << std::endl; + + IDL::traits::ref_type foo = IDL::traits::narrow (obj); + + if (!foo) + { + TAOX11_TEST_ERROR << "ERROR: IDL::traits::narrow (obj) returned null object." << std::endl; + return 1; + } + TAOX11_TEST_DEBUG << "narrowed Foo interface" << std::endl; + + bar sin; + bar sinout; + bar sout; + + TAOX11_TEST_DEBUG << "Sending StringLongMap sin: " << sin << " sinout: " << sinout << std::endl; + bar sret = foo->test_bar (sin, sinout, sout); + TAOX11_TEST_DEBUG << "Received StringLongMap sret: " << sret << " sinout: " << sinout << " sout: " << sout << std::endl; + + TAOX11_TEST_DEBUG << "shutting down..." << std::endl; + foo->shutdown (); + _orb->destroy (); + } + catch (const CORBA::BAD_PARAM& e) + { + TAOX11_TEST_ERROR << "main - ERROR - Unexpected CORBA::BAD_PARAM exception caught" + << e << std::endl; + ++error_count; + } + catch (const std::exception& e) + { + TAOX11_TEST_ERROR << "main - ERROR - Unexpected exception caught: " << e << std::endl; + ++error_count; + } + return error_count; } diff --git a/tests/idl4/optional/foo.cpp b/tests/idl4/optional/foo.cpp new file mode 100644 index 00000000..013ed648 --- /dev/null +++ b/tests/idl4/optional/foo.cpp @@ -0,0 +1,32 @@ +/** + * @file foo.cpp + * @author Johnny Willemsen + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ +#include "foo.h" + +#include "testlib/taox11_testlog.h" + +Foo::Foo (IDL::traits::ref_type orb, + IDL::traits::ref_type poa) + : orb_ (std::move(orb)) + , poa_ (std::move(poa)) +{ +} + +bar +Foo::test_bar (const bar & sin, bar & sinout, bar & sout) +{ + sout = sin; + sinout = sin; + bar sret = sin; + sret.z(6); + return sret; +} + +void +Foo::shutdown () +{ + this->orb_->shutdown (false); +} diff --git a/tests/idl4/optional/foo.h b/tests/idl4/optional/foo.h new file mode 100644 index 00000000..b11822e8 --- /dev/null +++ b/tests/idl4/optional/foo.h @@ -0,0 +1,33 @@ +/** + * @file foo.h + * @author Johnny Willemsen + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ +#ifndef FOO_H +#define FOO_H + +#include "testS.h" + +class Foo final + : public virtual CORBA::servant_traits::base_type +{ +public: + /// Constructor + Foo (IDL::traits::ref_type orb, + IDL::traits::ref_type poa); + + // = The skeleton methods + bar test_bar (const bar & sin, bar & sinout, bar & sout) override; + + void shutdown () override; + +private: + /// Use an ORB reference shutdown the server. + IDL::traits::ref_type orb_; + /// Use a POA reference to activate the references to + // the template module interface. + IDL::traits::ref_type poa_; +}; + +#endif /* FOO_H */ diff --git a/tests/idl4/optional/server.cpp b/tests/idl4/optional/server.cpp new file mode 100644 index 00000000..c16ce17c --- /dev/null +++ b/tests/idl4/optional/server.cpp @@ -0,0 +1,110 @@ +/** + * @file server.cpp + * @author Johnny Willemsen + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ + +#include "foo.h" +#include "testlib/taox11_testlog.h" +#include + +int +main(int argc, ACE_TCHAR *argv[]) +{ + try + { + IDL::traits::ref_type _orb = CORBA::ORB_init (argc, argv); + + if (_orb == nullptr) + { + TAOX11_TEST_ERROR << "ERROR: CORBA::ORB_init (argc, argv) returned null ORB." << std::endl; + return 1; + } + + IDL::traits::ref_type obj = _orb->resolve_initial_references ("RootPOA"); + + if (!obj) + { + TAOX11_TEST_ERROR << "ERROR: resolve_initial_references (\"RootPOA\") returned null reference." << std::endl; + return 1; + } + + TAOX11_TEST_DEBUG << "retrieved RootPOA object reference" << std::endl; + + IDL::traits::ref_type root_poa = IDL::traits::narrow (obj); + + if (!root_poa) + { + TAOX11_TEST_ERROR << "ERROR: IDL::traits::narrow (obj) returned null object." << std::endl; + return 1; + } + + TAOX11_TEST_DEBUG << "narrowed POA interface" << std::endl; + + IDL::traits::ref_type poaman = root_poa->the_POAManager (); + + if (!poaman) + { + TAOX11_TEST_ERROR << "ERROR: root_poa->the_POAManager () returned null object." << std::endl; + return 1; + } + + CORBA::servant_traits::ref_type foo_impl = CORBA::make_reference (_orb, root_poa); + + TAOX11_TEST_DEBUG << "created Foo servant" << std::endl; + + PortableServer::ObjectId id = root_poa->activate_object (foo_impl); + + TAOX11_TEST_DEBUG << "activated Foo servant" << std::endl; + + IDL::traits::ref_type foo_obj = root_poa->id_to_reference (id); + + if (foo_obj == nullptr) + { + TAOX11_TEST_ERROR << "ERROR: root_poa->id_to_reference (id) returned null reference." << std::endl; + return 1; + } + + IDL::traits::ref_type foo = IDL::traits::narrow (foo_obj); + + if (foo == nullptr) + { + TAOX11_TEST_ERROR << "ERROR: IDL::traits::narrow (foo_obj) returned null reference." << std::endl; + return 1; + } + + std::string ior = _orb->object_to_string (foo); + + // Output the IOR to the + std::ofstream fos("test.ior"); + if (!fos) + { + TAOX11_TEST_ERROR << "ERROR: failed to open file 'test.ior'" << std::endl; + return 1; + } + fos << ior; + fos.close (); + + TAOX11_TEST_DEBUG << "IOR for Foo servant written to 'test.ior' : " << ior << std::endl; + + poaman->activate (); + + TAOX11_TEST_DEBUG << "starting event loop" << std::endl; + + _orb->run (); + + TAOX11_TEST_DEBUG << "event loop finished" << std::endl; + + root_poa->destroy (true, true); + + _orb->destroy (); + } + catch (const std::exception& e) + { + TAOX11_TEST_ERROR << "exception caught: " << e << std::endl; + return 1; + } + + return 0; +} diff --git a/tests/idl4/optional/test.idl b/tests/idl4/optional/test.idl index d24815a0..b8d756a4 100644 --- a/tests/idl4/optional/test.idl +++ b/tests/idl4/optional/test.idl @@ -14,3 +14,16 @@ struct bar @optional string opt_string; string y; }; + +module Test +{ + interface Foo + { + bar test_bar (in bar bin, + inout bar binout, + out bar bout); + + /// A method to shutdown the ORB + oneway void shutdown (); + }; +}; diff --git a/tests/idl4/optional/test.mpc b/tests/idl4/optional/test.mpc index 66bd2e3b..4aa8c88f 100644 --- a/tests/idl4/optional/test.mpc +++ b/tests/idl4/optional/test.mpc @@ -8,6 +8,18 @@ project(*optional_gen_idl): ridl_ostream_defaults { custom_only = 1 } +project(*optional_server): taox11_server { + after += *optional_gen_idl + Source_Files { + foo.cpp + server.cpp + } + Source_Files { + testC.cpp + testS.cpp + } +} + project(*optional_client): taox11_client { after += *optional_gen_idl Source_Files { From 6ebe0647352998aca84a102f4f71f44c8f370bf4 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Fri, 6 Sep 2024 15:03:31 +0200 Subject: [PATCH 02/15] Further extend optional test IDL * tests/idl4/optional/test.idl: --- tests/idl4/optional/test.idl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/idl4/optional/test.idl b/tests/idl4/optional/test.idl index d24815a0..fb19b88e 100644 --- a/tests/idl4/optional/test.idl +++ b/tests/idl4/optional/test.idl @@ -14,3 +14,17 @@ struct bar @optional string opt_string; string y; }; + +exception Foo +{ + short x; + @optional short z; +}; + +union TestUnion_Octet switch(octet) { + case 1: + @optional short FirstCase; + case 2: + long SecondCase; +}; + From cd7791c902af8234a1bed65832eb5ddca4b78ed2 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Fri, 6 Sep 2024 15:37:45 +0200 Subject: [PATCH 03/15] Extend optional support * ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb: * ridlbe/c++11/templates/cli/inl/except_inl.erb: * ridlbe/c++11/templates/cli/inl/union_inl.erb: * ridlbe/c++11/templates/cli/prx/union_cdr.erb: * ridlbe/c++11/visitors/union.rb: * tests/idl4/optional/test.idl: --- .../cli/hdr/union_idl_traits_def.erb | 6 ++ ridlbe/c++11/templates/cli/inl/except_inl.erb | 4 +- ridlbe/c++11/templates/cli/inl/union_inl.erb | 4 +- ridlbe/c++11/templates/cli/prx/union_cdr.erb | 21 +++++++ ridlbe/c++11/visitors/union.rb | 58 +++++++++++++++++++ tests/idl4/optional/test.idl | 7 +++ 6 files changed, 96 insertions(+), 4 deletions(-) diff --git a/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb b/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb index d8aab8ba..8c28bfd1 100644 --- a/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb +++ b/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb @@ -38,7 +38,13 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> case <%= _lbl %>: % end { +% if _m.optional? + os_ << "<%= _m.cxxname %>="; if (val_.<%= _m.cxxname() %> ().has_value ()) { os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ().value ());} else { os_ << "std::nullopt"; } +% elsif _m.external? +%# TODO +% else os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ()); +% end } break; % end diff --git a/ridlbe/c++11/templates/cli/inl/except_inl.erb b/ridlbe/c++11/templates/cli/inl/except_inl.erb index 45187066..71800f3b 100644 --- a/ridlbe/c++11/templates/cli/inl/except_inl.erb +++ b/ridlbe/c++11/templates/cli/inl/except_inl.erb @@ -19,9 +19,9 @@ inline <%= scoped_cxxname %>::<%= cxxname %> ( % while !_ms.empty? % _m = _ms.shift % if _m.is_array? - <%= _indent %><%= "#{_m.scoped_cxx_in_type} #{_m.cxxname}" %><%= _ms.empty? ? ')' : ',' %> + <%= _indent %><%= "#{_m.cxx_in_type} #{_m.cxxname}" %><%= _ms.empty? ? ')' : ',' %> % else - <%= _indent %><%= "#{_m.scoped_cxx_byval_type} #{_m.cxxname}" %><%= _ms.empty? ? ')' : ',' %> + <%= _indent %><%= "#{_m.cxx_byval_type} #{_m.cxxname}" %><%= _ms.empty? ? ')' : ',' %> % end % end % end diff --git a/ridlbe/c++11/templates/cli/inl/union_inl.erb b/ridlbe/c++11/templates/cli/inl/union_inl.erb index 5907902c..c9cd202b 100644 --- a/ridlbe/c++11/templates/cli/inl/union_inl.erb +++ b/ridlbe/c++11/templates/cli/inl/union_inl.erb @@ -286,7 +286,7 @@ inline void <%= scoped_cxxname %>::<%= _m.cxxname %> (<%= _m.cxx_move_type %> _x } % end -inline <%= _m.scoped_cxx_in_type %> <%= scoped_cxxname %>::<%= _m.cxxname %> () const +inline <%= _m.cxx_in_type %> <%= scoped_cxxname %>::<%= _m.cxxname %> () const { % if switchtype_boolean? % if _m.labels.size == 1 @@ -321,7 +321,7 @@ inline <%= _m.scoped_cxx_in_type %> <%= scoped_cxxname %>::<%= _m.cxxname %> () return this->u_.<%= _m.cxxname %>_; } -inline <%= _m.scoped_cxx_out_type %> <%= scoped_cxxname %>::<%= _m.cxxname %> () +inline <%= _m.cxx_out_type %> <%= scoped_cxxname %>::<%= _m.cxxname %> () { % if switchtype_boolean? % if _m.labels.size == 1 diff --git a/ridlbe/c++11/templates/cli/prx/union_cdr.erb b/ridlbe/c++11/templates/cli/prx/union_cdr.erb index 86a94ebc..38b9d789 100644 --- a/ridlbe/c++11/templates/cli/prx/union_cdr.erb +++ b/ridlbe/c++11/templates/cli/prx/union_cdr.erb @@ -18,5 +18,26 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL <%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator<< (TAO_OutputCDR&, const <%= scoped_cxxname %>&); <%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator>> (TAO_InputCDR&, <%= scoped_cxxname %>&); //@} +%members.each do |_m| +% if _m.optional? +// Unaliased type : <%= _m.cxx_member_type %> +% alias_md5 = _m.cxx_member_type.to_md5 +// MD5 : <%= alias_md5 %> +#if !defined(_CDR_<%= alias_md5 %>_OPTIONAL_DECL_) +#define _CDR_<%= alias_md5 %>_OPTIONAL_DECL_ +/// @name CDR streaming operator specializations for <%= _m.cxx_member_type %> +//@{ +inline <%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator<< (TAO_OutputCDR& _strm, const <%= _m.cxx_member_type %>& _val) +{ + return taox11_optional_cdr<<%= _m.cxx_member_type %>>::insert (_strm, _val); +} +<%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator>> (TAO_InputCDR& _strm, <%= _m.cxx_member_type %>& _val) +{ + return taox11_optional_cdr<<%= _m.cxx_member_type %>>::extract (_strm, _val); +} +//@} +#endif +% end +%end TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/ridlbe/c++11/visitors/union.rb b/ridlbe/c++11/visitors/union.rb index 3092c13f..ab1a3aa6 100644 --- a/ridlbe/c++11/visitors/union.rb +++ b/ridlbe/c++11/visitors/union.rb @@ -161,6 +161,14 @@ def is_array? _resolved_idltype.is_a?(IDL::Type::Array) end + def optional? + !node.annotations[:optional].first.nil? + end + + def external? + !node.annotations[:external].first.nil? + end + # Does this union member has multiple legal discriminator values def has_multiple_discriminators? labels.size > 1 || is_default? @@ -182,6 +190,56 @@ def value_initializer _resolved_idltype.value_initializer end end + + def cxx_byval_type + if optional? + "IDL::optional<#{cxx_return_type}>" + elsif external? + "std::shared_ptr<#{cxx_return_type}>" + else + super + end + end + + def cxx_out_type + if optional? + "IDL::optional<#{cxx_return_type}>&" + elsif external? + "std::shared_ptr<#{cxx_return_type}>&" + else + super + end + end + + def cxx_in_type + if optional? + "const IDL::optional<#{cxx_return_type}>&" + elsif external? + "const std::shared_ptr<#{super}>&" + else + super + end + end + + def cxx_move_type + if optional? + "IDL::optional<#{cxx_return_type}>&&" + elsif external? + "std::shared_ptr<#{cxx_return_type}>&&" + else + super + end + end + + def cxx_member_type + if optional? + "IDL::optional<#{super}>" + elsif external? + "std::shared_ptr<#{super}>" + else + super + end + end end end end diff --git a/tests/idl4/optional/test.idl b/tests/idl4/optional/test.idl index fb19b88e..7ff5aa11 100644 --- a/tests/idl4/optional/test.idl +++ b/tests/idl4/optional/test.idl @@ -5,6 +5,10 @@ * @copyright Copyright (c) Remedy IT Expertise BV */ +module Mod +{ + typedef long longF; +}; struct bar { short x; @@ -13,6 +17,7 @@ struct bar @optional short a; @optional string opt_string; string y; + Mod::longF f; }; exception Foo @@ -26,5 +31,7 @@ union TestUnion_Octet switch(octet) { @optional short FirstCase; case 2: long SecondCase; + case 3: + @optional Mod::longF f; }; From 06c26f4dfb5e1e6a51f0fd43684f9b6d9d0668a3 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Fri, 6 Sep 2024 15:45:16 +0200 Subject: [PATCH 04/15] member name duplicated * ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb: --- ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb b/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb index 8c28bfd1..fb0ccf4f 100644 --- a/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb +++ b/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb @@ -39,7 +39,7 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> % end { % if _m.optional? - os_ << "<%= _m.cxxname %>="; if (val_.<%= _m.cxxname() %> ().has_value ()) { os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ().value ());} else { os_ << "std::nullopt"; } + os_ << "<%= _m.cxxname %>="; if (val_.<%= _m.cxxname() %> ().has_value ()) { os_ << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ().value ());} else { os_ << "std::nullopt"; } % elsif _m.external? %# TODO % else From cd6c24a7fe18e4e80f14bf2b2637b4d28163e0b0 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Fri, 6 Sep 2024 15:47:11 +0200 Subject: [PATCH 05/15] Test extension * tests/idl4/optional/client.cpp: * tests/idl4/optional/test.idl: --- tests/idl4/optional/client.cpp | 4 ++++ tests/idl4/optional/test.idl | 1 + 2 files changed, 5 insertions(+) diff --git a/tests/idl4/optional/client.cpp b/tests/idl4/optional/client.cpp index 6638c975..ee5c7eaf 100644 --- a/tests/idl4/optional/client.cpp +++ b/tests/idl4/optional/client.cpp @@ -14,8 +14,12 @@ int main (int /*argc*/, char* /*argv*/[]) { int retval {}; bar mybar; + Foo f; + TestUnion_Octet to; TAOX11_TEST_INFO << "mybar: " << mybar << std::endl; + TAOX11_TEST_INFO << "f: " << f << std::endl; + TAOX11_TEST_INFO << "to: " << to << std::endl; mybar.z(6); TAOX11_TEST_INFO << "mybar: " << mybar << std::endl; diff --git a/tests/idl4/optional/test.idl b/tests/idl4/optional/test.idl index 7ff5aa11..ee15a3ac 100644 --- a/tests/idl4/optional/test.idl +++ b/tests/idl4/optional/test.idl @@ -9,6 +9,7 @@ module Mod { typedef long longF; }; + struct bar { short x; From 9690dcec872b624e83a2fa85eeb7a3084fff51ea Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 9 Sep 2024 11:52:59 +0200 Subject: [PATCH 06/15] Test fixes * ridlbe/c++11/templates/cli/inl/except_inl.erb: * ridlbe/c++11/templates/cli/inl/union_inl.erb: * ridlbe/c++11/visitors/struct.rb: * ridlbe/c++11/visitors/union.rb: --- ridlbe/c++11/templates/cli/inl/except_inl.erb | 4 ++-- ridlbe/c++11/templates/cli/inl/union_inl.erb | 4 ++-- ridlbe/c++11/visitors/struct.rb | 20 +++++++++++++++++++ ridlbe/c++11/visitors/union.rb | 20 +++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/ridlbe/c++11/templates/cli/inl/except_inl.erb b/ridlbe/c++11/templates/cli/inl/except_inl.erb index 71800f3b..45187066 100644 --- a/ridlbe/c++11/templates/cli/inl/except_inl.erb +++ b/ridlbe/c++11/templates/cli/inl/except_inl.erb @@ -19,9 +19,9 @@ inline <%= scoped_cxxname %>::<%= cxxname %> ( % while !_ms.empty? % _m = _ms.shift % if _m.is_array? - <%= _indent %><%= "#{_m.cxx_in_type} #{_m.cxxname}" %><%= _ms.empty? ? ')' : ',' %> + <%= _indent %><%= "#{_m.scoped_cxx_in_type} #{_m.cxxname}" %><%= _ms.empty? ? ')' : ',' %> % else - <%= _indent %><%= "#{_m.cxx_byval_type} #{_m.cxxname}" %><%= _ms.empty? ? ')' : ',' %> + <%= _indent %><%= "#{_m.scoped_cxx_byval_type} #{_m.cxxname}" %><%= _ms.empty? ? ')' : ',' %> % end % end % end diff --git a/ridlbe/c++11/templates/cli/inl/union_inl.erb b/ridlbe/c++11/templates/cli/inl/union_inl.erb index c9cd202b..5907902c 100644 --- a/ridlbe/c++11/templates/cli/inl/union_inl.erb +++ b/ridlbe/c++11/templates/cli/inl/union_inl.erb @@ -286,7 +286,7 @@ inline void <%= scoped_cxxname %>::<%= _m.cxxname %> (<%= _m.cxx_move_type %> _x } % end -inline <%= _m.cxx_in_type %> <%= scoped_cxxname %>::<%= _m.cxxname %> () const +inline <%= _m.scoped_cxx_in_type %> <%= scoped_cxxname %>::<%= _m.cxxname %> () const { % if switchtype_boolean? % if _m.labels.size == 1 @@ -321,7 +321,7 @@ inline <%= _m.cxx_in_type %> <%= scoped_cxxname %>::<%= _m.cxxname %> () const return this->u_.<%= _m.cxxname %>_; } -inline <%= _m.cxx_out_type %> <%= scoped_cxxname %>::<%= _m.cxxname %> () +inline <%= _m.scoped_cxx_out_type %> <%= scoped_cxxname %>::<%= _m.cxxname %> () { % if switchtype_boolean? % if _m.labels.size == 1 diff --git a/ridlbe/c++11/visitors/struct.rb b/ridlbe/c++11/visitors/struct.rb index c8aa5a64..c9ddd0b9 100644 --- a/ridlbe/c++11/visitors/struct.rb +++ b/ridlbe/c++11/visitors/struct.rb @@ -150,6 +150,26 @@ def cxx_member_type super end end + + def scoped_cxx_in_type + if optional? + "const IDL::optional<#{scoped_cxx_return_type}>&" + elsif external? + "const std::shared_ptr<#{super}>&" + else + super + end + end + + def scoped_cxx_byval_type + if optional? + "IDL::optional<#{scoped_cxx_return_type}>" + elsif external? + "std::shared_ptr<#{scoped_cxx_return_type}>" + else + super + end + end end end end diff --git a/ridlbe/c++11/visitors/union.rb b/ridlbe/c++11/visitors/union.rb index ab1a3aa6..c6d28249 100644 --- a/ridlbe/c++11/visitors/union.rb +++ b/ridlbe/c++11/visitors/union.rb @@ -240,6 +240,26 @@ def cxx_member_type super end end + + def scoped_cxx_out_type + if optional? + "IDL::optional<#{scoped_cxx_return_type}>&" + elsif external? + "std::shared_ptr<#{scoped_cxx_return_type}>&" + else + super + end + end + + def scoped_cxx_in_type + if optional? + "const IDL::optional<#{scoped_cxx_return_type}>&" + elsif external? + "const std::shared_ptr<#{super}>&" + else + super + end + end end end end From 2151a1f3ee760b22fc574812a785a2a764e24222 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 9 Sep 2024 13:41:18 +0200 Subject: [PATCH 07/15] Further optimize and implement optional support * ridlbe/c++11/templates/cli/prx/struct_cdr.erb: * ridlbe/c++11/templates/cli/src/struct_cdr.erb: * tao/x11/optional_cdr_t.h: * tests/idl4/optional/test.idl: --- ridlbe/c++11/templates/cli/prx/struct_cdr.erb | 21 ------------------- ridlbe/c++11/templates/cli/src/struct_cdr.erb | 8 +++++++ tao/x11/optional_cdr_t.h | 6 ++---- tests/idl4/optional/test.idl | 2 ++ 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/ridlbe/c++11/templates/cli/prx/struct_cdr.erb b/ridlbe/c++11/templates/cli/prx/struct_cdr.erb index 38b9d789..86a94ebc 100644 --- a/ridlbe/c++11/templates/cli/prx/struct_cdr.erb +++ b/ridlbe/c++11/templates/cli/prx/struct_cdr.erb @@ -18,26 +18,5 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL <%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator<< (TAO_OutputCDR&, const <%= scoped_cxxname %>&); <%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator>> (TAO_InputCDR&, <%= scoped_cxxname %>&); //@} -%members.each do |_m| -% if _m.optional? -// Unaliased type : <%= _m.cxx_member_type %> -% alias_md5 = _m.cxx_member_type.to_md5 -// MD5 : <%= alias_md5 %> -#if !defined(_CDR_<%= alias_md5 %>_OPTIONAL_DECL_) -#define _CDR_<%= alias_md5 %>_OPTIONAL_DECL_ -/// @name CDR streaming operator specializations for <%= _m.cxx_member_type %> -//@{ -inline <%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator<< (TAO_OutputCDR& _strm, const <%= _m.cxx_member_type %>& _val) -{ - return taox11_optional_cdr<<%= _m.cxx_member_type %>>::insert (_strm, _val); -} -<%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator>> (TAO_InputCDR& _strm, <%= _m.cxx_member_type %>& _val) -{ - return taox11_optional_cdr<<%= _m.cxx_member_type %>>::extract (_strm, _val); -} -//@} -#endif -% end -%end TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/ridlbe/c++11/templates/cli/src/struct_cdr.erb b/ridlbe/c++11/templates/cli/src/struct_cdr.erb index 2f285f41..76d6fdef 100644 --- a/ridlbe/c++11/templates/cli/src/struct_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/struct_cdr.erb @@ -9,7 +9,11 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &<% if member_count > 0 || !base.ni % end % _n = member_count-1 % members.each_with_index do |_m, _i| +% if _m.optional? + (taox11_optional_cdr<<%= _m.cxx_member_type%>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> +% else (strm << <%= _m.cdr_from_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n ) ? ' &&' : ';') %> +% end % end % else return true; @@ -24,7 +28,11 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &<% if member_count > 0 || !base.nil (strm >> static_cast<<%= base.cxxname %>&>(_tao_aggregate))<%= ((member_count > 0) ? ' &&' : ';') %> % end % members.each_with_index do |_m, _i| +% if _m.optional? + (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> +% else (strm >> <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n) ? ' &&' : ';') %> +% end % end % else return true; diff --git a/tao/x11/optional_cdr_t.h b/tao/x11/optional_cdr_t.h index 37a09326..319c26cc 100644 --- a/tao/x11/optional_cdr_t.h +++ b/tao/x11/optional_cdr_t.h @@ -15,7 +15,7 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL /// Generic sequence CDR streaming helper template - template + template struct taox11_optional_cdr { /// Unbounded insert @@ -48,12 +48,10 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL if (_has_value) { // initialize associated default value - typename _Tp::value_type temp_val{}; + _T temp_val{_optional.value()}; // extract if (_strm >> temp_val) { - // set union member and associated discriminant when there are multiple legal discriminant values - _optional = std::move (temp_val); return true; } } diff --git a/tests/idl4/optional/test.idl b/tests/idl4/optional/test.idl index ee15a3ac..5c7411f2 100644 --- a/tests/idl4/optional/test.idl +++ b/tests/idl4/optional/test.idl @@ -17,6 +17,8 @@ struct bar long z_long; @optional short a; @optional string opt_string; + @optional boolean opt_b; + boolean b; string y; Mod::longF f; }; From 598e892a87fc3a15f0876c59c156655da3c361e0 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 9 Sep 2024 14:29:15 +0200 Subject: [PATCH 08/15] More optional work * ridlbe/c++11/templates/cli/src/struct_cdr.erb: * ridlbe/c++11/visitorbase.rb: --- ridlbe/c++11/templates/cli/src/struct_cdr.erb | 3 ++- ridlbe/c++11/visitorbase.rb | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ridlbe/c++11/templates/cli/src/struct_cdr.erb b/ridlbe/c++11/templates/cli/src/struct_cdr.erb index 76d6fdef..86b34ac4 100644 --- a/ridlbe/c++11/templates/cli/src/struct_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/struct_cdr.erb @@ -29,7 +29,8 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &<% if member_count > 0 || !base.nil % end % members.each_with_index do |_m, _i| % if _m.optional? - (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> +%# <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %> + (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> % else (strm >> <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n) ? ' &&' : ';') %> % end diff --git a/ridlbe/c++11/visitorbase.rb b/ridlbe/c++11/visitorbase.rb index 99059e80..31984405 100644 --- a/ridlbe/c++11/visitorbase.rb +++ b/ridlbe/c++11/visitorbase.rb @@ -474,19 +474,19 @@ def implementation_member_type end def cdr_to_type - @node._idltype.cdr_to_type(cur_scope) + self._idltype.cdr_to_type(cur_scope) end def cdr_from_type - @node._idltype.cdr_from_type(cur_scope) + self._idltype.cdr_from_type(cur_scope) end def scoped_cdr_to_type - @node._idltype.cdr_to_type + @self_idltype.cdr_to_type end def scoped_cdr_from_type - @node._idltype.cdr_from_type + self._idltype.cdr_from_type end def cdr_from_fmt From 9cf76187e1599102ba068381d5da6f029bade6c7 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 9 Sep 2024 15:13:31 +0200 Subject: [PATCH 09/15] Reworked optional support * ridlbe/c++11/config/cxx_type.rb: * ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb: * ridlbe/c++11/templates/cli/prx/union_cdr.erb: * ridlbe/c++11/templates/cli/src/except_cdr.erb: * ridlbe/c++11/templates/cli/src/struct_cdr.erb: * ridlbe/c++11/templates/cli/src/union_cdr.erb: * tao/x11/optional_cdr_t.h: * tests/idl4/optional/test.idl: --- ridlbe/c++11/config/cxx_type.rb | 76 +++++++++++++++---- .../cli/hdr/union_idl_traits_def.erb | 20 ++++- ridlbe/c++11/templates/cli/prx/union_cdr.erb | 21 ----- ridlbe/c++11/templates/cli/src/except_cdr.erb | 11 ++- ridlbe/c++11/templates/cli/src/struct_cdr.erb | 4 +- ridlbe/c++11/templates/cli/src/union_cdr.erb | 36 +++++++++ tao/x11/optional_cdr_t.h | 4 +- tests/idl4/optional/test.idl | 28 +++++++ 8 files changed, 158 insertions(+), 42 deletions(-) diff --git a/ridlbe/c++11/config/cxx_type.rb b/ridlbe/c++11/config/cxx_type.rb index 5bc10c15..44aa08ac 100644 --- a/ridlbe/c++11/config/cxx_type.rb +++ b/ridlbe/c++11/config/cxx_type.rb @@ -61,11 +61,11 @@ def cxx_member_type_name end def cdr_to_type(scope = nil) - cxx_out_type(scope) + cxx_type(scope) end def cdr_from_type(scope = nil) - cxx_in_type(scope) + cxx_type(scope) end def resolved_cxx_type(scope = nil) @@ -232,12 +232,20 @@ def idltype_name(_scope = nil) 'int8' end + def cdr_to_type(_scope = nil) + 'ACE_InputCDR::to_int8' + end + + def cdr_from_type(_scope = nil) + 'ACE_OutputCDR::from_int8' + end + def cdr_to_fmt - "ACE_InputCDR::to_int8 (#{super})" + "#{cdr_to_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_int8 (#{super})" + "#{cdr_from_type} (#{super})" end end @@ -267,12 +275,20 @@ def idltype_name(_scope = nil) 'uint8' end + def cdr_to_type(_scope = nil) + 'ACE_InputCDR::to_uint8' + end + + def cdr_from_type(_scope = nil) + 'ACE_OutputCDR::from_uint8' + end + def cdr_to_fmt - "ACE_InputCDR::to_uint8 (#{super})" + "#{cdr_to_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_uint8 (#{super})" + "#{cdr_from_type} (#{super})" end end @@ -339,12 +355,20 @@ def cxx_arg_type(_scope = nil) 'ACE_InputCDR::to_boolean' end + def cdr_to_type(_scope = nil) + 'ACE_InputCDR::to_boolean' + end + + def cdr_from_type(_scope = nil) + 'ACE_OutputCDR::from_boolean' + end + def cdr_to_fmt - "ACE_InputCDR::to_boolean (#{super})" + "#{cdr_to_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_boolean (#{super})" + "#{cdr_from_type} (#{super})" end def is_pod? @@ -375,12 +399,20 @@ def value_to_s(v, _scope = nil) end end + def cdr_to_type(_scope = nil) + 'ACE_InputCDR::to_char' + end + + def cdr_from_type(_scope = nil) + 'ACE_OutputCDR::from_char' + end + def cdr_to_fmt - "ACE_InputCDR::to_char (#{super})" + "#{cdr_to_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_char (#{super})" + "#{cdr_from_type} (#{super})" end def is_pod? @@ -415,12 +447,20 @@ def value_to_s(v, _scope = nil) end end + def cdr_to_type(_scope = nil) + 'ACE_InputCDR::to_wchar' + end + + def cdr_from_type(_scope = nil) + 'ACE_OutputCDR::from_wchar' + end + def cdr_to_fmt - "ACE_InputCDR::to_wchar (#{super})" + "#{cdr_to_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_wchar (#{super})" + "#{cdr_from_type} (#{super})" end def is_pod? @@ -433,12 +473,20 @@ def cxx_arg_type(_scope = nil) 'ACE_InputCDR::to_octet' end + def cdr_to_type(_scope = nil) + 'ACE_InputCDR::to_octet' + end + + def cdr_from_type(_scope = nil) + 'ACE_OutputCDR::from_octet' + end + def cdr_to_fmt - "ACE_InputCDR::to_octet (#{super})" + "#{cdr_to_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_octet (#{super})" + "#{cdr_from_type} (#{super})" end def os_fmt diff --git a/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb b/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb index fb0ccf4f..bc9c48c4 100644 --- a/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb +++ b/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb @@ -12,20 +12,32 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> % if (_defmem && _ndefmem.empty?) || (!_ndefmem.empty? && _ndefmem.first.labels.size>1) % # in these cases there is only a single member mapping all labels % _m = _defmem || _ndefmem.shift - os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ()); +% if _m.optional? + os_ << "<%= _m.cxxname %>="; if (val_.<%= _m.cxxname() %> ().has_value ()) { os_ << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ().value ());} else { os_ << "std::nullopt"; } +% else + os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ()); +% end % else % # here we have 1 or 2 nondef members with or without a default % _m = _ndefmem.shift # get first non-default member % _lbl = _m.labels.first if (<%= _lbl == 'false' ? '!' : '' %>val_._d ()) { +% if _m.optional? + os_ << "<%= _m.cxxname %>="; if (val_.<%= _m.cxxname() %> ().has_value ()) { os_ << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ().value ());} else { os_ << "std::nullopt"; } +% else os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ()); +% end } % if _defmem || !_ndefmem.empty? else { % _m = _defmem || _ndefmem.shift # get other (non-)default member +% if _m.optional? + os_ << "<%= _m.cxxname %>="; if (val_.<%= _m.cxxname() %> ().has_value ()) { os_ << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ().value ());} else { os_ << "std::nullopt"; } +% else os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ()); +% end } % end % end @@ -54,7 +66,13 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> % if has_default? % _m_def = default_member { +% if _m_def.optional? + os_ << "<%= _m_def.cxxname %>="; if (val_.<%= _m_def.cxxname() %> ().has_value ()) { os_ << IDL::traits<<%= _m_def.scoped_cxxtype %>>::write (val_.<%= _m_def.cxxname %> ().value ());} else { os_ << "std::nullopt"; } +% elsif _m_def.external? +%# TODO +% else os_ << "<%= _m_def.cxxname %>=" << IDL::traits<<%= _m_def.scoped_cxxtype %>>::write (val_.<%= _m_def.cxxname %> ()); +% end } % end break; diff --git a/ridlbe/c++11/templates/cli/prx/union_cdr.erb b/ridlbe/c++11/templates/cli/prx/union_cdr.erb index 38b9d789..86a94ebc 100644 --- a/ridlbe/c++11/templates/cli/prx/union_cdr.erb +++ b/ridlbe/c++11/templates/cli/prx/union_cdr.erb @@ -18,26 +18,5 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL <%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator<< (TAO_OutputCDR&, const <%= scoped_cxxname %>&); <%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator>> (TAO_InputCDR&, <%= scoped_cxxname %>&); //@} -%members.each do |_m| -% if _m.optional? -// Unaliased type : <%= _m.cxx_member_type %> -% alias_md5 = _m.cxx_member_type.to_md5 -// MD5 : <%= alias_md5 %> -#if !defined(_CDR_<%= alias_md5 %>_OPTIONAL_DECL_) -#define _CDR_<%= alias_md5 %>_OPTIONAL_DECL_ -/// @name CDR streaming operator specializations for <%= _m.cxx_member_type %> -//@{ -inline <%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator<< (TAO_OutputCDR& _strm, const <%= _m.cxx_member_type %>& _val) -{ - return taox11_optional_cdr<<%= _m.cxx_member_type %>>::insert (_strm, _val); -} -<%= stub_proxy_export_macro %>TAO_CORBA::Boolean operator>> (TAO_InputCDR& _strm, <%= _m.cxx_member_type %>& _val) -{ - return taox11_optional_cdr<<%= _m.cxx_member_type %>>::extract (_strm, _val); -} -//@} -#endif -% end -%end TAO_END_VERSIONED_NAMESPACE_DECL diff --git a/ridlbe/c++11/templates/cli/src/except_cdr.erb b/ridlbe/c++11/templates/cli/src/except_cdr.erb index 101c4a14..e8d91a9a 100644 --- a/ridlbe/c++11/templates/cli/src/except_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/except_cdr.erb @@ -7,7 +7,11 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> % if member_count > 0 % _n = member_count-1 % members.each_with_index do |_m, _i| +% if _m.optional? + (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> +% else (strm <<<%= _m.cdr_from_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n ) ? ' &&' : ';') %> +% end % end % else % end @@ -20,11 +24,14 @@ TAO_CORBA::Boolean operator>> ( { return % members.each_with_index do |_m, _i| +% if _m.optional? + (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> +% else (strm >> <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n) ? ' &&' : ';') %> +% end % end % else - TAO_InputCDR &, - <%= scoped_cxxname %> &) + TAO_InputCDR &, <%= scoped_cxxname %> &) { return true; % end diff --git a/ridlbe/c++11/templates/cli/src/struct_cdr.erb b/ridlbe/c++11/templates/cli/src/struct_cdr.erb index 86b34ac4..f9b368fc 100644 --- a/ridlbe/c++11/templates/cli/src/struct_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/struct_cdr.erb @@ -10,7 +10,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &<% if member_count > 0 || !base.ni % _n = member_count-1 % members.each_with_index do |_m, _i| % if _m.optional? - (taox11_optional_cdr<<%= _m.cxx_member_type%>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> + (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> % else (strm << <%= _m.cdr_from_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n ) ? ' &&' : ';') %> % end @@ -28,8 +28,8 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &<% if member_count > 0 || !base.nil (strm >> static_cast<<%= base.cxxname %>&>(_tao_aggregate))<%= ((member_count > 0) ? ' &&' : ';') %> % end % members.each_with_index do |_m, _i| -% if _m.optional? %# <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %> +% if _m.optional? (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> % else (strm >> <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n) ? ' &&' : ';') %> diff --git a/ridlbe/c++11/templates/cli/src/union_cdr.erb b/ridlbe/c++11/templates/cli/src/union_cdr.erb index e6a90852..4ed07959 100644 --- a/ridlbe/c++11/templates/cli/src/union_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/union_cdr.erb @@ -14,20 +14,32 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> % if (_defmem && _ndefmem.empty?) || (!_ndefmem.empty? && _ndefmem.first.labels.size>1) % # in these cases there is only a single member mapping all labels % _m = _defmem || _ndefmem.shift +% if _m.optional? + result = (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); +% else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; +% end % else % # here we have 1 or 2 nondef members with or without a default % _m = _ndefmem.shift # get first non-default member % _lbl = _m.labels.first if (<%= _lbl == 'false' ? '!' : '' %>_tao_union._d ()) { +% if _m.optional? + result = (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); +% else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; +% end } % if _defmem || !_ndefmem.empty? else { % _m = _defmem || _ndefmem.shift # get other (non-)default member +% if _m.optional? + result = (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); +% else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; +% end } % end % end @@ -40,7 +52,11 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> case <%= _lbl %>: % end { +% if _m.optional? + result = (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); +% else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; +% end } break; % end @@ -50,7 +66,11 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> % if has_default? % _m_def = default_member { +% if _m_def.optional? + result = (taox11_optional_cdr<<%= _m_def.cxx_member_type%>, <%= _m_def.cdr_from_type %>>::insert (strm, _tao_union.<%= _m_def.cxxname %> ())); +% else result = strm << <%= _m_def.cdr_from_fmt % "_tao_union.#{_m_def.cxxname} ()" %>; +% end } % end break; @@ -92,7 +112,11 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u // initialize associated default value <%= _m.cxx_member_type %> temp_val<%= _m.value_initializer %>; // extract +% if _m.optional? + if (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_type %>>::extract (strm, temp_val)) +% else if (strm >> <%= _m.cdr_to_fmt % "temp_val" %>) +% end { // set union member and associated discriminant when there are multiple legal discriminant values _tao_union.<%= _m.cxxname %> (std::move (temp_val)<% if _m.has_multiple_discriminators? %>, _tao_discriminant<% end %>); @@ -106,7 +130,11 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u // initialize associated default value <%= _m.cxx_member_type %> temp_val<%= _m.value_initializer %>; // extract +% if _m.optional? + if (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_type %>>::extract (strm, temp_val)) +% else if (strm >> <%= _m.cdr_to_fmt % "temp_val" %>) +% end { // set union member and associated discriminant when there are multiple legal discriminant values _tao_union.<%= _m.cxxname %> (std::move (temp_val)<% if _m.has_multiple_discriminators? %>, _tao_discriminant<% end %>); @@ -127,7 +155,11 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u // initialize associated default value <%= _m.cxx_member_type %> temp_val<%= _m.value_initializer %>; // extract +% if _m.optional? + if (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_type %>>::extract (strm, temp_val)) +% else if (strm >> <%= _m.cdr_to_fmt % "temp_val" %>) +% end { // set union member and associated discriminant when there are multiple legal discriminant values _tao_union.<%= _m.cxxname %> (std::move (temp_val)<% if _m.has_multiple_discriminators? %>, _tao_discriminant<% end %>); @@ -145,7 +177,11 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u // initialize associated default value <%= _m_def.cxx_member_type %> temp_val<%= _m_def.value_initializer %>; // extract +% if _m_def.optional? + if (taox11_optional_cdr<<%= _m_def.cxx_member_type%>, <%= _m_def.cdr_to_type %>>::extract (strm, temp_val)) +% else if (strm >> <%= _m_def.cdr_to_fmt % "temp_val" %>) +% end { // set union member and associated discriminant when there are multiple legal discriminant values _tao_union.<%= _m_def.cxxname %> (std::move (temp_val)<% if _m_def.has_multiple_discriminators? %>, _tao_discriminant<% end %>); diff --git a/tao/x11/optional_cdr_t.h b/tao/x11/optional_cdr_t.h index 319c26cc..88eccf15 100644 --- a/tao/x11/optional_cdr_t.h +++ b/tao/x11/optional_cdr_t.h @@ -15,7 +15,7 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL /// Generic sequence CDR streaming helper template - template + template struct taox11_optional_cdr { /// Unbounded insert @@ -30,7 +30,7 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL bool result { true }; if (_optional.has_value ()) { - result = _strm << _optional.value (); + result = _strm << _T (_optional.value ()); } return result; } diff --git a/tests/idl4/optional/test.idl b/tests/idl4/optional/test.idl index 5c7411f2..ce135664 100644 --- a/tests/idl4/optional/test.idl +++ b/tests/idl4/optional/test.idl @@ -10,6 +10,8 @@ module Mod typedef long longF; }; +typedef int8 myint8; + struct bar { short x; @@ -21,6 +23,12 @@ struct bar boolean b; string y; Mod::longF f; + @optional int8 int8_field; + @optional uint8 uint8_field; + @optional char char_field; + @optional wchar wchar_field; + @optional octet octet_field; + @optional myint8 myint8_field; }; exception Foo @@ -36,5 +44,25 @@ union TestUnion_Octet switch(octet) { long SecondCase; case 3: @optional Mod::longF f; + case 4: + myint8 myint8_field; + case 5: + @optional int8 int8_field; + case 6: + @optional uint8 uint8_field; + case 7: + @optional char char_field; + case 8: + @optional wchar wchar_field; + case 9: + @optional octet octet_field; + default: + @optional int8 myinft; }; +union TestUnion_Bool switch(boolean) { + case TRUE: + @optional int8 myunfi; + case FALSE: + @optional char jdd; +}; From 8c9950b8276bb96aa43aa9ec67a0850d6e5fe1d7 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 9 Sep 2024 15:47:58 +0200 Subject: [PATCH 10/15] Runtime suppor * tao/x11/optional_cdr_t.h: --- tao/x11/optional_cdr_t.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tao/x11/optional_cdr_t.h b/tao/x11/optional_cdr_t.h index a9307807..faeec4e0 100644 --- a/tao/x11/optional_cdr_t.h +++ b/tao/x11/optional_cdr_t.h @@ -48,11 +48,12 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL if (_has_value) { // If the optional doesn't contain a value initialize it - _T temp_val{_optional.emplace()}; + if (!_optional) _optional.emplace(); + _T temp_val(_optional.value ()); // extract if (_strm >> temp_val) { - _optional.value () = temp_val; + return true; } else { From faecc1b39f32ebf6bbaf5d612ec4dfbc692dbf1e Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 9 Sep 2024 16:25:23 +0200 Subject: [PATCH 11/15] Working CDR support * ridlbe/c++11/config/cxx_type.rb: * ridlbe/c++11/templates/cli/src/except_cdr.erb: * ridlbe/c++11/templates/cli/src/struct_cdr.erb: * ridlbe/c++11/templates/cli/src/union_cdr.erb: * tao/x11/optional_cdr_t.h: --- ridlbe/c++11/config/cxx_type.rb | 2 +- ridlbe/c++11/templates/cli/src/except_cdr.erb | 4 +- ridlbe/c++11/templates/cli/src/struct_cdr.erb | 4 +- ridlbe/c++11/templates/cli/src/union_cdr.erb | 18 +++---- tao/x11/optional_cdr_t.h | 50 +++++++++++++++++-- 5 files changed, 61 insertions(+), 17 deletions(-) diff --git a/ridlbe/c++11/config/cxx_type.rb b/ridlbe/c++11/config/cxx_type.rb index 44aa08ac..2a0c85ad 100644 --- a/ridlbe/c++11/config/cxx_type.rb +++ b/ridlbe/c++11/config/cxx_type.rb @@ -61,7 +61,7 @@ def cxx_member_type_name end def cdr_to_type(scope = nil) - cxx_type(scope) + #cxx_type(scope) end def cdr_from_type(scope = nil) diff --git a/ridlbe/c++11/templates/cli/src/except_cdr.erb b/ridlbe/c++11/templates/cli/src/except_cdr.erb index e8d91a9a..eef857f3 100644 --- a/ridlbe/c++11/templates/cli/src/except_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/except_cdr.erb @@ -8,7 +8,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> % _n = member_count-1 % members.each_with_index do |_m, _i| % if _m.optional? - (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> + (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> % else (strm <<<%= _m.cdr_from_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n ) ? ' &&' : ';') %> % end @@ -25,7 +25,7 @@ TAO_CORBA::Boolean operator>> ( return % members.each_with_index do |_m, _i| % if _m.optional? - (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> + (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_type.nil? ? ', ' : '' %><%= _m.cdr_to_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> % else (strm >> <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n) ? ' &&' : ';') %> % end diff --git a/ridlbe/c++11/templates/cli/src/struct_cdr.erb b/ridlbe/c++11/templates/cli/src/struct_cdr.erb index f9b368fc..15d1bc8c 100644 --- a/ridlbe/c++11/templates/cli/src/struct_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/struct_cdr.erb @@ -10,7 +10,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &<% if member_count > 0 || !base.ni % _n = member_count-1 % members.each_with_index do |_m, _i| % if _m.optional? - (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> + (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> % else (strm << <%= _m.cdr_from_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n ) ? ' &&' : ';') %> % end @@ -30,7 +30,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &<% if member_count > 0 || !base.nil % members.each_with_index do |_m, _i| %# <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %> % if _m.optional? - (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> + (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_type.nil? ? ', ' : '' %><%= _m.cdr_to_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> % else (strm >> <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n) ? ' &&' : ';') %> % end diff --git a/ridlbe/c++11/templates/cli/src/union_cdr.erb b/ridlbe/c++11/templates/cli/src/union_cdr.erb index 4ed07959..3487c84e 100644 --- a/ridlbe/c++11/templates/cli/src/union_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/union_cdr.erb @@ -15,7 +15,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> % # in these cases there is only a single member mapping all labels % _m = _defmem || _ndefmem.shift % if _m.optional? - result = (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); + result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); % else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; % end @@ -26,7 +26,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> if (<%= _lbl == 'false' ? '!' : '' %>_tao_union._d ()) { % if _m.optional? - result = (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); + result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); % else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; % end @@ -36,7 +36,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> { % _m = _defmem || _ndefmem.shift # get other (non-)default member % if _m.optional? - result = (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); + result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); % else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; % end @@ -53,7 +53,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> % end { % if _m.optional? - result = (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); + result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); % else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; % end @@ -67,7 +67,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> % _m_def = default_member { % if _m_def.optional? - result = (taox11_optional_cdr<<%= _m_def.cxx_member_type%>, <%= _m_def.cdr_from_type %>>::insert (strm, _tao_union.<%= _m_def.cxxname %> ())); + result = (taox11_optional_cdr_in<<%= _m_def.cxx_member_type%>, <%= _m_def.cdr_from_type %>>::insert (strm, _tao_union.<%= _m_def.cxxname %> ())); % else result = strm << <%= _m_def.cdr_from_fmt % "_tao_union.#{_m_def.cxxname} ()" %>; % end @@ -113,7 +113,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u <%= _m.cxx_member_type %> temp_val<%= _m.value_initializer %>; // extract % if _m.optional? - if (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_type %>>::extract (strm, temp_val)) + if (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_type.nil? ? ', ' : '' %><%= _m.cdr_to_type %>>::extract (strm, temp_val)) % else if (strm >> <%= _m.cdr_to_fmt % "temp_val" %>) % end @@ -131,7 +131,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u <%= _m.cxx_member_type %> temp_val<%= _m.value_initializer %>; // extract % if _m.optional? - if (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_type %>>::extract (strm, temp_val)) + if (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_type.nil? ? ', ' : '' %><%= _m.cdr_to_type %>>::extract (strm, temp_val)) % else if (strm >> <%= _m.cdr_to_fmt % "temp_val" %>) % end @@ -156,7 +156,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u <%= _m.cxx_member_type %> temp_val<%= _m.value_initializer %>; // extract % if _m.optional? - if (taox11_optional_cdr<<%= _m.cxx_member_type%>, <%= _m.cdr_to_type %>>::extract (strm, temp_val)) + if (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_type.nil? ? ', ' : '' %><%= _m.cdr_to_type %>>::extract (strm, temp_val)) % else if (strm >> <%= _m.cdr_to_fmt % "temp_val" %>) % end @@ -178,7 +178,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u <%= _m_def.cxx_member_type %> temp_val<%= _m_def.value_initializer %>; // extract % if _m_def.optional? - if (taox11_optional_cdr<<%= _m_def.cxx_member_type%>, <%= _m_def.cdr_to_type %>>::extract (strm, temp_val)) + if (taox11_optional_cdr_out<<%= _m_def.cxx_member_type%><%= !_m_def.cdr_to_type.nil? ? ', ' : '' %><%= _m_def.cdr_to_type %>>::extract (strm, temp_val)) % else if (strm >> <%= _m_def.cdr_to_fmt % "temp_val" %>) % end diff --git a/tao/x11/optional_cdr_t.h b/tao/x11/optional_cdr_t.h index faeec4e0..116f01ea 100644 --- a/tao/x11/optional_cdr_t.h +++ b/tao/x11/optional_cdr_t.h @@ -16,7 +16,7 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL /// Generic sequence CDR streaming helper template template - struct taox11_optional_cdr + struct taox11_optional_cdr_in { /// Unbounded insert template @@ -34,7 +34,15 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL } return result; } + }; + + template + struct taox11_optional_cdr_out; + /// Generic sequence CDR streaming helper template + template + struct taox11_optional_cdr_out<_Tp> + { /// Unbounded extract template static bool extract (_Stream& _strm, _Tp& _optional) @@ -49,9 +57,8 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL { // If the optional doesn't contain a value initialize it if (!_optional) _optional.emplace(); - _T temp_val(_optional.value ()); // extract - if (_strm >> temp_val) + if (_strm >> _optional.value ()) { return true; } @@ -68,6 +75,43 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL } }; + /// Generic sequence CDR streaming helper template + template + struct taox11_optional_cdr_out<_Tp, _T> + { + /// Unbounded extract + template + static bool extract (_Stream& _strm, _Tp& _optional) + { + bool _has_value{}; + if (!(_strm >> ACE_InputCDR::to_boolean (_has_value))) + { + return false; + } + + if (_has_value) + { + // If the optional doesn't contain a value initialize it + if (!_optional) _optional.emplace(); + // extract + if (_strm >> _T(_optional.value ())) + { + return true; + } + else + { + return false; + } + } + else + { + _optional.reset (); + } + return true; + } + }; + + TAO_END_VERSIONED_NAMESPACE_DECL #endif // TAOX11_OPTIONAL_CDR_T_H_INCLUDED From dc594f4fbfbe2f62a0fb6052f83f368fdbeaa1ff Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 9 Sep 2024 16:31:22 +0200 Subject: [PATCH 12/15] Add test * tests/idl4/optional/client.cpp: * tests/idl4/optional/foo.cpp: * tests/idl4/optional/test.idl: --- tests/idl4/optional/client.cpp | 10 ++++++++++ tests/idl4/optional/foo.cpp | 2 ++ tests/idl4/optional/test.idl | 1 + 3 files changed, 13 insertions(+) diff --git a/tests/idl4/optional/client.cpp b/tests/idl4/optional/client.cpp index 7ffc5d8a..e8b77a8e 100644 --- a/tests/idl4/optional/client.cpp +++ b/tests/idl4/optional/client.cpp @@ -56,6 +56,16 @@ int main (int argc, char* argv[]) TAOX11_TEST_ERROR << "ERROR: Incorrect z received, not 255 but " << sret.z ().value () << std::endl; return 1; } + if (sret.regular8 () != 64) + { + TAOX11_TEST_ERROR << "ERROR: Incorrect regular8 received, not 64 but " << sret.int8_field ().value () << std::endl; + return 1; + } + if (sret.int8_field () != 125) + { + TAOX11_TEST_ERROR << "ERROR: Incorrect int8_field received, not 125 but " << sret.int8_field ().value () << std::endl; + return 1; + } Fooexcep f; TestUnion_Octet to; diff --git a/tests/idl4/optional/foo.cpp b/tests/idl4/optional/foo.cpp index 267f7937..e918c246 100644 --- a/tests/idl4/optional/foo.cpp +++ b/tests/idl4/optional/foo.cpp @@ -23,6 +23,8 @@ Foo::test_bar (const bar & sin, bar & sinout, bar & sout) bar sret = sin; sret.z(255); sret.z_long(255); + sret.regular8(64); + sret.int8_field(125); return sret; } diff --git a/tests/idl4/optional/test.idl b/tests/idl4/optional/test.idl index 75a3d184..dcc20c0a 100644 --- a/tests/idl4/optional/test.idl +++ b/tests/idl4/optional/test.idl @@ -23,6 +23,7 @@ struct bar boolean b; string y; Mod::longF f; + int8 regular8; @optional int8 int8_field; @optional uint8 uint8_field; @optional char char_field; From 4aacb31aad82ff30d802033391df3308aaec9aca Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 9 Sep 2024 16:35:42 +0200 Subject: [PATCH 13/15] ostream simplification * tao/x11/base/idl_traits_t.h: --- tao/x11/base/idl_traits_t.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tao/x11/base/idl_traits_t.h b/tao/x11/base/idl_traits_t.h index 3bea6fbf..d1740df8 100644 --- a/tao/x11/base/idl_traits_t.h +++ b/tao/x11/base/idl_traits_t.h @@ -115,21 +115,21 @@ namespace TAOX11_NAMESPACE struct formatter { inline OStrm_& operator ()(OStrm_& os_, int8_t val_) - { os_ << std::hex << static_cast (val_) << std::dec; return os_;} + { return os_ << static_cast (val_); } }; template struct formatter { inline OStrm_& operator ()(OStrm_& os_, uint8_t val_) - { os_ << std::hex << static_cast (val_) << std::dec; return os_;} + { return os_ << static_cast (val_); } }; template struct formatter { inline OStrm_& operator ()(OStrm_& os_, char val_) - { os_ << '\'' << val_ << '\''; return os_; } + { return os_ << '\'' << val_ << '\''; } }; template <> @@ -146,7 +146,7 @@ namespace TAOX11_NAMESPACE struct formatter { inline OStrm_& operator ()(OStrm_& os_, wchar_t val_) - { os_ << L'\'' << val_ << L'\''; return os_; } + { return os_ << L'\'' << val_ << L'\''; } }; template <> @@ -163,7 +163,7 @@ namespace TAOX11_NAMESPACE struct formatter { inline OStrm_& operator ()(OStrm_& os_, std::string val_) - { os_ << '"' << val_ << '"'; return os_; } + { return os_ << '"' << val_ << '"'; } }; template <> @@ -180,7 +180,7 @@ namespace TAOX11_NAMESPACE struct formatter { inline OStrm_& operator ()(OStrm_& os_, std::string val_) - { os_ << L'"' << val_ << '"'; return os_; } + { return os_ << L'"' << val_ << '"'; } }; template <> From 6bf09d45290d8364a5293a72bb26d75d8d2b7468 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 9 Sep 2024 16:39:52 +0200 Subject: [PATCH 14/15] Removed not used methods * ridlbe/c++11/visitorbase.rb: --- ridlbe/c++11/visitorbase.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ridlbe/c++11/visitorbase.rb b/ridlbe/c++11/visitorbase.rb index 31984405..4d8d7a21 100644 --- a/ridlbe/c++11/visitorbase.rb +++ b/ridlbe/c++11/visitorbase.rb @@ -481,14 +481,6 @@ def cdr_from_type self._idltype.cdr_from_type(cur_scope) end - def scoped_cdr_to_type - @self_idltype.cdr_to_type - end - - def scoped_cdr_from_type - self._idltype.cdr_from_type - end - def cdr_from_fmt self._idltype.cdr_from_fmt end From 8f82fa507c5698f78e27dab4a9f8a5e09a36dea7 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 9 Sep 2024 17:12:24 +0200 Subject: [PATCH 15/15] Simplified ostream insertion * ridlbe/c++11/config/cxx_type.rb: * ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb: * ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb: * ridlbe/c++11/templates/cli/src/except_cdr.erb: * ridlbe/c++11/templates/cli/src/struct_cdr.erb: * ridlbe/c++11/templates/cli/src/union_cdr.erb: * ridlbe/c++11/visitorbase.rb: * tao/x11/optional_cdr_t.h: * tao/x11/optional_t.h: --- ridlbe/c++11/config/cxx_type.rb | 62 +++++++++---------- .../cli/hdr/struct_idl_traits_def.erb | 2 +- .../cli/hdr/union_idl_traits_def.erb | 10 +-- ridlbe/c++11/templates/cli/src/except_cdr.erb | 4 +- ridlbe/c++11/templates/cli/src/struct_cdr.erb | 4 +- ridlbe/c++11/templates/cli/src/union_cdr.erb | 18 +++--- ridlbe/c++11/visitorbase.rb | 8 +-- tao/x11/optional_cdr_t.h | 36 +++++++++-- tao/x11/optional_t.h | 14 +++++ 9 files changed, 97 insertions(+), 61 deletions(-) diff --git a/ridlbe/c++11/config/cxx_type.rb b/ridlbe/c++11/config/cxx_type.rb index 2a0c85ad..ce581182 100644 --- a/ridlbe/c++11/config/cxx_type.rb +++ b/ridlbe/c++11/config/cxx_type.rb @@ -60,12 +60,10 @@ def cxx_member_type_name self.respond_to?(:node) ? cxx_type(node.enclosure) : cxx_type end - def cdr_to_type(scope = nil) - #cxx_type(scope) + def cdr_to_helper_type end - def cdr_from_type(scope = nil) - cxx_type(scope) + def cdr_from_helper_type end def resolved_cxx_type(scope = nil) @@ -232,20 +230,20 @@ def idltype_name(_scope = nil) 'int8' end - def cdr_to_type(_scope = nil) + def cdr_to_helper_type 'ACE_InputCDR::to_int8' end - def cdr_from_type(_scope = nil) + def cdr_from_helper_type 'ACE_OutputCDR::from_int8' end def cdr_to_fmt - "#{cdr_to_type} (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "#{cdr_from_type} (#{super})" + "#{cdr_from_helper_type} (#{super})" end end @@ -275,20 +273,20 @@ def idltype_name(_scope = nil) 'uint8' end - def cdr_to_type(_scope = nil) + def cdr_to_helper_type 'ACE_InputCDR::to_uint8' end - def cdr_from_type(_scope = nil) + def cdr_from_helper_type 'ACE_OutputCDR::from_uint8' end def cdr_to_fmt - "#{cdr_to_type} (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "#{cdr_from_type} (#{super})" + "#{cdr_from_helper_type} (#{super})" end end @@ -355,20 +353,20 @@ def cxx_arg_type(_scope = nil) 'ACE_InputCDR::to_boolean' end - def cdr_to_type(_scope = nil) + def cdr_to_helper_type 'ACE_InputCDR::to_boolean' end - def cdr_from_type(_scope = nil) + def cdr_from_helper_type 'ACE_OutputCDR::from_boolean' end def cdr_to_fmt - "#{cdr_to_type} (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "#{cdr_from_type} (#{super})" + "#{cdr_from_helper_type} (#{super})" end def is_pod? @@ -399,20 +397,20 @@ def value_to_s(v, _scope = nil) end end - def cdr_to_type(_scope = nil) + def cdr_to_helper_type 'ACE_InputCDR::to_char' end - def cdr_from_type(_scope = nil) + def cdr_from_helper_type 'ACE_OutputCDR::from_char' end def cdr_to_fmt - "#{cdr_to_type} (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "#{cdr_from_type} (#{super})" + "#{cdr_from_helper_type} (#{super})" end def is_pod? @@ -447,20 +445,20 @@ def value_to_s(v, _scope = nil) end end - def cdr_to_type(_scope = nil) + def cdr_to_helper_type 'ACE_InputCDR::to_wchar' end - def cdr_from_type(_scope = nil) + def cdr_from_helper_type 'ACE_OutputCDR::from_wchar' end def cdr_to_fmt - "#{cdr_to_type} (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "#{cdr_from_type} (#{super})" + "#{cdr_from_helper_type} (#{super})" end def is_pod? @@ -473,20 +471,20 @@ def cxx_arg_type(_scope = nil) 'ACE_InputCDR::to_octet' end - def cdr_to_type(_scope = nil) + def cdr_to_helper_type 'ACE_InputCDR::to_octet' end - def cdr_from_type(_scope = nil) + def cdr_from_helper_type 'ACE_OutputCDR::from_octet' end def cdr_to_fmt - "#{cdr_to_type} (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "#{cdr_from_type} (#{super})" + "#{cdr_from_helper_type} (#{super})" end def os_fmt @@ -830,12 +828,12 @@ def cxx_arg_type(_scope = nil) resolved_type.cxx_arg_type end - def cdr_to_type(scope = nil) - resolved_type.cdr_to_type(scope) + def cdr_to_helper_type + resolved_type.cdr_to_helper_type end - def cdr_from_type(scope = nil) - resolved_type.cdr_from_type(scope) + def cdr_from_helper_type + resolved_type.cdr_from_helper_type end def cdr_to_fmt diff --git a/ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb b/ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb index 87a27231..fc044550 100644 --- a/ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb +++ b/ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb @@ -35,7 +35,7 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> % end % else % if _m.optional? - << "<%= _sep %><%= _m.cxxname %>="; if (val_.<%= _m.cxxname() %> ().has_value ()) { os_ << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ().value ()); } else { os_ << "std::nullopt"; } os_ + << "<%= _sep %><%= _m.cxxname %>=" << val_.<%= _m.cxxname %> () % elsif _m.external? %# TODO % else diff --git a/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb b/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb index bc9c48c4..bcff0845 100644 --- a/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb +++ b/ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb @@ -13,7 +13,7 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> % # in these cases there is only a single member mapping all labels % _m = _defmem || _ndefmem.shift % if _m.optional? - os_ << "<%= _m.cxxname %>="; if (val_.<%= _m.cxxname() %> ().has_value ()) { os_ << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ().value ());} else { os_ << "std::nullopt"; } + os_ << "<%= _m.cxxname %>=" << val_.<%= _m.cxxname %> (); % else os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ()); % end @@ -24,7 +24,7 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> if (<%= _lbl == 'false' ? '!' : '' %>val_._d ()) { % if _m.optional? - os_ << "<%= _m.cxxname %>="; if (val_.<%= _m.cxxname() %> ().has_value ()) { os_ << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ().value ());} else { os_ << "std::nullopt"; } + os_ << "<%= _m.cxxname %>=" << val_.<%= _m.cxxname %> (); % else os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ()); % end @@ -34,7 +34,7 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> { % _m = _defmem || _ndefmem.shift # get other (non-)default member % if _m.optional? - os_ << "<%= _m.cxxname %>="; if (val_.<%= _m.cxxname() %> ().has_value ()) { os_ << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ().value ());} else { os_ << "std::nullopt"; } + os_ << "<%= _m.cxxname %>=" << val_.<%= _m.cxxname %> (); % else os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ()); % end @@ -51,7 +51,7 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> % end { % if _m.optional? - os_ << "<%= _m.cxxname %>="; if (val_.<%= _m.cxxname() %> ().has_value ()) { os_ << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ().value ());} else { os_ << "std::nullopt"; } + os_ << "<%= _m.cxxname %>=" << val_.<%= _m.cxxname %> (); % elsif _m.external? %# TODO % else @@ -67,7 +67,7 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> % _m_def = default_member { % if _m_def.optional? - os_ << "<%= _m_def.cxxname %>="; if (val_.<%= _m_def.cxxname() %> ().has_value ()) { os_ << IDL::traits<<%= _m_def.scoped_cxxtype %>>::write (val_.<%= _m_def.cxxname %> ().value ());} else { os_ << "std::nullopt"; } + os_ << "<%= _m_def.cxxname %>=" << val_.<%= _m_def.cxxname %> (); % elsif _m_def.external? %# TODO % else diff --git a/ridlbe/c++11/templates/cli/src/except_cdr.erb b/ridlbe/c++11/templates/cli/src/except_cdr.erb index eef857f3..9dae9820 100644 --- a/ridlbe/c++11/templates/cli/src/except_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/except_cdr.erb @@ -8,7 +8,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> % _n = member_count-1 % members.each_with_index do |_m, _i| % if _m.optional? - (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> + (taox11_optional_cdr_in<<%= _m.cxx_member_type%><%= !_m.cdr_from_helper_type.nil? ? ', ' : '' %><%= _m.cdr_from_helper_type %>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> % else (strm <<<%= _m.cdr_from_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n ) ? ' &&' : ';') %> % end @@ -25,7 +25,7 @@ TAO_CORBA::Boolean operator>> ( return % members.each_with_index do |_m, _i| % if _m.optional? - (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_type.nil? ? ', ' : '' %><%= _m.cdr_to_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> + (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_helper_type.nil? ? ', ' : '' %><%= _m.cdr_to_helper_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> % else (strm >> <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n) ? ' &&' : ';') %> % end diff --git a/ridlbe/c++11/templates/cli/src/struct_cdr.erb b/ridlbe/c++11/templates/cli/src/struct_cdr.erb index 15d1bc8c..ccdafe2a 100644 --- a/ridlbe/c++11/templates/cli/src/struct_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/struct_cdr.erb @@ -10,7 +10,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &<% if member_count > 0 || !base.ni % _n = member_count-1 % members.each_with_index do |_m, _i| % if _m.optional? - (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> + (taox11_optional_cdr_in<<%= _m.cxx_member_type%><%= !_m.cdr_from_helper_type.nil? ? ', ' : '' %><%= _m.cdr_from_helper_type %>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> % else (strm << <%= _m.cdr_from_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n ) ? ' &&' : ';') %> % end @@ -30,7 +30,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &<% if member_count > 0 || !base.nil % members.each_with_index do |_m, _i| %# <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %> % if _m.optional? - (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_type.nil? ? ', ' : '' %><%= _m.cdr_to_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> + (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_helper_type.nil? ? ', ' : '' %><%= _m.cdr_to_helper_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %> % else (strm >> <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n) ? ' &&' : ';') %> % end diff --git a/ridlbe/c++11/templates/cli/src/union_cdr.erb b/ridlbe/c++11/templates/cli/src/union_cdr.erb index 3487c84e..26c1b2c4 100644 --- a/ridlbe/c++11/templates/cli/src/union_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/union_cdr.erb @@ -15,7 +15,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> % # in these cases there is only a single member mapping all labels % _m = _defmem || _ndefmem.shift % if _m.optional? - result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); + result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%><%= !_m.cdr_from_helper_type.nil? ? ', ' : '' %><%= _m.cdr_from_helper_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); % else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; % end @@ -26,7 +26,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> if (<%= _lbl == 'false' ? '!' : '' %>_tao_union._d ()) { % if _m.optional? - result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); + result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%><%= !_m.cdr_from_helper_type.nil? ? ', ' : '' %><%= _m.cdr_from_helper_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); % else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; % end @@ -36,7 +36,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> { % _m = _defmem || _ndefmem.shift # get other (non-)default member % if _m.optional? - result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); + result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%><%= !_m.cdr_from_helper_type.nil? ? ', ' : '' %><%= _m.cdr_from_helper_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); % else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; % end @@ -53,7 +53,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> % end { % if _m.optional? - result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%>, <%= _m.cdr_from_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); + result = (taox11_optional_cdr_in<<%= _m.cxx_member_type%><%= !_m.cdr_from_helper_type.nil? ? ', ' : '' %><%= _m.cdr_from_helper_type %>>::insert (strm, _tao_union.<%= _m.cxxname %> ())); % else result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>; % end @@ -67,7 +67,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> % _m_def = default_member { % if _m_def.optional? - result = (taox11_optional_cdr_in<<%= _m_def.cxx_member_type%>, <%= _m_def.cdr_from_type %>>::insert (strm, _tao_union.<%= _m_def.cxxname %> ())); + result = (taox11_optional_cdr_in<<%= _m_def.cxx_member_type%><%= !_m_def.cdr_from_helper_type.nil? ? ', ' : '' %><%= _m_def.cdr_from_helper_type %>>::insert (strm, _tao_union.<%= _m_def.cxxname %> ())); % else result = strm << <%= _m_def.cdr_from_fmt % "_tao_union.#{_m_def.cxxname} ()" %>; % end @@ -113,7 +113,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u <%= _m.cxx_member_type %> temp_val<%= _m.value_initializer %>; // extract % if _m.optional? - if (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_type.nil? ? ', ' : '' %><%= _m.cdr_to_type %>>::extract (strm, temp_val)) + if (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_helper_type.nil? ? ', ' : '' %><%= _m.cdr_to_helper_type %>>::extract (strm, temp_val)) % else if (strm >> <%= _m.cdr_to_fmt % "temp_val" %>) % end @@ -131,7 +131,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u <%= _m.cxx_member_type %> temp_val<%= _m.value_initializer %>; // extract % if _m.optional? - if (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_type.nil? ? ', ' : '' %><%= _m.cdr_to_type %>>::extract (strm, temp_val)) + if (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_helper_type.nil? ? ', ' : '' %><%= _m.cdr_to_helper_type %>>::extract (strm, temp_val)) % else if (strm >> <%= _m.cdr_to_fmt % "temp_val" %>) % end @@ -156,7 +156,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u <%= _m.cxx_member_type %> temp_val<%= _m.value_initializer %>; // extract % if _m.optional? - if (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_type.nil? ? ', ' : '' %><%= _m.cdr_to_type %>>::extract (strm, temp_val)) + if (taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_helper_type.nil? ? ', ' : '' %><%= _m.cdr_to_helper_type %>>::extract (strm, temp_val)) % else if (strm >> <%= _m.cdr_to_fmt % "temp_val" %>) % end @@ -178,7 +178,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &strm, <%= scoped_cxxname %> &_tao_u <%= _m_def.cxx_member_type %> temp_val<%= _m_def.value_initializer %>; // extract % if _m_def.optional? - if (taox11_optional_cdr_out<<%= _m_def.cxx_member_type%><%= !_m_def.cdr_to_type.nil? ? ', ' : '' %><%= _m_def.cdr_to_type %>>::extract (strm, temp_val)) + if (taox11_optional_cdr_out<<%= _m_def.cxx_member_type%><%= !_m_def.cdr_to_helper_type.nil? ? ', ' : '' %><%= _m_def.cdr_to_helper_type %>>::extract (strm, temp_val)) % else if (strm >> <%= _m_def.cdr_to_fmt % "temp_val" %>) % end diff --git a/ridlbe/c++11/visitorbase.rb b/ridlbe/c++11/visitorbase.rb index 4d8d7a21..bedae155 100644 --- a/ridlbe/c++11/visitorbase.rb +++ b/ridlbe/c++11/visitorbase.rb @@ -473,12 +473,12 @@ def implementation_member_type self._idltype.is_a?(IDL::Type::Any) ? 'CORBA::Any' : scoped_cxx_member_type end - def cdr_to_type - self._idltype.cdr_to_type(cur_scope) + def cdr_to_helper_type + self._idltype.cdr_to_helper_type end - def cdr_from_type - self._idltype.cdr_from_type(cur_scope) + def cdr_from_helper_type + self._idltype.cdr_from_helper_type end def cdr_from_fmt diff --git a/tao/x11/optional_cdr_t.h b/tao/x11/optional_cdr_t.h index 116f01ea..d08ab0b1 100644 --- a/tao/x11/optional_cdr_t.h +++ b/tao/x11/optional_cdr_t.h @@ -15,8 +15,32 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL /// Generic sequence CDR streaming helper template - template - struct taox11_optional_cdr_in + template + struct taox11_optional_cdr_in; + + template + struct taox11_optional_cdr_in<_Tp> + { + /// Unbounded insert + template + static bool insert (_Stream& _strm, const _Tp& _optional) + { + if (!(_strm << ACE_OutputCDR::from_boolean (_optional.has_value ()))) + { + return false; + } + + bool result { true }; + if (_optional.has_value ()) + { + result = _strm << _optional.value (); + } + return result; + } + }; + + template + struct taox11_optional_cdr_in<_Tp, _Thelper> { /// Unbounded insert template @@ -30,7 +54,7 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL bool result { true }; if (_optional.has_value ()) { - result = _strm << _T (_optional.value ()); + result = _strm << _Thelper(_optional.value ()); } return result; } @@ -76,8 +100,8 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL }; /// Generic sequence CDR streaming helper template - template - struct taox11_optional_cdr_out<_Tp, _T> + template + struct taox11_optional_cdr_out<_Tp, _Thelper> { /// Unbounded extract template @@ -94,7 +118,7 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL // If the optional doesn't contain a value initialize it if (!_optional) _optional.emplace(); // extract - if (_strm >> _T(_optional.value ())) + if (_strm >> _Thelper(_optional.value ())) { return true; } diff --git a/tao/x11/optional_t.h b/tao/x11/optional_t.h index be47fd21..1214b617 100644 --- a/tao/x11/optional_t.h +++ b/tao/x11/optional_t.h @@ -20,6 +20,20 @@ namespace TAOX11_NAMESPACE { template using optional = std::optional; + + template + std::ostream& operator <<(std::ostream& stream, const optional& optional) + { + if (optional.has_value()) + { + stream << IDL::traits::write(optional.value ()); + } + else + { + stream << "std::nullopt"; + } + return stream; + } } // namespace IDL } // namespace TAOX11_NAMESPACE