Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked optional supported for union/struct/exception #399

Merged
merged 8 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 62 additions & 14 deletions ridlbe/c++11/config/cxx_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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?
Expand All @@ -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
Expand Down
26 changes: 25 additions & 1 deletion ridlbe/c++11/templates/cli/hdr/union_idl_traits_def.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,7 +50,13 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_>
case <%= _lbl %>:
% 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"; }
% elsif _m.external?
%# TODO
% else
os_ << "<%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write (val_.<%= _m.cxxname %> ());
% end
}
break;
% end
Expand All @@ -48,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;
Expand Down
21 changes: 0 additions & 21 deletions ridlbe/c++11/templates/cli/prx/struct_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 9 additions & 2 deletions ridlbe/c++11/templates/cli/src/except_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions ridlbe/c++11/templates/cli/src/struct_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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%>, <%= _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
return true;
Expand All @@ -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<<%= _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
return true;
Expand Down
36 changes: 36 additions & 0 deletions ridlbe/c++11/templates/cli/src/union_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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 %>);
Expand All @@ -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 %>);
Expand All @@ -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 %>);
Expand All @@ -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 %>);
Expand Down
Loading