Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental support for CORBA CDR support for the IDL4 optional annotation #386

Merged
merged 7 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ridlbe/c++11/templates/cli/prx/struct_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,26 @@ 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
2 changes: 1 addition & 1 deletion ridlbe/c++11/templates/cli/src/union_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// generated from <%= ridl_template_path %>
TAO_CORBA::Boolean operator<< (TAO_OutputCDR &strm, const <%= scoped_cxxname %> &_tao_union)
{
if (!(strm <<<%= switchtype.cdr_from_fmt % "_tao_union._d ()" %>))
if (!(strm << <%= switchtype.cdr_from_fmt % "_tao_union._d ()" %>))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion ridlbe/c++11/visitors/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def cxx_out_type

def cxx_in_type
if optional?
"const IDL::optional<#{super}>&"
"const IDL::optional<#{cxx_return_type}>&"
elsif external?
"const std::shared_ptr<#{super}>&"
else
Expand Down
1 change: 1 addition & 0 deletions ridlbe/c++11/writers/stubproxyheader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def enter_struct(node)

add_include('tao/x11/basic_argument_t.h')
node.members.each { |m| check_idl_type(m.idltype) }
node.members.each { |m| add_include('tao/x11/optional_cdr_t.h') if !m.annotations[:optional].first.nil? }
end

def enter_union(node)
Expand Down
2 changes: 0 additions & 2 deletions tao/x11/base/bounded_map_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ namespace TAOX11_NAMESPACE
using size_type = typename _Map::size_type;
using difference_type = typename _Map::difference_type;
using allocator_type = typename _Map::allocator_type;
#if defined (ACE_HAS_CPP17)
using node_type = typename _Map::node_type;
using insert_return_type = typename _Map::insert_return_type;
#endif /* ACE_HAS_CPP17 */

using bound = std::integral_constant<uint32_t, _Bound>;

Expand Down
70 changes: 70 additions & 0 deletions tao/x11/optional_cdr_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* @file optional_cdr_t.h
* @author Johnny Willemsen
*
* @brief x11 optional marshaling templates
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

#ifndef TAOX11_OPTIONAL_CDR_T_H_INCLUDED
#define TAOX11_OPTIONAL_CDR_T_H_INCLUDED

#include "tao/x11/base/tao_corba.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

/// Generic sequence CDR streaming helper template
template <typename _Tp>
struct taox11_optional_cdr
{
/// Unbounded insert
template <typename _Stream>
static bool insert (_Stream& _strm, const _Tp& _optional)
{
if (!(_strm << ACE_OutputCDR::from_boolean (_optional.has_value ())))
{
return false;
}

bool result { true };
if (_optional.has_value ())
{
result = _strm << _optional.value ();
}
return result;
}

/// Unbounded extract
template <typename _Stream>
static bool extract (_Stream& _strm, _Tp& _optional)
{
bool _has_value{};
if (!(_strm >> ACE_InputCDR::to_boolean (_has_value)))
{
return false;
}

if (_has_value)
{
// initialize associated default value
typename _Tp::value_type temp_val{};
// extract
if (_strm >> temp_val)
{
// set union member and associated discriminant when there are multiple legal discriminant values
_optional = std::move (temp_val);
return true;
}
}
else
{
_optional.reset ();
}
return false;
}
};

TAO_END_VERSIONED_NAMESPACE_DECL

#endif // TAOX11_OPTIONAL_CDR_T_H_INCLUDED
20 changes: 1 addition & 19 deletions tao/x11/optional_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @file optional_t.h
* @author Johnny Willemsen
*
* @brief template for IDL4 optional annotaiton
* @brief template for IDL4 optional annotation
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/
Expand All @@ -14,8 +14,6 @@
#include <optional>
#include "tao/x11/base/versioned_x11_namespace.h"

#if defined (ACE_HAS_CPP17)

namespace TAOX11_NAMESPACE
{
namespace IDL
Expand All @@ -25,20 +23,4 @@ namespace TAOX11_NAMESPACE
} // namespace IDL
} // namespace TAOX11_NAMESPACE

