diff --git a/ridlbe/c++11/config/cxx_type.rb b/ridlbe/c++11/config/cxx_type.rb index 5bc10c15..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_out_type(scope) + def cdr_to_helper_type end - def cdr_from_type(scope = nil) - cxx_in_type(scope) + def cdr_from_helper_type end def resolved_cxx_type(scope = nil) @@ -232,12 +230,20 @@ def idltype_name(_scope = nil) 'int8' end + def cdr_to_helper_type + 'ACE_InputCDR::to_int8' + end + + def cdr_from_helper_type + 'ACE_OutputCDR::from_int8' + end + def cdr_to_fmt - "ACE_InputCDR::to_int8 (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_int8 (#{super})" + "#{cdr_from_helper_type} (#{super})" end end @@ -267,12 +273,20 @@ def idltype_name(_scope = nil) 'uint8' end + def cdr_to_helper_type + 'ACE_InputCDR::to_uint8' + end + + def cdr_from_helper_type + 'ACE_OutputCDR::from_uint8' + end + def cdr_to_fmt - "ACE_InputCDR::to_uint8 (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_uint8 (#{super})" + "#{cdr_from_helper_type} (#{super})" end end @@ -339,12 +353,20 @@ def cxx_arg_type(_scope = nil) 'ACE_InputCDR::to_boolean' end + def cdr_to_helper_type + 'ACE_InputCDR::to_boolean' + end + + def cdr_from_helper_type + 'ACE_OutputCDR::from_boolean' + end + def cdr_to_fmt - "ACE_InputCDR::to_boolean (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_boolean (#{super})" + "#{cdr_from_helper_type} (#{super})" end def is_pod? @@ -375,12 +397,20 @@ def value_to_s(v, _scope = nil) end end + def cdr_to_helper_type + 'ACE_InputCDR::to_char' + end + + def cdr_from_helper_type + 'ACE_OutputCDR::from_char' + end + def cdr_to_fmt - "ACE_InputCDR::to_char (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_char (#{super})" + "#{cdr_from_helper_type} (#{super})" end def is_pod? @@ -415,12 +445,20 @@ def value_to_s(v, _scope = nil) end end + def cdr_to_helper_type + 'ACE_InputCDR::to_wchar' + end + + def cdr_from_helper_type + 'ACE_OutputCDR::from_wchar' + end + def cdr_to_fmt - "ACE_InputCDR::to_wchar (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_wchar (#{super})" + "#{cdr_from_helper_type} (#{super})" end def is_pod? @@ -433,12 +471,20 @@ def cxx_arg_type(_scope = nil) 'ACE_InputCDR::to_octet' end + def cdr_to_helper_type + 'ACE_InputCDR::to_octet' + end + + def cdr_from_helper_type + 'ACE_OutputCDR::from_octet' + end + def cdr_to_fmt - "ACE_InputCDR::to_octet (#{super})" + "#{cdr_to_helper_type} (#{super})" end def cdr_from_fmt - "ACE_OutputCDR::from_octet (#{super})" + "#{cdr_from_helper_type} (#{super})" end def os_fmt @@ -782,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 d8aab8ba..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 @@ -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 %>=" << val_.<%= _m.cxxname %> (); +% 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 %>=" << val_.<%= _m.cxxname %> (); +% 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 %>=" << val_.<%= _m.cxxname %> (); +% else os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ()); +% end } % end % end @@ -38,7 +50,13 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> case <%= _lbl %>: % end { +% if _m.optional? + os_ << "<%= _m.cxxname %>=" << val_.<%= _m.cxxname %> (); +% elsif _m.external? +%# TODO +% else os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ()); +% end } break; % end @@ -48,7 +66,13 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> % if has_default? % _m_def = default_member { +% if _m_def.optional? + os_ << "<%= _m_def.cxxname %>=" << val_.<%= _m_def.cxxname %> (); +% 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/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/except_cdr.erb b/ridlbe/c++11/templates/cli/src/except_cdr.erb index 101c4a14..9dae9820 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_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 % 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_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 % 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 2f285f41..ccdafe2a 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_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 % end % else return true; @@ -24,7 +28,12 @@ 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| +%# <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %> +% if _m.optional? + (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 % end % else return true; diff --git a/ridlbe/c++11/templates/cli/src/union_cdr.erb b/ridlbe/c++11/templates/cli/src/union_cdr.erb index e6a90852..26c1b2c4 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_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 % 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_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 } % if _defmem || !_ndefmem.empty? else { % _m = _defmem || _ndefmem.shift # get other (non-)default member +% if _m.optional? + 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 } % 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_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 } 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_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 } % 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_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 { // 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_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 { // 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_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 { // 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_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 { // 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/ridlbe/c++11/visitorbase.rb b/ridlbe/c++11/visitorbase.rb index 99059e80..bedae155 100644 --- a/ridlbe/c++11/visitorbase.rb +++ b/ridlbe/c++11/visitorbase.rb @@ -473,20 +473,12 @@ def implementation_member_type self._idltype.is_a?(IDL::Type::Any) ? 'CORBA::Any' : scoped_cxx_member_type end - def cdr_to_type - @node._idltype.cdr_to_type(cur_scope) + def cdr_to_helper_type + self._idltype.cdr_to_helper_type end - def cdr_from_type - @node._idltype.cdr_from_type(cur_scope) - end - - def scoped_cdr_to_type - @node._idltype.cdr_to_type - end - - def scoped_cdr_from_type - @node._idltype.cdr_from_type + def cdr_from_helper_type + self._idltype.cdr_from_helper_type end def cdr_from_fmt 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 3092c13f..c6d28249 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,76 @@ 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 + + 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 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 <> diff --git a/tao/x11/optional_cdr_t.h b/tao/x11/optional_cdr_t.h index 37a09326..d08ab0b1 100644 --- a/tao/x11/optional_cdr_t.h +++ b/tao/x11/optional_cdr_t.h @@ -15,8 +15,11 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL /// Generic sequence CDR streaming helper template + template + struct taox11_optional_cdr_in; + template - struct taox11_optional_cdr + struct taox11_optional_cdr_in<_Tp> { /// Unbounded insert template @@ -34,7 +37,36 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL } return result; } + }; + + template + struct taox11_optional_cdr_in<_Tp, _Thelper> + { + /// 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 << _Thelper(_optional.value ()); + } + 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) @@ -47,24 +79,63 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL if (_has_value) { - // initialize associated default value - typename _Tp::value_type temp_val{}; + // If the optional doesn't contain a value initialize it + if (!_optional) _optional.emplace(); // extract - if (_strm >> temp_val) + if (_strm >> _optional.value ()) { - // set union member and associated discriminant when there are multiple legal discriminant values - _optional = std::move (temp_val); return true; } + else + { + return false; + } } else { _optional.reset (); } - return false; + return true; } }; + /// Generic sequence CDR streaming helper template + template + struct taox11_optional_cdr_out<_Tp, _Thelper> + { + /// 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 >> _Thelper(_optional.value ())) + { + return true; + } + else + { + return false; + } + } + else + { + _optional.reset (); + } + return true; + } + }; + + 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 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 diff --git a/tests/idl4/optional/client.cpp b/tests/idl4/optional/client.cpp index 6638c975..e8b77a8e 100644 --- a/tests/idl4/optional/client.cpp +++ b/tests/idl4/optional/client.cpp @@ -10,14 +10,83 @@ #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; + + if (sret.z () != 255) + { + 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; + + TAOX11_TEST_INFO << "f: " << f << std::endl; + TAOX11_TEST_INFO << "to: " << to << 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..e918c246 --- /dev/null +++ b/tests/idl4/optional/foo.cpp @@ -0,0 +1,35 @@ +/** + * @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(255); + sret.z_long(255); + sret.regular8(64); + sret.int8_field(125); + 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/run_test.pl b/tests/idl4/optional/run_test.pl index 1a1bcc10..4dce5db5 100755 --- a/tests/idl4/optional/run_test.pl +++ b/tests/idl4/optional/run_test.pl @@ -1,6 +1,6 @@ #--------------------------------------------------------------------- # @file run_test.pl -# @author Marcel Smit +# @author Johnny Willemsen # # @copyright Copyright (c) Remedy IT Expertise BV #--------------------------------------------------------------------- @@ -13,19 +13,66 @@ use lib "$ENV{ACE_ROOT}/bin"; use PerlACE::TestTarget; -my $target = PerlACE::TestTarget::create_target(2) || die "Create target 2 failed\n"; +my $status = 0; +my $debug_level = '0'; -$status = 0; +foreach $i (@ARGV) { + if ($i eq '-debug') { + $debug_level = '10'; + } +} + +my $server = PerlACE::TestTarget::create_target(2) || die "Create target 2 failed\n"; +my $client = PerlACE::TestTarget::create_target(3) || die "Create target 3 failed\n"; + +my $iorbase = "test.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +my $client_iorfile = $client->LocalFile ($iorbase); +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +my $SV = $server->CreateProcess ("server", "-ORBdebuglevel $debug_level -o $server_iorfile"); +my $CL = $client->CreateProcess ("client", "-ORBdebuglevel $debug_level -k file://$client_iorfile"); +my $server_status = $SV->Spawn (); + +if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; +} + +if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +if ($server->GetFile ($iorbase) == -1) { + print STDERR "ERROR: cannot retrieve file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} +if ($client->PutFile ($iorbase) == -1) { + print STDERR "ERROR: cannot set file <$client_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} -$SV = $target->CreateProcess ("client"); +my $client_status = $CL->SpawnWaitKill ($client->ProcessStartWaitInterval()); + +if ($client_status != 0) { + print STDERR "ERROR: client returned $client_status\n"; + $status = 1; +} -$server = $SV->SpawnWaitKill ($target->ProcessStartWaitInterval()); +$server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); -if ($server != 0) { - print STDERR "ERROR: client returned $server\n"; +if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; $status = 1; } -$target->GetStderrLog(); +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); exit $status; 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..dcc20c0a 100644 --- a/tests/idl4/optional/test.idl +++ b/tests/idl4/optional/test.idl @@ -5,6 +5,13 @@ * @copyright Copyright (c) Remedy IT Expertise BV */ +module Mod +{ + typedef long longF; +}; + +typedef int8 myint8; + struct bar { short x; @@ -12,5 +19,64 @@ struct bar long z_long; @optional short a; @optional string opt_string; + @optional boolean opt_b; + boolean b; string y; + Mod::longF f; + int8 regular8; + @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 Fooexcep +{ + short x; + @optional short z; +}; + +union TestUnion_Octet switch(octet) { + case 1: + @optional short FirstCase; + case 2: + 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; +}; + +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 {