From 6b9a431d9da2e8d70f49ce86f84f63bc7e196560 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Tue, 11 Jun 2024 11:56:05 +0200 Subject: [PATCH 1/2] Add ostream formatting for optional * ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb: * tests/idl4/optional/client.cpp: * tests/idl4/optional/test.idl: --- ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb | 3 +-- tests/idl4/optional/client.cpp | 3 +++ tests/idl4/optional/test.idl | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) 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 4892e0fc..d0018b8c 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 @@ -37,8 +37,7 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> % unless _m.optional? || _m.external? << "<%= _sep %><%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ()) % else -%# TODO -%# << "<%= _sep %><%= _m.cxxname %>=" << (val_.<%= _m.cxxname() %> ().has_value () ? IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ().value ()) : "") + << "<%= _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_ % end % end % _sep = ',' unless _sep diff --git a/tests/idl4/optional/client.cpp b/tests/idl4/optional/client.cpp index 71c79c4c..6638c975 100644 --- a/tests/idl4/optional/client.cpp +++ b/tests/idl4/optional/client.cpp @@ -16,5 +16,8 @@ int main (int /*argc*/, char* /*argv*/[]) bar mybar; TAOX11_TEST_INFO << "mybar: " << mybar << std::endl; + mybar.z(6); + TAOX11_TEST_INFO << "mybar: " << mybar << std::endl; + return retval; } diff --git a/tests/idl4/optional/test.idl b/tests/idl4/optional/test.idl index e47e3521..d24815a0 100644 --- a/tests/idl4/optional/test.idl +++ b/tests/idl4/optional/test.idl @@ -8,8 +8,9 @@ struct bar { short x; - string y; @optional short z; + long z_long; @optional short a; @optional string opt_string; + string y; }; From 0cbcabd3a8b24d6106989298f65464f891d0df22 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Tue, 11 Jun 2024 14:12:03 +0200 Subject: [PATCH 2/2] External needs some additional logic later * ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb: --- ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 d0018b8c..87a27231 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,10 +34,12 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_> << "object}" % end % else -% unless _m.optional? || _m.external? - << "<%= _sep %><%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ()) -% 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_ +% elsif _m.external? +%# TODO +% else + << "<%= _sep %><%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ()) % end % end % _sep = ',' unless _sep