#else

namespace TAOX11_NAMESPACE
{
namespace IDL
{
template<typename T>
class optional
{
public:
T value_;
};
}
}
#endif

#endif // __IDL__OPTIONAL_T_H_INCLUDED__
4 changes: 0 additions & 4 deletions tao/x11/portable_server/operation_table_std_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ class TAOX11_PortableServer_Export Std_Map_OpTable final
const TAO::Operation_Skeletons skel_ptr) override;

private:
#if defined (ACE_HAS_CPP17)
using key_map_type = std::string_view ;
#else
using key_map_type = std::string ;
#endif /* ACE_HAS_CPP17 */

using map_type = std::unordered_map<key_map_type, TAO::Operation_Skeletons>;

Expand Down
2 changes: 2 additions & 0 deletions tao/x11/taox11.mpc
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ project(taox11) : taox11_defaults, taolib {
object_ostream.h
object_traits_t.h
objproxy.h
optional_t.h
optional_cdr_t.h
orb.h
orb_constants.h
orb_registry.h
Expand Down
3 changes: 2 additions & 1 deletion tests/idl4/optional/test.idl
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ struct bar
short x;
string y;
@optional short z;
@optional short a;
@optional string opt_string;
};

2 changes: 1 addition & 1 deletion tests/idl4/optional/test.mpc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
project(*optional_gen_idl): ridl_ostream_defaults {
IDL_Files {
test.idl
idlflags += --idl-version=4 -Scdr
idlflags += --idl-version=4
}
custom_only = 1
}
Expand Down
2 changes: 0 additions & 2 deletions tests/interface/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ int main(int argc, char* argv[])
IDL::traits<CORBA::Object>::ref_type obj2;
std::swap (obj, obj2);
std::swap (obj, obj2);
#if defined (ACE_HAS_CPP17)
if (!std::is_swappable<IDL::traits<CORBA::Object>::ref_type>())
{
TAOX11_TEST_ERROR << "ERROR: IDL::traits<CORBA::Object>::ref_type is not swappable." << std::endl;
Expand All @@ -71,7 +70,6 @@ int main(int argc, char* argv[])
{
TAOX11_TEST_DEBUG << "IDL::traits<CORBA::Object>::ref_type is swappable." << std::endl;
}
#endif /* ACE_HAS_CPP17 */

if (!test_nil_invocation())
++result;
Expand Down
2 changes: 0 additions & 2 deletions tests/struct/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ int main(int argc, char* argv[])
V s5;
V s6;
test_swap (s5, s6);
#if defined (ACE_HAS_CPP17)
if (!std::is_swappable<V>())
{
TAOX11_TEST_ERROR << "ERROR: V is not swappable." << std::endl;
Expand All @@ -116,7 +115,6 @@ int main(int argc, char* argv[])
{
TAOX11_TEST_DEBUG << "V is swappable." << std::endl;
}
#endif /* ACE_HAS_CPP17 */

TAOX11_TEST_DEBUG << "successfully called Foo::update_struct (" << simple3 << ") => " << simple4 << std::endl;

Expand Down
2 changes: 0 additions & 2 deletions tests/union/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ test_data_union (IDL::traits<Test::Foo>::ref_type foo)
data.pointData (Test::Point (12, 34));
retval += check_union (data, Test::DataType::dtPoint, "before pass_union");

#if defined (ACE_HAS_CPP17)
if (!std::is_swappable<Test::Data>())
{
TAOX11_TEST_ERROR << "ERROR: V is not swappable." << std::endl;
Expand All @@ -36,7 +35,6 @@ test_data_union (IDL::traits<Test::Foo>::ref_type foo)
{
TAOX11_TEST_DEBUG << "Test::Data is swappable." << std::endl;
}
#endif /* ACE_HAS_CPP17 */

if (foo->pass_union (data))
{
Expand Down
Loading