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
);
168 ~ACE_OutputCDR (void);
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_string
202 from_string (ACE_CDR::Char
* s
,
204 ACE_CDR::Boolean nocopy
= 0);
205 from_string (const ACE_CDR::Char
* s
,
207 ACE_CDR::Boolean nocopy
= 0);
209 ACE_CDR::ULong bound_
;
210 ACE_CDR::Boolean nocopy_
;
213 struct ACE_Export from_wstring
215 from_wstring (ACE_CDR::WChar
* ws
,
217 ACE_CDR::Boolean nocopy
= 0);
218 from_wstring (const ACE_CDR::WChar
* ws
,
220 ACE_CDR::Boolean nocopy
= 0);
221 ACE_CDR::WChar
*val_
;
222 ACE_CDR::ULong bound_
;
223 ACE_CDR::Boolean nocopy_
;
226 struct ACE_Export from_std_string
228 from_std_string (const std::string
&s
,
230 const std::string
&val_
;
231 ACE_CDR::ULong bound_
;
234 #if !defined(ACE_LACKS_STD_WSTRING)
235 struct ACE_Export from_std_wstring
237 from_std_wstring (const std::wstring
&ws
,
239 const std::wstring
&val_
;
240 ACE_CDR::ULong bound_
;
246 * @{ @name Write operations
247 * Return 0 on failure and 1 on success.
249 ACE_CDR::Boolean
write_boolean (ACE_CDR::Boolean x
);
250 ACE_CDR::Boolean
write_char (ACE_CDR::Char x
);
251 ACE_CDR::Boolean
write_wchar (ACE_CDR::WChar x
);
252 ACE_CDR::Boolean
write_octet (ACE_CDR::Octet x
);
253 ACE_CDR::Boolean
write_short (ACE_CDR::Short x
);
254 ACE_CDR::Boolean
write_ushort (ACE_CDR::UShort x
);
255 ACE_CDR::Boolean
write_long (ACE_CDR::Long x
);
256 ACE_CDR::Boolean
write_ulong (ACE_CDR::ULong x
);
257 ACE_CDR::Boolean
write_longlong (const ACE_CDR::LongLong
&x
);
258 ACE_CDR::Boolean
write_ulonglong (const ACE_CDR::ULongLong
&x
);
259 ACE_CDR::Boolean
write_float (ACE_CDR::Float x
);
260 ACE_CDR::Boolean
write_double (const ACE_CDR::Double
&x
);
261 ACE_CDR::Boolean
write_longdouble (const ACE_CDR::LongDouble
&x
);
262 ACE_CDR::Boolean
write_fixed (const ACE_CDR::Fixed
&x
);
264 /// For string we offer methods that accept a precomputed length.
265 ACE_CDR::Boolean
write_string (const ACE_CDR::Char
*x
);
266 ACE_CDR::Boolean
write_string (ACE_CDR::ULong len
,
267 const ACE_CDR::Char
*x
);
268 ACE_CDR::Boolean
write_string (const ACE_CString
&x
);
269 ACE_CDR::Boolean
write_wstring (const ACE_CDR::WChar
*x
);
270 ACE_CDR::Boolean
write_wstring (ACE_CDR::ULong length
,
271 const ACE_CDR::WChar
*x
);
272 ACE_CDR::Boolean
write_string (const std::string
&x
);
273 #if !defined(ACE_LACKS_STD_WSTRING)
274 ACE_CDR::Boolean
write_wstring (const std::wstring
&x
);
279 /// @note the portion written starts at @a x and ends
280 /// at @a x + @a length.
281 /// The length is *NOT* stored into the CDR stream.
282 //@{ @name Array write operations
283 ACE_CDR::Boolean
write_boolean_array (const ACE_CDR::Boolean
*x
,
284 ACE_CDR::ULong length
);
285 ACE_CDR::Boolean
write_char_array (const ACE_CDR::Char
*x
,
286 ACE_CDR::ULong length
);
287 ACE_CDR::Boolean
write_wchar_array (const ACE_CDR::WChar
* x
,
288 ACE_CDR::ULong length
);
289 ACE_CDR::Boolean
write_octet_array (const ACE_CDR::Octet
* x
,
290 ACE_CDR::ULong length
);
291 ACE_CDR::Boolean
write_short_array (const ACE_CDR::Short
*x
,
292 ACE_CDR::ULong length
);
293 ACE_CDR::Boolean
write_ushort_array (const ACE_CDR::UShort
*x
,
294 ACE_CDR::ULong length
);
295 ACE_CDR::Boolean
write_long_array (const ACE_CDR::Long
*x
,
296 ACE_CDR::ULong length
);
297 ACE_CDR::Boolean
write_ulong_array (const ACE_CDR::ULong
*x
,
298 ACE_CDR::ULong length
);
299 ACE_CDR::Boolean
write_longlong_array (const ACE_CDR::LongLong
* x
,
300 ACE_CDR::ULong length
);
301 ACE_CDR::Boolean
write_ulonglong_array (const ACE_CDR::ULongLong
*x
,
302 ACE_CDR::ULong length
);
303 ACE_CDR::Boolean
write_float_array (const ACE_CDR::Float
*x
,
304 ACE_CDR::ULong length
);
305 ACE_CDR::Boolean
write_double_array (const ACE_CDR::Double
*x
,
306 ACE_CDR::ULong length
);
307 ACE_CDR::Boolean
write_longdouble_array (const ACE_CDR::LongDouble
* x
,
308 ACE_CDR::ULong length
);
310 /// Write an octet array contained inside a MB, this can be optimized
311 /// to minimize copies.
312 ACE_CDR::Boolean
write_octet_array_mb (const ACE_Message_Block
* mb
);
316 * @{ @name Placeholder/replace operations
317 * Facilitates writing a placeholder into a CDR stream to be replaced
318 * later with a different value.
320 * @note An example use for this facility is:
323 ... // insert values...
324 char *pos = strm.write_long_placeholder ();
325 ... // insert more values
326 ACE_CDR::Long real_val; // Somehow assign the "correct" value
327 strm.replace (real_val, pos); // Replace earlier placeholder
332 * Write a placeholder into the stream. The placeholder's pointer
333 * is returned so it may later be passed as the @a loc argument to
335 * These methods align the stream's write pointer properly prior to
336 * writing the placeholder.
338 * @retval Pointer to the placeholder; 0 if there is not enough space
339 * in the stream and memory could not be allocated.
341 char* write_long_placeholder (void);
342 char* write_short_placeholder (void);
343 char* write_boolean_placeholder (void);
344 char* write_char_placeholder (void);
345 char* write_longlong_placeholder (void);
346 char* write_octet_placeholder (void);
347 char* write_float_placeholder (void);
348 char* write_double_placeholder (void);
351 * Writes a new value into a specific location. This is commonly
352 * used to update a prior "placeholder" location in the stream.
353 * The specified location is assumed to have proper CDR alignment for the
354 * type to insert. This requirement is satisfied by using one of the
355 * placeholder-writing methods to align the stream for the anticipated
356 * value and obtain the correct location.
357 * Treatment of @a x with respect to byte swapping is the same as for when
358 * any value is inserted.
360 * @param x The value to insert into the specified location.
361 * @param loc The location at which to insert @a x. @a loc must be a valid
362 * position within the stream's current set of message blocks.
364 * @sa write_long_placeholder(), write_short_placeholder ()
366 ACE_CDR::Boolean
replace (ACE_CDR::Long x
, char* loc
);
367 ACE_CDR::Boolean
replace (ACE_CDR::ULong x
, char* loc
);
368 ACE_CDR::Boolean
replace (ACE_CDR::Short x
, char* loc
);
369 ACE_CDR::Boolean
replace (ACE_CDR::UShort x
, char* loc
);
370 ACE_CDR::Boolean
replace (ACE_CDR::Boolean x
, char* loc
);
371 ACE_CDR::Boolean
replace (ACE_CDR::Char x
, char* loc
);
372 ACE_CDR::Boolean
replace (ACE_CDR::LongLong x
, char* loc
);
373 ACE_CDR::Boolean
replace (ACE_CDR::ULongLong x
, char* loc
);
374 ACE_CDR::Boolean
replace (ACE_CDR::Octet x
, char* loc
);
375 ACE_CDR::Boolean
replace (ACE_CDR::Float x
, char* loc
);
376 ACE_CDR::Boolean
replace (ACE_CDR::Double x
, char* loc
);
380 * Return 0 on failure and 1 on success.
382 //@{ @name Append contents of own CDR stream to another
383 ACE_CDR::Boolean
append_boolean (ACE_InputCDR
&);
384 ACE_CDR::Boolean
append_char (ACE_InputCDR
&);
385 ACE_CDR::Boolean
append_wchar (ACE_InputCDR
&);
386 ACE_CDR::Boolean
append_octet (ACE_InputCDR
&);
387 ACE_CDR::Boolean
append_short (ACE_InputCDR
&);
388 ACE_CDR::Boolean
append_ushort (ACE_InputCDR
&);
389 ACE_CDR::Boolean
append_long (ACE_InputCDR
&);
390 ACE_CDR::Boolean
append_ulong (ACE_InputCDR
&);
391 ACE_CDR::Boolean
append_longlong (ACE_InputCDR
&);
392 ACE_CDR::Boolean
append_ulonglong (ACE_InputCDR
&);
393 ACE_CDR::Boolean
append_float (ACE_InputCDR
&);
394 ACE_CDR::Boolean
append_double (ACE_InputCDR
&);
395 ACE_CDR::Boolean
append_longdouble (ACE_InputCDR
&);
396 ACE_CDR::Boolean
append_fixed (ACE_InputCDR
&);
398 ACE_CDR::Boolean
append_wstring (ACE_InputCDR
&);
399 ACE_CDR::Boolean
append_string (ACE_InputCDR
&);
402 /// Returns @c false if an error has occurred.
404 * @note The only expected error is to run out of memory.
406 bool good_bit (void) const;
408 /// Reuse the CDR stream to write on the old buffer.
411 /// Add the length of each message block in the chain.
412 size_t total_length (void) const;
415 * Return the start of the message block chain for this CDR stream.
416 * @note The complete CDR stream is represented by a chain of
419 const ACE_Message_Block
*begin (void) const;
421 /// Return the last message in the chain that is is use.
422 const ACE_Message_Block
*end (void) const;
424 /// Return the <current_> message block in chain.
425 const ACE_Message_Block
*current (void) const;
427 /// Replace the message block chain with a single message block.
429 * Upon successful completion, there will be a single message block
430 * containing the data from the complete message block chain.
432 * @note The only expected error is to run out of memory.
434 int consolidate (void);
437 * Access the underlying buffer (read only). @note This
438 * method only returns a pointer to the first block in the
441 const char *buffer (void) const;
444 * Return the size of first message block in the block chain. @note This
445 * method only returns information about the first block in the
448 size_t length (void) const;
451 * Utility function to allow the user more flexibility.
452 * Pads the stream up to the nearest @a alignment byte boundary.
453 * Argument MUST be a power of 2.
454 * Returns 0 on success and -1 on failure.
456 int align_write_ptr (size_t alignment
);
458 /// Access the codeset translators. They can be null!
459 ACE_Char_Codeset_Translator
*char_translator (void) const;
460 ACE_WChar_Codeset_Translator
*wchar_translator (void) const;
462 /// Set the char codeset translator.
463 void char_translator (ACE_Char_Codeset_Translator
*);
464 /// Set the wchar codeset translator.
465 void wchar_translator (ACE_WChar_Codeset_Translator
*);
467 /// set the global size of serialized wchars. This may be different
468 /// than the size of a wchar_t.
469 static void wchar_maxbytes (size_t max_bytes
);
471 /// access the serialized size of wchars.
472 static size_t wchar_maxbytes (void);
475 * Return alignment of the wr_ptr(), with respect to the start of
476 * the CDR stream. This is not the same as the alignment of
479 size_t current_alignment (void) const;
481 void current_alignment (size_t current_alignment
);
484 * Returns (in @a buf) the next position in the buffer aligned to
485 * @a size, it advances the Message_Block wr_ptr past the data
486 * (i.e., @a buf + @a size). If necessary it grows the Message_Block
487 * buffer. Sets the good_bit to false and returns a -1 on failure.
489 int adjust (size_t size
,
492 /// As above, but now the size and alignment requirements may be
494 int adjust (size_t size
,
498 /// Returns true if this stream is writing in non-native byte order
499 /// and false otherwise. For example, it would be true if either
500 /// ACE_ENABLE_SWAP_ON_WRITE is defined or a specific byte order was
501 /// specified for this stream.
502 bool do_byte_swap (void) const;
504 /// Returns the byte order this stream is marshaling data in. Will be one
505 /// of the values in ACE_CDR::Byte_Order.
506 int byte_order (void) const;
508 /// For use by a gateway, which creates the output stream for the
509 /// reply to the client in its native byte order, but which must
510 /// send the reply in the byte order of the target's reply to the
512 void reset_byte_order (int byte_order
);
514 /// Set GIOP version info
515 void set_version (ACE_CDR::Octet major
, ACE_CDR::Octet minor
);
517 /// Set the underlying GIOP version..
518 void get_version (ACE_CDR::Octet
&major
, ACE_CDR::Octet
&minor
);
520 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
521 /// Register and unregister our buffer size monitor.
522 void register_monitor (const char* id
);
523 void unregister_monitor (void);
524 #endif /* ACE_HAS_MONITOR_POINTS==1 */
527 // Find the message block in the chain of message blocks
528 // that the provide location locates.
529 ACE_Message_Block
* find (char* loc
);
531 /// disallow copying...
532 ACE_OutputCDR (const ACE_OutputCDR
& rhs
);
533 ACE_OutputCDR
& operator= (const ACE_OutputCDR
& rhs
);
535 ACE_CDR::Boolean
write_1 (const ACE_CDR::Octet
*x
);
536 ACE_CDR::Boolean
write_2 (const ACE_CDR::UShort
*x
);
537 ACE_CDR::Boolean
write_4 (const ACE_CDR::ULong
*x
);
538 ACE_CDR::Boolean
write_8 (const ACE_CDR::ULongLong
*x
);
539 ACE_CDR::Boolean
write_16 (const ACE_CDR::LongDouble
*x
);
542 * write an array of @a length elements, each of @a size bytes and the
543 * start aligned at a multiple of @a align. The elements are assumed
544 * to be packed with the right alignment restrictions. It is mostly
545 * designed for buffers of the basic types.
547 * This operation uses @c memcpy; as explained above it is expected
548 * that using assignment is faster that @c memcpy for one element,
549 * but for several elements @c memcpy should be more efficient, it
550 * could be interesting to find the break even point and optimize
551 * for that case, but that would be too platform dependent.
553 ACE_CDR::Boolean
write_array (const void *x
,
556 ACE_CDR::ULong length
);
559 ACE_CDR::Boolean
write_wchar_array_i (const ACE_CDR::WChar
* x
,
560 ACE_CDR::ULong length
);
564 * Grow the CDR stream. When it returns @a buf contains a pointer to
565 * memory in the CDR stream, with at least @a size bytes ahead of it
566 * and aligned to an @a align boundary. It moved the <wr_ptr> to <buf
569 int grow_and_adjust (size_t size
,
574 /// The start of the chain of message blocks.
575 ACE_Message_Block start_
;
577 /// The current block in the chain where we are writing.
578 ACE_Message_Block
*current_
;
580 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
582 * The current alignment as measured from the start of the buffer.
583 * Usually this coincides with the alignment of the buffer in
584 * memory, but, when we chain another buffer this "quasi invariant"
586 * The current_alignment is used to readjust the buffer following
587 * the stolen message block.
589 size_t current_alignment_
;
590 #endif /* ACE_LACKS_CDR_ALIGNMENT */
593 * Is the current block writable. When we steal a buffer from the
594 * user and just chain it into the message block we are not supposed
595 * to write on it, even if it is past the start and end of the
598 bool current_is_writable_
;
601 * If not zero swap bytes at writing so the created CDR stream byte
602 * order does *not* match the machine byte order. The motivation
603 * for such a beast is that in some setting a few (fast) machines
604 * can be serving hundreds of slow machines with the opposite byte
605 * order, so it makes sense (as a load balancing device) to put the
606 * responsibility in the writers.
608 * @warning THIS IS NOT A STANDARD IN CORBA, USE AT YOUR OWN RISK
612 /// Set to false when an error ocurrs.
615 /// Break-even point for copying.
616 size_t const memcpy_tradeoff_
;
618 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
619 ACE::Monitor_Control::Size_Monitor
*monitor_
;
620 #endif /* ACE_HAS_MONITOR_POINTS==1 */
623 /// GIOP version information
624 ACE_CDR::Octet major_version_
;
625 ACE_CDR::Octet minor_version_
;
627 /// If not nil, invoke for translation of character and string data.
628 ACE_Char_Codeset_Translator
*char_translator_
;
629 ACE_WChar_Codeset_Translator
*wchar_translator_
;
632 * Some wide char codesets may be defined with a maximum number
633 * of bytes that is smaller than the size of a wchar_t. This means
634 * that the CDR cannot simply memcpy a block of wchars to and from
635 * the stream, but must instead realign the bytes appropriately.
636 * In cases when wchar i/o is not allowed, such as with GIOP 1.0,
637 * or not having a native wchar codeset defined, the maxbytes is
638 * set to zero, indicating no wchar data is allowed.
640 static size_t wchar_maxbytes_
;
644 // ****************************************************************
647 * @class ACE_InputCDR
649 * @brief A CDR stream for demarshalling CDR-encoded data.
651 * This class is based on the the CORBA spec for Java (98-02-29),
652 * java class omg.org.CORBA.portable.InputStream. It diverts in a
654 * @li Operations to retrieve basic types take parameters by
656 * @li Operations taking arrays don't have offsets, because in C++
657 * it is easier to describe an array starting from x+offset.
658 * @li Operations return an error status, because exceptions are
659 * not widely available in C++ (yet).
661 class ACE_Export ACE_InputCDR
664 // The translators need privileged access to efficiently demarshal
666 friend class ACE_Char_Codeset_Translator
;
667 friend class ACE_WChar_Codeset_Translator
;
670 * Create an input stream from an arbitrary buffer. The buffer must
671 * be properly aligned because this constructor will *not* work if
672 * the buffer is aligned unproperly.See ACE_ptr_align_binary() for
673 * instructions on how to align a pointer properly and use
674 * ACE_CDR::MAX_ALIGNMENT for the correct alignment.
676 ACE_InputCDR (const char *buf
,
678 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
679 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
680 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
682 /// Create an empty input stream. The caller is responsible for
683 /// putting the right data and providing the right alignment.
684 ACE_InputCDR (size_t bufsiz
,
685 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
686 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
687 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
689 /// Create an input stream from an ACE_Message_Block
691 * The alignment of the @a data block is carried into the new
692 * ACE_InputCDR object. This constructor either increments the
693 * @a data reference count, or copies the data (if it's a compound
694 * message block) so the caller can release the block immediately
697 ACE_InputCDR (const ACE_Message_Block
*data
,
698 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
699 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
700 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
,
703 /// Create an input stream from an ACE_Data_Block. The @a flag
704 /// indicates whether the @a data can be deleted by the CDR stream
706 ACE_InputCDR (ACE_Data_Block
*data
,
707 ACE_Message_Block::Message_Flags flag
= 0,
708 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
709 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
710 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
712 /// Create an input stream from an ACE_Data_Block. It also sets the
713 /// read and write pointers at the desired positions. This would be
714 /// helpful if the applications desires to create a new CDR stream
715 /// from a semi-processed datablock.
716 ACE_InputCDR (ACE_Data_Block
*data
,
717 ACE_Message_Block::Message_Flags flag
,
718 size_t read_pointer_position
,
719 size_t write_pointer_position
,
720 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
721 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
722 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
725 * These make a copy of the current stream state, but do not copy
726 * the internal buffer, so the same stream can be read multiple
729 ACE_InputCDR (const ACE_InputCDR
& rhs
);
731 ACE_InputCDR
& operator= (const ACE_InputCDR
& rhs
);
733 /// When interpreting indirected TypeCodes it is useful to make a
734 /// "copy" of the stream starting in the new position.
735 ACE_InputCDR (const ACE_InputCDR
& rhs
,
737 ACE_CDR::Long offset
);
739 /// This creates an encapsulated stream, the first byte must be (per
740 /// the spec) the byte order of the encapsulation.
741 ACE_InputCDR (const ACE_InputCDR
& rhs
,
744 /// Create an input CDR from an output CDR.
745 ACE_InputCDR (const ACE_OutputCDR
& rhs
,
746 ACE_Allocator
* buffer_allocator
= 0,
747 ACE_Allocator
* data_block_allocator
= 0,
748 ACE_Allocator
* message_block_allocator
= 0);
750 /// Helper class to transfer the contents from one input CDR to
751 /// another without requiring any extra memory allocations, data
752 /// copies or too many temporaries.
753 struct ACE_Export Transfer_Contents
755 Transfer_Contents (ACE_InputCDR
&rhs
);
759 /// Transfer the contents from @a rhs to a new CDR
760 ACE_InputCDR (Transfer_Contents rhs
);
763 virtual ~ACE_InputCDR (void);
765 /// Disambiguate overloading when extracting octets, chars,
766 /// booleans, and bounded strings
767 //@{ @name Helper classes
769 struct ACE_Export to_boolean
771 explicit to_boolean (ACE_CDR::Boolean
&b
);
772 ACE_CDR::Boolean
&ref_
;
775 struct ACE_Export to_char
777 explicit to_char (ACE_CDR::Char
&c
);
781 struct ACE_Export to_wchar
783 explicit to_wchar (ACE_CDR::WChar
&wc
);
784 ACE_CDR::WChar
&ref_
;
787 struct ACE_Export to_octet
789 explicit to_octet (ACE_CDR::Octet
&o
);
790 ACE_CDR::Octet
&ref_
;
793 struct ACE_Export to_string
796 * @deprecated The constructor taking a non-const string is now
797 * deprecated (C++ mapping 00-01-02), but we keep it
798 * around for backward compatibility.
800 to_string (ACE_CDR::Char
*&s
,
802 to_string (const ACE_CDR::Char
*&s
,
804 const ACE_CDR::Char
*&val_
;
805 ACE_CDR::ULong bound_
;
808 struct ACE_Export to_wstring
810 /// The constructor taking a non-const wstring is
811 /// now deprecated (C++ mapping 00-01-02), but we
812 /// keep it around for backward compatibility.
813 to_wstring (ACE_CDR::WChar
*&ws
,
815 to_wstring (const ACE_CDR::WChar
*&ws
,
817 const ACE_CDR::WChar
*&val_
;
818 ACE_CDR::ULong bound_
;
821 /// Helper classes for extracting bounded strings into std::string/wstring.
822 struct ACE_Export to_std_string
824 to_std_string (std::string
&s
,
827 ACE_CDR::ULong bound_
;
830 #if !defined(ACE_LACKS_STD_WSTRING)
831 struct ACE_Export to_std_wstring
833 to_std_wstring (std::wstring
&ws
,
836 ACE_CDR::ULong bound_
;
838 #endif /* ACE_LACKS_STD_WSTRING */
842 * Return @c false on failure and @c true on success.
844 //@{ @name Read basic IDL types
845 ACE_CDR::Boolean
read_boolean (ACE_CDR::Boolean
& x
);
846 ACE_CDR::Boolean
read_char (ACE_CDR::Char
&x
);
847 ACE_CDR::Boolean
read_wchar (ACE_CDR::WChar
& x
);
848 ACE_CDR::Boolean
read_octet (ACE_CDR::Octet
& x
);
849 ACE_CDR::Boolean
read_short (ACE_CDR::Short
&x
);
850 ACE_CDR::Boolean
read_ushort (ACE_CDR::UShort
&x
);
851 ACE_CDR::Boolean
read_long (ACE_CDR::Long
&x
);
852 ACE_CDR::Boolean
read_ulong (ACE_CDR::ULong
&x
);
853 ACE_CDR::Boolean
read_longlong (ACE_CDR::LongLong
& x
);
854 ACE_CDR::Boolean
read_ulonglong (ACE_CDR::ULongLong
& x
);
855 ACE_CDR::Boolean
read_float (ACE_CDR::Float
&x
);
856 ACE_CDR::Boolean
read_double (ACE_CDR::Double
&x
);
857 ACE_CDR::Boolean
read_longdouble (ACE_CDR::LongDouble
&x
);
858 ACE_CDR::Boolean
read_fixed (ACE_CDR::Fixed
&x
);
860 ACE_CDR::Boolean
read_string (ACE_CDR::Char
*&x
);
861 ACE_CDR::Boolean
read_string (ACE_CString
&x
);
862 ACE_CDR::Boolean
read_wstring (ACE_CDR::WChar
*& x
);
863 ACE_CDR::Boolean
read_string (std::string
& x
);
864 #if !defined(ACE_LACKS_STD_WSTRING)
865 ACE_CDR::Boolean
read_wstring (std::wstring
& x
);
870 * The buffer @a x must be large enough to contain @a length
872 * Return @c false on failure and @c true on success.
874 //@{ @name Read basic IDL types arrays
875 ACE_CDR::Boolean
read_boolean_array (ACE_CDR::Boolean
* x
,
876 ACE_CDR::ULong length
);
877 ACE_CDR::Boolean
read_char_array (ACE_CDR::Char
*x
,
878 ACE_CDR::ULong length
);
879 ACE_CDR::Boolean
read_wchar_array (ACE_CDR::WChar
* x
,
880 ACE_CDR::ULong length
);
881 ACE_CDR::Boolean
read_octet_array (ACE_CDR::Octet
* x
,
882 ACE_CDR::ULong length
);
883 ACE_CDR::Boolean
read_short_array (ACE_CDR::Short
*x
,
884 ACE_CDR::ULong length
);
885 ACE_CDR::Boolean
read_ushort_array (ACE_CDR::UShort
*x
,
886 ACE_CDR::ULong length
);
887 ACE_CDR::Boolean
read_long_array (ACE_CDR::Long
*x
,
888 ACE_CDR::ULong length
);
889 ACE_CDR::Boolean
read_ulong_array (ACE_CDR::ULong
*x
,
890 ACE_CDR::ULong length
);
891 ACE_CDR::Boolean
read_longlong_array (ACE_CDR::LongLong
* x
,
892 ACE_CDR::ULong length
);
893 ACE_CDR::Boolean
read_ulonglong_array (ACE_CDR::ULongLong
* x
,
894 ACE_CDR::ULong length
);
895 ACE_CDR::Boolean
read_float_array (ACE_CDR::Float
*x
,
896 ACE_CDR::ULong length
);
897 ACE_CDR::Boolean
read_double_array (ACE_CDR::Double
*x
,
898 ACE_CDR::ULong length
);
899 ACE_CDR::Boolean
read_longdouble_array (ACE_CDR::LongDouble
* x
,
900 ACE_CDR::ULong length
);
904 * Return @c false on failure and @c true on success.
906 //@{ @name Skip elements
907 ACE_CDR::Boolean
skip_boolean (void);
908 ACE_CDR::Boolean
skip_char (void);
909 ACE_CDR::Boolean
skip_wchar (void);
910 ACE_CDR::Boolean
skip_octet (void);
911 ACE_CDR::Boolean
skip_short (void);
912 ACE_CDR::Boolean
skip_ushort (void);
913 ACE_CDR::Boolean
skip_long (void);
914 ACE_CDR::Boolean
skip_ulong (void);
915 ACE_CDR::Boolean
skip_longlong (void);
916 ACE_CDR::Boolean
skip_ulonglong (void);
917 ACE_CDR::Boolean
skip_float (void);
918 ACE_CDR::Boolean
skip_double (void);
919 ACE_CDR::Boolean
skip_longdouble (void);
920 ACE_CDR::Boolean
skip_fixed (void);
924 * The next field must be a string, this method skips it. It is
925 * useful in parsing a TypeCode.
926 * @return @c false on failure and @c true on success.
928 ACE_CDR::Boolean
skip_wstring (void);
929 ACE_CDR::Boolean
skip_string (void);
931 /// Skip @a n bytes in the CDR stream.
933 * @return @c false on failure and @c true on success.
935 ACE_CDR::Boolean
skip_bytes (size_t n
);
937 /// returns @c false if a problem has been detected.
938 bool good_bit (void) const;
941 * @return The start of the message block chain for this CDR
944 * @note In the current implementation the chain has length 1, but
945 * we are planning to change that.
947 const ACE_Message_Block
* start (void) const;
949 // = The following functions are useful to read the contents of the
950 // CDR stream from a socket or file.
953 * Grow the internal buffer, reset @c rd_ptr to the first byte in
954 * the new buffer that is properly aligned, and set @c wr_ptr to @c
955 * rd_ptr @c + @c newsize
957 int grow (size_t newsize
);
960 * After reading and partially parsing the contents the user can
961 * detect a change in the byte order, this method will let him/her
964 void reset_byte_order (int byte_order
);
966 /// Re-initialize the CDR stream, copying the contents of the chain
967 /// of message_blocks starting from @a data.
968 void reset (const ACE_Message_Block
*data
,
971 /// Steal the contents from the current CDR.
972 ACE_Message_Block
*steal_contents (void);
974 /// Steal the contents of @a cdr and make a shallow copy into this
976 void steal_from (ACE_InputCDR
&cdr
);
978 /// Exchange data blocks with the caller of this method. The read
979 /// and write pointers are also exchanged.
981 * @note We now do only with the start_ message block.
983 void exchange_data_blocks (ACE_InputCDR
&cdr
);
985 /// Copy the data portion from the @a cdr to this cdr and return the
986 /// data content (ie. the ACE_Data_Block) from this CDR to the
989 * @note The caller is responsible for managing the memory of the
990 * returned ACE_Data_Block.
992 ACE_Data_Block
* clone_from (ACE_InputCDR
&cdr
);
994 /// Re-initialize the CDR stream, forgetting about the old contents
995 /// of the stream and allocating a new buffer (from the allocators).
996 void reset_contents (void);
998 /// Returns the current position for the @c rd_ptr.
1001 /// Returns the current position for the @c wr_ptr.
1002 char* wr_ptr (void);
1004 /// Return how many bytes are left in the stream.
1005 size_t length (void) const;
1008 * Utility function to allow the user more flexibility.
1009 * Skips up to the nearest @a alignment-byte boundary.
1010 * Argument MUST be a power of 2.
1012 * @return 0 on success and -1 on failure.
1014 int align_read_ptr (size_t alignment
);
1016 /// If @c true then this stream is writing in non-native byte order.
1017 /// This is only meaningful if ACE_ENABLE_SWAP_ON_WRITE is defined.
1018 bool do_byte_swap (void) const;
1020 /// If @c do_byte_swap() returns @c false, this returns
1021 /// ACE_CDR_BYTE_ORDER else it returns !ACE_CDR_BYTE_ORDER.
1022 int byte_order (void) const;
1024 /// Access the codeset translators. They can be nil!
1025 ACE_Char_Codeset_Translator
*char_translator (void) const;
1026 ACE_WChar_Codeset_Translator
*wchar_translator (void) const;
1028 /// Set the codeset translators.
1029 void char_translator (ACE_Char_Codeset_Translator
*);
1030 void wchar_translator (ACE_WChar_Codeset_Translator
*);
1033 * Returns (in @a buf) the next position in the buffer aligned to
1034 * @a size. It advances the Message_Block @c rd_ptr past the data
1035 * (i.e., @c buf @c + @c size). Sets the good_bit to @c false and
1036 * returns a -1 on failure.
1038 int adjust (size_t size
,
1041 /// As above, but now the size and alignment requirements may be
1043 int adjust (size_t size
,
1047 /// Set the underlying GIOP version..
1048 void set_version (ACE_CDR::Octet major
, ACE_CDR::Octet minor
);
1050 /// Set the underlying GIOP version..
1051 void get_version (ACE_CDR::Octet
&major
, ACE_CDR::Octet
&minor
);
1053 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1054 /// Register and unregister our buffer size monitor.
1055 void register_monitor (const char* id
);
1056 void unregister_monitor (void);
1057 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1061 /// The start of the chain of message blocks, even though in the
1062 /// current version the chain always has length 1.
1063 ACE_Message_Block start_
;
1065 /// The CDR stream byte order does not match the one on the machine,
1066 /// swapping is needed while reading.
1069 /// set to @c false when an error occurs.
1072 /// The GIOP versions for this stream
1073 ACE_CDR::Octet major_version_
;
1074 ACE_CDR::Octet minor_version_
;
1076 /// If not nil, invoke for translation of character and string data.
1077 ACE_Char_Codeset_Translator
*char_translator_
;
1078 ACE_WChar_Codeset_Translator
*wchar_translator_
;
1080 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1081 ACE::Monitor_Control::Size_Monitor
*monitor_
;
1082 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1085 ACE_CDR::Boolean
read_1 (ACE_CDR::Octet
*x
);
1086 ACE_CDR::Boolean
read_2 (ACE_CDR::UShort
*x
);
1087 ACE_CDR::Boolean
read_4 (ACE_CDR::ULong
*x
);
1088 ACE_CDR::Boolean
read_8 (ACE_CDR::ULongLong
*x
);
1089 ACE_CDR::Boolean
read_16 (ACE_CDR::LongDouble
*x
);
1091 // Several types can be read using the same routines, since TAO
1092 // tries to use native types with known size for each CORBA type.
1093 // We could use void* or char* to make the interface more
1094 // consistent, but using native types let us exploit the strict
1095 // alignment requirements of CDR streams and implement the
1096 // operations using assignment.
1099 * Read an array of @a length elements, each of @a size bytes and the
1100 * start aligned at a multiple of @a align. The elements are assumed
1101 * to be packed with the right alignment restrictions. It is mostly
1102 * designed for buffers of the basic types.
1104 * This operation uses @c memcpy; as explained above it is expected
1105 * that using assignment is faster that @c memcpy for one element,
1106 * but for several elements @c memcpy should be more efficient, it
1107 * could be interesting to find the break even point and optimize
1108 * for that case, but that would be too platform dependent.
1110 ACE_CDR::Boolean
read_array (void* x
,
1113 ACE_CDR::ULong length
);
1116 * On those occasions when the native codeset for wchar is smaller than
1117 * the size of a wchar_t, such as using UTF-16 with a 4-byte wchar_t, a
1118 * special form of reading the array is needed. Actually, this should be
1119 * a default translator.
1121 ACE_CDR::Boolean
read_wchar_array_i (ACE_CDR::WChar
* x
,
1122 ACE_CDR::ULong length
);
1124 /// Move the rd_ptr ahead by @a offset bytes.
1125 void rd_ptr (size_t offset
);
1127 /// Points to the continuation field of the current message block.
1131 // ****************************************************************
1134 * @class ACE_Char_Codeset_Translator
1136 * @brief Codeset translation routines common to both Output and Input
1139 * This class is a base class for defining codeset translation
1140 * routines to handle the character set translations required by
1141 * both CDR Input streams and CDR Output streams.
1143 * Translators are reference counted. This allows for stateful as well
1144 * as stateless translators. Stateless translators will be allocated
1145 * once whereas CDR Streams own their own copy of a stateful translator.
1147 class ACE_Export ACE_Char_Codeset_Translator
1150 virtual ~ACE_Char_Codeset_Translator ();
1152 /// Read a single character from the stream, converting from the
1153 /// stream codeset to the native codeset
1154 virtual ACE_CDR::Boolean
read_char (ACE_InputCDR
&,
1155 ACE_CDR::Char
&) = 0;
1157 /// Read a string from the stream, including the length, converting
1158 /// the characters from the stream codeset to the native codeset
1159 virtual ACE_CDR::Boolean
read_string (ACE_InputCDR
&,
1160 ACE_CDR::Char
*&) = 0;
1162 /// Read a std::string from the stream, including the length, converting
1163 /// the characters from the stream codeset to the native codeset
1164 /// (provide non-optimized default implementation)
1165 virtual ACE_CDR::Boolean
read_string (ACE_InputCDR
&,
1168 /// Read an array of characters from the stream, converting the
1169 /// characters from the stream codeset to the native codeset.
1170 virtual ACE_CDR::Boolean
read_char_array (ACE_InputCDR
&,
1172 ACE_CDR::ULong
) = 0;
1174 /// Write a single character to the stream, converting from the
1175 /// native codeset to the stream codeset
1176 virtual ACE_CDR::Boolean
write_char (ACE_OutputCDR
&,
1179 /// Write a string to the stream, including the length, converting
1180 /// from the native codeset to the stream codeset
1181 virtual ACE_CDR::Boolean
write_string (ACE_OutputCDR
&,
1183 const ACE_CDR::Char
*) = 0;
1185 /// Write an array of characters to the stream, converting from the
1186 /// native codeset to the stream codeset
1187 virtual ACE_CDR::Boolean
write_char_array (ACE_OutputCDR
&,
1188 const ACE_CDR::Char
*,
1189 ACE_CDR::ULong
) = 0;
1191 virtual ACE_CDR::ULong
ncs () = 0;
1192 virtual ACE_CDR::ULong
tcs () = 0;
1194 /// Children have access to low-level routines because they cannot
1195 /// use read_char or something similar (it would recurse).
1196 ACE_CDR::Boolean
read_1 (ACE_InputCDR
& input
,
1198 ACE_CDR::Boolean
write_1 (ACE_OutputCDR
& output
,
1199 const ACE_CDR::Octet
*x
);
1201 /// Efficiently read @a length elements of size @a size each from
1202 /// @a input into @a x; the data must be aligned to @a align.
1203 ACE_CDR::Boolean
read_array (ACE_InputCDR
& input
,
1207 ACE_CDR::ULong length
);
1210 * Efficiently write @a length elements of size @a size from <x> into
1211 * <output>. Before inserting the elements enough padding is added
1212 * to ensure that the elements will be aligned to <align> in the
1215 ACE_CDR::Boolean
write_array (ACE_OutputCDR
& output
,
1219 ACE_CDR::ULong length
);
1222 * Exposes the stream implementation of <adjust>, this is useful in
1223 * many cases to minimize memory allocations during marshaling.
1224 * On success @a buf will contain a contiguous area in the CDR stream
1225 * that can hold @a size bytes aligned to @a align.
1228 int adjust (ACE_OutputCDR
& out
,
1233 /// Used by derived classes to set errors in the CDR stream.
1234 void good_bit (ACE_OutputCDR
& out
, bool bit
);
1236 /// Obtain the CDR Stream's major & minor version values.
1237 ACE_CDR::Octet
major_version (ACE_InputCDR
& input
);
1238 ACE_CDR::Octet
minor_version (ACE_InputCDR
& input
);
1239 ACE_CDR::Octet
major_version (ACE_OutputCDR
& output
);
1240 ACE_CDR::Octet
minor_version (ACE_OutputCDR
& output
);
1243 // ****************************************************************
1246 * @class ACE_WChar_Codeset_Translator
1248 * @brief Codeset translation routines common to both Output and Input
1251 * This class is a base class for defining codeset translation
1252 * routines to handle the character set translations required by
1253 * both CDR Input streams and CDR Output streams.
1255 class ACE_Export ACE_WChar_Codeset_Translator
1258 virtual ~ACE_WChar_Codeset_Translator ();
1260 virtual ACE_CDR::Boolean
read_wchar (ACE_InputCDR
&,
1261 ACE_CDR::WChar
&) = 0;
1262 virtual ACE_CDR::Boolean
read_wstring (ACE_InputCDR
&,
1263 ACE_CDR::WChar
*&) = 0;
1264 #if !defined(ACE_LACKS_STD_WSTRING)
1265 /// Read a std::wstring from the stream, including the length, converting
1266 /// the characters from the stream codeset to the native codeset
1267 /// (provide non-optimized default implementation)
1268 virtual ACE_CDR::Boolean
read_wstring (ACE_InputCDR
&,
1271 virtual ACE_CDR::Boolean
read_wchar_array (ACE_InputCDR
&,
1273 ACE_CDR::ULong
) = 0;
1274 virtual ACE_CDR::Boolean
write_wchar (ACE_OutputCDR
&,
1275 ACE_CDR::WChar
) = 0;
1276 virtual ACE_CDR::Boolean
write_wstring (ACE_OutputCDR
&,
1278 const ACE_CDR::WChar
*) = 0;
1279 virtual ACE_CDR::Boolean
write_wchar_array (ACE_OutputCDR
&,
1280 const ACE_CDR::WChar
*,
1281 ACE_CDR::ULong
) = 0;
1283 virtual ACE_CDR::ULong
ncs () = 0;
1284 virtual ACE_CDR::ULong
tcs () = 0;
1286 /// Children have access to low-level routines because they cannot
1287 /// use read_char or something similar (it would recurse).
1288 ACE_CDR::Boolean
read_1 (ACE_InputCDR
& input
,
1290 ACE_CDR::Boolean
read_2 (ACE_InputCDR
& input
,
1291 ACE_CDR::UShort
*x
);
1292 ACE_CDR::Boolean
read_4 (ACE_InputCDR
& input
,
1294 ACE_CDR::Boolean
write_1 (ACE_OutputCDR
& output
,
1295 const ACE_CDR::Octet
*x
);
1296 ACE_CDR::Boolean
write_2 (ACE_OutputCDR
& output
,
1297 const ACE_CDR::UShort
*x
);
1298 ACE_CDR::Boolean
write_4 (ACE_OutputCDR
& output
,
1299 const ACE_CDR::ULong
*x
);
1301 /// Efficiently read @a length elements of size @a size each from
1302 /// @a input into @a x; the data must be aligned to @a align.
1303 ACE_CDR::Boolean
read_array (ACE_InputCDR
& input
,
1307 ACE_CDR::ULong length
);
1310 * Efficiently write @a length elements of size @a size from @a x into
1311 * @a output. Before inserting the elements enough padding is added
1312 * to ensure that the elements will be aligned to @a align in the
1315 ACE_CDR::Boolean
write_array (ACE_OutputCDR
& output
,
1319 ACE_CDR::ULong length
);
1322 * Exposes the stream implementation of @a adjust, this is useful in
1323 * many cases to minimize memory allocations during marshaling.
1324 * On success @a buf will contain a contiguous area in the CDR stream
1325 * that can hold @a size bytes aligned to @a align.
1328 int adjust (ACE_OutputCDR
& out
,
1333 /// Used by derived classes to set errors in the CDR stream.
1334 void good_bit (ACE_OutputCDR
& out
, bool bit
);
1336 /// Obtain the CDR Stream's major & minor version values.
1337 ACE_CDR::Octet
major_version (ACE_InputCDR
& input
);
1338 ACE_CDR::Octet
minor_version (ACE_InputCDR
& input
);
1339 ACE_CDR::Octet
major_version (ACE_OutputCDR
& output
);
1340 ACE_CDR::Octet
minor_version (ACE_OutputCDR
& output
);
1344 // @@ These operators should not be inlined since they force SString.h
1345 // to be included in this header.
1346 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1347 const ACE_CString
&x
);
1349 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1353 ACE_END_VERSIONED_NAMESPACE_DECL
1355 #if defined (__ACE_INLINE__)
1356 # include "ace/CDR_Stream.inl"
1357 #else /* __ACE_INLINE__ */
1359 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
1361 // Not used by CORBA or TAO
1362 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1364 // CDR output operators for primitive types
1366 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1368 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1370 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1372 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1374 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1375 ACE_CDR::LongLong x
);
1376 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1377 ACE_CDR::ULongLong x
);
1378 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
& os
,
1379 ACE_CDR::LongDouble x
);
1380 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1382 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1384 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1385 const ACE_CDR::Fixed
&x
);
1387 // CDR output operator from helper classes
1389 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1390 ACE_OutputCDR::from_boolean x
);
1391 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1392 ACE_OutputCDR::from_char x
);
1393 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1394 ACE_OutputCDR::from_wchar x
);
1395 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1396 ACE_OutputCDR::from_octet x
);
1397 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1398 ACE_OutputCDR::from_string x
);
1399 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1400 ACE_OutputCDR::from_wstring x
);
1401 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1402 const ACE_CDR::Char
* x
);
1403 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1404 const ACE_CDR::WChar
* x
);
1405 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1406 ACE_OutputCDR::from_std_string x
);
1407 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1408 const std::string
& x
);
1409 #if !defined(ACE_LACKS_STD_WSTRING)
1410 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1411 ACE_OutputCDR::from_std_wstring x
);
1412 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1413 const std::wstring
& x
);
1416 // Not used by CORBA or TAO
1417 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1419 // CDR input operators for primitive types
1421 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1423 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1424 ACE_CDR::UShort
&x
);
1425 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1427 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1429 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1430 ACE_CDR::LongLong
&x
);
1431 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1432 ACE_CDR::ULongLong
&x
);
1433 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1434 ACE_CDR::LongDouble
&x
);
1435 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1437 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1438 ACE_CDR::Double
&x
);
1439 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1442 // CDR input operator from helper classes
1444 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1445 ACE_InputCDR::to_boolean x
);
1446 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1447 ACE_InputCDR::to_char x
);
1448 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1449 ACE_InputCDR::to_wchar x
);
1450 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1451 ACE_InputCDR::to_octet x
);
1452 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1453 ACE_InputCDR::to_string x
);
1454 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1455 ACE_InputCDR::to_wstring x
);
1456 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1458 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1459 ACE_CDR::WChar
*& x
);
1460 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_InputCDR
&os
,
1461 ACE_InputCDR::to_std_string x
);
1462 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1464 #if !defined(ACE_LACKS_STD_WSTRING)
1465 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_InputCDR
&os
,
1466 ACE_InputCDR::to_std_wstring x
);
1467 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1471 ACE_END_VERSIONED_NAMESPACE_DECL
1473 #endif /* __ACE_INLINE__ */
1475 #if defined (GEN_OSTREAM_OPS)
1477 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
1479 // ostream insertion operators for debugging code generated from IDL. All
1480 // but these below are either in generated code itself or are unambiguous
1483 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1484 ACE_OutputCDR::from_boolean x
);
1486 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1487 ACE_OutputCDR::from_char x
);
1489 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1490 ACE_OutputCDR::from_wchar x
);
1492 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1493 ACE_OutputCDR::from_octet x
);
1495 ACE_END_VERSIONED_NAMESPACE_DECL
1497 #endif /* GEN_OSTREAM_OPS */
1499 #include /**/ "ace/post.h"
1501 #endif /* ACE_CDR_STREAM_H */