#ifndef guard_vector_cdr #define guard_vector_cdr /** * @file * * @brief CDR (de)marshaling for std::vector * * @author Jeff Parsons */ #include TAO_BEGIN_VERSIONED_NAMESPACE_DECL namespace TAO { template bool marshal_value_vector ( TAO_OutputCDR &strm, const std::vector &source) { ::CORBA::ULong const length = source.size (); if (! (strm << length)) { return false; } for (typename std::vector::const_iterator iter = source.begin (); iter != source.end (); ++iter) { if (! (strm << *iter)) { return false; } } return true; } template bool demarshal_value_vector ( TAO_InputCDR &strm, std::vector &target) { ::CORBA::ULong new_length = 0; if (! (strm >> new_length)) { return false; } if (new_length > strm.length ()) { return false; } std::vector tmp; tmp.reserve (new_length); T tmp_elem; for ( ::CORBA::ULong i = 0; i < new_length; ++i) { if (! (strm >> tmp_elem)) { return false; } tmp[i] = tmp_elem; } tmp.swap(target); return true; } template bool marshal_objref_vector ( TAO_OutputCDR &strm, const std::vector &source) { ::CORBA::ULong const length = source.size (); if (! (strm << length)) { return false; } for (typename std::vector::const_iterator i = source.begin (); i != source.end (); ++i) { if (! (TAO::Objref_Traits::marshal (*i, strm))) { return false; } } return true; } template bool demarshal_objref_vector ( TAO_InputCDR &strm, std::vector &target) { ::CORBA::ULong new_length = 0; if (! (strm >> new_length)) { return false; } if (new_length > strm.length ()) { return false; } std::vector tmp; tmp.reserve (new_length); typename T::_ptr_type tmp_elem = T::_nil (); for ( ::CORBA::ULong i = 0; i < new_length; ++i) { if (! (strm >> tmp_elem)) { return false; } tmp[i] = tmp_elem; } tmp.swap (target); return true; } template bool marshal_array_vector ( TAO_OutputCDR &strm, const std::vector &source) { typedef TAO_FixedArray_Var_T var_type; ::CORBA::ULong const length = source.size (); if (! (strm << length)) { return false; } for (std::vector i = source.begin (); i != source.end (); ++i) { var_type tmp_array = TAO::Array_Traits::dup (*i); T_forany const tmp (tmp_array.inout ()); if (! (strm << tmp)) { return false; } } return true; } template bool demarshal_array_vector ( TAO_InputCDR &strm, const std::vector &source) { typedef TAO::Array_Traits array_traits; ::CORBA::ULong new_length = 0; if (! (strm >> new_length)) { return false; } if (new_length > strm.length ()) { return false; } std::vector tmp_vec; tmp_vec.reserve (new_length); for ( ::CORBA::ULong i = 0; i < new_length; ++i) { T_forany tmp_array (array_traits::alloc ()); bool const _tao_marshal_flag = (strm >> tmp_array); if (_tao_marshal_flag) { array_traits::copy (tmp_vec[i], tmp_array.in ()); } array_traits::free (tmp_array.inout ()); if (!_tao_marshal_flag) { return false; } } tmp_vec.swap (source); return true; } } TAO_END_VERSIONED_NAMESPACE_DECL #endif // guard_vector_cdr