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 9e562604..e72af613 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 @@ -34,7 +34,10 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> << "object}" % end % else +% unless _m.optional? +%# TODO Add optional support << "<%= _sep %><%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ()) +% end % end % _sep = ',' unless _sep % end diff --git a/ridlbe/c++11/visitors/struct.rb b/ridlbe/c++11/visitors/struct.rb index 4c44efca..ea6eab15 100644 --- a/ridlbe/c++11/visitors/struct.rb +++ b/ridlbe/c++11/visitors/struct.rb @@ -73,6 +73,66 @@ def value_initializer _resolved_idltype.zero_initializer end end + + def optional? + !node.annotations[:optional].first.nil? + end + + def is_reference? + if optional? + false + else + super + end + end + + def is_pod? + if optional? + false + else + super + end + end + + def cxx_byval_type + unless optional? + super + else + "std::optional<#{cxx_return_type}>" + end + end + + def cxx_out_type + unless optional? + super + else + "std::optional<#{cxx_return_type}>&" + end + end + + def cxx_in_type + unless optional? + super + else + "const std::optional<#{super}>&" + end + end + + def cxx_move_type + unless optional? + super + else + "std::optional<#{cxx_return_type}>&&" + end + end + + def cxx_member_type + unless optional? + super + else + "std::optional<#{super}>" + end + end end end end diff --git a/ridlbe/c++11/writers/stubheader.rb b/ridlbe/c++11/writers/stubheader.rb index 5b91a042..220fb0a9 100644 --- a/ridlbe/c++11/writers/stubheader.rb +++ b/ridlbe/c++11/writers/stubheader.rb @@ -407,6 +407,7 @@ def visit_valuebox(node) def enter_struct(node) node.members.each { |m| check_idl_type(m.idltype) } + node.members.each { |m| add_post_include('optional') if member_optional(m) } end def enter_union(node) @@ -446,6 +447,10 @@ def visit_typedef(node) private + def member_optional(node) + !node.annotations[:optional].first.nil? + end + def check_idl_type(idl_type) idl_type = idl_type.resolved_type case idl_type diff --git a/tests/idl4/optional/client.cpp b/tests/idl4/optional/client.cpp new file mode 100644 index 00000000..71c79c4c --- /dev/null +++ b/tests/idl4/optional/client.cpp @@ -0,0 +1,20 @@ +/** + * @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*/[]) +{ + int retval {}; + bar mybar; + + TAOX11_TEST_INFO << "mybar: " << mybar << std::endl; + return retval; +} diff --git a/tests/idl4/optional/run_test.pl b/tests/idl4/optional/run_test.pl new file mode 100755 index 00000000..82d03efe --- /dev/null +++ b/tests/idl4/optional/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: const returned $server\n"; + $status = 1; +} + +$target->GetStderrLog(); + +exit $status; diff --git a/tests/idl4/optional/test.idl b/tests/idl4/optional/test.idl new file mode 100644 index 00000000..5afcbc71 --- /dev/null +++ b/tests/idl4/optional/test.idl @@ -0,0 +1,14 @@ +/** + * @file test.idl + * @author Johnny Willemsen + * + * @copyright Copyright (c) Remedy IT Expertise BV + */ + +struct bar +{ + short x; + string y; + @optional short z; +}; + diff --git a/tests/idl4/optional/test.mpc b/tests/idl4/optional/test.mpc new file mode 100644 index 00000000..0607b3c3 --- /dev/null +++ b/tests/idl4/optional/test.mpc @@ -0,0 +1,20 @@ +// -*- MPC -*- + +project(*optional_gen_idl): ridl_ostream_defaults { + IDL_Files { + test.idl + idlflags += --idl-version=4 -Scdr + } + custom_only = 1 +} + +project(*optional_client): taox11_client { + after += *optional_gen_idl + Source_Files { + client.cpp + } + Source_Files { + testC.cpp + } +} +