1 #ifndef guard_bounded_array_sequence_hpp
2 #define guard_bounded_array_sequence_hpp
6 * @brief Implement unbounded sequences for arrays.
8 * @author Carlos O'Ryan
10 #include "tao/Bounded_Array_Allocation_Traits_T.h"
11 #include "tao/Generic_Sequence_T.h"
12 #include "tao/Array_Traits_T.h"
14 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
18 template<typename T_array
, typename T_slice
, typename T_tag
, CORBA::ULong MAX
>
19 class bounded_array_sequence
22 typedef T_array
* element_type
;
23 typedef T_array value_type
;
24 typedef T_array
* T_slice_ptr
;
25 typedef T_slice_ptr
* const_value_type
;
26 typedef value_type
& subscript_type
;
27 typedef value_type
const & const_subscript_type
;
28 typedef ::CORBA::ULong size_type
;
30 typedef details::bounded_array_allocation_traits
<value_type
,MAX
,true> allocation_traits
;
31 typedef TAO_Array_Forany_T
<T_array
, T_slice
, T_tag
> forany
;
32 typedef details::array_traits
<forany
> element_traits
;
33 typedef details::generic_sequence
<value_type
, allocation_traits
, element_traits
> implementation_type
;
35 inline bounded_array_sequence()
38 inline bounded_array_sequence(
41 CORBA::Boolean release
= false)
42 : impl_(MAX
, length
, data
, release
)
44 inline CORBA::ULong
maximum() const {
45 return impl_
.maximum();
47 inline CORBA::Boolean
release() const {
48 return impl_
.release();
50 inline CORBA::ULong
length() const {
51 return impl_
.length();
53 inline void length(CORBA::ULong length
) {
54 implementation_type::range::check_length(length
, MAX
);
57 inline value_type
const & operator[](CORBA::ULong i
) const {
60 inline value_type
& operator[](CORBA::ULong i
) {
66 CORBA::Boolean release
= false) {
67 impl_
.replace(MAX
, length
, data
, release
);
69 inline value_type
const * get_buffer() const {
70 return impl_
.get_buffer();
72 inline value_type
* get_buffer(CORBA::Boolean orphan
= false) {
73 return impl_
.get_buffer(orphan
);
75 inline void swap(bounded_array_sequence
& rhs
) noexcept
{
76 impl_
.swap(rhs
.impl_
);
78 static value_type
* allocbuf(CORBA::ULong maximum
) {
79 return implementation_type::allocbuf(maximum
);
81 static value_type
* allocbuf() {
82 return implementation_type::allocbuf(MAX
);
84 static void freebuf(value_type
* buffer
) {
85 implementation_type::freebuf(buffer
);
89 implementation_type impl_
;
95 template <typename stream
, typename T_array
, typename T_slice
, typename T_tag
, CORBA::ULong MAX
>
96 bool demarshal_sequence (stream
&strm
, TAO::bounded_array_sequence
<T_array
, T_slice
, T_tag
, MAX
> &target
) {
97 typedef typename
TAO::bounded_array_sequence
<T_array
, T_slice
, T_tag
, MAX
> sequence
;
98 typedef TAO_Array_Forany_T
<T_array
, T_slice
, T_tag
> forany
;
99 typedef TAO::Array_Traits
<forany
> array_traits
;
101 ::CORBA::ULong new_length
= 0;
102 if (!(strm
>> new_length
))
106 if ((new_length
> strm
.length ()) || (new_length
> target
.maximum ()))
111 tmp
.length (new_length
);
112 typename
sequence::value_type
*const buffer
= tmp
.get_buffer ();
113 for (CORBA::ULong i
= 0; i
< new_length
; ++i
)
115 forany
wrapper (array_traits::alloc ());
116 bool const _tao_marshal_flag
= strm
>> wrapper
;
117 if (_tao_marshal_flag
)
119 array_traits::copy (buffer
[i
], wrapper
.in ());
121 array_traits::free (wrapper
.inout ());
122 if (!_tao_marshal_flag
)
131 template <typename stream
, typename T_array
, typename T_slice
, typename T_tag
, CORBA::ULong MAX
>
132 bool marshal_sequence(stream
& strm
, const TAO::bounded_array_sequence
<T_array
, T_slice
, T_tag
, MAX
> & source
) {
133 typedef TAO_Array_Forany_T
<T_array
, T_slice
, T_tag
> forany
;
134 typedef TAO_FixedArray_Var_T
<T_array
, T_slice
, T_tag
> fixed_array
;
135 typedef TAO::Array_Traits
<forany
> array_traits
;
136 ::CORBA::ULong
const length
= source
.length ();
137 if (length
> source
.maximum () || !(strm
<< length
)) {
140 for(CORBA::ULong i
= 0; i
< length
; ++i
) {
141 fixed_array tmp_array
= array_traits::dup (source
[i
]);
142 forany
tmp (tmp_array
.inout ());
143 if (!(strm
<< tmp
)) {
151 TAO_END_VERSIONED_NAMESPACE_DECL
153 #endif // guard_bounded_array_sequence_hpp