diff --git a/ridlbe/c++11/templates/cli/prx/struct_cdr.erb b/ridlbe/c++11/templates/cli/prx/struct_cdr.erb index 86a94ebc..38b9d789 100644 --- a/ridlbe/c++11/templates/cli/prx/struct_cdr.erb +++ b/ridlbe/c++11/templates/cli/prx/struct_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/templates/cli/src/union_cdr.erb b/ridlbe/c++11/templates/cli/src/union_cdr.erb index fb2fe042..e6a90852 100644 --- a/ridlbe/c++11/templates/cli/src/union_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/union_cdr.erb @@ -2,7 +2,7 @@ // generated from <%= ridl_template_path %> TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> &_tao_union) { - if (!(strm <<<%= switchtype.cdr_from_fmt % "_tao_union._d ()" %>)) + if (!(strm << <%= switchtype.cdr_from_fmt % "_tao_union._d ()" %>)) { return false; } diff --git a/ridlbe/c++11/visitors/struct.rb b/ridlbe/c++11/visitors/struct.rb index 1ece1e28..c8aa5a64 100644 --- a/ridlbe/c++11/visitors/struct.rb +++ b/ridlbe/c++11/visitors/struct.rb @@ -123,7 +123,7 @@ def cxx_out_type def cxx_in_type if optional? - "const IDL::optional<#{super}>&" + "const IDL::optional<#{cxx_return_type}>&" elsif external? "const std::shared_ptr<#{super}>&" else diff --git a/ridlbe/c++11/writers/stubproxyheader.rb b/ridlbe/c++11/writers/stubproxyheader.rb index a0a658b1..d536362b 100644 --- a/ridlbe/c++11/writers/stubproxyheader.rb +++ b/ridlbe/c++11/writers/stubproxyheader.rb @@ -189,6 +189,7 @@ def enter_struct(node) add_include('tao/x11/basic_argument_t.h') node.members.each { |m| check_idl_type(m.idltype) } + node.members.each { |m| add_include('tao/x11/optional_cdr_t.h') if !m.annotations[:optional].first.nil? } end def enter_union(node) diff --git a/tao/x11/base/bounded_map_t.h b/tao/x11/base/bounded_map_t.h index 6750d2be..609af3f4 100644 --- a/tao/x11/base/bounded_map_t.h +++ b/tao/x11/base/bounded_map_t.h @@ -44,10 +44,8 @@ namespace TAOX11_NAMESPACE using size_type = typename _Map::size_type; using difference_type = typename _Map::difference_type; using allocator_type = typename _Map::allocator_type; -#if defined (ACE_HAS_CPP17) using node_type = typename _Map::node_type; using insert_return_type = typename _Map::insert_return_type; -#endif /* ACE_HAS_CPP17 */ using bound = std::integral_constant; diff --git a/tao/x11/optional_cdr_t.h b/tao/x11/optional_cdr_t.h new file mode 100644 index 00000000..37a09326 --- /dev/null +++ b/tao/x11/optional_cdr_t.h @@ -0,0 +1,70 @@ +/** + * @file optional_cdr_t.h + * @author Johnny Willemsen + * + * @brief x11 optional marshaling templates + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ + +#ifndef TAOX11_OPTIONAL_CDR_T_H_INCLUDED +#define TAOX11_OPTIONAL_CDR_T_H_INCLUDED + +#include "tao/x11/base/tao_corba.h" + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + + /// Generic sequence CDR streaming helper template + template + struct taox11_optional_cdr + { + /// 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; + } + + /// 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) + { + // initialize associated default value + typename _Tp::value_type temp_val{}; + // 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; + } + } + else + { + _optional.reset (); + } + return false; + } + }; + +TAO_END_VERSIONED_NAMESPACE_DECL + +#endif // TAOX11_OPTIONAL_CDR_T_H_INCLUDED diff --git a/tao/x11/optional_t.h b/tao/x11/optional_t.h index aff68909..be47fd21 100644 --- a/tao/x11/optional_t.h +++ b/tao/x11/optional_t.h @@ -3,7 +3,7 @@ * @file optional_t.h * @author Johnny Willemsen * - * @brief template for IDL4 optional annotaiton + * @brief template for IDL4 optional annotation * * @copyright Copyright (c) Remedy IT Expertise BV */ @@ -14,8 +14,6 @@ #include #include "tao/x11/base/versioned_x11_namespace.h" -#if defined (ACE_HAS_CPP17) - namespace TAOX11_NAMESPACE { namespace IDL @@ -25,20 +23,4 @@ namespace TAOX11_NAMESPACE } // namespace IDL } // namespace TAOX11_NAMESPACE -#else - -namespace TAOX11_NAMESPACE -{ - namespace IDL - { - template - class optional - { - public: - T value_; - }; - } -} -#endif - #endif // __IDL__OPTIONAL_T_H_INCLUDED__ diff --git a/tao/x11/portable_server/operation_table_std_map.h b/tao/x11/portable_server/operation_table_std_map.h index 1d804abb..93171d54 100644 --- a/tao/x11/portable_server/operation_table_std_map.h +++ b/tao/x11/portable_server/operation_table_std_map.h @@ -72,11 +72,7 @@ class TAOX11_PortableServer_Export Std_Map_OpTable final const TAO::Operation_Skeletons skel_ptr) override; private: -#if defined (ACE_HAS_CPP17) using key_map_type = std::string_view ; -#else - using key_map_type = std::string ; -#endif /* ACE_HAS_CPP17 */ using map_type = std::unordered_map; diff --git a/tao/x11/taox11.mpc b/tao/x11/taox11.mpc index b29487de..ee29a608 100644 --- a/tao/x11/taox11.mpc +++ b/tao/x11/taox11.mpc @@ -312,6 +312,8 @@ project(taox11) : taox11_defaults, taolib { object_ostream.h object_traits_t.h objproxy.h + optional_t.h + optional_cdr_t.h orb.h orb_constants.h orb_registry.h diff --git a/tests/idl4/optional/test.idl b/tests/idl4/optional/test.idl index 5afcbc71..e47e3521 100644 --- a/tests/idl4/optional/test.idl +++ b/tests/idl4/optional/test.idl @@ -10,5 +10,6 @@ struct bar short x; string y; @optional short z; + @optional short a; + @optional string opt_string; }; - diff --git a/tests/idl4/optional/test.mpc b/tests/idl4/optional/test.mpc index 0607b3c3..66bd2e3b 100644 --- a/tests/idl4/optional/test.mpc +++ b/tests/idl4/optional/test.mpc @@ -3,7 +3,7 @@ project(*optional_gen_idl): ridl_ostream_defaults { IDL_Files { test.idl - idlflags += --idl-version=4 -Scdr + idlflags += --idl-version=4 } custom_only = 1 } diff --git a/tests/interface/client.cpp b/tests/interface/client.cpp index a22c777f..9113ea93 100644 --- a/tests/interface/client.cpp +++ b/tests/interface/client.cpp @@ -61,7 +61,6 @@ int main(int argc, char* argv[]) IDL::traits::ref_type obj2; std::swap (obj, obj2); std::swap (obj, obj2); -#if defined (ACE_HAS_CPP17) if (!std::is_swappable::ref_type>()) { TAOX11_TEST_ERROR << "ERROR: IDL::traits::ref_type is not swappable." << std::endl; @@ -71,7 +70,6 @@ int main(int argc, char* argv[]) { TAOX11_TEST_DEBUG << "IDL::traits::ref_type is swappable." << std::endl; } -#endif /* ACE_HAS_CPP17 */ if (!test_nil_invocation()) ++result; diff --git a/tests/struct/client.cpp b/tests/struct/client.cpp index 2c79208e..5ca32df9 100644 --- a/tests/struct/client.cpp +++ b/tests/struct/client.cpp @@ -106,7 +106,6 @@ int main(int argc, char* argv[]) V s5; V s6; test_swap (s5, s6); -#if defined (ACE_HAS_CPP17) if (!std::is_swappable()) { TAOX11_TEST_ERROR << "ERROR: V is not swappable." << std::endl; @@ -116,7 +115,6 @@ int main(int argc, char* argv[]) { TAOX11_TEST_DEBUG << "V is swappable." << std::endl; } -#endif /* ACE_HAS_CPP17 */ TAOX11_TEST_DEBUG << "successfully called Foo::update_struct (" << simple3 << ") => " << simple4 << std::endl; diff --git a/tests/union/client.cpp b/tests/union/client.cpp index 24150340..64e2db25 100644 --- a/tests/union/client.cpp +++ b/tests/union/client.cpp @@ -26,7 +26,6 @@ test_data_union (IDL::traits::ref_type foo) data.pointData (Test::Point (12, 34)); retval += check_union (data, Test::DataType::dtPoint, "before pass_union"); -#if defined (ACE_HAS_CPP17) if (!std::is_swappable()) { TAOX11_TEST_ERROR << "ERROR: V is not swappable." << std::endl; @@ -36,7 +35,6 @@ test_data_union (IDL::traits::ref_type foo) { TAOX11_TEST_DEBUG << "Test::Data is swappable." << std::endl; } -#endif /* ACE_HAS_CPP17 */ if (foo->pass_union (data)) {