2 #include "ace/OS_NS_string.h"
4 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
7 ACE_SizeCDR::ACE_SizeCDR (ACE_CDR::Octet major_version,
8 ACE_CDR::Octet minor_version)
11 major_version_ (major_version),
12 minor_version_ (minor_version)
17 ACE_SizeCDR::good_bit () const
19 return this->good_bit_;
29 ACE_SizeCDR::total_length () const
35 // Encode the CDR stream.
37 ACE_INLINE ACE_CDR::Boolean
38 ACE_SizeCDR::write_octet (ACE_CDR::Octet x)
40 return this->write_1 (reinterpret_cast<const ACE_CDR::Octet *> (&x));
43 ACE_INLINE ACE_CDR::Boolean
44 ACE_SizeCDR::write_boolean (ACE_CDR::Boolean x)
46 return this->write_octet (x ? (ACE_CDR::Octet) 1 : (ACE_CDR::Octet) 0);
49 ACE_INLINE ACE_CDR::Boolean
50 ACE_SizeCDR::write_char (ACE_CDR::Char x)
52 // Note: translator framework is not supported.
54 return this->write_1 (reinterpret_cast<const ACE_CDR::Octet*> (&x));
57 ACE_INLINE ACE_CDR::Boolean
58 ACE_SizeCDR::write_short (ACE_CDR::Short x)
60 return this->write_2 (reinterpret_cast<const ACE_CDR::UShort*> (&x));
63 ACE_INLINE ACE_CDR::Boolean
64 ACE_SizeCDR::write_ushort (ACE_CDR::UShort x)
66 return this->write_2 (reinterpret_cast<const ACE_CDR::UShort*> (&x));
69 ACE_INLINE ACE_CDR::Boolean
70 ACE_SizeCDR::write_long (ACE_CDR::Long x)
72 return this->write_4 (reinterpret_cast<const ACE_CDR::ULong*> (&x));
75 ACE_INLINE ACE_CDR::Boolean
76 ACE_SizeCDR::write_ulong (ACE_CDR::ULong x)
78 return this->write_4 (reinterpret_cast<const ACE_CDR::ULong*> (&x));
81 ACE_INLINE ACE_CDR::Boolean
82 ACE_SizeCDR::write_longlong (const ACE_CDR::LongLong &x)
84 return this->write_8 (reinterpret_cast<const ACE_CDR::ULongLong*> (&x));
87 ACE_INLINE ACE_CDR::Boolean
88 ACE_SizeCDR::write_ulonglong (const ACE_CDR::ULongLong &x)
90 const void *temp = &x;
91 return this->write_8 (reinterpret_cast<const ACE_CDR::ULongLong *> (temp));
94 ACE_INLINE ACE_CDR::Boolean
95 ACE_SizeCDR::write_float (ACE_CDR::Float x)
97 const void *temp = &x;
98 return this->write_4 (reinterpret_cast<const ACE_CDR::ULong *> (temp));
101 ACE_INLINE ACE_CDR::Boolean
102 ACE_SizeCDR::write_double (const ACE_CDR::Double &x)
104 const void *temp = &x;
105 return this->write_8 (reinterpret_cast<const ACE_CDR::ULongLong*> (temp));
108 ACE_INLINE ACE_CDR::Boolean
109 ACE_SizeCDR::write_longdouble (const ACE_CDR::LongDouble &x)
111 const void *temp = &x;
112 return this->write_16 (reinterpret_cast<const ACE_CDR::LongDouble*> (temp));
115 ACE_INLINE ACE_CDR::Boolean
116 ACE_SizeCDR::write_fixed (const ACE_CDR::Fixed &x)
118 return this->write_array (&x, ACE_CDR::OCTET_SIZE, ACE_CDR::OCTET_ALIGN,
119 (x.fixed_digits () + 2) / 2);
122 ACE_INLINE ACE_CDR::Boolean
123 ACE_SizeCDR::write_string (const ACE_CDR::Char *x)
127 const ACE_CDR::ULong len =
128 static_cast<ACE_CDR::ULong> (ACE_OS::strlen (x));
129 return this->write_string (len, x);
131 return this->write_string (0, 0);
134 ACE_INLINE ACE_CDR::Boolean
135 ACE_SizeCDR::write_wstring (const ACE_CDR::WChar *x)
140 static_cast<ACE_CDR::ULong> (ACE_OS::strlen (x));
141 return this->write_wstring (len, x);
143 return this->write_wstring (0, 0);
146 ACE_INLINE ACE_CDR::Boolean
147 ACE_SizeCDR::write_string (const std::string &x)
150 static_cast<ACE_CDR::ULong> (x.size ());
151 return this->write_string (len,
152 x.empty () ? 0 : x.c_str ());
155 #if !defined(ACE_LACKS_STD_WSTRING)
156 ACE_INLINE ACE_CDR::Boolean
157 ACE_SizeCDR::write_wstring (const std::wstring &x)
160 static_cast<ACE_CDR::ULong> (x.size ());
161 return this->write_wstring (len,
162 x.empty () ? 0 : x.c_str ());
166 ACE_INLINE ACE_CDR::Boolean
167 ACE_SizeCDR::write_char_array (const ACE_CDR::Char *x,
168 ACE_CDR::ULong length)
170 // Note: translator framework is not supported.
172 return this->write_array (x,
174 ACE_CDR::OCTET_ALIGN,
178 ACE_INLINE ACE_CDR::Boolean
179 ACE_SizeCDR::write_wchar_array (const ACE_CDR::WChar* x,
180 ACE_CDR::ULong length)
182 // Note: translator framework is not supported.
184 if (ACE_OutputCDR::wchar_maxbytes () == 0)
187 return (this->good_bit_ = false);
189 if (ACE_OutputCDR::wchar_maxbytes () == sizeof (ACE_CDR::WChar))
190 return this->write_array (x,
191 sizeof (ACE_CDR::WChar),
192 sizeof (ACE_CDR::WChar) == 2
193 ? ACE_CDR::SHORT_ALIGN
194 : ACE_CDR::LONG_ALIGN,
196 return this->write_wchar_array_i (x,length);
199 ACE_INLINE ACE_CDR::Boolean
200 ACE_SizeCDR::write_octet_array (const ACE_CDR::Octet* x,
201 ACE_CDR::ULong length)
203 return this->write_array (x,
205 ACE_CDR::OCTET_ALIGN,
209 ACE_INLINE ACE_CDR::Boolean
210 ACE_SizeCDR::write_short_array (const ACE_CDR::Short *x,
211 ACE_CDR::ULong length)
213 return this->write_array (x,
215 ACE_CDR::SHORT_ALIGN,
219 ACE_INLINE ACE_CDR::Boolean
220 ACE_SizeCDR::write_ushort_array (const ACE_CDR::UShort *x,
221 ACE_CDR::ULong length)
223 return this->write_array (x,
225 ACE_CDR::SHORT_ALIGN,
229 ACE_INLINE ACE_CDR::Boolean
230 ACE_SizeCDR::write_long_array (const ACE_CDR::Long *x,
231 ACE_CDR::ULong length)
233 return this->write_array (x,
239 ACE_INLINE ACE_CDR::Boolean
240 ACE_SizeCDR::write_ulong_array (const ACE_CDR::ULong *x,
241 ACE_CDR::ULong length)
243 return this->write_array (x,
249 ACE_INLINE ACE_CDR::Boolean
250 ACE_SizeCDR::write_longlong_array (const ACE_CDR::LongLong *x,
251 ACE_CDR::ULong length)
253 return this->write_array (x,
254 ACE_CDR::LONGLONG_SIZE,
255 ACE_CDR::LONGLONG_ALIGN,
259 ACE_INLINE ACE_CDR::Boolean
260 ACE_SizeCDR::write_ulonglong_array (const ACE_CDR::ULongLong *x,
261 ACE_CDR::ULong length)
263 return this->write_array (x,
264 ACE_CDR::LONGLONG_SIZE,
265 ACE_CDR::LONGLONG_ALIGN,
269 ACE_INLINE ACE_CDR::Boolean
270 ACE_SizeCDR::write_float_array (const ACE_CDR::Float *x,
271 ACE_CDR::ULong length)
273 return this->write_array (x,
280 ACE_INLINE ACE_CDR::Boolean
281 ACE_SizeCDR::write_double_array (const ACE_CDR::Double *x,
282 ACE_CDR::ULong length)
284 return this->write_array (x,
285 ACE_CDR::LONGLONG_SIZE,
286 ACE_CDR::LONGLONG_ALIGN,
290 ACE_INLINE ACE_CDR::Boolean
291 ACE_SizeCDR::write_longdouble_array (const ACE_CDR::LongDouble* x,
292 ACE_CDR::ULong length)
294 return this->write_array (x,
295 ACE_CDR::LONGDOUBLE_SIZE,
296 ACE_CDR::LONGDOUBLE_ALIGN,
301 // ****************************************************************
304 ACE_INLINE ACE_CDR::Boolean
305 operator<< (ACE_SizeCDR &ss, ACE_CDR::Char x)
308 return ss.good_bit ();
311 ACE_INLINE ACE_CDR::Boolean
312 operator<< (ACE_SizeCDR &ss, ACE_CDR::Short x)
315 return ss.good_bit ();
318 ACE_INLINE ACE_CDR::Boolean
319 operator<< (ACE_SizeCDR &ss, ACE_CDR::UShort x)
322 return ss.good_bit ();
325 ACE_INLINE ACE_CDR::Boolean
326 operator<< (ACE_SizeCDR &ss, ACE_CDR::Long x)
329 return ss.good_bit ();
332 ACE_INLINE ACE_CDR::Boolean
333 operator<< (ACE_SizeCDR &ss, ACE_CDR::ULong x)
336 return ss.good_bit ();
339 ACE_INLINE ACE_CDR::Boolean
340 operator<< (ACE_SizeCDR &ss, ACE_CDR::LongLong x)
342 ss.write_longlong (x);
343 return ss.good_bit ();
346 ACE_INLINE ACE_CDR::Boolean
347 operator<< (ACE_SizeCDR &ss, ACE_CDR::ULongLong x)
349 ss.write_ulonglong (x);
350 return ss.good_bit ();
353 ACE_INLINE ACE_CDR::Boolean
354 operator<< (ACE_SizeCDR &ss, ACE_CDR::LongDouble x)
356 ss.write_longdouble (x);
357 return ss.good_bit ();
360 ACE_INLINE ACE_CDR::Boolean
361 operator<< (ACE_SizeCDR &ss, ACE_CDR::Float x)
364 return ss.good_bit ();
367 ACE_INLINE ACE_CDR::Boolean
368 operator<< (ACE_SizeCDR &ss, ACE_CDR::Double x)
371 return ss.good_bit ();
374 ACE_INLINE ACE_CDR::Boolean
375 operator<< (ACE_SizeCDR &ss, const ACE_CDR::Fixed &x)
378 return ss.good_bit ();
381 ACE_INLINE ACE_CDR::Boolean
382 operator<< (ACE_SizeCDR &ss, const ACE_CDR::Char *x)
385 return ss.good_bit ();
388 ACE_INLINE ACE_CDR::Boolean
389 operator<< (ACE_SizeCDR &ss, const ACE_CDR::WChar *x)
391 ss.write_wstring (x);
392 return ss.good_bit ();
395 ACE_INLINE ACE_CDR::Boolean
396 operator<< (ACE_SizeCDR &ss, const std::string& x)
399 return ss.good_bit ();
402 #if !defined(ACE_LACKS_STD_WSTRING)
403 ACE_INLINE ACE_CDR::Boolean
404 operator<< (ACE_SizeCDR &ss, const std::wstring& x)
406 ss.write_wstring (x);
407 return ss.good_bit ();
411 // The following use the helper classes
412 ACE_INLINE ACE_CDR::Boolean
413 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_boolean x)
415 ss.write_boolean (x.val_);
416 return ss.good_bit ();
419 ACE_INLINE ACE_CDR::Boolean
420 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_char x)
422 ss.write_char (x.val_);
423 return ss.good_bit ();
426 ACE_INLINE ACE_CDR::Boolean
427 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_wchar x)
429 ss.write_wchar (x.val_);
430 return ss.good_bit ();
433 ACE_INLINE ACE_CDR::Boolean
434 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_octet x)
436 ss.write_octet (x.val_);
437 return ss.good_bit ();
440 ACE_INLINE ACE_CDR::Boolean
441 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_string x)
443 ACE_CDR::ULong len = 0;
447 len = static_cast<ACE_CDR::ULong> (ACE_OS::strlen (x.val_));
450 ss.write_string (len, x.val_);
451 return (ss.good_bit () && (!x.bound_ || len <= x.bound_));
454 ACE_INLINE ACE_CDR::Boolean
455 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_wstring x)
457 ACE_CDR::ULong len = 0;
461 len = static_cast<ACE_CDR::ULong> (ACE_OS::strlen (x.val_));
464 ss.write_wstring (len, x.val_);
465 return (ss.good_bit () && (!x.bound_ || len <= x.bound_));
469 ACE_END_VERSIONED_NAMESPACE_DECL