Skip to content

Commit

Permalink
Merge pull request #400 from jwillemsen/jwi-optionaltest2
Browse files Browse the repository at this point in the history
IDL optional support
  • Loading branch information
jwillemsen authored Sep 10, 2024
2 parents c0945bd + e83a505 commit 2845dd7
Show file tree
Hide file tree
Showing 20 changed files with 733 additions and 85 deletions.
86 changes: 66 additions & 20 deletions ridlbe/c++11/config/cxx_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

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

Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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?
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 %>=" << 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
Expand All @@ -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
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 %>=" << 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;
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_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
Expand All @@ -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
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_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;
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_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;
Expand Down
Loading

0 comments on commit 2845dd7

Please sign in to comment.