Skip to content

Commit

Permalink
Merge pull request RemedyIT#391 from jwillemsen/jwi-ostreamoptional2
Browse files Browse the repository at this point in the history
Add ostream logging for optional struct members
  • Loading branch information
jwillemsen authored Jun 11, 2024
2 parents 8096477 + c17bc28 commit cca21bd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 5 additions & 4 deletions ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +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
%# << "<%= _sep %><%= _m.cxxname %>=" << (val_.<%= _m.cxxname() %> ().has_value () ? IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ().value ()) : "<empty>")
% else
<< "<%= _sep %><%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ())
% end
% end
% _sep = ',' unless _sep
Expand Down
3 changes: 3 additions & 0 deletions tests/idl4/optional/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion tests/idl4/optional/test.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit cca21bd

Please sign in to comment.