Go to the documentation of this file.00001 #ifndef guard_vector_cdr
00002 #define guard_vector_cdr
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <vector>
00014
00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00016
00017 namespace TAO
00018 {
00019 template<typename T>
00020 bool
00021 marshal_value_vector (
00022 TAO_OutputCDR &strm,
00023 const std::vector<T> &source)
00024 {
00025 ::CORBA::ULong const length = source.size ();
00026
00027 if (! (strm << length))
00028 {
00029 return false;
00030 }
00031
00032 for (typename std::vector<T>::const_iterator iter =
00033 source.begin ();
00034 iter != source.end ();
00035 ++iter)
00036 {
00037 if (! (strm << *iter))
00038 {
00039 return false;
00040 }
00041 }
00042
00043 return true;
00044 }
00045
00046 template<typename T>
00047 bool
00048 demarshal_value_vector (
00049 TAO_InputCDR &strm,
00050 std::vector<T> &target)
00051 {
00052 ::CORBA::ULong new_length = 0;
00053
00054 if (! (strm >> new_length))
00055 {
00056 return false;
00057 }
00058
00059 if (new_length > strm.length ())
00060 {
00061 return false;
00062 }
00063
00064 std::vector<T> tmp;
00065 tmp.reserve (new_length);
00066 T tmp_elem;
00067
00068 for ( ::CORBA::ULong i = 0; i < new_length; ++i)
00069 {
00070 if (! (strm >> tmp_elem))
00071 {
00072 return false;
00073 }
00074
00075 tmp[i] = tmp_elem;
00076 }
00077
00078 tmp.swap(target);
00079 return true;
00080 }
00081
00082 template<typename T>
00083 bool
00084 marshal_objref_vector (
00085 TAO_OutputCDR &strm,
00086 const std::vector<typename T::_ptr_type> &source)
00087 {
00088 ::CORBA::ULong const length = source.size ();
00089
00090 if (! (strm << length))
00091 {
00092 return false;
00093 }
00094
00095 for (typename std::vector<typename T::_ptr_type>::const_iterator i =
00096 source.begin ();
00097 i != source.end ();
00098 ++i)
00099 {
00100 if (! (TAO::Objref_Traits<T>::marshal (*i, strm)))
00101 {
00102 return false;
00103 }
00104 }
00105
00106 return true;
00107 }
00108
00109 template<typename T>
00110 bool
00111 demarshal_objref_vector (
00112 TAO_InputCDR &strm,
00113 std::vector<typename T::_ptr_type> &target)
00114 {
00115 ::CORBA::ULong new_length = 0;
00116
00117 if (! (strm >> new_length))
00118 {
00119 return false;
00120 }
00121
00122 if (new_length > strm.length ())
00123 {
00124 return false;
00125 }
00126
00127 std::vector<typename T::_ptr_type> tmp;
00128 tmp.reserve (new_length);
00129 typename T::_ptr_type tmp_elem = T::_nil ();
00130
00131 for ( ::CORBA::ULong i = 0; i < new_length; ++i)
00132 {
00133 if (! (strm >> tmp_elem))
00134 {
00135 return false;
00136 }
00137
00138 tmp[i] = tmp_elem;
00139 }
00140
00141 tmp.swap (target);
00142 return true;
00143 }
00144
00145 template<typename T_forany>
00146 bool
00147 marshal_array_vector (
00148 TAO_OutputCDR &strm,
00149 const std::vector<typename T_forany::_slice_type *> &source)
00150 {
00151 typedef TAO_FixedArray_Var_T <typename T_forany::_array_type,
00152 typename T_forany::_slice_type,
00153 typename T_forany::_tag_type> var_type;
00154 ::CORBA::ULong const length = source.size ();
00155
00156 if (! (strm << length))
00157 {
00158 return false;
00159 }
00160
00161 for (std::vector<typename T_forany::_slice_type *> i =
00162 source.begin ();
00163 i != source.end ();
00164 ++i)
00165 {
00166 var_type tmp_array =
00167 TAO::Array_Traits<T_forany>::dup (*i);
00168 T_forany const tmp (tmp_array.inout ());
00169
00170 if (! (strm << tmp))
00171 {
00172 return false;
00173 }
00174 }
00175
00176 return true;
00177 }
00178
00179 template<typename T_forany>
00180 bool
00181 demarshal_array_vector (
00182 TAO_InputCDR &strm,
00183 const std::vector<typename T_forany::_slice_type *> &source)
00184 {
00185 typedef TAO::Array_Traits<T_forany> array_traits;
00186 ::CORBA::ULong new_length = 0;
00187
00188 if (! (strm >> new_length))
00189 {
00190 return false;
00191 }
00192
00193 if (new_length > strm.length ())
00194 {
00195 return false;
00196 }
00197
00198 std::vector<typename T_forany::_slice_type *> tmp_vec;
00199 tmp_vec.reserve (new_length);
00200
00201 for ( ::CORBA::ULong i = 0; i < new_length; ++i)
00202 {
00203 T_forany tmp_array (array_traits::alloc ());
00204 bool const _tao_marshal_flag = (strm >> tmp_array);
00205
00206 if (_tao_marshal_flag)
00207 {
00208 array_traits::copy (tmp_vec[i], tmp_array.in ());
00209 }
00210
00211 array_traits::free (tmp_array.inout ());
00212
00213 if (!_tao_marshal_flag)
00214 {
00215 return false;
00216 }
00217 }
00218
00219 tmp_vec.swap (source);
00220 return true;
00221 }
00222 }
00223
00224 TAO_END_VERSIONED_NAMESPACE_DECL
00225
00226 #endif // guard_vector_cdr