GitHub Actions: Try MSVC builds with /std:c++17 and 20
[ACE_TAO.git] / ACE / ace / CDR_Stream.h
blob059a4633e073677253cb282b9fc130fb8a7abb17
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file CDR_Stream.h
7 * ACE Common Data Representation (CDR) marshaling and demarshaling
8 * classes.
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.
20 * Optimizations
21 * -------------
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)
45 # 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 */
59 #include <string>
61 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
63 class ACE_Char_Codeset_Translator;
64 class ACE_WChar_Codeset_Translator;
66 class ACE_InputCDR;
68 /**
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
76 * a few ways:
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
84 public:
85 /**
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;
94 /**
95 * Default constructor; allows one to set byte ordering, allocators, and
96 * tuning information.
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,
132 size_t size,
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);
167 /// destructor
168 ~ACE_OutputCDR (void);
171 * Disambiguate overload when inserting booleans, octets, chars, and
172 * bounded strings.
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);
185 ACE_CDR::Octet val_;
188 struct ACE_Export from_char
190 explicit from_char (ACE_CDR::Char c);
191 ACE_CDR::Char val_;
194 struct ACE_Export from_wchar
196 explicit from_wchar (ACE_CDR::WChar wc);
197 ACE_CDR::WChar val_;
200 struct ACE_Export from_int8
202 explicit from_int8 (ACE_CDR::Int8 val);
203 ACE_CDR::Int8 val_;
206 struct ACE_Export from_uint8
208 explicit from_uint8 (ACE_CDR::UInt8 val);
209 ACE_CDR::UInt8 val_;
212 struct ACE_Export from_string
214 from_string (ACE_CDR::Char* s,
215 ACE_CDR::ULong b,
216 ACE_CDR::Boolean nocopy = 0);
217 from_string (const ACE_CDR::Char* s,
218 ACE_CDR::ULong b,
219 ACE_CDR::Boolean nocopy = 0);
220 ACE_CDR::Char *val_;
221 ACE_CDR::ULong bound_;
222 ACE_CDR::Boolean nocopy_;
225 struct ACE_Export from_wstring
227 from_wstring (ACE_CDR::WChar* ws,
228 ACE_CDR::ULong b,
229 ACE_CDR::Boolean nocopy = 0);
230 from_wstring (const ACE_CDR::WChar* ws,
231 ACE_CDR::ULong b,
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,
241 ACE_CDR::ULong b);
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,
250 ACE_CDR::ULong b);
251 const std::wstring &val_;
252 ACE_CDR::ULong bound_;
254 #endif
255 //@}
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);
289 #endif
291 //@}
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);
329 //@}
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:
337 * @code
338 ACE_OutputCDR strm;
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
344 @endcode
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
350 * replace ().
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 (void);
358 char* write_short_placeholder (void);
359 char* write_boolean_placeholder (void);
360 char* write_char_placeholder (void);
361 char* write_longlong_placeholder (void);
362 char* write_octet_placeholder (void);
363 char* write_float_placeholder (void);
364 char* write_double_placeholder (void);
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);
393 //@}
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 &);
416 //@}
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 (void) const;
424 /// Reuse the CDR stream to write on the old buffer.
425 void reset (void);
427 /// Add the length of each message block in the chain.
428 size_t total_length (void) 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
433 * message blocks.
435 const ACE_Message_Block *begin (void) const;
437 /// Return the last message in the chain that is is use.
438 const ACE_Message_Block *end (void) const;
440 /// Return the <current_> message block in chain.
441 const ACE_Message_Block *current (void) 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.
450 int consolidate (void);
453 * Access the underlying buffer (read only). @note This
454 * method only returns a pointer to the first block in the
455 * chain.
457 const char *buffer (void) 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
462 * chain.
464 size_t length (void) 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 (void) const;
476 ACE_WChar_Codeset_Translator *wchar_translator (void) 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 (void);
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
493 * current->wr_ptr()!
495 size_t current_alignment (void) 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,
506 char *&buf);
508 /// As above, but now the size and alignment requirements may be
509 /// different.
510 int adjust (size_t size,
511 size_t align,
512 char *&buf);
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 (void) 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 (void) 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
527 /// gateway.
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 (void);
540 #endif /* ACE_HAS_MONITOR_POINTS==1 */
542 private:
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 /// disallow copying...
548 ACE_OutputCDR (const ACE_OutputCDR& rhs);
549 ACE_OutputCDR& operator= (const ACE_OutputCDR& rhs);
551 ACE_CDR::Boolean write_1 (const ACE_CDR::Octet *x);
552 ACE_CDR::Boolean write_2 (const ACE_CDR::UShort *x);
553 ACE_CDR::Boolean write_4 (const ACE_CDR::ULong *x);
554 ACE_CDR::Boolean write_8 (const ACE_CDR::ULongLong *x);
555 ACE_CDR::Boolean write_16 (const ACE_CDR::LongDouble *x);
558 * write an array of @a length elements, each of @a size bytes and the
559 * start aligned at a multiple of @a align. The elements are assumed
560 * to be packed with the right alignment restrictions. It is mostly
561 * designed for buffers of the basic types.
563 * This operation uses @c memcpy; as explained above it is expected
564 * that using assignment is faster that @c memcpy for one element,
565 * but for several elements @c memcpy should be more efficient, it
566 * could be interesting to find the break even point and optimize
567 * for that case, but that would be too platform dependent.
569 ACE_CDR::Boolean write_array (const void *x,
570 size_t size,
571 size_t align,
572 ACE_CDR::ULong length);
575 ACE_CDR::Boolean write_wchar_array_i (const ACE_CDR::WChar* x,
576 ACE_CDR::ULong length);
580 * Grow the CDR stream. When it returns @a buf contains a pointer to
581 * memory in the CDR stream, with at least @a size bytes ahead of it
582 * and aligned to an @a align boundary. It moved the <wr_ptr> to <buf
583 * + size>.
585 int grow_and_adjust (size_t size,
586 size_t align,
587 char *&buf);
589 private:
590 /// The start of the chain of message blocks.
591 ACE_Message_Block start_;
593 /// The current block in the chain where we are writing.
594 ACE_Message_Block *current_;
596 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
598 * The current alignment as measured from the start of the buffer.
599 * Usually this coincides with the alignment of the buffer in
600 * memory, but, when we chain another buffer this "quasi invariant"
601 * is broken.
602 * The current_alignment is used to readjust the buffer following
603 * the stolen message block.
605 size_t current_alignment_;
606 #endif /* ACE_LACKS_CDR_ALIGNMENT */
609 * Is the current block writable. When we steal a buffer from the
610 * user and just chain it into the message block we are not supposed
611 * to write on it, even if it is past the start and end of the
612 * buffer.
614 bool current_is_writable_;
617 * If not zero swap bytes at writing so the created CDR stream byte
618 * order does *not* match the machine byte order. The motivation
619 * for such a beast is that in some setting a few (fast) machines
620 * can be serving hundreds of slow machines with the opposite byte
621 * order, so it makes sense (as a load balancing device) to put the
622 * responsibility in the writers.
624 * @warning THIS IS NOT A STANDARD IN CORBA, USE AT YOUR OWN RISK
626 bool do_byte_swap_;
628 /// Set to false when an error ocurrs.
629 bool good_bit_;
631 /// Break-even point for copying.
632 size_t const memcpy_tradeoff_;
634 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
635 ACE::Monitor_Control::Size_Monitor *monitor_;
636 #endif /* ACE_HAS_MONITOR_POINTS==1 */
638 protected:
639 /// GIOP version information
640 ACE_CDR::Octet major_version_;
641 ACE_CDR::Octet minor_version_;
643 /// If not nil, invoke for translation of character and string data.
644 ACE_Char_Codeset_Translator *char_translator_;
645 ACE_WChar_Codeset_Translator *wchar_translator_;
648 * Some wide char codesets may be defined with a maximum number
649 * of bytes that is smaller than the size of a wchar_t. This means
650 * that the CDR cannot simply memcpy a block of wchars to and from
651 * the stream, but must instead realign the bytes appropriately.
652 * In cases when wchar i/o is not allowed, such as with GIOP 1.0,
653 * or not having a native wchar codeset defined, the maxbytes is
654 * set to zero, indicating no wchar data is allowed.
656 static size_t wchar_maxbytes_;
660 // ****************************************************************
663 * @class ACE_InputCDR
665 * @brief A CDR stream for demarshalling CDR-encoded data.
667 * This class is based on the the CORBA spec for Java (98-02-29),
668 * java class omg.org.CORBA.portable.InputStream. It diverts in a
669 * few ways:
670 * @li Operations to retrieve basic types take parameters by
671 * reference.
672 * @li Operations taking arrays don't have offsets, because in C++
673 * it is easier to describe an array starting from x+offset.
674 * @li Operations return an error status, because exceptions are
675 * not widely available in C++ (yet).
677 class ACE_Export ACE_InputCDR
679 public:
680 // The translators need privileged access to efficiently demarshal
681 // arrays and such.
682 friend class ACE_Char_Codeset_Translator;
683 friend class ACE_WChar_Codeset_Translator;
686 * Create an input stream from an arbitrary buffer. The buffer must
687 * be properly aligned because this constructor will *not* work if
688 * the buffer is aligned unproperly.See ACE_ptr_align_binary() for
689 * instructions on how to align a pointer properly and use
690 * ACE_CDR::MAX_ALIGNMENT for the correct alignment.
692 ACE_InputCDR (const char *buf,
693 size_t bufsiz,
694 int byte_order = ACE_CDR::BYTE_ORDER_NATIVE,
695 ACE_CDR::Octet major_version = ACE_CDR_GIOP_MAJOR_VERSION,
696 ACE_CDR::Octet minor_version = ACE_CDR_GIOP_MINOR_VERSION);
698 /// Create an empty input stream. The caller is responsible for
699 /// putting the right data and providing the right alignment.
700 ACE_InputCDR (size_t bufsiz,
701 int byte_order = ACE_CDR::BYTE_ORDER_NATIVE,
702 ACE_CDR::Octet major_version = ACE_CDR_GIOP_MAJOR_VERSION,
703 ACE_CDR::Octet minor_version = ACE_CDR_GIOP_MINOR_VERSION);
705 /// Create an input stream from an ACE_Message_Block
707 * The alignment of the @a data block is carried into the new
708 * ACE_InputCDR object. This constructor either increments the
709 * @a data reference count, or copies the data (if it's a compound
710 * message block) so the caller can release the block immediately
711 * upon return.
713 ACE_InputCDR (const ACE_Message_Block *data,
714 int byte_order = ACE_CDR::BYTE_ORDER_NATIVE,
715 ACE_CDR::Octet major_version = ACE_CDR_GIOP_MAJOR_VERSION,
716 ACE_CDR::Octet minor_version = ACE_CDR_GIOP_MINOR_VERSION,
717 ACE_Lock* lock = 0);
719 /// Create an input stream from an ACE_Data_Block. The @a flag
720 /// indicates whether the @a data can be deleted by the CDR stream
721 /// or not
722 ACE_InputCDR (ACE_Data_Block *data,
723 ACE_Message_Block::Message_Flags flag = 0,
724 int byte_order = ACE_CDR::BYTE_ORDER_NATIVE,
725 ACE_CDR::Octet major_version = ACE_CDR_GIOP_MAJOR_VERSION,
726 ACE_CDR::Octet minor_version = ACE_CDR_GIOP_MINOR_VERSION);
728 /// Create an input stream from an ACE_Data_Block. It also sets the
729 /// read and write pointers at the desired positions. This would be
730 /// helpful if the applications desires to create a new CDR stream
731 /// from a semi-processed datablock.
732 ACE_InputCDR (ACE_Data_Block *data,
733 ACE_Message_Block::Message_Flags flag,
734 size_t read_pointer_position,
735 size_t write_pointer_position,
736 int byte_order = ACE_CDR::BYTE_ORDER_NATIVE,
737 ACE_CDR::Octet major_version = ACE_CDR_GIOP_MAJOR_VERSION,
738 ACE_CDR::Octet minor_version = ACE_CDR_GIOP_MINOR_VERSION);
741 * These make a copy of the current stream state, but do not copy
742 * the internal buffer, so the same stream can be read multiple
743 * times efficiently.
745 ACE_InputCDR (const ACE_InputCDR& rhs);
747 ACE_InputCDR& operator= (const ACE_InputCDR& rhs);
749 /// When interpreting indirected TypeCodes it is useful to make a
750 /// "copy" of the stream starting in the new position.
751 ACE_InputCDR (const ACE_InputCDR& rhs,
752 size_t size,
753 ACE_CDR::Long offset);
755 /// This creates an encapsulated stream, the first byte must be (per
756 /// the spec) the byte order of the encapsulation.
757 ACE_InputCDR (const ACE_InputCDR& rhs,
758 size_t size);
760 /// Create an input CDR from an output CDR.
761 ACE_InputCDR (const ACE_OutputCDR& rhs,
762 ACE_Allocator* buffer_allocator = 0,
763 ACE_Allocator* data_block_allocator = 0,
764 ACE_Allocator* message_block_allocator = 0);
766 /// Helper class to transfer the contents from one input CDR to
767 /// another without requiring any extra memory allocations, data
768 /// copies or too many temporaries.
769 struct ACE_Export Transfer_Contents
771 Transfer_Contents (ACE_InputCDR &rhs);
773 ACE_InputCDR &rhs_;
775 /// Transfer the contents from @a rhs to a new CDR
776 ACE_InputCDR (Transfer_Contents rhs);
778 /// Destructor
779 virtual ~ACE_InputCDR (void);
781 /// Disambiguate overloading when extracting octets, chars,
782 /// booleans, and bounded strings
783 //@{ @name Helper classes
785 struct ACE_Export to_boolean
787 explicit to_boolean (ACE_CDR::Boolean &b);
788 ACE_CDR::Boolean &ref_;
791 struct ACE_Export to_char
793 explicit to_char (ACE_CDR::Char &c);
794 ACE_CDR::Char &ref_;
797 struct ACE_Export to_wchar
799 explicit to_wchar (ACE_CDR::WChar &wc);
800 ACE_CDR::WChar &ref_;
803 struct ACE_Export to_octet
805 explicit to_octet (ACE_CDR::Octet &o);
806 ACE_CDR::Octet &ref_;
809 struct ACE_Export to_int8
811 explicit to_int8 (ACE_CDR::Int8 &ref);
812 ACE_CDR::Int8 &ref_;
815 struct ACE_Export to_uint8
817 explicit to_uint8 (ACE_CDR::UInt8 &ref);
818 ACE_CDR::UInt8 &ref_;
821 struct ACE_Export to_string
824 * @deprecated The constructor taking a non-const string is now
825 * deprecated (C++ mapping 00-01-02), but we keep it
826 * around for backward compatibility.
828 to_string (ACE_CDR::Char *&s,
829 ACE_CDR::ULong b);
830 to_string (const ACE_CDR::Char *&s,
831 ACE_CDR::ULong b);
832 const ACE_CDR::Char *&val_;
833 ACE_CDR::ULong bound_;
836 struct ACE_Export to_wstring
838 /// The constructor taking a non-const wstring is
839 /// now deprecated (C++ mapping 00-01-02), but we
840 /// keep it around for backward compatibility.
841 to_wstring (ACE_CDR::WChar *&ws,
842 ACE_CDR::ULong b);
843 to_wstring (const ACE_CDR::WChar *&ws,
844 ACE_CDR::ULong b);
845 const ACE_CDR::WChar *&val_;
846 ACE_CDR::ULong bound_;
849 /// Helper classes for extracting bounded strings into std::string/wstring.
850 struct ACE_Export to_std_string
852 to_std_string (std::string &s,
853 ACE_CDR::ULong b);
854 std::string &val_;
855 ACE_CDR::ULong bound_;
858 #if !defined(ACE_LACKS_STD_WSTRING)
859 struct ACE_Export to_std_wstring
861 to_std_wstring (std::wstring &ws,
862 ACE_CDR::ULong b);
863 std::wstring &val_;
864 ACE_CDR::ULong bound_;
866 #endif /* ACE_LACKS_STD_WSTRING */
867 //@}
870 * Return @c false on failure and @c true on success.
872 //@{ @name Read basic IDL types
873 ACE_CDR::Boolean read_boolean (ACE_CDR::Boolean& x);
874 ACE_CDR::Boolean read_char (ACE_CDR::Char &x);
875 ACE_CDR::Boolean read_wchar (ACE_CDR::WChar& x);
876 ACE_CDR::Boolean read_octet (ACE_CDR::Octet& x);
877 ACE_CDR::Boolean read_short (ACE_CDR::Short &x);
878 ACE_CDR::Boolean read_ushort (ACE_CDR::UShort &x);
879 ACE_CDR::Boolean read_long (ACE_CDR::Long &x);
880 ACE_CDR::Boolean read_ulong (ACE_CDR::ULong &x);
881 ACE_CDR::Boolean read_longlong (ACE_CDR::LongLong& x);
882 ACE_CDR::Boolean read_ulonglong (ACE_CDR::ULongLong& x);
883 ACE_CDR::Boolean read_float (ACE_CDR::Float &x);
884 ACE_CDR::Boolean read_double (ACE_CDR::Double &x);
885 ACE_CDR::Boolean read_longdouble (ACE_CDR::LongDouble &x);
886 ACE_CDR::Boolean read_fixed (ACE_CDR::Fixed &x);
887 ACE_CDR::Boolean read_int8 (ACE_CDR::Int8 &x);
888 ACE_CDR::Boolean read_uint8 (ACE_CDR::UInt8 &x);
890 ACE_CDR::Boolean read_string (ACE_CDR::Char *&x);
891 ACE_CDR::Boolean read_string (ACE_CString &x);
892 ACE_CDR::Boolean read_wstring (ACE_CDR::WChar*& x);
893 ACE_CDR::Boolean read_string (std::string& x);
894 #if !defined(ACE_LACKS_STD_WSTRING)
895 ACE_CDR::Boolean read_wstring (std::wstring& x);
896 #endif
897 //@}
900 * The buffer @a x must be large enough to contain @a length
901 * elements.
902 * Return @c false on failure and @c true on success.
904 //@{ @name Read basic IDL types arrays
905 ACE_CDR::Boolean read_boolean_array (ACE_CDR::Boolean* x,
906 ACE_CDR::ULong length);
907 ACE_CDR::Boolean read_char_array (ACE_CDR::Char *x,
908 ACE_CDR::ULong length);
909 ACE_CDR::Boolean read_wchar_array (ACE_CDR::WChar* x,
910 ACE_CDR::ULong length);
911 ACE_CDR::Boolean read_octet_array (ACE_CDR::Octet* x,
912 ACE_CDR::ULong length);
913 ACE_CDR::Boolean read_short_array (ACE_CDR::Short *x,
914 ACE_CDR::ULong length);
915 ACE_CDR::Boolean read_ushort_array (ACE_CDR::UShort *x,
916 ACE_CDR::ULong length);
917 ACE_CDR::Boolean read_long_array (ACE_CDR::Long *x,
918 ACE_CDR::ULong length);
919 ACE_CDR::Boolean read_ulong_array (ACE_CDR::ULong *x,
920 ACE_CDR::ULong length);
921 ACE_CDR::Boolean read_longlong_array (ACE_CDR::LongLong* x,
922 ACE_CDR::ULong length);
923 ACE_CDR::Boolean read_ulonglong_array (ACE_CDR::ULongLong* x,
924 ACE_CDR::ULong length);
925 ACE_CDR::Boolean read_float_array (ACE_CDR::Float *x,
926 ACE_CDR::ULong length);
927 ACE_CDR::Boolean read_double_array (ACE_CDR::Double *x,
928 ACE_CDR::ULong length);
929 ACE_CDR::Boolean read_longdouble_array (ACE_CDR::LongDouble* x,
930 ACE_CDR::ULong length);
931 ACE_CDR::Boolean read_int8_array (ACE_CDR::Int8 *x, ACE_CDR::ULong length);
932 ACE_CDR::Boolean read_uint8_array (ACE_CDR::UInt8 *x, ACE_CDR::ULong length);
933 //@}
936 * Return @c false on failure and @c true on success.
938 //@{ @name Skip elements
939 ACE_CDR::Boolean skip_boolean (void);
940 ACE_CDR::Boolean skip_char (void);
941 ACE_CDR::Boolean skip_wchar (void);
942 ACE_CDR::Boolean skip_octet (void);
943 ACE_CDR::Boolean skip_short (void);
944 ACE_CDR::Boolean skip_ushort (void);
945 ACE_CDR::Boolean skip_long (void);
946 ACE_CDR::Boolean skip_ulong (void);
947 ACE_CDR::Boolean skip_longlong (void);
948 ACE_CDR::Boolean skip_ulonglong (void);
949 ACE_CDR::Boolean skip_float (void);
950 ACE_CDR::Boolean skip_double (void);
951 ACE_CDR::Boolean skip_longdouble (void);
952 ACE_CDR::Boolean skip_fixed (void);
953 //@}
956 * The next field must be a string, this method skips it. It is
957 * useful in parsing a TypeCode.
958 * @return @c false on failure and @c true on success.
960 ACE_CDR::Boolean skip_wstring (void);
961 ACE_CDR::Boolean skip_string (void);
963 /// Skip @a n bytes in the CDR stream.
965 * @return @c false on failure and @c true on success.
967 ACE_CDR::Boolean skip_bytes (size_t n);
969 /// returns @c false if a problem has been detected.
970 bool good_bit (void) const;
973 * @return The start of the message block chain for this CDR
974 * stream.
976 * @note In the current implementation the chain has length 1, but
977 * we are planning to change that.
979 const ACE_Message_Block* start (void) const;
981 // = The following functions are useful to read the contents of the
982 // CDR stream from a socket or file.
985 * Grow the internal buffer, reset @c rd_ptr to the first byte in
986 * the new buffer that is properly aligned, and set @c wr_ptr to @c
987 * rd_ptr @c + @c newsize
989 int grow (size_t newsize);
992 * After reading and partially parsing the contents the user can
993 * detect a change in the byte order, this method will let him/her
994 * change it.
996 void reset_byte_order (int byte_order);
998 /// Re-initialize the CDR stream, copying the contents of the chain
999 /// of message_blocks starting from @a data.
1000 void reset (const ACE_Message_Block *data,
1001 int byte_order);
1003 /// Steal the contents from the current CDR.
1004 ACE_Message_Block *steal_contents (void);
1006 /// Steal the contents of @a cdr and make a shallow copy into this
1007 /// stream.
1008 void steal_from (ACE_InputCDR &cdr);
1010 /// Exchange data blocks with the caller of this method. The read
1011 /// and write pointers are also exchanged.
1013 * @note We now do only with the start_ message block.
1015 void exchange_data_blocks (ACE_InputCDR &cdr);
1017 /// Copy the data portion from the @a cdr to this cdr and return the
1018 /// data content (ie. the ACE_Data_Block) from this CDR to the
1019 /// caller.
1021 * @note The caller is responsible for managing the memory of the
1022 * returned ACE_Data_Block.
1024 ACE_Data_Block* clone_from (ACE_InputCDR &cdr);
1026 /// Re-initialize the CDR stream, forgetting about the old contents
1027 /// of the stream and allocating a new buffer (from the allocators).
1028 void reset_contents (void);
1030 /// Returns the current position for the @c rd_ptr.
1031 char* rd_ptr (void);
1033 /// Returns the current position for the @c wr_ptr.
1034 char* wr_ptr (void);
1036 /// Return how many bytes are left in the stream.
1037 size_t length (void) const;
1040 * Utility function to allow the user more flexibility.
1041 * Skips up to the nearest @a alignment-byte boundary.
1042 * Argument MUST be a power of 2.
1044 * @return 0 on success and -1 on failure.
1046 int align_read_ptr (size_t alignment);
1048 /// If @c true then this stream is writing in non-native byte order.
1049 /// This is only meaningful if ACE_ENABLE_SWAP_ON_WRITE is defined.
1050 bool do_byte_swap (void) const;
1052 /// If @c do_byte_swap() returns @c false, this returns
1053 /// ACE_CDR_BYTE_ORDER else it returns !ACE_CDR_BYTE_ORDER.
1054 int byte_order (void) const;
1056 /// Access the codeset translators. They can be nil!
1057 ACE_Char_Codeset_Translator *char_translator (void) const;
1058 ACE_WChar_Codeset_Translator *wchar_translator (void) const;
1060 /// Set the codeset translators.
1061 void char_translator (ACE_Char_Codeset_Translator *);
1062 void wchar_translator (ACE_WChar_Codeset_Translator *);
1065 * Returns (in @a buf) the next position in the buffer aligned to
1066 * @a size. It advances the Message_Block @c rd_ptr past the data
1067 * (i.e., @c buf @c + @c size). Sets the good_bit to @c false and
1068 * returns a -1 on failure.
1070 int adjust (size_t size,
1071 char *&buf);
1073 /// As above, but now the size and alignment requirements may be
1074 /// different.
1075 int adjust (size_t size,
1076 size_t align,
1077 char *&buf);
1079 /// Set the underlying GIOP version..
1080 void set_version (ACE_CDR::Octet major, ACE_CDR::Octet minor);
1082 /// Set the underlying GIOP version..
1083 void get_version (ACE_CDR::Octet &major, ACE_CDR::Octet &minor);
1085 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1086 /// Register and unregister our buffer size monitor.
1087 void register_monitor (const char* id);
1088 void unregister_monitor (void);
1089 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1091 protected:
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.
1099 bool do_byte_swap_;
1101 /// set to @c false when an error occurs.
1102 bool good_bit_;
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 */
1116 private:
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,
1143 size_t size,
1144 size_t align,
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.
1160 char* end (void);
1163 // ****************************************************************
1166 * @class ACE_Char_Codeset_Translator
1168 * @brief Codeset translation routines common to both Output and Input
1169 * CDR streams.
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
1181 public:
1182 virtual ~ACE_Char_Codeset_Translator ();
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&,
1198 std::string &);
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&,
1203 ACE_CDR::Char*,
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&,
1209 ACE_CDR::Char) = 0;
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&,
1214 ACE_CDR::ULong,
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;
1225 protected:
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,
1229 ACE_CDR::Octet *x);
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,
1236 void* x,
1237 size_t size,
1238 size_t align,
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
1245 * stream.
1247 ACE_CDR::Boolean write_array (ACE_OutputCDR& output,
1248 const void *x,
1249 size_t size,
1250 size_t align,
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.
1258 * Results
1260 int adjust (ACE_OutputCDR& out,
1261 size_t size,
1262 size_t align,
1263 char *&buf);
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
1281 * CDR streams.
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
1289 public:
1290 virtual ~ACE_WChar_Codeset_Translator ();
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&,
1301 std::wstring &);
1302 #endif
1303 virtual ACE_CDR::Boolean read_wchar_array (ACE_InputCDR&,
1304 ACE_CDR::WChar*,
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&,
1309 ACE_CDR::ULong,
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;
1317 protected:
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,
1321 ACE_CDR::Octet *x);
1322 ACE_CDR::Boolean read_2 (ACE_InputCDR& input,
1323 ACE_CDR::UShort *x);
1324 ACE_CDR::Boolean read_4 (ACE_InputCDR& input,
1325 ACE_CDR::ULong *x);
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,
1336 void* x,
1337 size_t size,
1338 size_t align,
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
1345 * stream.
1347 ACE_CDR::Boolean write_array (ACE_OutputCDR& output,
1348 const void *x,
1349 size_t size,
1350 size_t align,
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.
1358 * Results
1360 int adjust (ACE_OutputCDR& out,
1361 size_t size,
1362 size_t align,
1363 char *&buf);
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);
1376 // @@ These operators should not be inlined since they force SString.h
1377 // to be included in this header.
1378 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1379 const ACE_CString &x);
1381 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1382 ACE_CString &x);
1385 ACE_END_VERSIONED_NAMESPACE_DECL
1387 #if defined (__ACE_INLINE__)
1388 # include "ace/CDR_Stream.inl"
1389 #else /* __ACE_INLINE__ */
1391 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
1393 // Not used by CORBA or TAO
1394 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1395 ACE_CDR::Char x);
1396 // CDR output operators for primitive types
1398 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1399 ACE_CDR::Short x);
1400 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1401 ACE_CDR::UShort x);
1402 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1403 ACE_CDR::Long x);
1404 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1405 ACE_CDR::ULong x);
1406 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1407 ACE_CDR::LongLong x);
1408 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1409 ACE_CDR::ULongLong x);
1410 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR& os,
1411 ACE_CDR::LongDouble x);
1412 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1413 ACE_CDR::Float x);
1414 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1415 ACE_CDR::Double x);
1416 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1417 const ACE_CDR::Fixed &x);
1419 // CDR output operator from helper classes
1421 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1422 ACE_OutputCDR::from_boolean x);
1423 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1424 ACE_OutputCDR::from_char x);
1425 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1426 ACE_OutputCDR::from_wchar x);
1427 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1428 ACE_OutputCDR::from_octet x);
1429 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1430 ACE_OutputCDR::from_string x);
1431 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1432 ACE_OutputCDR::from_wstring x);
1433 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1434 const ACE_CDR::Char* x);
1435 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1436 const ACE_CDR::WChar* x);
1437 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1438 ACE_OutputCDR::from_std_string x);
1439 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1440 const std::string& x);
1441 #if !defined(ACE_LACKS_STD_WSTRING)
1442 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1443 ACE_OutputCDR::from_std_wstring x);
1444 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
1445 const std::wstring& x);
1446 #endif
1447 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os, ACE_OutputCDR::from_uint8 x);
1448 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os, ACE_OutputCDR::from_int8 x);
1450 // Not used by CORBA or TAO
1451 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1452 ACE_CDR::Char &x);
1453 // CDR input operators for primitive types
1455 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1456 ACE_CDR::Short &x);
1457 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1458 ACE_CDR::UShort &x);
1459 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1460 ACE_CDR::Long &x);
1461 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1462 ACE_CDR::ULong &x);
1463 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1464 ACE_CDR::LongLong &x);
1465 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1466 ACE_CDR::ULongLong &x);
1467 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1468 ACE_CDR::LongDouble &x);
1469 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1470 ACE_CDR::Float &x);
1471 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1472 ACE_CDR::Double &x);
1473 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1474 ACE_CDR::Fixed &x);
1476 // CDR input operator from helper classes
1478 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1479 ACE_InputCDR::to_boolean x);
1480 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1481 ACE_InputCDR::to_char x);
1482 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1483 ACE_InputCDR::to_wchar x);
1484 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1485 ACE_InputCDR::to_octet x);
1486 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1487 ACE_InputCDR::to_string x);
1488 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1489 ACE_InputCDR::to_wstring x);
1490 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1491 ACE_CDR::Char*& x);
1492 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1493 ACE_CDR::WChar*& x);
1494 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_InputCDR &os,
1495 ACE_InputCDR::to_std_string x);
1496 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1497 std::string& x);
1498 #if !defined(ACE_LACKS_STD_WSTRING)
1499 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_InputCDR &os,
1500 ACE_InputCDR::to_std_wstring x);
1501 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
1502 std::wstring& x);
1503 #endif
1504 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &os, ACE_InputCDR::to_uint8 x);
1505 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &os, ACE_InputCDR::to_int8 x);
1507 ACE_END_VERSIONED_NAMESPACE_DECL
1509 #endif /* __ACE_INLINE__ */
1511 #if defined (GEN_OSTREAM_OPS)
1513 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
1515 // ostream insertion operators for debugging code generated from IDL. All
1516 // but these below are either in generated code itself or are unambiguous
1517 // primitive types.
1519 ACE_Export std::ostream& operator<< (std::ostream &os,
1520 ACE_OutputCDR::from_boolean x);
1522 ACE_Export std::ostream& operator<< (std::ostream &os,
1523 ACE_OutputCDR::from_char x);
1525 ACE_Export std::ostream& operator<< (std::ostream &os,
1526 ACE_OutputCDR::from_wchar x);
1528 ACE_Export std::ostream& operator<< (std::ostream &os,
1529 ACE_OutputCDR::from_octet x);
1531 ACE_END_VERSIONED_NAMESPACE_DECL
1533 #endif /* GEN_OSTREAM_OPS */
1535 #include /**/ "ace/post.h"
1537 #endif /* ACE_CDR_STREAM_H */