3 //=============================================================================
7 * ACE Common Data Representation (CDR) marshaling and demarshaling
10 * This implementation was inspired in the CDR class in SunSoft's
11 * IIOP engine, but has a completely different implementation and a
12 * different interface too.
14 * The current implementation assumes that the host has 1-byte,
15 * 2-byte and 4-byte integral types, and that it has single
16 * precision and double precision IEEE floats.
17 * Those assumptions are pretty good these days, with Crays being
18 * the only known exception.
22 * ACE_LACKS_CDR_ALIGNMENT
23 * @author Arvind S. Krishna <arvindk@dre.vanderbilt.edu>
25 * CDR stream ignores alignment when marshaling data. Use this option
26 * only when ACE_DISABLE_SWAP_ON_READ can be enabled. This option requires
27 * ACE CDR engine to do both marshaling and demarshaling.
29 * @author TAO version by Aniruddha Gokhale <gokhale@cs.wustl.edu>
30 * @author Carlos O'Ryan <coryan@cs.wustl.edu>
31 * @author ACE version by Jeff Parsons <parsons@cs.wustl.edu>
32 * @author Istvan Buki <istvan.buki@euronet.be>
33 * @author Codeset translation by Jim Rogers <jrogers@viasoft.com>
35 //=============================================================================
37 #ifndef ACE_CDR_STREAM_H
38 #define ACE_CDR_STREAM_H
40 #include /**/ "ace/pre.h"
42 #include "ace/CDR_Base.h"
44 #if !defined (ACE_LACKS_PRAGMA_ONCE)
46 #endif /* ACE_LACKS_PRAGMA_ONCE */
48 #include "ace/SStringfwd.h"
49 #include "ace/Message_Block.h"
51 #if defined (GEN_OSTREAM_OPS)
52 #include "ace/streams.h"
53 #endif /* GEN_OSTREAM_OPS */
55 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
56 #include "Monitor_Size.h"
57 #endif /* ACE_HAS_MONITOR_POINTS==1 */
61 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
63 class ACE_Char_Codeset_Translator
;
64 class ACE_WChar_Codeset_Translator
;
69 * @class ACE_OutputCDR
71 * @brief A CDR stream for marshalling data, most often for transmission to
72 * another system which may or may not have the same byte order.
74 * This class is based on the the CORBA spec for Java (98-02-29),
75 * java class omg.org.CORBA.portable.OutputStream. It diverts in
77 * @li Operations taking arrays don't have offsets, because in C++
78 * it is easier to describe an array starting from x+offset.
79 * @li Operations return an error status, because exceptions are
80 * not widely available in C++ (yet).
82 class ACE_Export ACE_OutputCDR
86 * The Codeset translators need access to some private members to
87 * efficiently marshal arrays
88 * For reading from an output CDR stream.
90 friend class ACE_Char_Codeset_Translator
;
91 friend class ACE_WChar_Codeset_Translator
;
92 friend class ACE_InputCDR
;
95 * Default constructor; allows one to set byte ordering, allocators, and
98 * @param size Causes constructor to preallocate @a size bytes; if
99 * @a size is 0 it allocates the default size.
101 * @param byte_order The byte order that data will have within this
102 * object. Unless otherwise specified, the byte order
103 * will be the order native to the hardware this is
104 * executed on. To force the marshalled data to have
105 * a specific order, specify one of the values defined
106 * in ACE_CDR::Byte_Order.
107 * @note The @c ACE_ENABLE_SWAP_ON_WRITE config macro
108 * must be set for any local byte swapping to occur
109 * as data is inserted into an ACE_OutputCDR object.
111 ACE_OutputCDR (size_t size
= 0,
112 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
113 ACE_Allocator
* buffer_allocator
= 0,
114 ACE_Allocator
* data_block_allocator
= 0,
115 ACE_Allocator
* message_block_allocator
= 0,
116 size_t memcpy_tradeoff
= ACE_DEFAULT_CDR_MEMCPY_TRADEOFF
,
117 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
118 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
120 /// Build a CDR stream with an initial buffer, it will *not* remove
121 /// @a data, since it did not allocated it. It's important to be careful
122 /// with the alignment of @a data.
124 * Create an output stream from an arbitrary buffer, care must be
125 * exercised with alignment, because this constructor will align if
126 * needed. In this case @a data will not point to the start of the
127 * output stream. @c begin()->rd_ptr() points to the start of the
128 * output stream. See @c ACE_ptr_align_binary() to properly align a
129 * pointer and use ACE_CDR::MAX_ALIGNMENT for the correct alignment.
131 ACE_OutputCDR (char *data
,
133 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
134 ACE_Allocator
* buffer_allocator
= 0,
135 ACE_Allocator
* data_block_allocator
= 0,
136 ACE_Allocator
* message_block_allocator
= 0,
137 size_t memcpy_tradeoff
= ACE_DEFAULT_CDR_MEMCPY_TRADEOFF
,
138 ACE_CDR::Octet giop_major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
139 ACE_CDR::Octet giop_minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
141 /// Build a CDR stream with an initial data block, it will *not* remove
142 /// @a data_block, since it did not allocated it. It's important to be
143 /// careful with the alignment of @a data_block.
145 * Create an output stream from an arbitrary data block, care must be
146 * exercised with alignment, because this constructor will align if
147 * needed. In this case @a data_block will not point to the
148 * start of the output stream. begin()->rd_ptr() points to the start
149 * off the output stream. See ACE_ptr_align_binary() to properly align a
150 * pointer and use ACE_CDR::MAX_ALIGNMENT for the correct alignment.
152 ACE_OutputCDR (ACE_Data_Block
*data_block
,
153 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
154 ACE_Allocator
* message_block_allocator
= 0,
155 size_t memcpy_tradeoff
= ACE_DEFAULT_CDR_MEMCPY_TRADEOFF
,
156 ACE_CDR::Octet giop_major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
157 ACE_CDR::Octet giop_minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
159 /// Build a CDR stream with an initial Message_Block chain, it will
160 /// *not* remove @a data, since it did not allocate it.
161 ACE_OutputCDR (ACE_Message_Block
*data
,
162 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
163 size_t memcpy_tradeoff
= ACE_DEFAULT_CDR_MEMCPY_TRADEOFF
,
164 ACE_CDR::Octet giop_major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
165 ACE_CDR::Octet giop_minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
171 * Disambiguate overload when inserting booleans, octets, chars, and
174 //@{ @name Helper classes
176 struct ACE_Export from_boolean
178 explicit from_boolean (ACE_CDR::Boolean b
);
179 ACE_CDR::Boolean val_
;
182 struct ACE_Export from_octet
184 explicit from_octet (ACE_CDR::Octet o
);
188 struct ACE_Export from_char
190 explicit from_char (ACE_CDR::Char c
);
194 struct ACE_Export from_wchar
196 explicit from_wchar (ACE_CDR::WChar wc
);
200 struct ACE_Export from_int8
202 explicit from_int8 (ACE_CDR::Int8 val
);
206 struct ACE_Export from_uint8
208 explicit from_uint8 (ACE_CDR::UInt8 val
);
212 struct ACE_Export from_string
214 from_string (ACE_CDR::Char
* s
,
216 ACE_CDR::Boolean nocopy
= 0);
217 from_string (const ACE_CDR::Char
* s
,
219 ACE_CDR::Boolean nocopy
= 0);
221 ACE_CDR::ULong bound_
;
222 ACE_CDR::Boolean nocopy_
;
225 struct ACE_Export from_wstring
227 from_wstring (ACE_CDR::WChar
* ws
,
229 ACE_CDR::Boolean nocopy
= 0);
230 from_wstring (const ACE_CDR::WChar
* ws
,
232 ACE_CDR::Boolean nocopy
= 0);
233 ACE_CDR::WChar
*val_
;
234 ACE_CDR::ULong bound_
;
235 ACE_CDR::Boolean nocopy_
;
238 struct ACE_Export from_std_string
240 from_std_string (const std::string
&s
,
242 const std::string
&val_
;
243 ACE_CDR::ULong bound_
;
246 #if !defined(ACE_LACKS_STD_WSTRING)
247 struct ACE_Export from_std_wstring
249 from_std_wstring (const std::wstring
&ws
,
251 const std::wstring
&val_
;
252 ACE_CDR::ULong bound_
;
258 * @{ @name Write operations
259 * Return 0 on failure and 1 on success.
261 ACE_CDR::Boolean
write_boolean (ACE_CDR::Boolean x
);
262 ACE_CDR::Boolean
write_char (ACE_CDR::Char x
);
263 ACE_CDR::Boolean
write_wchar (ACE_CDR::WChar x
);
264 ACE_CDR::Boolean
write_octet (ACE_CDR::Octet x
);
265 ACE_CDR::Boolean
write_short (ACE_CDR::Short x
);
266 ACE_CDR::Boolean
write_ushort (ACE_CDR::UShort x
);
267 ACE_CDR::Boolean
write_long (ACE_CDR::Long x
);
268 ACE_CDR::Boolean
write_ulong (ACE_CDR::ULong x
);
269 ACE_CDR::Boolean
write_longlong (const ACE_CDR::LongLong
&x
);
270 ACE_CDR::Boolean
write_ulonglong (const ACE_CDR::ULongLong
&x
);
271 ACE_CDR::Boolean
write_float (ACE_CDR::Float x
);
272 ACE_CDR::Boolean
write_double (const ACE_CDR::Double
&x
);
273 ACE_CDR::Boolean
write_longdouble (const ACE_CDR::LongDouble
&x
);
274 ACE_CDR::Boolean
write_fixed (const ACE_CDR::Fixed
&x
);
275 ACE_CDR::Boolean
write_int8 (ACE_CDR::Int8 x
);
276 ACE_CDR::Boolean
write_uint8 (ACE_CDR::UInt8 x
);
278 /// For string we offer methods that accept a precomputed length.
279 ACE_CDR::Boolean
write_string (const ACE_CDR::Char
*x
);
280 ACE_CDR::Boolean
write_string (ACE_CDR::ULong len
,
281 const ACE_CDR::Char
*x
);
282 ACE_CDR::Boolean
write_string (const ACE_CString
&x
);
283 ACE_CDR::Boolean
write_wstring (const ACE_CDR::WChar
*x
);
284 ACE_CDR::Boolean
write_wstring (ACE_CDR::ULong length
,
285 const ACE_CDR::WChar
*x
);
286 ACE_CDR::Boolean
write_string (const std::string
&x
);
287 #if !defined(ACE_LACKS_STD_WSTRING)
288 ACE_CDR::Boolean
write_wstring (const std::wstring
&x
);
293 /// @note the portion written starts at @a x and ends
294 /// at @a x + @a length.
295 /// The length is *NOT* stored into the CDR stream.
296 //@{ @name Array write operations
297 ACE_CDR::Boolean
write_boolean_array (const ACE_CDR::Boolean
*x
,
298 ACE_CDR::ULong length
);
299 ACE_CDR::Boolean
write_char_array (const ACE_CDR::Char
*x
,
300 ACE_CDR::ULong length
);
301 ACE_CDR::Boolean
write_wchar_array (const ACE_CDR::WChar
* x
,
302 ACE_CDR::ULong length
);
303 ACE_CDR::Boolean
write_octet_array (const ACE_CDR::Octet
* x
,
304 ACE_CDR::ULong length
);
305 ACE_CDR::Boolean
write_short_array (const ACE_CDR::Short
*x
,
306 ACE_CDR::ULong length
);
307 ACE_CDR::Boolean
write_ushort_array (const ACE_CDR::UShort
*x
,
308 ACE_CDR::ULong length
);
309 ACE_CDR::Boolean
write_long_array (const ACE_CDR::Long
*x
,
310 ACE_CDR::ULong length
);
311 ACE_CDR::Boolean
write_ulong_array (const ACE_CDR::ULong
*x
,
312 ACE_CDR::ULong length
);
313 ACE_CDR::Boolean
write_longlong_array (const ACE_CDR::LongLong
* x
,
314 ACE_CDR::ULong length
);
315 ACE_CDR::Boolean
write_ulonglong_array (const ACE_CDR::ULongLong
*x
,
316 ACE_CDR::ULong length
);
317 ACE_CDR::Boolean
write_float_array (const ACE_CDR::Float
*x
,
318 ACE_CDR::ULong length
);
319 ACE_CDR::Boolean
write_double_array (const ACE_CDR::Double
*x
,
320 ACE_CDR::ULong length
);
321 ACE_CDR::Boolean
write_longdouble_array (const ACE_CDR::LongDouble
* x
,
322 ACE_CDR::ULong length
);
323 ACE_CDR::Boolean
write_int8_array (const ACE_CDR::Int8
*x
, ACE_CDR::ULong length
);
324 ACE_CDR::Boolean
write_uint8_array (const ACE_CDR::UInt8
*x
, ACE_CDR::ULong length
);
326 /// Write an octet array contained inside a MB, this can be optimized
327 /// to minimize copies.
328 ACE_CDR::Boolean
write_octet_array_mb (const ACE_Message_Block
* mb
);
332 * @{ @name Placeholder/replace operations
333 * Facilitates writing a placeholder into a CDR stream to be replaced
334 * later with a different value.
336 * @note An example use for this facility is:
339 ... // insert values...
340 char *pos = strm.write_long_placeholder ();
341 ... // insert more values
342 ACE_CDR::Long real_val; // Somehow assign the "correct" value
343 strm.replace (real_val, pos); // Replace earlier placeholder
348 * Write a placeholder into the stream. The placeholder's pointer
349 * is returned so it may later be passed as the @a loc argument to
351 * These methods align the stream's write pointer properly prior to
352 * writing the placeholder.
354 * @retval Pointer to the placeholder; 0 if there is not enough space
355 * in the stream and memory could not be allocated.
357 char* write_long_placeholder ();
358 char* write_short_placeholder ();
359 char* write_boolean_placeholder ();
360 char* write_char_placeholder ();
361 char* write_longlong_placeholder ();
362 char* write_octet_placeholder ();
363 char* write_float_placeholder ();
364 char* write_double_placeholder ();
367 * Writes a new value into a specific location. This is commonly
368 * used to update a prior "placeholder" location in the stream.
369 * The specified location is assumed to have proper CDR alignment for the
370 * type to insert. This requirement is satisfied by using one of the
371 * placeholder-writing methods to align the stream for the anticipated
372 * value and obtain the correct location.
373 * Treatment of @a x with respect to byte swapping is the same as for when
374 * any value is inserted.
376 * @param x The value to insert into the specified location.
377 * @param loc The location at which to insert @a x. @a loc must be a valid
378 * position within the stream's current set of message blocks.
380 * @sa write_long_placeholder(), write_short_placeholder ()
382 ACE_CDR::Boolean
replace (ACE_CDR::Long x
, char* loc
);
383 ACE_CDR::Boolean
replace (ACE_CDR::ULong x
, char* loc
);
384 ACE_CDR::Boolean
replace (ACE_CDR::Short x
, char* loc
);
385 ACE_CDR::Boolean
replace (ACE_CDR::UShort x
, char* loc
);
386 ACE_CDR::Boolean
replace (ACE_CDR::Boolean x
, char* loc
);
387 ACE_CDR::Boolean
replace (ACE_CDR::Char x
, char* loc
);
388 ACE_CDR::Boolean
replace (ACE_CDR::LongLong x
, char* loc
);
389 ACE_CDR::Boolean
replace (ACE_CDR::ULongLong x
, char* loc
);
390 ACE_CDR::Boolean
replace (ACE_CDR::Octet x
, char* loc
);
391 ACE_CDR::Boolean
replace (ACE_CDR::Float x
, char* loc
);
392 ACE_CDR::Boolean
replace (ACE_CDR::Double x
, char* loc
);
396 * Return 0 on failure and 1 on success.
398 //@{ @name Append contents of own CDR stream to another
399 ACE_CDR::Boolean
append_boolean (ACE_InputCDR
&);
400 ACE_CDR::Boolean
append_char (ACE_InputCDR
&);
401 ACE_CDR::Boolean
append_wchar (ACE_InputCDR
&);
402 ACE_CDR::Boolean
append_octet (ACE_InputCDR
&);
403 ACE_CDR::Boolean
append_short (ACE_InputCDR
&);
404 ACE_CDR::Boolean
append_ushort (ACE_InputCDR
&);
405 ACE_CDR::Boolean
append_long (ACE_InputCDR
&);
406 ACE_CDR::Boolean
append_ulong (ACE_InputCDR
&);
407 ACE_CDR::Boolean
append_longlong (ACE_InputCDR
&);
408 ACE_CDR::Boolean
append_ulonglong (ACE_InputCDR
&);
409 ACE_CDR::Boolean
append_float (ACE_InputCDR
&);
410 ACE_CDR::Boolean
append_double (ACE_InputCDR
&);
411 ACE_CDR::Boolean
append_longdouble (ACE_InputCDR
&);
412 ACE_CDR::Boolean
append_fixed (ACE_InputCDR
&);
414 ACE_CDR::Boolean
append_wstring (ACE_InputCDR
&);
415 ACE_CDR::Boolean
append_string (ACE_InputCDR
&);
418 /// Returns @c false if an error has occurred.
420 * @note The only expected error is to run out of memory.
422 bool good_bit () const;
424 /// Reuse the CDR stream to write on the old buffer.
427 /// Add the length of each message block in the chain.
428 size_t total_length () const;
431 * Return the start of the message block chain for this CDR stream.
432 * @note The complete CDR stream is represented by a chain of
435 const ACE_Message_Block
*begin () const;
437 /// Return the last message in the chain that is is use.
438 const ACE_Message_Block
*end () const;
440 /// Return the <current_> message block in chain.
441 const ACE_Message_Block
*current () const;
443 /// Replace the message block chain with a single message block.
445 * Upon successful completion, there will be a single message block
446 * containing the data from the complete message block chain.
448 * @note The only expected error is to run out of memory.
453 * Access the underlying buffer (read only). @note This
454 * method only returns a pointer to the first block in the
457 const char *buffer () const;
460 * Return the size of first message block in the block chain. @note This
461 * method only returns information about the first block in the
464 size_t length () const;
467 * Utility function to allow the user more flexibility.
468 * Pads the stream up to the nearest @a alignment byte boundary.
469 * Argument MUST be a power of 2.
470 * Returns 0 on success and -1 on failure.
472 int align_write_ptr (size_t alignment
);
474 /// Access the codeset translators. They can be null!
475 ACE_Char_Codeset_Translator
*char_translator () const;
476 ACE_WChar_Codeset_Translator
*wchar_translator () const;
478 /// Set the char codeset translator.
479 void char_translator (ACE_Char_Codeset_Translator
*);
480 /// Set the wchar codeset translator.
481 void wchar_translator (ACE_WChar_Codeset_Translator
*);
483 /// set the global size of serialized wchars. This may be different
484 /// than the size of a wchar_t.
485 static void wchar_maxbytes (size_t max_bytes
);
487 /// access the serialized size of wchars.
488 static size_t wchar_maxbytes ();
491 * Return alignment of the wr_ptr(), with respect to the start of
492 * the CDR stream. This is not the same as the alignment of
495 size_t current_alignment () const;
497 void current_alignment (size_t current_alignment
);
500 * Returns (in @a buf) the next position in the buffer aligned to
501 * @a size, it advances the Message_Block wr_ptr past the data
502 * (i.e., @a buf + @a size). If necessary it grows the Message_Block
503 * buffer. Sets the good_bit to false and returns a -1 on failure.
505 int adjust (size_t size
,
508 /// As above, but now the size and alignment requirements may be
510 int adjust (size_t size
,
514 /// Returns true if this stream is writing in non-native byte order
515 /// and false otherwise. For example, it would be true if either
516 /// ACE_ENABLE_SWAP_ON_WRITE is defined or a specific byte order was
517 /// specified for this stream.
518 bool do_byte_swap () const;
520 /// Returns the byte order this stream is marshaling data in. Will be one
521 /// of the values in ACE_CDR::Byte_Order.
522 int byte_order () const;
524 /// For use by a gateway, which creates the output stream for the
525 /// reply to the client in its native byte order, but which must
526 /// send the reply in the byte order of the target's reply to the
528 void reset_byte_order (int byte_order
);
530 /// Set GIOP version info
531 void set_version (ACE_CDR::Octet major
, ACE_CDR::Octet minor
);
533 /// Set the underlying GIOP version..
534 void get_version (ACE_CDR::Octet
&major
, ACE_CDR::Octet
&minor
);
536 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
537 /// Register and unregister our buffer size monitor.
538 void register_monitor (const char* id
);
539 void unregister_monitor ();
540 #endif /* ACE_HAS_MONITOR_POINTS==1 */
543 // Find the message block in the chain of message blocks
544 // that the provide location locates.
545 ACE_Message_Block
* find (char* loc
);
547 ACE_OutputCDR (const ACE_OutputCDR
&) = delete;
548 ACE_OutputCDR
& operator= (const ACE_OutputCDR
&) = delete;
549 ACE_OutputCDR (ACE_OutputCDR
&&) = delete;
550 ACE_OutputCDR
& operator= (ACE_OutputCDR
&&) = delete;
552 ACE_CDR::Boolean
write_1 (const ACE_CDR::Octet
*x
);
553 ACE_CDR::Boolean
write_2 (const ACE_CDR::UShort
*x
);
554 ACE_CDR::Boolean
write_4 (const ACE_CDR::ULong
*x
);
555 ACE_CDR::Boolean
write_8 (const ACE_CDR::ULongLong
*x
);
556 ACE_CDR::Boolean
write_16 (const ACE_CDR::LongDouble
*x
);
559 * write an array of @a length elements, each of @a size bytes and the
560 * start aligned at a multiple of @a align. The elements are assumed
561 * to be packed with the right alignment restrictions. It is mostly
562 * designed for buffers of the basic types.
564 * This operation uses @c memcpy; as explained above it is expected
565 * that using assignment is faster that @c memcpy for one element,
566 * but for several elements @c memcpy should be more efficient, it
567 * could be interesting to find the break even point and optimize
568 * for that case, but that would be too platform dependent.
570 ACE_CDR::Boolean
write_array (const void *x
,
573 ACE_CDR::ULong length
);
576 ACE_CDR::Boolean
write_wchar_array_i (const ACE_CDR::WChar
* x
,
577 ACE_CDR::ULong length
);
581 * Grow the CDR stream. When it returns @a buf contains a pointer to
582 * memory in the CDR stream, with at least @a size bytes ahead of it
583 * and aligned to an @a align boundary. It moved the <wr_ptr> to <buf
586 int grow_and_adjust (size_t size
,
591 /// The start of the chain of message blocks.
592 ACE_Message_Block start_
;
594 /// The current block in the chain where we are writing.
595 ACE_Message_Block
*current_
;
597 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
599 * The current alignment as measured from the start of the buffer.
600 * Usually this coincides with the alignment of the buffer in
601 * memory, but, when we chain another buffer this "quasi invariant"
603 * The current_alignment is used to readjust the buffer following
604 * the stolen message block.
606 size_t current_alignment_
;
607 #endif /* ACE_LACKS_CDR_ALIGNMENT */
610 * Is the current block writable. When we steal a buffer from the
611 * user and just chain it into the message block we are not supposed
612 * to write on it, even if it is past the start and end of the
615 bool current_is_writable_
;
618 * If not zero swap bytes at writing so the created CDR stream byte
619 * order does *not* match the machine byte order. The motivation
620 * for such a beast is that in some setting a few (fast) machines
621 * can be serving hundreds of slow machines with the opposite byte
622 * order, so it makes sense (as a load balancing device) to put the
623 * responsibility in the writers.
625 * @warning THIS IS NOT A STANDARD IN CORBA, USE AT YOUR OWN RISK
629 /// Set to false when an error ocurrs.
632 /// Break-even point for copying.
633 size_t const memcpy_tradeoff_
;
635 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
636 ACE::Monitor_Control::Size_Monitor
*monitor_
;
637 #endif /* ACE_HAS_MONITOR_POINTS==1 */
640 /// GIOP version information
641 ACE_CDR::Octet major_version_
;
642 ACE_CDR::Octet minor_version_
;
644 /// If not nil, invoke for translation of character and string data.
645 ACE_Char_Codeset_Translator
*char_translator_
;
646 ACE_WChar_Codeset_Translator
*wchar_translator_
;
649 * Some wide char codesets may be defined with a maximum number
650 * of bytes that is smaller than the size of a wchar_t. This means
651 * that the CDR cannot simply memcpy a block of wchars to and from
652 * the stream, but must instead realign the bytes appropriately.
653 * In cases when wchar i/o is not allowed, such as with GIOP 1.0,
654 * or not having a native wchar codeset defined, the maxbytes is
655 * set to zero, indicating no wchar data is allowed.
657 static size_t wchar_maxbytes_
;
661 // ****************************************************************
664 * @class ACE_InputCDR
666 * @brief A CDR stream for demarshalling CDR-encoded data.
668 * This class is based on the the CORBA spec for Java (98-02-29),
669 * java class omg.org.CORBA.portable.InputStream. It diverts in a
671 * @li Operations to retrieve basic types take parameters by
673 * @li Operations taking arrays don't have offsets, because in C++
674 * it is easier to describe an array starting from x+offset.
675 * @li Operations return an error status, because exceptions are
676 * not widely available in C++ (yet).
678 class ACE_Export ACE_InputCDR
681 // The translators need privileged access to efficiently demarshal
683 friend class ACE_Char_Codeset_Translator
;
684 friend class ACE_WChar_Codeset_Translator
;
687 * Create an input stream from an arbitrary buffer. The buffer must
688 * be properly aligned because this constructor will *not* work if
689 * the buffer is aligned unproperly.See ACE_ptr_align_binary() for
690 * instructions on how to align a pointer properly and use
691 * ACE_CDR::MAX_ALIGNMENT for the correct alignment.
693 ACE_InputCDR (const char *buf
,
695 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
696 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
697 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
699 /// Create an empty input stream. The caller is responsible for
700 /// putting the right data and providing the right alignment.
701 ACE_InputCDR (size_t bufsiz
,
702 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
703 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
704 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
706 /// Create an input stream from an ACE_Message_Block
708 * The alignment of the @a data block is carried into the new
709 * ACE_InputCDR object. This constructor either increments the
710 * @a data reference count, or copies the data (if it's a compound
711 * message block) so the caller can release the block immediately
714 ACE_InputCDR (const ACE_Message_Block
*data
,
715 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
716 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
717 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
,
720 /// Create an input stream from an ACE_Data_Block. The @a flag
721 /// indicates whether the @a data can be deleted by the CDR stream
723 ACE_InputCDR (ACE_Data_Block
*data
,
724 ACE_Message_Block::Message_Flags flag
= 0,
725 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
726 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
727 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
729 /// Create an input stream from an ACE_Data_Block. It also sets the
730 /// read and write pointers at the desired positions. This would be
731 /// helpful if the applications desires to create a new CDR stream
732 /// from a semi-processed datablock.
733 ACE_InputCDR (ACE_Data_Block
*data
,
734 ACE_Message_Block::Message_Flags flag
,
735 size_t read_pointer_position
,
736 size_t write_pointer_position
,
737 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
738 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
739 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
742 * These make a copy of the current stream state, but do not copy
743 * the internal buffer, so the same stream can be read multiple
746 ACE_InputCDR (const ACE_InputCDR
& rhs
);
748 ACE_InputCDR
& operator= (const ACE_InputCDR
& rhs
);
750 /// When interpreting indirected TypeCodes it is useful to make a
751 /// "copy" of the stream starting in the new position.
752 ACE_InputCDR (const ACE_InputCDR
& rhs
,
754 ACE_CDR::Long offset
);
756 /// This creates an encapsulated stream, the first byte must be (per
757 /// the spec) the byte order of the encapsulation.
758 ACE_InputCDR (const ACE_InputCDR
& rhs
,
761 /// Create an input CDR from an output CDR.
762 ACE_InputCDR (const ACE_OutputCDR
& rhs
,
763 ACE_Allocator
* buffer_allocator
= 0,
764 ACE_Allocator
* data_block_allocator
= 0,
765 ACE_Allocator
* message_block_allocator
= 0);
767 /// Helper class to transfer the contents from one input CDR to
768 /// another without requiring any extra memory allocations, data
769 /// copies or too many temporaries.
770 struct ACE_Export Transfer_Contents
772 Transfer_Contents (ACE_InputCDR
&rhs
);
776 /// Transfer the contents from @a rhs to a new CDR
777 ACE_InputCDR (Transfer_Contents rhs
);
780 virtual ~ACE_InputCDR ();
782 /// Disambiguate overloading when extracting octets, chars,
783 /// booleans, and bounded strings
784 //@{ @name Helper classes
786 struct ACE_Export to_boolean
788 explicit to_boolean (ACE_CDR::Boolean
&b
);
789 ACE_CDR::Boolean
&ref_
;
792 struct ACE_Export to_char
794 explicit to_char (ACE_CDR::Char
&c
);
798 struct ACE_Export to_wchar
800 explicit to_wchar (ACE_CDR::WChar
&wc
);
801 ACE_CDR::WChar
&ref_
;
804 struct ACE_Export to_octet
806 explicit to_octet (ACE_CDR::Octet
&o
);
807 ACE_CDR::Octet
&ref_
;
810 struct ACE_Export to_int8
812 explicit to_int8 (ACE_CDR::Int8
&ref
);
816 struct ACE_Export to_uint8
818 explicit to_uint8 (ACE_CDR::UInt8
&ref
);
819 ACE_CDR::UInt8
&ref_
;
822 struct ACE_Export to_string
825 * @deprecated The constructor taking a non-const string is now
826 * deprecated (C++ mapping 00-01-02), but we keep it
827 * around for backward compatibility.
829 to_string (ACE_CDR::Char
*&s
,
831 to_string (const ACE_CDR::Char
*&s
,
833 const ACE_CDR::Char
*&val_
;
834 ACE_CDR::ULong bound_
;
837 struct ACE_Export to_wstring
839 /// The constructor taking a non-const wstring is
840 /// now deprecated (C++ mapping 00-01-02), but we
841 /// keep it around for backward compatibility.
842 to_wstring (ACE_CDR::WChar
*&ws
,
844 to_wstring (const ACE_CDR::WChar
*&ws
,
846 const ACE_CDR::WChar
*&val_
;
847 ACE_CDR::ULong bound_
;
850 /// Helper classes for extracting bounded strings into std::string/wstring.
851 struct ACE_Export to_std_string
853 to_std_string (std::string
&s
,
856 ACE_CDR::ULong bound_
;
859 #if !defined(ACE_LACKS_STD_WSTRING)
860 struct ACE_Export to_std_wstring
862 to_std_wstring (std::wstring
&ws
,
865 ACE_CDR::ULong bound_
;
867 #endif /* ACE_LACKS_STD_WSTRING */
871 * Return @c false on failure and @c true on success.
873 //@{ @name Read basic IDL types
874 ACE_CDR::Boolean
read_boolean (ACE_CDR::Boolean
& x
);
875 ACE_CDR::Boolean
read_char (ACE_CDR::Char
&x
);
876 ACE_CDR::Boolean
read_wchar (ACE_CDR::WChar
& x
);
877 ACE_CDR::Boolean
read_octet (ACE_CDR::Octet
& x
);
878 ACE_CDR::Boolean
read_short (ACE_CDR::Short
&x
);
879 ACE_CDR::Boolean
read_ushort (ACE_CDR::UShort
&x
);
880 ACE_CDR::Boolean
read_long (ACE_CDR::Long
&x
);
881 ACE_CDR::Boolean
read_ulong (ACE_CDR::ULong
&x
);
882 ACE_CDR::Boolean
read_longlong (ACE_CDR::LongLong
& x
);
883 ACE_CDR::Boolean
read_ulonglong (ACE_CDR::ULongLong
& x
);
884 ACE_CDR::Boolean
read_float (ACE_CDR::Float
&x
);
885 ACE_CDR::Boolean
read_double (ACE_CDR::Double
&x
);
886 ACE_CDR::Boolean
read_longdouble (ACE_CDR::LongDouble
&x
);
887 ACE_CDR::Boolean
read_fixed (ACE_CDR::Fixed
&x
);
888 ACE_CDR::Boolean
read_int8 (ACE_CDR::Int8
&x
);
889 ACE_CDR::Boolean
read_uint8 (ACE_CDR::UInt8
&x
);
891 ACE_CDR::Boolean
read_string (ACE_CDR::Char
*&x
);
892 ACE_CDR::Boolean
read_string (ACE_CString
&x
);
893 ACE_CDR::Boolean
read_wstring (ACE_CDR::WChar
*& x
);
894 ACE_CDR::Boolean
read_string (std::string
& x
);
895 #if !defined(ACE_LACKS_STD_WSTRING)
896 ACE_CDR::Boolean
read_wstring (std::wstring
& x
);
901 * The buffer @a x must be large enough to contain @a length
903 * Return @c false on failure and @c true on success.
905 //@{ @name Read basic IDL types arrays
906 ACE_CDR::Boolean
read_boolean_array (ACE_CDR::Boolean
* x
,
907 ACE_CDR::ULong length
);
908 ACE_CDR::Boolean
read_char_array (ACE_CDR::Char
*x
,
909 ACE_CDR::ULong length
);
910 ACE_CDR::Boolean
read_wchar_array (ACE_CDR::WChar
* x
,
911 ACE_CDR::ULong length
);
912 ACE_CDR::Boolean
read_octet_array (ACE_CDR::Octet
* x
,
913 ACE_CDR::ULong length
);
914 ACE_CDR::Boolean
read_short_array (ACE_CDR::Short
*x
,
915 ACE_CDR::ULong length
);
916 ACE_CDR::Boolean
read_ushort_array (ACE_CDR::UShort
*x
,
917 ACE_CDR::ULong length
);
918 ACE_CDR::Boolean
read_long_array (ACE_CDR::Long
*x
,
919 ACE_CDR::ULong length
);
920 ACE_CDR::Boolean
read_ulong_array (ACE_CDR::ULong
*x
,
921 ACE_CDR::ULong length
);
922 ACE_CDR::Boolean
read_longlong_array (ACE_CDR::LongLong
* x
,
923 ACE_CDR::ULong length
);
924 ACE_CDR::Boolean
read_ulonglong_array (ACE_CDR::ULongLong
* x
,
925 ACE_CDR::ULong length
);
926 ACE_CDR::Boolean
read_float_array (ACE_CDR::Float
*x
,
927 ACE_CDR::ULong length
);
928 ACE_CDR::Boolean
read_double_array (ACE_CDR::Double
*x
,
929 ACE_CDR::ULong length
);
930 ACE_CDR::Boolean
read_longdouble_array (ACE_CDR::LongDouble
* x
,
931 ACE_CDR::ULong length
);
932 ACE_CDR::Boolean
read_int8_array (ACE_CDR::Int8
*x
, ACE_CDR::ULong length
);
933 ACE_CDR::Boolean
read_uint8_array (ACE_CDR::UInt8
*x
, ACE_CDR::ULong length
);
937 * Return @c false on failure and @c true on success.
939 //@{ @name Skip elements
940 ACE_CDR::Boolean
skip_boolean ();
941 ACE_CDR::Boolean
skip_char ();
942 ACE_CDR::Boolean
skip_wchar ();
943 ACE_CDR::Boolean
skip_octet ();
944 ACE_CDR::Boolean
skip_short ();
945 ACE_CDR::Boolean
skip_ushort ();
946 ACE_CDR::Boolean
skip_long ();
947 ACE_CDR::Boolean
skip_ulong ();
948 ACE_CDR::Boolean
skip_longlong ();
949 ACE_CDR::Boolean
skip_ulonglong ();
950 ACE_CDR::Boolean
skip_float ();
951 ACE_CDR::Boolean
skip_double ();
952 ACE_CDR::Boolean
skip_longdouble ();
953 ACE_CDR::Boolean
skip_fixed ();
957 * The next field must be a string, this method skips it. It is
958 * useful in parsing a TypeCode.
959 * @return @c false on failure and @c true on success.
961 ACE_CDR::Boolean
skip_wstring ();
962 ACE_CDR::Boolean
skip_string ();
964 /// Skip @a n bytes in the CDR stream.
966 * @return @c false on failure and @c true on success.
968 ACE_CDR::Boolean
skip_bytes (size_t n
);
970 /// returns @c false if a problem has been detected.
971 bool good_bit () const;
974 * @return The start of the message block chain for this CDR
977 * @note In the current implementation the chain has length 1, but
978 * we are planning to change that.
980 const ACE_Message_Block
* start () const;
982 // = The following functions are useful to read the contents of the
983 // CDR stream from a socket or file.
986 * Grow the internal buffer, reset @c rd_ptr to the first byte in
987 * the new buffer that is properly aligned, and set @c wr_ptr to @c
988 * rd_ptr @c + @c newsize
990 int grow (size_t newsize
);
993 * After reading and partially parsing the contents the user can
994 * detect a change in the byte order, this method will let him/her
997 void reset_byte_order (int byte_order
);
999 /// Re-initialize the CDR stream, copying the contents of the chain
1000 /// of message_blocks starting from @a data.
1001 void reset (const ACE_Message_Block
*data
,
1004 /// Steal the contents from the current CDR.
1005 ACE_Message_Block
*steal_contents ();
1007 /// Steal the contents of @a cdr and make a shallow copy into this
1009 void steal_from (ACE_InputCDR
&cdr
);
1011 /// Exchange data blocks with the caller of this method. The read
1012 /// and write pointers are also exchanged.
1014 * @note We now do only with the start_ message block.
1016 void exchange_data_blocks (ACE_InputCDR
&cdr
);
1018 /// Copy the data portion from the @a cdr to this cdr and return the
1019 /// data content (ie. the ACE_Data_Block) from this CDR to the
1022 * @note The caller is responsible for managing the memory of the
1023 * returned ACE_Data_Block.
1025 ACE_Data_Block
* clone_from (ACE_InputCDR
&cdr
);
1027 /// Re-initialize the CDR stream, forgetting about the old contents
1028 /// of the stream and allocating a new buffer (from the allocators).
1029 void reset_contents ();
1031 /// Returns the current position for the @c rd_ptr.
1034 /// Returns the current position for the @c wr_ptr.
1037 /// Return how many bytes are left in the stream.
1038 size_t length () const;
1041 * Utility function to allow the user more flexibility.
1042 * Skips up to the nearest @a alignment-byte boundary.
1043 * Argument MUST be a power of 2.
1045 * @return 0 on success and -1 on failure.
1047 int align_read_ptr (size_t alignment
);
1049 /// If @c true then this stream is writing in non-native byte order.
1050 /// This is only meaningful if ACE_ENABLE_SWAP_ON_WRITE is defined.
1051 bool do_byte_swap () const;
1053 /// If @c do_byte_swap() returns @c false, this returns
1054 /// ACE_CDR_BYTE_ORDER else it returns !ACE_CDR_BYTE_ORDER.
1055 int byte_order () const;
1057 /// Access the codeset translators. They can be nil!
1058 ACE_Char_Codeset_Translator
*char_translator () const;
1059 ACE_WChar_Codeset_Translator
*wchar_translator () const;
1061 /// Set the codeset translators.
1062 void char_translator (ACE_Char_Codeset_Translator
*);
1063 void wchar_translator (ACE_WChar_Codeset_Translator
*);
1066 * Returns (in @a buf) the next position in the buffer aligned to
1067 * @a size. It advances the Message_Block @c rd_ptr past the data
1068 * (i.e., @c buf @c + @c size). Sets the good_bit to @c false and
1069 * returns a -1 on failure.
1071 int adjust (size_t size
,
1074 /// As above, but now the size and alignment requirements may be
1076 int adjust (size_t size
,
1080 /// Set the underlying GIOP version..
1081 void set_version (ACE_CDR::Octet major
, ACE_CDR::Octet minor
);
1083 /// Set the underlying GIOP version..
1084 void get_version (ACE_CDR::Octet
&major
, ACE_CDR::Octet
&minor
);
1086 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1087 /// Register and unregister our buffer size monitor.
1088 void register_monitor (const char* id
);
1089 void unregister_monitor ();
1090 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1093 /// The start of the chain of message blocks, even though in the
1094 /// current version the chain always has length 1.
1095 ACE_Message_Block start_
;
1097 /// The CDR stream byte order does not match the one on the machine,
1098 /// swapping is needed while reading.
1101 /// set to @c false when an error occurs.
1104 /// The GIOP versions for this stream
1105 ACE_CDR::Octet major_version_
;
1106 ACE_CDR::Octet minor_version_
;
1108 /// If not nil, invoke for translation of character and string data.
1109 ACE_Char_Codeset_Translator
*char_translator_
;
1110 ACE_WChar_Codeset_Translator
*wchar_translator_
;
1112 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1113 ACE::Monitor_Control::Size_Monitor
*monitor_
;
1114 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1117 ACE_CDR::Boolean
read_1 (ACE_CDR::Octet
*x
);
1118 ACE_CDR::Boolean
read_2 (ACE_CDR::UShort
*x
);
1119 ACE_CDR::Boolean
read_4 (ACE_CDR::ULong
*x
);
1120 ACE_CDR::Boolean
read_8 (ACE_CDR::ULongLong
*x
);
1121 ACE_CDR::Boolean
read_16 (ACE_CDR::LongDouble
*x
);
1123 // Several types can be read using the same routines, since TAO
1124 // tries to use native types with known size for each CORBA type.
1125 // We could use void* or char* to make the interface more
1126 // consistent, but using native types let us exploit the strict
1127 // alignment requirements of CDR streams and implement the
1128 // operations using assignment.
1131 * Read an array of @a length elements, each of @a size bytes and the
1132 * start aligned at a multiple of @a align. The elements are assumed
1133 * to be packed with the right alignment restrictions. It is mostly
1134 * designed for buffers of the basic types.
1136 * This operation uses @c memcpy; as explained above it is expected
1137 * that using assignment is faster that @c memcpy for one element,
1138 * but for several elements @c memcpy should be more efficient, it
1139 * could be interesting to find the break even point and optimize
1140 * for that case, but that would be too platform dependent.
1142 ACE_CDR::Boolean
read_array (void* x
,
1145 ACE_CDR::ULong length
);
1148 * On those occasions when the native codeset for wchar is smaller than
1149 * the size of a wchar_t, such as using UTF-16 with a 4-byte wchar_t, a
1150 * special form of reading the array is needed. Actually, this should be
1151 * a default translator.
1153 ACE_CDR::Boolean
read_wchar_array_i (ACE_CDR::WChar
* x
,
1154 ACE_CDR::ULong length
);
1156 /// Move the rd_ptr ahead by @a offset bytes.
1157 void rd_ptr (size_t offset
);
1159 /// Points to the continuation field of the current message block.
1163 // ****************************************************************
1166 * @class ACE_Char_Codeset_Translator
1168 * @brief Codeset translation routines common to both Output and Input
1171 * This class is a base class for defining codeset translation
1172 * routines to handle the character set translations required by
1173 * both CDR Input streams and CDR Output streams.
1175 * Translators are reference counted. This allows for stateful as well
1176 * as stateless translators. Stateless translators will be allocated
1177 * once whereas CDR Streams own their own copy of a stateful translator.
1179 class ACE_Export ACE_Char_Codeset_Translator
1182 virtual ~ACE_Char_Codeset_Translator () = default;
1184 /// Read a single character from the stream, converting from the
1185 /// stream codeset to the native codeset
1186 virtual ACE_CDR::Boolean
read_char (ACE_InputCDR
&,
1187 ACE_CDR::Char
&) = 0;
1189 /// Read a string from the stream, including the length, converting
1190 /// the characters from the stream codeset to the native codeset
1191 virtual ACE_CDR::Boolean
read_string (ACE_InputCDR
&,
1192 ACE_CDR::Char
*&) = 0;
1194 /// Read a std::string from the stream, including the length, converting
1195 /// the characters from the stream codeset to the native codeset
1196 /// (provide non-optimized default implementation)
1197 virtual ACE_CDR::Boolean
read_string (ACE_InputCDR
&,
1200 /// Read an array of characters from the stream, converting the
1201 /// characters from the stream codeset to the native codeset.
1202 virtual ACE_CDR::Boolean
read_char_array (ACE_InputCDR
&,
1204 ACE_CDR::ULong
) = 0;
1206 /// Write a single character to the stream, converting from the
1207 /// native codeset to the stream codeset
1208 virtual ACE_CDR::Boolean
write_char (ACE_OutputCDR
&,
1211 /// Write a string to the stream, including the length, converting
1212 /// from the native codeset to the stream codeset
1213 virtual ACE_CDR::Boolean
write_string (ACE_OutputCDR
&,
1215 const ACE_CDR::Char
*) = 0;
1217 /// Write an array of characters to the stream, converting from the
1218 /// native codeset to the stream codeset
1219 virtual ACE_CDR::Boolean
write_char_array (ACE_OutputCDR
&,
1220 const ACE_CDR::Char
*,
1221 ACE_CDR::ULong
) = 0;
1223 virtual ACE_CDR::ULong
ncs () = 0;
1224 virtual ACE_CDR::ULong
tcs () = 0;
1226 /// Children have access to low-level routines because they cannot
1227 /// use read_char or something similar (it would recurse).
1228 ACE_CDR::Boolean
read_1 (ACE_InputCDR
& input
,
1230 ACE_CDR::Boolean
write_1 (ACE_OutputCDR
& output
,
1231 const ACE_CDR::Octet
*x
);
1233 /// Efficiently read @a length elements of size @a size each from
1234 /// @a input into @a x; the data must be aligned to @a align.
1235 ACE_CDR::Boolean
read_array (ACE_InputCDR
& input
,
1239 ACE_CDR::ULong length
);
1242 * Efficiently write @a length elements of size @a size from <x> into
1243 * <output>. Before inserting the elements enough padding is added
1244 * to ensure that the elements will be aligned to <align> in the
1247 ACE_CDR::Boolean
write_array (ACE_OutputCDR
& output
,
1251 ACE_CDR::ULong length
);
1254 * Exposes the stream implementation of <adjust>, this is useful in
1255 * many cases to minimize memory allocations during marshaling.
1256 * On success @a buf will contain a contiguous area in the CDR stream
1257 * that can hold @a size bytes aligned to @a align.
1260 int adjust (ACE_OutputCDR
& out
,
1265 /// Used by derived classes to set errors in the CDR stream.
1266 void good_bit (ACE_OutputCDR
& out
, bool bit
);
1268 /// Obtain the CDR Stream's major & minor version values.
1269 ACE_CDR::Octet
major_version (ACE_InputCDR
& input
);
1270 ACE_CDR::Octet
minor_version (ACE_InputCDR
& input
);
1271 ACE_CDR::Octet
major_version (ACE_OutputCDR
& output
);
1272 ACE_CDR::Octet
minor_version (ACE_OutputCDR
& output
);
1275 // ****************************************************************
1278 * @class ACE_WChar_Codeset_Translator
1280 * @brief Codeset translation routines common to both Output and Input
1283 * This class is a base class for defining codeset translation
1284 * routines to handle the character set translations required by
1285 * both CDR Input streams and CDR Output streams.
1287 class ACE_Export ACE_WChar_Codeset_Translator
1290 virtual ~ACE_WChar_Codeset_Translator () = default;
1292 virtual ACE_CDR::Boolean
read_wchar (ACE_InputCDR
&,
1293 ACE_CDR::WChar
&) = 0;
1294 virtual ACE_CDR::Boolean
read_wstring (ACE_InputCDR
&,
1295 ACE_CDR::WChar
*&) = 0;
1296 #if !defined(ACE_LACKS_STD_WSTRING)
1297 /// Read a std::wstring from the stream, including the length, converting
1298 /// the characters from the stream codeset to the native codeset
1299 /// (provide non-optimized default implementation)
1300 virtual ACE_CDR::Boolean
read_wstring (ACE_InputCDR
&,
1303 virtual ACE_CDR::Boolean
read_wchar_array (ACE_InputCDR
&,
1305 ACE_CDR::ULong
) = 0;
1306 virtual ACE_CDR::Boolean
write_wchar (ACE_OutputCDR
&,
1307 ACE_CDR::WChar
) = 0;
1308 virtual ACE_CDR::Boolean
write_wstring (ACE_OutputCDR
&,
1310 const ACE_CDR::WChar
*) = 0;
1311 virtual ACE_CDR::Boolean
write_wchar_array (ACE_OutputCDR
&,
1312 const ACE_CDR::WChar
*,
1313 ACE_CDR::ULong
) = 0;
1315 virtual ACE_CDR::ULong
ncs () = 0;
1316 virtual ACE_CDR::ULong
tcs () = 0;
1318 /// Children have access to low-level routines because they cannot
1319 /// use read_char or something similar (it would recurse).
1320 ACE_CDR::Boolean
read_1 (ACE_InputCDR
& input
,
1322 ACE_CDR::Boolean
read_2 (ACE_InputCDR
& input
,
1323 ACE_CDR::UShort
*x
);
1324 ACE_CDR::Boolean
read_4 (ACE_InputCDR
& input
,
1326 ACE_CDR::Boolean
write_1 (ACE_OutputCDR
& output
,
1327 const ACE_CDR::Octet
*x
);
1328 ACE_CDR::Boolean
write_2 (ACE_OutputCDR
& output
,
1329 const ACE_CDR::UShort
*x
);
1330 ACE_CDR::Boolean
write_4 (ACE_OutputCDR
& output
,
1331 const ACE_CDR::ULong
*x
);
1333 /// Efficiently read @a length elements of size @a size each from
1334 /// @a input into @a x; the data must be aligned to @a align.
1335 ACE_CDR::Boolean
read_array (ACE_InputCDR
& input
,
1339 ACE_CDR::ULong length
);
1342 * Efficiently write @a length elements of size @a size from @a x into
1343 * @a output. Before inserting the elements enough padding is added
1344 * to ensure that the elements will be aligned to @a align in the
1347 ACE_CDR::Boolean
write_array (ACE_OutputCDR
& output
,
1351 ACE_CDR::ULong length
);
1354 * Exposes the stream implementation of @a adjust, this is useful in
1355 * many cases to minimize memory allocations during marshaling.
1356 * On success @a buf will contain a contiguous area in the CDR stream
1357 * that can hold @a size bytes aligned to @a align.
1360 int adjust (ACE_OutputCDR
& out
,
1365 /// Used by derived classes to set errors in the CDR stream.
1366 void good_bit (ACE_OutputCDR
& out
, bool bit
);
1368 /// Obtain the CDR Stream's major & minor version values.
1369 ACE_CDR::Octet
major_version (ACE_InputCDR
& input
);
1370 ACE_CDR::Octet
minor_version (ACE_InputCDR
& input
);
1371 ACE_CDR::Octet
major_version (ACE_OutputCDR
& output
);
1372 ACE_CDR::Octet
minor_version (ACE_OutputCDR
& output
);
1375 // @@ These operators should not be inlined since they force SString.h
1376 // to be included in this header.
1377 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1378 const ACE_CString
&x
);
1380 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1384 ACE_END_VERSIONED_NAMESPACE_DECL
1386 #if defined (__ACE_INLINE__)
1387 # include "ace/CDR_Stream.inl"
1388 #else /* __ACE_INLINE__ */
1390 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
1392 // Not used by CORBA or TAO
1393 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1395 // CDR output operators for primitive types
1397 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1399 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1401 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1403 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1405 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1406 ACE_CDR::LongLong x
);
1407 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1408 ACE_CDR::ULongLong x
);
1409 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
& os
,
1410 ACE_CDR::LongDouble x
);
1411 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1413 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1415 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1416 const ACE_CDR::Fixed
&x
);
1418 // CDR output operator from helper classes
1420 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1421 ACE_OutputCDR::from_boolean x
);
1422 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1423 ACE_OutputCDR::from_char x
);
1424 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1425 ACE_OutputCDR::from_wchar x
);
1426 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1427 ACE_OutputCDR::from_octet x
);
1428 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1429 ACE_OutputCDR::from_string x
);
1430 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1431 ACE_OutputCDR::from_wstring x
);
1432 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1433 const ACE_CDR::Char
* x
);
1434 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1435 const ACE_CDR::WChar
* x
);
1436 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1437 ACE_OutputCDR::from_std_string x
);
1438 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1439 const std::string
& x
);
1440 #if !defined(ACE_LACKS_STD_WSTRING)
1441 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1442 ACE_OutputCDR::from_std_wstring x
);
1443 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1444 const std::wstring
& x
);
1446 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
, ACE_OutputCDR::from_uint8 x
);
1447 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
, ACE_OutputCDR::from_int8 x
);
1449 // Not used by CORBA or TAO
1450 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1452 // CDR input operators for primitive types
1454 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1456 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1457 ACE_CDR::UShort
&x
);
1458 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1460 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1462 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1463 ACE_CDR::LongLong
&x
);
1464 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1465 ACE_CDR::ULongLong
&x
);
1466 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1467 ACE_CDR::LongDouble
&x
);
1468 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1470 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1471 ACE_CDR::Double
&x
);
1472 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1475 // CDR input operator from helper classes
1477 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1478 ACE_InputCDR::to_boolean x
);
1479 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1480 ACE_InputCDR::to_char x
);
1481 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1482 ACE_InputCDR::to_wchar x
);
1483 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1484 ACE_InputCDR::to_octet x
);
1485 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1486 ACE_InputCDR::to_string x
);
1487 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1488 ACE_InputCDR::to_wstring x
);
1489 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1491 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1492 ACE_CDR::WChar
*& x
);
1493 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_InputCDR
&os
,
1494 ACE_InputCDR::to_std_string x
);
1495 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1497 #if !defined(ACE_LACKS_STD_WSTRING)
1498 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_InputCDR
&os
,
1499 ACE_InputCDR::to_std_wstring x
);
1500 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1503 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&os
, ACE_InputCDR::to_uint8 x
);
1504 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&os
, ACE_InputCDR::to_int8 x
);
1506 ACE_END_VERSIONED_NAMESPACE_DECL
1508 #endif /* __ACE_INLINE__ */
1510 #if defined (GEN_OSTREAM_OPS)
1512 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
1514 // ostream insertion operators for debugging code generated from IDL. All
1515 // but these below are either in generated code itself or are unambiguous
1518 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1519 ACE_OutputCDR::from_boolean x
);
1521 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1522 ACE_OutputCDR::from_char x
);
1524 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1525 ACE_OutputCDR::from_wchar x
);
1527 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1528 ACE_OutputCDR::from_octet x
);
1530 ACE_END_VERSIONED_NAMESPACE_DECL
1532 #endif /* GEN_OSTREAM_OPS */
1534 #include /**/ "ace/post.h"
1536 #endif /* ACE_CDR_STREAM_H */