1 #ifndef guard_unbounded_array_sequence_hpp
2 #define guard_unbounded_array_sequence_hpp
6 * @brief Implement unbounded sequences for arrays.
8 * @author Carlos O'Ryan
10 #include "tao/Unbounded_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
>
19 class unbounded_array_sequence
22 typedef T_array
* element_type
;
23 typedef T_array value_type
;
24 typedef T_slice
* T_slice_ptr
;
25 typedef T_slice
* slice_type
;
26 typedef T_slice_ptr
* const_value_type
;
27 typedef value_type
& subscript_type
;
28 typedef value_type
const & const_subscript_type
;
29 typedef ::CORBA::ULong size_type
;
31 typedef details::unbounded_array_allocation_traits
<value_type
,true> allocation_traits
;
32 typedef TAO_Array_Forany_T
<T_array
, T_slice
, T_tag
> forany
;
33 typedef details::array_traits
<forany
> element_traits
;
34 typedef details::generic_sequence
<value_type
, allocation_traits
, element_traits
> implementation_type
;
36 inline unbounded_array_sequence()
39 inline explicit unbounded_array_sequence(CORBA::ULong maximum
)
42 inline unbounded_array_sequence(
46 CORBA::Boolean release
= false)
47 : impl_(maximum
, length
, data
, release
)
49 inline CORBA::ULong
maximum() const {
50 return impl_
.maximum();
52 inline CORBA::Boolean
release() const {
53 return impl_
.release();
55 inline CORBA::ULong
length() const {
56 return impl_
.length();
58 inline void length(CORBA::ULong length
) {
61 inline value_type
const & operator[](CORBA::ULong i
) const {
64 inline value_type
& operator[](CORBA::ULong i
) {
71 CORBA::Boolean release
= false) {
72 impl_
.replace(maximum
, length
, data
, release
);
74 inline value_type
const * get_buffer() const {
75 return impl_
.get_buffer();
77 inline value_type
* get_buffer(CORBA::Boolean orphan
= false) {
78 return impl_
.get_buffer(orphan
);
80 inline void swap(unbounded_array_sequence
& rhs
) noexcept
{
81 impl_
.swap(rhs
.impl_
);
83 static value_type
* allocbuf(CORBA::ULong maximum
) {
84 return implementation_type::allocbuf(maximum
);
86 static void freebuf(value_type
* buffer
) {
87 implementation_type::freebuf(buffer
);
91 implementation_type impl_
;
97 template <typename stream
, typename T_array
, typename T_slice
, typename T_tag
>
98 bool demarshal_sequence(stream
& strm
, TAO::unbounded_array_sequence
<T_array
, T_slice
, T_tag
> & target
) {
99 typedef TAO::unbounded_array_sequence
<T_array
, T_slice
, T_tag
> sequence
;
100 typedef TAO_Array_Forany_T
<T_array
, T_slice
, T_tag
> forany
;
101 typedef TAO::Array_Traits
<forany
> array_traits
;
103 ::CORBA::ULong new_length
= 0;
104 if (!(strm
>> new_length
)) {
107 if (new_length
> strm
.length()) {
110 sequence
tmp(new_length
);
111 tmp
.length(new_length
);
112 typename
sequence::value_type
* buffer
= tmp
.get_buffer();
113 for(CORBA::ULong i
= 0; i
< new_length
; ++i
) {
114 forany
tmp (array_traits::alloc ());
115 bool const _tao_marshal_flag
= (strm
>> tmp
);
116 if (_tao_marshal_flag
) {
117 array_traits::copy (buffer
[i
], tmp
.in ());
119 array_traits::free (tmp
.inout ());
120 if (!_tao_marshal_flag
) {
128 template <typename stream
, typename T_array
, typename T_slice
, typename T_tag
>
129 bool marshal_sequence(stream
& strm
, const TAO::unbounded_array_sequence
<T_array
, T_slice
, T_tag
> & source
) {
130 typedef TAO_FixedArray_Var_T
<T_array
, T_slice
, T_tag
> fixed_array
;
131 typedef TAO_Array_Forany_T
<T_array
, T_slice
, T_tag
> forany
;
132 typedef TAO::Array_Traits
<forany
> array_traits
;
133 ::CORBA::ULong
const length
= source
.length ();
134 if (!(strm
<< length
)) {
137 for(CORBA::ULong i
= 0; i
< length
; ++i
) {
138 fixed_array tmp_array
= array_traits::dup (source
[i
]);
139 forany
const tmp (tmp_array
.inout ());
140 if (!(strm
<< tmp
)) {
148 TAO_END_VERSIONED_NAMESPACE_DECL
150 #endif // guard_unbounded_array_sequence_hpp