diff --git a/bin/taox11_tests.lst b/bin/taox11_tests.lst index f528de63..dd981231 100644 --- a/bin/taox11_tests.lst +++ b/bin/taox11_tests.lst @@ -88,6 +88,7 @@ tests/idl4/illegal_idl/run_test.pl: tests/idl4/map/run_test.pl: tests/idl4/map/run_illegal_idl3_test.pl: tests/idl4/optional/run_test.pl: +tests/idl4/struct_cppmapping/run_test.pl: tests/idl4/struct_inheritance/run_test.pl: tests/idl4/struct_inheritance/run_illegal_idl3_test.pl: tests/idl4/union/run_test.pl: 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 fc044550..7a96a126 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 @@ -39,7 +39,7 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> % elsif _m.external? %# TODO % else - << "<%= _sep %><%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ()) + << "<%= _sep %><%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %><%= member_accessor %>) % end % end % _sep = ',' unless _sep diff --git a/ridlbe/c++11/templates/cli/hdr/struct_post.erb b/ridlbe/c++11/templates/cli/hdr/struct_post.erb index 98c24c32..a6e71d62 100644 --- a/ridlbe/c++11/templates/cli/hdr/struct_post.erb +++ b/ridlbe/c++11/templates/cli/hdr/struct_post.erb @@ -1,4 +1,5 @@ // generated from <%= ridl_template_path %> +%if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS' <%= cxxname %> () = default; ~<%= cxxname %> () = default; % unless base.nil? @@ -43,9 +44,20 @@ inline void swap (<%= cxx_inout_type %> s); private: +%end % members.each do |_m| - <%= _m.cxx_member_type %> <%= _m.cxxname %>_<%= _m.value_initializer %>; + <%= _m.cxx_member_type %> <%= _m.cxxname %><%= member_postfix %><%= _m.value_initializer %>; % end };// <%= cxxname %> +%if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS' inline void swap (<%= scoped_cxx_out_type %> m1, <%= scoped_cxx_out_type %> m2) { m1.swap (m2); } +%else +inline void swap (<%= scoped_cxx_out_type %> m1, <%= scoped_cxx_out_type %> m2) +{ +%# Add support for base +% members.each do |_m| + std::swap (m1.<%= _m.cxxname %>, m2.<%= _m.cxxname %>); +% end +} +%end diff --git a/ridlbe/c++11/templates/cli/hdr/struct_pre.erb b/ridlbe/c++11/templates/cli/hdr/struct_pre.erb index c318d4f0..12359c07 100644 --- a/ridlbe/c++11/templates/cli/hdr/struct_pre.erb +++ b/ridlbe/c++11/templates/cli/hdr/struct_pre.erb @@ -1,6 +1,8 @@ // generated from <%= ridl_template_path %> /// @copydoc <%= doc_scoped_name %> -class <%= stub_export_macro %><%= cxxname %><% unless base.nil? %> : public <%= base.cxxname %><% end %> +<%= class_struct %> <%= stub_export_macro %><%= cxxname %><% unless base.nil? %> : public <%= base.cxxname %><% end %> { +%if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS' public: +%end diff --git a/ridlbe/c++11/templates/cli/inl/struct_inl.erb b/ridlbe/c++11/templates/cli/inl/struct_inl.erb index c2c5f6da..5e2730d5 100644 --- a/ridlbe/c++11/templates/cli/inl/struct_inl.erb +++ b/ridlbe/c++11/templates/cli/inl/struct_inl.erb @@ -1,3 +1,4 @@ +%if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS' // generated from <%= ridl_template_path %> %# @@ -40,3 +41,4 @@ inline void <%= scoped_cxxtype %>::swap (<%= scoped_cxx_out_type %><% if member_ std::swap (this-><%= _m.cxxname %>_, s.<%= _m.cxxname %>_); % end } +%end diff --git a/ridlbe/c++11/templates/cli/src/struct_cdr.erb b/ridlbe/c++11/templates/cli/src/struct_cdr.erb index ccdafe2a..104f84f7 100644 --- a/ridlbe/c++11/templates/cli/src/struct_cdr.erb +++ b/ridlbe/c++11/templates/cli/src/struct_cdr.erb @@ -12,7 +12,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &<% if member_count > 0 || !base.ni % 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 ) ? ' &&' : ';') %> + (strm << <%= _m.cdr_from_fmt % "_tao_aggregate.#{_m.cxxname}#{member_accessor}" %>)<%= ((_i < _n ) ? ' &&' : ';') %> % end % end % else @@ -32,7 +32,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &<% if member_count > 0 || !base.nil % 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) ? ' &&' : ';') %> + (strm >> <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname}#{member_accessor}" %>)<%= ((_i < _n) ? ' &&' : ';') %> % end % end % else diff --git a/ridlbe/c++11/visitors/struct.rb b/ridlbe/c++11/visitors/struct.rb index c9ddd0b9..7d7febf8 100644 --- a/ridlbe/c++11/visitors/struct.rb +++ b/ridlbe/c++11/visitors/struct.rb @@ -34,6 +34,30 @@ def base node.base end + # Which cpp_mapping we should use, default to class with methods + def cpp_mapping + return 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS' if node.annotations[:cpp_mapping].first.nil? + node.annotations[:cpp_mapping].first.fields[:value] + end + + # How can we access a struct member, directly or through a method call + def member_accessor + return ' ()' if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS' + '' + end + + # Possible postfix for all members in C++ + def member_postfix + return '_' if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS' + '' + end + + # Do we map to a C++ class or struct + def class_struct + return 'class' if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS' + 'struct' + end + # template mapping map_template :typecode, :typecode diff --git a/tests/idl4/struct_cppmapping/client.cpp b/tests/idl4/struct_cppmapping/client.cpp new file mode 100644 index 00000000..5523b5f0 --- /dev/null +++ b/tests/idl4/struct_cppmapping/client.cpp @@ -0,0 +1,22 @@ +/** + * @file client.cpp + * @author Johnny Willemsen + * + * @brief CORBA C++11 client application + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ + +#include "testC.h" +#include "testlib/taox11_testlog.h" + +int main (int /*argc*/, char* /*argv*/[]) +{ + bar_struct bs1; + bar_class bc1; + + // Just compilation test + TAOX11_TEST_INFO << "bs1: " << bs1 << std::endl; + + return 0; +} diff --git a/tests/idl4/struct_cppmapping/run_test.pl b/tests/idl4/struct_cppmapping/run_test.pl new file mode 100755 index 00000000..1a1bcc10 --- /dev/null +++ b/tests/idl4/struct_cppmapping/run_test.pl @@ -0,0 +1,31 @@ +#--------------------------------------------------------------------- +# @file run_test.pl +# @author Marcel Smit +# +# @copyright Copyright (c) Remedy IT Expertise BV +#--------------------------------------------------------------------- +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# -*- perl -*- + +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::TestTarget; + +my $target = PerlACE::TestTarget::create_target(2) || die "Create target 2 failed\n"; + +$status = 0; + +$SV = $target->CreateProcess ("client"); + +$server = $SV->SpawnWaitKill ($target->ProcessStartWaitInterval()); + +if ($server != 0) { + print STDERR "ERROR: client returned $server\n"; + $status = 1; +} + +$target->GetStderrLog(); + +exit $status; diff --git a/tests/idl4/struct_cppmapping/test.idl b/tests/idl4/struct_cppmapping/test.idl new file mode 100644 index 00000000..12e9f425 --- /dev/null +++ b/tests/idl4/struct_cppmapping/test.idl @@ -0,0 +1,16 @@ +/** + * @file test.idl + * @author Johnny Willemsen + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ + +@cpp_mapping(STRUCT_WITH_PUBLIC_MEMBERS) +struct bar_struct { + short b; +}; + +@cpp_mapping(CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS) +struct bar_class { + short b; +}; diff --git a/tests/idl4/struct_cppmapping/test.mpc b/tests/idl4/struct_cppmapping/test.mpc new file mode 100644 index 00000000..7077d2f1 --- /dev/null +++ b/tests/idl4/struct_cppmapping/test.mpc @@ -0,0 +1,20 @@ +// -*- MPC -*- + +project(*structmap_gen_idl): ridl_ostream_defaults { + IDL_Files { + test.idl + idlflags += --idl-version=4 + } + custom_only = 1 +} + +project(*structmap_client): taox11_client { + after += *structmap_gen_idl + Source_Files { + client.cpp + } + Source_Files { + testC.cpp + } +} +