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 ACE_INLINE ACE_CDR::Boolean
156 ACE_SizeCDR::write_string_view (const std::string_view &x)
159 static_cast<ACE_CDR::ULong> (x.size ());
160 return this->write_string (len,
161 x.empty () ? 0 : x.data ());
164 #if !defined(ACE_LACKS_STD_WSTRING)
165 ACE_INLINE ACE_CDR::Boolean
166 ACE_SizeCDR::write_wstring (const std::wstring &x)
169 static_cast<ACE_CDR::ULong> (x.size ());
170 return this->write_wstring (len,
171 x.empty () ? 0 : x.c_str ());
175 ACE_INLINE ACE_CDR::Boolean
176 ACE_SizeCDR::write_char_array (const ACE_CDR::Char *x,
177 ACE_CDR::ULong length)
179 // Note: translator framework is not supported.
181 return this->write_array (x,
183 ACE_CDR::OCTET_ALIGN,
187 ACE_INLINE ACE_CDR::Boolean
188 ACE_SizeCDR::write_wchar_array (const ACE_CDR::WChar* x,
189 ACE_CDR::ULong length)
191 // Note: translator framework is not supported.
193 if (ACE_OutputCDR::wchar_maxbytes () == 0)
196 return (this->good_bit_ = false);
198 if (ACE_OutputCDR::wchar_maxbytes () == sizeof (ACE_CDR::WChar))
199 return this->write_array (x,
200 sizeof (ACE_CDR::WChar),
201 sizeof (ACE_CDR::WChar) == 2
202 ? ACE_CDR::SHORT_ALIGN
203 : ACE_CDR::LONG_ALIGN,
205 return this->write_wchar_array_i (x,length);
208 ACE_INLINE ACE_CDR::Boolean
209 ACE_SizeCDR::write_octet_array (const ACE_CDR::Octet* x,
210 ACE_CDR::ULong length)
212 return this->write_array (x,
214 ACE_CDR::OCTET_ALIGN,
218 ACE_INLINE ACE_CDR::Boolean
219 ACE_SizeCDR::write_short_array (const ACE_CDR::Short *x,
220 ACE_CDR::ULong length)
222 return this->write_array (x,
224 ACE_CDR::SHORT_ALIGN,
228 ACE_INLINE ACE_CDR::Boolean
229 ACE_SizeCDR::write_ushort_array (const ACE_CDR::UShort *x,
230 ACE_CDR::ULong length)
232 return this->write_array (x,
234 ACE_CDR::SHORT_ALIGN,
238 ACE_INLINE ACE_CDR::Boolean
239 ACE_SizeCDR::write_long_array (const ACE_CDR::Long *x,
240 ACE_CDR::ULong length)
242 return this->write_array (x,
248 ACE_INLINE ACE_CDR::Boolean
249 ACE_SizeCDR::write_ulong_array (const ACE_CDR::ULong *x,
250 ACE_CDR::ULong length)
252 return this->write_array (x,
258 ACE_INLINE ACE_CDR::Boolean
259 ACE_SizeCDR::write_longlong_array (const ACE_CDR::LongLong *x,
260 ACE_CDR::ULong length)
262 return this->write_array (x,
263 ACE_CDR::LONGLONG_SIZE,
264 ACE_CDR::LONGLONG_ALIGN,
268 ACE_INLINE ACE_CDR::Boolean
269 ACE_SizeCDR::write_ulonglong_array (const ACE_CDR::ULongLong *x,
270 ACE_CDR::ULong length)
272 return this->write_array (x,
273 ACE_CDR::LONGLONG_SIZE,
274 ACE_CDR::LONGLONG_ALIGN,
278 ACE_INLINE ACE_CDR::Boolean
279 ACE_SizeCDR::write_float_array (const ACE_CDR::Float *x,
280 ACE_CDR::ULong length)
282 return this->write_array (x,
289 ACE_INLINE ACE_CDR::Boolean
290 ACE_SizeCDR::write_double_array (const ACE_CDR::Double *x,
291 ACE_CDR::ULong length)
293 return this->write_array (x,
294 ACE_CDR::LONGLONG_SIZE,
295 ACE_CDR::LONGLONG_ALIGN,
299 ACE_INLINE ACE_CDR::Boolean
300 ACE_SizeCDR::write_longdouble_array (const ACE_CDR::LongDouble* x,
301 ACE_CDR::ULong length)
303 return this->write_array (x,
304 ACE_CDR::LONGDOUBLE_SIZE,
305 ACE_CDR::LONGDOUBLE_ALIGN,
310 // ****************************************************************
313 ACE_INLINE ACE_CDR::Boolean
314 operator<< (ACE_SizeCDR &ss, ACE_CDR::Char x)
317 return ss.good_bit ();
320 ACE_INLINE ACE_CDR::Boolean
321 operator<< (ACE_SizeCDR &ss, ACE_CDR::Short x)
324 return ss.good_bit ();
327 ACE_INLINE ACE_CDR::Boolean
328 operator<< (ACE_SizeCDR &ss, ACE_CDR::UShort x)
331 return ss.good_bit ();
334 ACE_INLINE ACE_CDR::Boolean
335 operator<< (ACE_SizeCDR &ss, ACE_CDR::Long x)
338 return ss.good_bit ();
341 ACE_INLINE ACE_CDR::Boolean
342 operator<< (ACE_SizeCDR &ss, ACE_CDR::ULong x)
345 return ss.good_bit ();
348 ACE_INLINE ACE_CDR::Boolean
349 operator<< (ACE_SizeCDR &ss, ACE_CDR::LongLong x)
351 ss.write_longlong (x);
352 return ss.good_bit ();
355 ACE_INLINE ACE_CDR::Boolean
356 operator<< (ACE_SizeCDR &ss, ACE_CDR::ULongLong x)
358 ss.write_ulonglong (x);
359 return ss.good_bit ();
362 ACE_INLINE ACE_CDR::Boolean
363 operator<< (ACE_SizeCDR &ss, ACE_CDR::LongDouble x)
365 ss.write_longdouble (x);
366 return ss.good_bit ();
369 ACE_INLINE ACE_CDR::Boolean
370 operator<< (ACE_SizeCDR &ss, ACE_CDR::Float x)
373 return ss.good_bit ();
376 ACE_INLINE ACE_CDR::Boolean
377 operator<< (ACE_SizeCDR &ss, ACE_CDR::Double x)
380 return ss.good_bit ();
383 ACE_INLINE ACE_CDR::Boolean
384 operator<< (ACE_SizeCDR &ss, const ACE_CDR::Fixed &x)
387 return ss.good_bit ();
390 ACE_INLINE ACE_CDR::Boolean
391 operator<< (ACE_SizeCDR &ss, const ACE_CDR::Char *x)
394 return ss.good_bit ();
397 ACE_INLINE ACE_CDR::Boolean
398 operator<< (ACE_SizeCDR &ss, const ACE_CDR::WChar *x)
400 ss.write_wstring (x);
401 return ss.good_bit ();
404 ACE_INLINE ACE_CDR::Boolean
405 operator<< (ACE_SizeCDR &ss, const std::string& x)
408 return ss.good_bit ();
411 ACE_INLINE ACE_CDR::Boolean
412 operator<< (ACE_SizeCDR &ss, const std::string_view& x)
414 ss.write_string_view (x);
415 return ss.good_bit ();
418 #if !defined(ACE_LACKS_STD_WSTRING)
419 ACE_INLINE ACE_CDR::Boolean
420 operator<< (ACE_SizeCDR &ss, const std::wstring& x)
422 ss.write_wstring (x);
423 return ss.good_bit ();
427 // The following use the helper classes
428 ACE_INLINE ACE_CDR::Boolean
429 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_boolean x)
431 ss.write_boolean (x.val_);
432 return ss.good_bit ();
435 ACE_INLINE ACE_CDR::Boolean
436 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_char x)
438 ss.write_char (x.val_);
439 return ss.good_bit ();
442 ACE_INLINE ACE_CDR::Boolean
443 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_wchar x)
445 ss.write_wchar (x.val_);
446 return ss.good_bit ();
449 ACE_INLINE ACE_CDR::Boolean
450 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_octet x)
452 ss.write_octet (x.val_);
453 return ss.good_bit ();
456 ACE_INLINE ACE_CDR::Boolean
457 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_string x)
459 ACE_CDR::ULong len = 0;
463 len = static_cast<ACE_CDR::ULong> (ACE_OS::strlen (x.val_));
466 ss.write_string (len, x.val_);
467 return (ss.good_bit () && (!x.bound_ || len <= x.bound_));
470 ACE_INLINE ACE_CDR::Boolean
471 operator<< (ACE_SizeCDR &ss, ACE_OutputCDR::from_wstring x)
473 ACE_CDR::ULong len = 0;
477 len = static_cast<ACE_CDR::ULong> (ACE_OS::strlen (x.val_));
480 ss.write_wstring (len, x.val_);
481 return (ss.good_bit () && (!x.bound_ || len <= x.bound_));
485 ACE_END_VERSIONED_NAMESPACE_DECL