Skip to content

Commit

Permalink
Merge pull request #310 from jwillemsen/jwi-tinyshortcdr
Browse files Browse the repository at this point in the history
Add (u)int8 CDR support
  • Loading branch information
jwillemsen authored Aug 10, 2023
2 parents 72260c7 + 264be31 commit 4583344
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 13 deletions.
8 changes: 2 additions & 6 deletions ridlbe/c++11/templates/cli/prx/array_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL
//@{
inline TAO_CORBA::Boolean operator<< (TAO_OutputCDR &cdr, const IDL::traits<<%= scoped_cxxtype %>>::value_type &v)
{
return taox11_array_cdr<<%= cxxdim_sizes.size-1 %>U,
<%= scoped_cxxtype %>::value_type,
<%= cxxdim_sizes.first %>>::insert (cdr, v);
return taox11_array_cdr<<%= cxxdim_sizes.size-1 %>U, <%= scoped_cxxtype %>::value_type, <%= cxxdim_sizes.first %>>::insert (cdr, v);
}
inline TAO_CORBA::Boolean operator>> (TAO_InputCDR &cdr, IDL::traits<<%= scoped_cxxtype %>>::value_type& v)
{
return taox11_array_cdr<<%= cxxdim_sizes.size-1 %>U,
<%= scoped_cxxtype %>::value_type,
<%= cxxdim_sizes.first %>>::extract (cdr, v);
return taox11_array_cdr<<%= cxxdim_sizes.size-1 %>U, <%= scoped_cxxtype %>::value_type, <%= cxxdim_sizes.first %>>::extract (cdr, v);
}
//@}

Expand Down
12 changes: 6 additions & 6 deletions ridlbe/c++11/templates/cli/src/union_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ TAO_CORBA::Boolean operator<< (
% if (_defmem && _ndefmem.empty?) || (!_ndefmem.empty? && _ndefmem.first.labels.size>1)
% # in these cases there is only a single member mapping all labels
% _m = _defmem || _ndefmem.shift
result = strm <<<%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>;
result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>;
% else
% # here we have 1 or 2 nondef members with or without a default
% _m = _ndefmem.shift # get first non-default member
% _lbl = _m.labels.first
if (<%= _lbl == 'false' ? '!' : '' %>_tao_union._d ())
{
result = strm <<<%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>;
result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>;
}
% if _defmem || !_ndefmem.empty?
else
{
% _m = _defmem || _ndefmem.shift # get other (non-)default member
result = strm <<<%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>;
result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>;
}
% end
% end
Expand All @@ -42,7 +42,7 @@ TAO_CORBA::Boolean operator<< (
case <%= _lbl %>:
% end
{
result = strm <<<%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>;
result = strm << <%= _m.cdr_from_fmt % "_tao_union.#{_m.cxxname} ()" %>;
}
break;
% end
Expand All @@ -52,7 +52,7 @@ TAO_CORBA::Boolean operator<< (
% if has_default?
% _m_def = default_member
{
result = strm <<<%= _m_def.cdr_from_fmt % "_tao_union.#{_m_def.cxxname} ()" %>;
result = strm << <%= _m_def.cdr_from_fmt % "_tao_union.#{_m_def.cxxname} ()" %>;
}
% end
break;
Expand All @@ -66,7 +66,7 @@ TAO_CORBA::Boolean operator>> (
TAO_InputCDR &strm,
<%= scoped_cxxname %> &_tao_union)
{
<%= scoped_switch_cxxtype %> _tao_discriminant;
<%= scoped_switch_cxxtype %> _tao_discriminant<%= switchtype.zero_initializer %>;
if (!(strm >> <%= switchtype.cdr_to_fmt % "_tao_discriminant" %>))
{
return false;
Expand Down
21 changes: 21 additions & 0 deletions tao/x11/array_cdr_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL
}
};

/// TinyShort array specialization
template <const std::size_t _Nm>
struct taox11_array_cdr<0U, int8_t, _Nm>
{
template <typename _Stream>
static inline bool insert (
_Stream& strm ,
const std::array<int8_t, _Nm>& _v)
{
return strm.write_int8_array (_v.data (), _Nm);
}

template <typename _Stream>
static inline bool extract (
_Stream& strm ,
std::array<int8_t, _Nm>& _v)
{
return strm.read_int8_array (_v.data (), _Nm);
}
};

/// Short array specialization
template <const std::size_t _Nm>
struct taox11_array_cdr<0U, int16_t, _Nm>
Expand Down
82 changes: 82 additions & 0 deletions tao/x11/sequence_cdr_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,88 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL
}
};

/// TinyShort sequence CDR streaming helper template
template <>
struct taox11_sequence_cdr<int8_t>
{
/// Unbounded insert
template <typename _Stream>
static inline bool insert (
_Stream& _strm,
const std::vector<int8_t>& _seq)
{
uint32_t const length = ACE_Utils::truncate_cast<uint32_t> (_seq.size ());

if (!(_strm << length))
{
return false;
}

return _strm.write_int8_array (_seq.data (), length);
}

/// Bounded insert
template <const uint32_t _Bound, typename _Stream>
static inline bool insert (
_Stream& _strm,
const TAOX11_IDL::bounded_vector<int8_t, _Bound>& _seq)
{
uint32_t const length = ACE_Utils::truncate_cast<uint32_t> (_seq.size ());

if (_Bound && length > _Bound)
{
throw TAO_CORBA::BAD_PARAM ();
}

return insert<_Stream> (_strm, _seq);
}

/// Unbounded extract
template <typename _Stream>
static inline bool extract (
_Stream& _strm,
std::vector<int8_t>& _seq)
{
uint32_t length {};

if (!(_strm >> length))
{
return false;
}

std::vector<int8_t> _new_seq (length);
if (!_strm.read_int8_array (_new_seq.data (), length))
return false;
_seq.swap (_new_seq);
return true;
}

/// Bounded extract
template <const uint32_t _Bound, typename _Stream>
static inline bool extract (
_Stream& _strm,
TAOX11_IDL::bounded_vector<int8_t, _Bound>& _seq)
{
uint32_t length {};

if (!(_strm >> length))
{
return false;
}

if (_Bound && length > _Bound)
{
throw TAO_CORBA::BAD_PARAM ();
}

std::vector<int8_t> _new_seq (length);
if (!_strm.read_int8_array (_new_seq.data (), length))
return false;
_seq.swap (_new_seq);
return true;
}
};

/// Short sequence CDR streaming helper template
template <>
struct taox11_sequence_cdr<int16_t>
Expand Down
2 changes: 1 addition & 1 deletion tests/idl4/explicit_ints/explicit_ints.mpc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
project(*explicit_ints_gen_Idl): ridl_defaults {
IDL_Files {
test.idl
idlflags += --idl-version=4 -Scdr
idlflags += --idl-version=4
}
custom_only = 1
}
Expand Down

0 comments on commit 4583344

Please sign in to comment.