1 #ifndef guard_vector_cdr
2 #define guard_vector_cdr
6 * @brief CDR (de)marshaling for std::vector
13 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
19 marshal_value_vector (
21 const std::vector
<T
> &source
)
23 ::CORBA::ULong
const length
= source
.size ();
25 if (! (strm
<< length
))
30 for (typename
std::vector
<T
>::const_iterator iter
=
32 iter
!= source
.end ();
35 if (! (strm
<< *iter
))
46 demarshal_value_vector (
48 std::vector
<T
> &target
)
50 ::CORBA::ULong new_length
= 0;
52 if (! (strm
>> new_length
))
57 if (new_length
> strm
.length ())
63 tmp
.reserve (new_length
);
66 for ( ::CORBA::ULong i
= 0; i
< new_length
; ++i
)
68 if (! (strm
>> tmp_elem
))
82 marshal_objref_vector (
84 const std::vector
<typename
T::_ptr_type
> &source
)
86 ::CORBA::ULong
const length
= source
.size ();
88 if (! (strm
<< length
))
93 for (typename
std::vector
<typename
T::_ptr_type
>::const_iterator i
=
98 if (! (TAO::Objref_Traits
<T
>::marshal (*i
, strm
)))
109 demarshal_objref_vector (
111 std::vector
<typename
T::_ptr_type
> &target
)
113 ::CORBA::ULong new_length
= 0;
115 if (! (strm
>> new_length
))
120 if (new_length
> strm
.length ())
125 std::vector
<typename
T::_ptr_type
> tmp
;
126 tmp
.reserve (new_length
);
127 typename
T::_ptr_type tmp_elem
= T::_nil ();
129 for ( ::CORBA::ULong i
= 0; i
< new_length
; ++i
)
131 if (! (strm
>> tmp_elem
))
143 template<typename T_forany
>
145 marshal_array_vector (
147 const std::vector
<typename
T_forany::_slice_type
*> &source
)
149 typedef TAO_FixedArray_Var_T
<typename
T_forany::_array_type
,
150 typename
T_forany::_slice_type
,
151 typename
T_forany::_tag_type
> var_type
;
152 ::CORBA::ULong
const length
= source
.size ();
154 if (! (strm
<< length
))
159 for (std::vector
<typename
T_forany::_slice_type
*> i
=
165 TAO::Array_Traits
<T_forany
>::dup (*i
);
166 T_forany
const tmp (tmp_array
.inout ());
177 template<typename T_forany
>
179 demarshal_array_vector (
181 const std::vector
<typename
T_forany::_slice_type
*> &source
)
183 typedef TAO::Array_Traits
<T_forany
> array_traits
;
184 ::CORBA::ULong new_length
= 0;
186 if (! (strm
>> new_length
))
191 if (new_length
> strm
.length ())
196 std::vector
<typename
T_forany::_slice_type
*> tmp_vec
;
197 tmp_vec
.reserve (new_length
);
199 for ( ::CORBA::ULong i
= 0; i
< new_length
; ++i
)
201 T_forany
tmp_array (array_traits::alloc ());
202 bool const _tao_marshal_flag
= (strm
>> tmp_array
);
204 if (_tao_marshal_flag
)
206 array_traits::copy (tmp_vec
[i
], tmp_array
.in ());
209 array_traits::free (tmp_array
.inout ());
211 if (!_tao_marshal_flag
)
217 tmp_vec
.swap (source
);
222 TAO_END_VERSIONED_NAMESPACE_DECL
224 #endif // guard_vector_cdr