CDR_Stream.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   CDR_Stream.h
00006  *
00007  *  CDR_Stream.h,v 1.93 2006/04/25 16:49:26 mesnier_p Exp
00008  *
00009  * ACE Common Data Representation (CDR) marshaling and demarshaling
00010  * classes.
00011  *
00012  * This implementation was inspired in the CDR class in SunSoft's
00013  * IIOP engine, but has a completely different implementation and a
00014  * different interface too.
00015  *
00016  * The current implementation assumes that the host has 1-byte,
00017  * 2-byte and 4-byte integral types, and that it has single
00018  * precision and double precision IEEE floats.
00019  * Those assumptions are pretty good these days, with Crays beign
00020  * the only known exception.
00021  *
00022  * Optimizations
00023  * -------------
00024  *  ACE_LACKS_CDR_ALIGNMENT
00025  *  @author Arvind S. Krishna <arvindk@dre.vanderbilt.edu>
00026  *
00027  *  CDR stream ignores alignment when marshaling data. Use this option
00028  *  only when ACE_DISABLE_SWAP_ON_READ can be enabled. This option requires
00029  *  ACE CDR engine to do both marshaling and demarshaling.
00030  *
00031  *
00032  *  @author TAO version by Aniruddha Gokhale <gokhale@cs.wustl.edu>
00033  *  @author Carlos O'Ryan <coryan@cs.wustl.edu>
00034  *  @author ACE version by Jeff Parsons <parsons@cs.wustl.edu>
00035  *  @author Istvan Buki <istvan.buki@euronet.be>
00036  *  @author Codeset translation by Jim Rogers <jrogers@viasoft.com>
00037  */
00038 //=============================================================================
00039 
00040 #ifndef ACE_CDR_STREAM_H
00041 #define ACE_CDR_STREAM_H
00042 
00043 #include /**/ "ace/pre.h"
00044 
00045 #include "ace/CDR_Base.h"
00046 
00047 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00048 # pragma once
00049 #endif /* ACE_LACKS_PRAGMA_ONCE */
00050 
00051 #include "ace/SStringfwd.h"
00052 #include "ace/Message_Block.h"
00053 
00054 
00055 // Stuff used by the ACE CDR classes.
00056 #if defined ACE_LITTLE_ENDIAN
00057 #  define ACE_CDR_BYTE_ORDER 1
00058 // little endian encapsulation byte order has value = 1
00059 #else  /* ! ACE_LITTLE_ENDIAN */
00060 #  define ACE_CDR_BYTE_ORDER 0
00061 // big endian encapsulation byte order has value = 0
00062 #endif /* ! ACE_LITTLE_ENDIAN */
00063 
00064 
00065 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00066 
00067 class ACE_Char_Codeset_Translator;
00068 class ACE_WChar_Codeset_Translator;
00069 
00070 class ACE_InputCDR;
00071 
00072 /**
00073  * @class ACE_OutputCDR
00074  *
00075  * @brief A CDR stream for writing, i.e. for marshalling.
00076  *
00077  * This class is based on the the CORBA spec for Java (98-02-29),
00078  * java class omg.org.CORBA.portable.OutputStream.  It diverts in
00079  * a few ways:
00080  * + Operations taking arrays don't have offsets, because in C++
00081  *   it is easier to describe an array starting from x+offset.
00082  * + Operations return an error status, because exceptions are
00083  *   not widely available in C++ (yet).
00084  */
00085 class ACE_Export ACE_OutputCDR
00086 {
00087 public:
00088   /**
00089    * The Codeset translators need access to some private members to
00090    * efficiently marshal arrays
00091    * For reading from an output CDR stream.
00092    */
00093   friend class ACE_Char_Codeset_Translator;
00094   friend class ACE_WChar_Codeset_Translator;
00095   friend class ACE_InputCDR;
00096 
00097   /// Default constructor, allocates <size> bytes in the internal
00098   /// buffer, if <size> == 0 it allocates the default size.
00099   ACE_OutputCDR (size_t size = 0,
00100                  int byte_order = ACE_CDR_BYTE_ORDER,
00101                  ACE_Allocator* buffer_allocator = 0,
00102                  ACE_Allocator* data_block_allocator = 0,
00103                  ACE_Allocator* message_block_allocator = 0,
00104                  size_t memcpy_tradeoff =
00105                  ACE_DEFAULT_CDR_MEMCPY_TRADEOFF,
00106                  ACE_CDR::Octet major_version =
00107                  ACE_CDR_GIOP_MAJOR_VERSION,
00108                  ACE_CDR::Octet minor_version =
00109                  ACE_CDR_GIOP_MINOR_VERSION);
00110 
00111   /// Build a CDR stream with an initial buffer, it will *not* remove
00112   /// <data>, since it did not allocated it.  It's important to be careful
00113   /// with the alignment of <data>.
00114   /**
00115    * Create an output stream from an arbitrary buffer, care must be
00116    * exercised with alignment, because this contructor will align if
00117    * needed.  In this case <data> will not point to the start off the
00118    * output stream. begin()->rd_prt() points to the start off the
00119    * output stream.  See ACE_ptr_align_binary() to properly align a
00120    * pointer and use ACE_CDR::MAX_ALIGNMENT for the correct alignment.
00121    */
00122   ACE_OutputCDR (char *data,
00123                  size_t size,
00124                  int byte_order = ACE_CDR_BYTE_ORDER,
00125                  ACE_Allocator* buffer_allocator = 0,
00126                  ACE_Allocator* data_block_allocator = 0,
00127                  ACE_Allocator* message_block_allocator = 0,
00128                  size_t memcpy_tradeoff=
00129                  ACE_DEFAULT_CDR_MEMCPY_TRADEOFF,
00130                  ACE_CDR::Octet giop_major_version =
00131                  ACE_CDR_GIOP_MAJOR_VERSION,
00132                  ACE_CDR::Octet giop_minor_version =
00133                  ACE_CDR_GIOP_MINOR_VERSION);
00134 
00135   /// Build a CDR stream with an initial Message_Block chain, it will
00136   /// *not* remove <data>, since it did not allocate it.
00137   ACE_OutputCDR (ACE_Message_Block *data,
00138                  int byte_order = ACE_CDR_BYTE_ORDER,
00139                  size_t memcpy_tradeoff=
00140                  ACE_DEFAULT_CDR_MEMCPY_TRADEOFF,
00141                  ACE_CDR::Octet giop_major_version =
00142                  ACE_CDR_GIOP_MAJOR_VERSION,
00143                  ACE_CDR::Octet giop_minor_version =
00144                  ACE_CDR_GIOP_MINOR_VERSION);
00145 
00146   /// destructor
00147   ~ACE_OutputCDR (void);
00148 
00149   /**
00150    * Disambiguate overload when inserting booleans, octets, chars, and
00151    * bounded strings.
00152    */
00153   //@{ @name Helper classes
00154 
00155   struct ACE_Export from_boolean
00156   {
00157     explicit from_boolean (ACE_CDR::Boolean b);
00158     ACE_CDR::Boolean val_;
00159   };
00160 
00161   struct ACE_Export from_octet
00162   {
00163     explicit from_octet (ACE_CDR::Octet o);
00164     ACE_CDR::Octet val_;
00165   };
00166 
00167   struct ACE_Export from_char
00168   {
00169     explicit from_char (ACE_CDR::Char c);
00170     ACE_CDR::Char val_;
00171   };
00172 
00173   struct ACE_Export from_wchar
00174   {
00175     explicit from_wchar (ACE_CDR::WChar wc);
00176     ACE_CDR::WChar val_;
00177   };
00178 
00179   struct ACE_Export from_string
00180   {
00181     from_string (ACE_CDR::Char* s,
00182                  ACE_CDR::ULong b,
00183                  ACE_CDR::Boolean nocopy = 0);
00184     from_string (const ACE_CDR::Char* s,
00185                  ACE_CDR::ULong b,
00186                  ACE_CDR::Boolean nocopy = 0);
00187     ACE_CDR::Char *val_;
00188     ACE_CDR::ULong bound_;
00189     ACE_CDR::Boolean nocopy_;
00190   };
00191 
00192   struct ACE_Export from_wstring
00193   {
00194     from_wstring (ACE_CDR::WChar* ws,
00195                   ACE_CDR::ULong b,
00196                   ACE_CDR::Boolean nocopy = 0);
00197     from_wstring (const ACE_CDR::WChar* ws,
00198                   ACE_CDR::ULong b,
00199                   ACE_CDR::Boolean nocopy = 0);
00200     ACE_CDR::WChar *val_;
00201     ACE_CDR::ULong bound_;
00202     ACE_CDR::Boolean nocopy_;
00203   };
00204   //@}
00205 
00206   // Return 0 on failure and 1 on success.
00207   //@{ @name Write operations
00208   ACE_CDR::Boolean write_boolean (ACE_CDR::Boolean x);
00209   ACE_CDR::Boolean write_char (ACE_CDR::Char x);
00210   ACE_CDR::Boolean write_wchar (ACE_CDR::WChar x);
00211   ACE_CDR::Boolean write_octet (ACE_CDR::Octet x);
00212   ACE_CDR::Boolean write_short (ACE_CDR::Short x);
00213   ACE_CDR::Boolean write_ushort (ACE_CDR::UShort x);
00214   ACE_CDR::Boolean write_long (ACE_CDR::Long x);
00215   ACE_CDR::Boolean write_ulong (ACE_CDR::ULong x);
00216   ACE_CDR::Boolean write_longlong (const ACE_CDR::LongLong &x);
00217   ACE_CDR::Boolean write_ulonglong (const ACE_CDR::ULongLong &x);
00218   ACE_CDR::Boolean write_float (ACE_CDR::Float x);
00219   ACE_CDR::Boolean write_double (const ACE_CDR::Double &x);
00220   ACE_CDR::Boolean write_longdouble (const ACE_CDR::LongDouble &x);
00221 
00222   // Overwrite the stream at the specified location that is previously
00223   // written as a long type placeholder. There is no alignment required
00224   // since the alignment is done before writing the long type placeholder.
00225   ACE_CDR::Boolean replace (ACE_CDR::Long x, char* loc);
00226 
00227   /// For string we offer methods that accept a precomputed length.
00228   ACE_CDR::Boolean write_string (const ACE_CDR::Char *x);
00229   ACE_CDR::Boolean write_string (ACE_CDR::ULong len,
00230                                  const ACE_CDR::Char *x);
00231   ACE_CDR::Boolean write_string (const ACE_CString &x);
00232   ACE_CDR::Boolean write_wstring (const ACE_CDR::WChar *x);
00233   ACE_CDR::Boolean write_wstring (ACE_CDR::ULong length,
00234                                   const ACE_CDR::WChar *x);
00235   //@}
00236 
00237   /// @note the portion written starts at <x> and ends
00238   ///    at <x + length>.
00239   /// The length is *NOT* stored into the CDR stream.
00240   //@{ @name Array write operations
00241   ACE_CDR::Boolean write_boolean_array (const ACE_CDR::Boolean *x,
00242                                         ACE_CDR::ULong length);
00243   ACE_CDR::Boolean write_char_array (const ACE_CDR::Char *x,
00244                                      ACE_CDR::ULong length);
00245   ACE_CDR::Boolean write_wchar_array (const ACE_CDR::WChar* x,
00246                                       ACE_CDR::ULong length);
00247   ACE_CDR::Boolean write_octet_array (const ACE_CDR::Octet* x,
00248                                       ACE_CDR::ULong length);
00249   ACE_CDR::Boolean write_short_array (const ACE_CDR::Short *x,
00250                                       ACE_CDR::ULong length);
00251   ACE_CDR::Boolean write_ushort_array (const ACE_CDR::UShort *x,
00252                                        ACE_CDR::ULong length);
00253   ACE_CDR::Boolean write_long_array (const ACE_CDR::Long *x,
00254                                      ACE_CDR::ULong length);
00255   ACE_CDR::Boolean write_ulong_array (const ACE_CDR::ULong *x,
00256                                       ACE_CDR::ULong length);
00257   ACE_CDR::Boolean write_longlong_array (const ACE_CDR::LongLong* x,
00258                                          ACE_CDR::ULong length);
00259   ACE_CDR::Boolean write_ulonglong_array (const ACE_CDR::ULongLong *x,
00260                                           ACE_CDR::ULong length);
00261   ACE_CDR::Boolean write_float_array (const ACE_CDR::Float *x,
00262                                       ACE_CDR::ULong length);
00263   ACE_CDR::Boolean write_double_array (const ACE_CDR::Double *x,
00264                                        ACE_CDR::ULong length);
00265   ACE_CDR::Boolean write_longdouble_array (const ACE_CDR::LongDouble* x,
00266                                            ACE_CDR::ULong length);
00267 
00268   /// Write an octet array contained inside a MB, this can be optimized
00269   /// to minimize copies.
00270   ACE_CDR::Boolean write_octet_array_mb (const ACE_Message_Block* mb);
00271   //@}
00272 
00273   /**
00274    * Return 0 on failure and 1 on success.
00275    */
00276   //@{ @name Append contents of own CDR stream to another
00277   ACE_CDR::Boolean append_boolean (ACE_InputCDR &);
00278   ACE_CDR::Boolean append_char (ACE_InputCDR &);
00279   ACE_CDR::Boolean append_wchar (ACE_InputCDR &);
00280   ACE_CDR::Boolean append_octet (ACE_InputCDR &);
00281   ACE_CDR::Boolean append_short (ACE_InputCDR &);
00282   ACE_CDR::Boolean append_ushort (ACE_InputCDR &);
00283   ACE_CDR::Boolean append_long (ACE_InputCDR &);
00284   ACE_CDR::Boolean append_ulong (ACE_InputCDR &);
00285   ACE_CDR::Boolean append_longlong (ACE_InputCDR &);
00286   ACE_CDR::Boolean append_ulonglong (ACE_InputCDR &);
00287   ACE_CDR::Boolean append_float (ACE_InputCDR &);
00288   ACE_CDR::Boolean append_double (ACE_InputCDR &);
00289   ACE_CDR::Boolean append_longdouble (ACE_InputCDR &);
00290 
00291   ACE_CDR::Boolean append_wstring (ACE_InputCDR &);
00292   ACE_CDR::Boolean append_string (ACE_InputCDR &);
00293   //@}
00294 
00295   /// Returns @c false if an error has ocurred.
00296   /**
00297    * @note The only expected error is to run out of memory.
00298    */
00299   bool good_bit (void) const;
00300 
00301   /// Reuse the CDR stream to write on the old buffer.
00302   void reset (void);
00303 
00304   /// Add the length of each message block in the chain.
00305   size_t total_length (void) const;
00306 
00307   /**
00308    * Return the start of the message block chain for this CDR stream.
00309    * @note The complete CDR stream is represented by a chain of
00310    * message blocks.
00311    */
00312   const ACE_Message_Block *begin (void) const;
00313 
00314   /// Return the last message in the chain that is is use.
00315   const ACE_Message_Block *end (void) const;
00316 
00317   /// Return the <current_> message block in chain.
00318   const ACE_Message_Block *current (void) const;
00319 
00320   /**
00321    * Access the underlying buffer (read only).  @note This
00322    * method only returns a pointer to the first block in the
00323    * chain.
00324    */
00325   const char *buffer (void) const;
00326 
00327   /**
00328    * Return the start and size of the internal buffer.@note This
00329    * method only returns information about the first block in the
00330    * chain.
00331    */
00332   size_t length (void) const;
00333 
00334   /**
00335    * Utility function to allow the user more flexibility.
00336    * Pads the stream up to the nearest <alignment>-byte boundary.
00337    * Argument MUST be a power of 2.
00338    * Returns 0 on success and -1 on failure.
00339    */
00340   int align_write_ptr (size_t alignment);
00341 
00342   /// Access the codeset translators. They can be null!
00343   ACE_Char_Codeset_Translator *char_translator (void) const;
00344   ACE_WChar_Codeset_Translator *wchar_translator (void) const;
00345 
00346   /// Set the char codeset translator.
00347   void char_translator (ACE_Char_Codeset_Translator *);
00348   /// Set the wchar codeset translator.
00349   void wchar_translator (ACE_WChar_Codeset_Translator *);
00350 
00351   /// set the global size of serialized wchars. This may be different
00352   /// than the size of a wchar_t.
00353   static void wchar_maxbytes (int );
00354 
00355   /// access the serialized size of wchars.
00356   static int wchar_maxbytes (void);
00357 
00358   /**
00359    * Return alignment of the wr_ptr(), with respect to the start of
00360    * the CDR stream.  This is not the same as the alignment of
00361    * current->wr_ptr()!
00362    */
00363   size_t current_alignment (void) const;
00364 
00365   /**
00366    * Returns (in <buf>) the next position in the buffer aligned to
00367    * <size>, it advances the Message_Block wr_ptr past the data
00368    * (i.e., <buf> + <size>). If necessary it grows the Message_Block
00369    * buffer.  Sets the good_bit to 0 and returns a -1 on failure.
00370    */
00371   int adjust (size_t size,
00372               char *&buf);
00373 
00374   /// As above, but now the size and alignment requirements may be
00375   /// different.
00376   int adjust (size_t size,
00377               size_t align,
00378               char *&buf);
00379 
00380   /// If non-zero then this stream is writing in non-native byte order,
00381   /// this is only meaningful if ACE_ENABLE_SWAP_ON_WRITE is defined.
00382   bool do_byte_swap (void) const;
00383 
00384   /// If <do_byte_swap> returns 0, this returns ACE_CDR_BYTE_ORDER else
00385   /// it returns !ACE_CDR_BYTE_ORDER.
00386   int byte_order (void) const;
00387 
00388   /// For use by a gateway, which creates the output stream for the
00389   /// reply to the client in its native byte order, but which must
00390   /// send the reply in the byte order of the target's reply to the
00391   /// gateway.
00392   void reset_byte_order (int byte_order);
00393 
00394   /// set GIOP version info
00395   int set_version (ACE_CDR::Octet major,
00396                    ACE_CDR::Octet minor);
00397 
00398   /// Set the underlying GIOP version..
00399   int get_version (ACE_CDR::Octet &major,
00400                    ACE_CDR::Octet &minor);
00401 
00402 private:
00403 
00404   // Find the message block in the chain of message blocks
00405   // that the provide location locates.
00406   ACE_Message_Block* find (char* loc);
00407 
00408   /// disallow copying...
00409   ACE_OutputCDR (const ACE_OutputCDR& rhs);
00410   ACE_OutputCDR& operator= (const ACE_OutputCDR& rhs);
00411 
00412   ACE_CDR::Boolean write_1 (const ACE_CDR::Octet *x);
00413   ACE_CDR::Boolean write_2 (const ACE_CDR::UShort *x);
00414   ACE_CDR::Boolean write_4 (const ACE_CDR::ULong *x);
00415   ACE_CDR::Boolean write_8 (const ACE_CDR::ULongLong *x);
00416   ACE_CDR::Boolean write_16 (const ACE_CDR::LongDouble *x);
00417 
00418   /**
00419    * write an array of <length> elements, each of <size> bytes and the
00420    * start aligned at a multiple of <align>. The elements are assumed
00421    * to be packed with the right alignment restrictions.  It is mostly
00422    * designed for buffers of the basic types.
00423    *
00424    * This operation uses <memcpy>; as explained above it is expected
00425    * that using assignment is faster that <memcpy> for one element,
00426    * but for several elements <memcpy> should be more efficient, it
00427    * could be interesting to find the break even point and optimize
00428    * for that case, but that would be too platform dependent.
00429    */
00430   ACE_CDR::Boolean write_array (const void *x,
00431                                 size_t size,
00432                                 size_t align,
00433                                 ACE_CDR::ULong length);
00434 
00435 
00436   ACE_CDR::Boolean write_wchar_array_i (const ACE_CDR::WChar* x,
00437                                         ACE_CDR::ULong length);
00438 
00439 
00440   /**
00441    * Grow the CDR stream. When it returns <buf> contains a pointer to
00442    * memory in the CDR stream, with at least <size> bytes ahead of it
00443    * and aligned to an <align> boundary. It moved the <wr_ptr> to <buf
00444    * + size>.
00445    */
00446   int grow_and_adjust (size_t size,
00447                        size_t align,
00448                        char *&buf);
00449 
00450 private:
00451   /// The start of the chain of message blocks.
00452   ACE_Message_Block start_;
00453 
00454   /// The current block in the chain were we are writing.
00455   ACE_Message_Block *current_;
00456 
00457 #if !defined (ACE_LACKS_CDR_IALIGNMENT)
00458   /**
00459    * The current alignment as measured from the start of the buffer.
00460    * Usually this coincides with the alignment of the buffer in
00461    * memory, but, when we chain another buffer this "quasi invariant"
00462    * is broken.
00463    * The current_alignment is used to readjust the buffer following
00464    * the stolen message block.
00465    */
00466   size_t current_alignment_;
00467 #endif /* ACE_LACKS_CDR_ALIGNMENT */
00468 
00469   /**
00470    * Is the current block writable.  When we steal a buffer from the
00471    * user and just chain it into the message block we are not supposed
00472    * to write on it, even if it is past the start and end of the
00473    * buffer.
00474    */
00475   bool current_is_writable_;
00476 
00477   /**
00478    * If not zero swap bytes at writing so the created CDR stream byte
00479    * order does *not* match the machine byte order.  The motivation
00480    * for such a beast is that in some setting a few (fast) machines
00481    * can be serving hundreds of slow machines with the opposite byte
00482    * order, so it makes sense (as a load balancing device) to put the
00483    * responsibility in the writers.  THIS IS NOT A STANDARD IN CORBA,
00484    * USE AT YOUR OWN RISK
00485    */
00486   bool do_byte_swap_;
00487 
00488   /// Set to 0 when an error ocurrs.
00489   bool good_bit_;
00490 
00491   /// Break-even point for copying.
00492   size_t memcpy_tradeoff_;
00493 
00494 protected:
00495   /// GIOP version information
00496   ACE_CDR::Octet major_version_;
00497   ACE_CDR::Octet minor_version_;
00498 
00499   /// If not nil, invoke for translation of character and string data.
00500   ACE_Char_Codeset_Translator *char_translator_;
00501   ACE_WChar_Codeset_Translator *wchar_translator_;
00502 
00503   /**
00504    * Some wide char codesets may be defined with a maximum number
00505    * of bytes that is smaller than the size of a wchar_t. This means
00506    * that the CDR cannot simply memcpy a block of wchars to and from
00507    * the stream, but must instead realign the bytes appropriately.
00508    * In cases when wchar i/o is not allowed, such as with GIOP 1.0,
00509    * or not having a native wchar codeset defined, the maxbytes is
00510    * set to zero, indicating no wchar data is allowed.
00511    */
00512   static int wchar_maxbytes_;
00513 };
00514 
00515 
00516 // ****************************************************************
00517 
00518 /**
00519  * @class ACE_InputCDR
00520  *
00521  * @brief A CDR stream for reading, i.e. for demarshalling.
00522  *
00523  * This class is based on the the CORBA spec for Java (98-02-29),
00524  * java class omg.org.CORBA.portable.InputStream.  It diverts in a
00525  * few ways:
00526  * + Operations to retrieve basic types take parameters by
00527  * reference.
00528  * + Operations taking arrays don't have offsets, because in C++
00529  * it is easier to describe an array starting from x+offset.
00530  * + Operations return an error status, because exceptions are
00531  * not widely available in C++ (yet).
00532  */
00533 class ACE_Export ACE_InputCDR
00534 {
00535 public:
00536   /// The translator need privileged access to efficiently demarshal
00537   /// arrays and the such
00538   friend class ACE_Char_Codeset_Translator;
00539   friend class ACE_WChar_Codeset_Translator;
00540 
00541   /**
00542    * Create an input stream from an arbitrary buffer.  The buffer must
00543    * be properly aligned because this contructor will *not* work if
00544    * the buffer is aligned unproperly.See ACE_ptr_align_binary() for
00545    * instructions on how to align a pointer properly and use
00546    * ACE_CDR::MAX_ALIGNMENT for the correct alignment.
00547    */
00548   ACE_InputCDR (const char *buf,
00549                 size_t bufsiz,
00550                 int byte_order = ACE_CDR_BYTE_ORDER,
00551                 ACE_CDR::Octet major_version =
00552                 ACE_CDR_GIOP_MAJOR_VERSION,
00553                 ACE_CDR::Octet minor_version =
00554                 ACE_CDR_GIOP_MINOR_VERSION);
00555 
00556   /// Create an empty input stream. The caller is responsible for
00557   /// putting the right data and providing the right alignment.
00558   ACE_InputCDR (size_t bufsiz,
00559                 int byte_order = ACE_CDR_BYTE_ORDER,
00560                 ACE_CDR::Octet major_version =
00561                 ACE_CDR_GIOP_MAJOR_VERSION,
00562                 ACE_CDR::Octet minor_version =
00563                 ACE_CDR_GIOP_MINOR_VERSION);
00564 
00565   /// Create an input stream from an ACE_Message_Block
00566   /**
00567    * The alignment of the @arg data block is carried into the new
00568    * ACE_InputCDR object. This constructor either increments the
00569    * @arg data reference count, or copies the data (if it's a compound
00570    * message block) so the caller can release the block immediately
00571    * upon return.
00572    */
00573   ACE_InputCDR (const ACE_Message_Block *data,
00574                 int byte_order = ACE_CDR_BYTE_ORDER,
00575                 ACE_CDR::Octet major_version = ACE_CDR_GIOP_MAJOR_VERSION,
00576                 ACE_CDR::Octet minor_version = ACE_CDR_GIOP_MINOR_VERSION,
00577                 ACE_Lock* lock = 0);
00578 
00579   /// Create an input stream from an ACE_Data_Block. The <flag>
00580   /// indicates whether the <data> can be deleted by the CDR stream
00581   /// or not
00582   ACE_InputCDR (ACE_Data_Block *data,
00583                 ACE_Message_Block::Message_Flags flag = 0,
00584                 int byte_order = ACE_CDR_BYTE_ORDER,
00585                 ACE_CDR::Octet major_version =
00586                 ACE_CDR_GIOP_MAJOR_VERSION,
00587                 ACE_CDR::Octet minor_version =
00588                 ACE_CDR_GIOP_MINOR_VERSION);
00589 
00590   /// Create an input stream from an ACE_Data_Block. It also sets the
00591   /// read and write pointers at the desired positions. This would be
00592   /// helpful if the applications desires to create a new CDR stream
00593   /// from a semi-processed datablock.
00594   ACE_InputCDR (ACE_Data_Block *data,
00595                 ACE_Message_Block::Message_Flags flag,
00596                 size_t read_pointer_position,
00597                 size_t write_pointer_position,
00598                 int byte_order = ACE_CDR_BYTE_ORDER,
00599                 ACE_CDR::Octet major_version =
00600                 ACE_CDR_GIOP_MAJOR_VERSION,
00601                 ACE_CDR::Octet minor_version =
00602                 ACE_CDR_GIOP_MINOR_VERSION);
00603 
00604   /**
00605    * These make a copy of the current stream state, but do not copy
00606    * the internal buffer, so the same stream can be read multiple
00607    * times efficiently.
00608    */
00609   ACE_InputCDR (const ACE_InputCDR& rhs);
00610 
00611   ACE_InputCDR& operator= (const ACE_InputCDR& rhs);
00612 
00613   /// When interpreting indirected TypeCodes it is useful to make a
00614   /// "copy" of the stream starting in the new position.
00615   ACE_InputCDR (const ACE_InputCDR& rhs,
00616                 size_t size,
00617                 ACE_CDR::Long offset);
00618 
00619   /// This creates an encapsulated stream, the first byte must be (per
00620   /// the spec) the byte order of the encapsulation.
00621   ACE_InputCDR (const ACE_InputCDR& rhs,
00622                 size_t size);
00623 
00624   /// Create an input CDR from an output CDR.
00625   ACE_InputCDR (const ACE_OutputCDR& rhs,
00626                 ACE_Allocator* buffer_allocator = 0,
00627                 ACE_Allocator* data_block_allocator = 0,
00628                 ACE_Allocator* message_block_allocator = 0);
00629 
00630   /// Helper class to transfer the contents from one input CDR to
00631   /// another without requiring any extra memory allocations, data
00632   /// copies or too many temporaries.
00633   struct ACE_Export Transfer_Contents
00634   {
00635     Transfer_Contents (ACE_InputCDR &rhs);
00636 
00637     ACE_InputCDR &rhs_;
00638   };
00639   /// Transfer the contents from <rhs> to a new CDR
00640   ACE_InputCDR (Transfer_Contents rhs);
00641 
00642   /// Destructor
00643   ~ACE_InputCDR (void);
00644 
00645   /// Disambiguate overloading when extracting octets, chars,
00646   /// booleans, and bounded strings
00647   //@{ @name Helper classes
00648 
00649   struct ACE_Export to_boolean
00650   {
00651     explicit to_boolean (ACE_CDR::Boolean &b);
00652     ACE_CDR::Boolean &ref_;
00653   };
00654 
00655   struct ACE_Export to_char
00656   {
00657     explicit to_char (ACE_CDR::Char &c);
00658     ACE_CDR::Char &ref_;
00659   };
00660 
00661   struct ACE_Export to_wchar
00662   {
00663     explicit to_wchar (ACE_CDR::WChar &wc);
00664     ACE_CDR::WChar &ref_;
00665   };
00666 
00667   struct ACE_Export to_octet
00668   {
00669     explicit to_octet (ACE_CDR::Octet &o);
00670     ACE_CDR::Octet &ref_;
00671   };
00672 
00673   struct ACE_Export to_string
00674   {
00675     /**
00676      * @deprecated The constructor taking a non-const string is now
00677      *             deprecated (C++ mapping 00-01-02), but we keep it
00678      *             around for backward compatibility.
00679      */
00680     to_string (ACE_CDR::Char *&s,
00681                ACE_CDR::ULong b);
00682     to_string (const ACE_CDR::Char *&s,
00683                ACE_CDR::ULong b);
00684     const ACE_CDR::Char *&val_;
00685     ACE_CDR::ULong bound_;
00686   };
00687 
00688   struct ACE_Export to_wstring
00689   {
00690     /// The constructor taking a non-const wstring is
00691     /// now deprecated (C++ mapping 00-01-02), but we
00692     /// keep it around for backward compatibility.
00693     to_wstring (ACE_CDR::WChar *&ws,
00694                 ACE_CDR::ULong b);
00695     to_wstring (const ACE_CDR::WChar *&ws,
00696                 ACE_CDR::ULong b);
00697     const ACE_CDR::WChar *&val_;
00698     ACE_CDR::ULong bound_;
00699   };
00700   //@}
00701 
00702   /**
00703    * Return @c false on failure and @c true on success.
00704    */
00705   //@{ @name Read basic IDL types
00706   ACE_CDR::Boolean read_boolean (ACE_CDR::Boolean& x);
00707   ACE_CDR::Boolean read_char (ACE_CDR::Char &x);
00708   ACE_CDR::Boolean read_wchar (ACE_CDR::WChar& x);
00709   ACE_CDR::Boolean read_octet (ACE_CDR::Octet& x);
00710   ACE_CDR::Boolean read_short (ACE_CDR::Short &x);
00711   ACE_CDR::Boolean read_ushort (ACE_CDR::UShort &x);
00712   ACE_CDR::Boolean read_long (ACE_CDR::Long &x);
00713   ACE_CDR::Boolean read_ulong (ACE_CDR::ULong &x);
00714   ACE_CDR::Boolean read_longlong (ACE_CDR::LongLong& x);
00715   ACE_CDR::Boolean read_ulonglong (ACE_CDR::ULongLong& x);
00716   ACE_CDR::Boolean read_float (ACE_CDR::Float &x);
00717   ACE_CDR::Boolean read_double (ACE_CDR::Double &x);
00718   ACE_CDR::Boolean read_longdouble (ACE_CDR::LongDouble &x);
00719 
00720   ACE_CDR::Boolean read_string (ACE_CDR::Char *&x);
00721   ACE_CDR::Boolean read_string (ACE_CString &x);
00722   ACE_CDR::Boolean read_wstring (ACE_CDR::WChar*& x);
00723   //@}
00724 
00725   /**
00726    * The buffer @a x must be large enough to contain @a length
00727    * elements.
00728    * Return @c false on failure and @c true on success.
00729    */
00730   //@{ @name Read basic IDL types arrays
00731   ACE_CDR::Boolean read_boolean_array (ACE_CDR::Boolean* x,
00732                                        ACE_CDR::ULong length);
00733   ACE_CDR::Boolean read_char_array (ACE_CDR::Char *x,
00734                                     ACE_CDR::ULong length);
00735   ACE_CDR::Boolean read_wchar_array (ACE_CDR::WChar* x,
00736                                      ACE_CDR::ULong length);
00737   ACE_CDR::Boolean read_octet_array (ACE_CDR::Octet* x,
00738                                      ACE_CDR::ULong length);
00739   ACE_CDR::Boolean read_short_array (ACE_CDR::Short *x,
00740                                      ACE_CDR::ULong length);
00741   ACE_CDR::Boolean read_ushort_array (ACE_CDR::UShort *x,
00742                                       ACE_CDR::ULong length);
00743   ACE_CDR::Boolean read_long_array (ACE_CDR::Long *x,
00744                                     ACE_CDR::ULong length);
00745   ACE_CDR::Boolean read_ulong_array (ACE_CDR::ULong *x,
00746                                      ACE_CDR::ULong length);
00747   ACE_CDR::Boolean read_longlong_array (ACE_CDR::LongLong* x,
00748                                         ACE_CDR::ULong length);
00749   ACE_CDR::Boolean read_ulonglong_array (ACE_CDR::ULongLong* x,
00750                                          ACE_CDR::ULong length);
00751   ACE_CDR::Boolean read_float_array (ACE_CDR::Float *x,
00752                                      ACE_CDR::ULong length);
00753   ACE_CDR::Boolean read_double_array (ACE_CDR::Double *x,
00754                                       ACE_CDR::ULong length);
00755   ACE_CDR::Boolean read_longdouble_array (ACE_CDR::LongDouble* x,
00756                                           ACE_CDR::ULong length);
00757   //@}
00758 
00759   /**
00760    * Return @c false on failure and @c true on success.
00761    */
00762   //@{ @name Skip elements
00763   ACE_CDR::Boolean skip_boolean (void);
00764   ACE_CDR::Boolean skip_char (void);
00765   ACE_CDR::Boolean skip_wchar (void);
00766   ACE_CDR::Boolean skip_octet (void);
00767   ACE_CDR::Boolean skip_short (void);
00768   ACE_CDR::Boolean skip_ushort (void);
00769   ACE_CDR::Boolean skip_long (void);
00770   ACE_CDR::Boolean skip_ulong (void);
00771   ACE_CDR::Boolean skip_longlong (void);
00772   ACE_CDR::Boolean skip_ulonglong (void);
00773   ACE_CDR::Boolean skip_float (void);
00774   ACE_CDR::Boolean skip_double (void);
00775   ACE_CDR::Boolean skip_longdouble (void);
00776   //@}
00777 
00778   /**
00779    * The next field must be a string, this method skips it. It is
00780    * useful in parsing a TypeCode.
00781    * @return @c false on failure and @c true on success.
00782    */
00783   ACE_CDR::Boolean skip_wstring (void);
00784   ACE_CDR::Boolean skip_string (void);
00785 
00786   /// Skip @a n bytes in the CDR stream.
00787   /**
00788    * @return @c false on failure and @c true on success.
00789    */
00790   ACE_CDR::Boolean skip_bytes (size_t n);
00791 
00792   /// returns @c false if a problem has been detected.
00793   bool good_bit (void) const;
00794 
00795   /**
00796    * @return The start of the message block chain for this CDR
00797    *         stream.
00798    *
00799    * @note In the current implementation the chain has length 1, but
00800    *       we are planning to change that.
00801    */
00802   const ACE_Message_Block* start (void) const;
00803 
00804   // = The following functions are useful to read the contents of the
00805   //   CDR stream from a socket or file.
00806 
00807   /**
00808    * Grow the internal buffer, reset @c rd_ptr to the first byte in
00809    * the new buffer that is properly aligned, and set @c wr_ptr to @c
00810    * rd_ptr @c + @c newsize
00811    */
00812   int grow (size_t newsize);
00813 
00814   /**
00815    * After reading and partially parsing the contents the user can
00816    * detect a change in the byte order, this method will let him/her
00817    * change it.
00818    */
00819   void reset_byte_order (int byte_order);
00820 
00821   /// Re-initialize the CDR stream, copying the contents of the chain
00822   /// of message_blocks starting from @a data.
00823   void reset (const ACE_Message_Block *data,
00824               int byte_order);
00825 
00826   /// Steal the contents from the current CDR.
00827   ACE_Message_Block *steal_contents (void);
00828 
00829   /// Steal the contents of @a cdr and make a shallow copy into this
00830   /// stream.
00831   void steal_from (ACE_InputCDR &cdr);
00832 
00833   /// Exchange data blocks with the caller of this method. The read
00834   /// and write pointers are also exchanged.
00835   /**
00836    * @note We now do only with the start_ message block.
00837    */
00838   void exchange_data_blocks (ACE_InputCDR &cdr);
00839 
00840   /// Copy the data portion from the @c cdr to this cdr and return the
00841   /// data content (ie. the ACE_Data_Block) from this CDR to the
00842   /// caller.
00843   /**
00844    * @note The caller is responsible for managing the memory of the
00845    *       returned ACE_Data_Block.
00846    */
00847   ACE_Data_Block* clone_from (ACE_InputCDR &cdr);
00848 
00849   /// Re-initialize the CDR stream, forgetting about the old contents
00850   /// of the stream and allocating a new buffer (from the allocators).
00851   void reset_contents (void);
00852 
00853   /// Returns the current position for the @c rd_ptr.
00854   char* rd_ptr (void);
00855 
00856   /// Returns the current position for the @c wr_ptr.
00857   char* wr_ptr (void);
00858 
00859   /// Return how many bytes are left in the stream.
00860   size_t length (void) const;
00861 
00862   /**
00863    * Utility function to allow the user more flexibility.
00864    * Skips up to the nearest @a alignment-byte boundary.
00865    * Argument MUST be a power of 2.
00866    *
00867    * @return 0 on success and -1 on failure.
00868    */
00869   int align_read_ptr (size_t alignment);
00870 
00871   /// If @c true then this stream is writing in non-native byte order.
00872   /// This is only meaningful if ACE_ENABLE_SWAP_ON_WRITE is defined.
00873   bool do_byte_swap (void) const;
00874 
00875   /// If @c do_byte_swap() returns @c false, this returns
00876   /// ACE_CDR_BYTE_ORDER else it returns !ACE_CDR_BYTE_ORDER.
00877   int byte_order (void) const;
00878 
00879   /// Access the codeset translators. They can be nil!
00880   ACE_Char_Codeset_Translator *char_translator (void) const;
00881   ACE_WChar_Codeset_Translator *wchar_translator (void) const;
00882 
00883   /// Set the codeset translators.
00884   void char_translator (ACE_Char_Codeset_Translator *);
00885   void wchar_translator (ACE_WChar_Codeset_Translator *);
00886 
00887   /**
00888    * Returns (in @a buf) the next position in the buffer aligned to
00889    * @a size.  It advances the Message_Block @c rd_ptr past the data
00890    * (i.e., @c buf @c + @c size).  Sets the good_bit to @c false and
00891    * returns a -1 on failure.
00892    */
00893   int adjust (size_t size,
00894               char *&buf);
00895 
00896   /// As above, but now the size and alignment requirements may be
00897   /// different.
00898   int adjust (size_t size,
00899               size_t align,
00900               char *&buf);
00901 
00902   /// Set the underlying GIOP version..
00903   int set_version (ACE_CDR::Octet major,
00904                    ACE_CDR::Octet minor);
00905 
00906   /// Set the underlying GIOP version..
00907   int get_version (ACE_CDR::Octet &major,
00908                    ACE_CDR::Octet &minor);
00909 
00910 protected:
00911 
00912   /// The start of the chain of message blocks, even though in the
00913   /// current version the chain always has length 1.
00914   ACE_Message_Block start_;
00915 
00916   /// The CDR stream byte order does not match the one on the machine,
00917   /// swapping is needed while reading.
00918   bool do_byte_swap_;
00919 
00920   /// set to @c false when an error occurs.
00921   bool good_bit_;
00922 
00923   /// The GIOP versions for this stream
00924   ACE_CDR::Octet major_version_;
00925   ACE_CDR::Octet minor_version_;
00926 
00927   /// If not nil, invoke for translation of character and string data.
00928   ACE_Char_Codeset_Translator *char_translator_;
00929   ACE_WChar_Codeset_Translator *wchar_translator_;
00930 
00931 private:
00932 
00933   ACE_CDR::Boolean read_1 (ACE_CDR::Octet *x);
00934   ACE_CDR::Boolean read_2 (ACE_CDR::UShort *x);
00935   ACE_CDR::Boolean read_4 (ACE_CDR::ULong *x);
00936   ACE_CDR::Boolean read_8 (ACE_CDR::ULongLong *x);
00937   ACE_CDR::Boolean read_16 (ACE_CDR::LongDouble *x);
00938 
00939   // Several types can be read using the same routines, since TAO
00940   // tries to use native types with known size for each CORBA type.
00941   // We could use void* or char* to make the interface more
00942   // consistent, but using native types let us exploit the strict
00943   // alignment requirements of CDR streams and implement the
00944   // operations using asignment.
00945 
00946   /**
00947    * Read an array of <length> elements, each of <size> bytes and the
00948    * start aligned at a multiple of <align>. The elements are assumed
00949    * to be packed with the right alignment restrictions.  It is mostly
00950    * designed for buffers of the basic types.
00951    *
00952    * This operation uses <memcpy>; as explained above it is expected
00953    * that using assignment is faster that <memcpy> for one element,
00954    * but for several elements <memcpy> should be more efficient, it
00955    * could be interesting to find the break even point and optimize
00956    * for that case, but that would be too platform dependent.
00957    */
00958   ACE_CDR::Boolean read_array (void* x,
00959                                size_t size,
00960                                size_t align,
00961                                ACE_CDR::ULong length);
00962 
00963   /**
00964    * On those occasions when the native codeset for wchar is smaller than
00965    * the size of a wchar_t, such as using UTF-16 with a 4-byte wchar_t, a
00966    * special form of reading the array is needed. Actually, this should be
00967    * a default translator.
00968    */
00969   ACE_CDR::Boolean read_wchar_array_i (ACE_CDR::WChar * x,
00970                                        ACE_CDR::ULong length);
00971 
00972   /// Move the rd_ptr ahead by <offset> bytes.
00973   void rd_ptr (size_t offset);
00974 
00975   /// Points to the continuation field of the current message block.
00976   char* end (void);
00977 };
00978 
00979 // ****************************************************************
00980 
00981 /**
00982  * @class ACE_Char_Codeset_Translator
00983  *
00984  * @brief Codeset translation routines common to both Output and Input
00985  * CDR streams.
00986  *
00987  * This class is a base class for defining codeset translation
00988  * routines to handle the character set translations required by
00989  * both CDR Input streams and CDR Output streams.
00990  *
00991  * Translators are reference counted. This allows for stateful as well
00992  * as stateless translators. Stateless translators will be allocated
00993  * once whereas CDR Streams own their own copy of a stateful translator.
00994  */
00995 class ACE_Export ACE_Char_Codeset_Translator
00996 {
00997 public:
00998   virtual ~ACE_Char_Codeset_Translator ();
00999 
01000   /// Read a single character from the stream, converting from the
01001   /// stream codeset to the native codeset
01002   virtual ACE_CDR::Boolean read_char (ACE_InputCDR&,
01003                                       ACE_CDR::Char&) = 0;
01004 
01005   /// Read a string from the stream, including the length, converting
01006   /// the characters from the stream codeset to the native codeset
01007   virtual ACE_CDR::Boolean read_string (ACE_InputCDR&,
01008                                         ACE_CDR::Char *&) = 0;
01009 
01010   /// Read an array of characters from the stream, converting the
01011   /// characters from the stream codeset to the native codeset.
01012   virtual ACE_CDR::Boolean read_char_array (ACE_InputCDR&,
01013                                             ACE_CDR::Char*,
01014                                             ACE_CDR::ULong) = 0;
01015 
01016   /// Write a single character to the stream, converting from the
01017   /// native codeset to the stream codeset
01018   virtual ACE_CDR::Boolean write_char (ACE_OutputCDR&,
01019                                        ACE_CDR::Char) = 0;
01020 
01021   /// Write a string to the stream, including the length, converting
01022   /// from the native codeset to the stream codeset
01023   virtual ACE_CDR::Boolean write_string (ACE_OutputCDR&,
01024                                          ACE_CDR::ULong,
01025                                          const ACE_CDR::Char*) = 0;
01026 
01027   /// Write an array of characters to the stream, converting from the
01028   /// native codeset to the stream codeset
01029   virtual ACE_CDR::Boolean write_char_array (ACE_OutputCDR&,
01030                                              const ACE_CDR::Char*,
01031                                              ACE_CDR::ULong) = 0;
01032 
01033   virtual ACE_CDR::ULong ncs () = 0;
01034   virtual ACE_CDR::ULong tcs () = 0;
01035 protected:
01036   /// Children have access to low-level routines because they cannot
01037   /// use read_char or something similar (it would recurse).
01038   ACE_CDR::Boolean read_1 (ACE_InputCDR& input,
01039                            ACE_CDR::Octet *x);
01040   ACE_CDR::Boolean write_1 (ACE_OutputCDR& output,
01041                             const ACE_CDR::Octet *x);
01042 
01043   /// Efficiently read <length> elements of size <size> each from
01044   /// <input> into <x>; the data must be aligned to <align>.
01045   ACE_CDR::Boolean read_array (ACE_InputCDR& input,
01046                                void* x,
01047                                size_t size,
01048                                size_t align,
01049                                ACE_CDR::ULong length);
01050 
01051   /**
01052    * Efficiently write <length> elements of size <size> from <x> into
01053    * <output>. Before inserting the elements enough padding is added
01054    * to ensure that the elements will be aligned to <align> in the
01055    * stream.
01056    */
01057   ACE_CDR::Boolean write_array (ACE_OutputCDR& output,
01058                                 const void *x,
01059                                 size_t size,
01060                                 size_t align,
01061                                 ACE_CDR::ULong length);
01062 
01063   /**
01064    * Exposes the stream implementation of <adjust>, this is useful in
01065    * many cases to minimize memory allocations during marshaling.
01066    * On success <buf> will contain a contiguous area in the CDR stream
01067    * that can hold <size> bytes aligned to <align>.
01068    * Results
01069    */
01070   int adjust (ACE_OutputCDR& out,
01071               size_t size,
01072               size_t align,
01073               char *&buf);
01074 
01075   /// Used by derived classes to set errors in the CDR stream.
01076   void good_bit (ACE_OutputCDR& out, bool bit);
01077 
01078   /// Obtain the CDR Stream's major & minor version values.
01079   ACE_CDR::Octet major_version (ACE_InputCDR& input);
01080   ACE_CDR::Octet minor_version (ACE_InputCDR& input);
01081   ACE_CDR::Octet major_version (ACE_OutputCDR& output);
01082   ACE_CDR::Octet minor_version (ACE_OutputCDR& output);
01083 };
01084 
01085 // ****************************************************************
01086 
01087 /**
01088  * @class ACE_WChar_Codeset_Translator
01089  *
01090  * @brief Codeset translation routines common to both Output and Input
01091  * CDR streams.
01092  *
01093  * This class is a base class for defining codeset translation
01094  * routines to handle the character set translations required by
01095  * both CDR Input streams and CDR Output streams.
01096  */
01097 class ACE_Export ACE_WChar_Codeset_Translator
01098 {
01099 public:
01100   virtual ~ACE_WChar_Codeset_Translator ();
01101 
01102   virtual ACE_CDR::Boolean read_wchar (ACE_InputCDR&,
01103                                        ACE_CDR::WChar&) = 0;
01104   virtual ACE_CDR::Boolean read_wstring (ACE_InputCDR&,
01105                                          ACE_CDR::WChar *&) = 0;
01106   virtual ACE_CDR::Boolean read_wchar_array (ACE_InputCDR&,
01107                                              ACE_CDR::WChar*,
01108                                              ACE_CDR::ULong) = 0;
01109   virtual ACE_CDR::Boolean write_wchar (ACE_OutputCDR&,
01110                                         ACE_CDR::WChar) = 0;
01111   virtual ACE_CDR::Boolean write_wstring (ACE_OutputCDR&,
01112                                           ACE_CDR::ULong,
01113                                           const ACE_CDR::WChar*) = 0;
01114   virtual ACE_CDR::Boolean write_wchar_array (ACE_OutputCDR&,
01115                                               const ACE_CDR::WChar*,
01116                                               ACE_CDR::ULong) = 0;
01117 
01118   virtual ACE_CDR::ULong ncs () = 0;
01119   virtual ACE_CDR::ULong tcs () = 0;
01120 protected:
01121   /// Children have access to low-level routines because they cannot
01122   /// use read_char or something similar (it would recurse).
01123   ACE_CDR::Boolean read_1 (ACE_InputCDR& input,
01124                            ACE_CDR::Octet *x);
01125   ACE_CDR::Boolean read_2 (ACE_InputCDR& input,
01126                            ACE_CDR::UShort *x);
01127   ACE_CDR::Boolean read_4 (ACE_InputCDR& input,
01128                            ACE_CDR::ULong *x);
01129   ACE_CDR::Boolean write_1 (ACE_OutputCDR& output,
01130                             const ACE_CDR::Octet *x);
01131   ACE_CDR::Boolean write_2 (ACE_OutputCDR& output,
01132                             const ACE_CDR::UShort *x);
01133   ACE_CDR::Boolean write_4 (ACE_OutputCDR& output,
01134                             const ACE_CDR::ULong *x);
01135 
01136   /// Efficiently read <length> elements of size <size> each from
01137   /// <input> into <x>; the data must be aligned to <align>.
01138   ACE_CDR::Boolean read_array (ACE_InputCDR& input,
01139                                void* x,
01140                                size_t size,
01141                                size_t align,
01142                                ACE_CDR::ULong length);
01143 
01144   /**
01145    * Efficiently write <length> elements of size <size> from <x> into
01146    * <output>. Before inserting the elements enough padding is added
01147    * to ensure that the elements will be aligned to <align> in the
01148    * stream.
01149    */
01150   ACE_CDR::Boolean write_array (ACE_OutputCDR& output,
01151                                 const void *x,
01152                                 size_t size,
01153                                 size_t align,
01154                                 ACE_CDR::ULong length);
01155 
01156   /**
01157    * Exposes the stream implementation of <adjust>, this is useful in
01158    * many cases to minimize memory allocations during marshaling.
01159    * On success <buf> will contain a contiguous area in the CDR stream
01160    * that can hold <size> bytes aligned to <align>.
01161    * Results
01162    */
01163   int adjust (ACE_OutputCDR& out,
01164               size_t size,
01165               size_t align,
01166               char *&buf);
01167 
01168   /// Used by derived classes to set errors in the CDR stream.
01169   void good_bit (ACE_OutputCDR& out, bool bit);
01170 
01171   /// Obtain the CDR Stream's major & minor version values.
01172   ACE_CDR::Octet major_version (ACE_InputCDR& input);
01173   ACE_CDR::Octet minor_version (ACE_InputCDR& input);
01174   ACE_CDR::Octet major_version (ACE_OutputCDR& output);
01175   ACE_CDR::Octet minor_version (ACE_OutputCDR& output);
01176 
01177 };
01178 
01179 // @@ These operators should not be inlined since they force SString.h
01180 //    to be included in this header.
01181 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01182                                                const ACE_CString &x);
01183 
01184 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01185                                                ACE_CString &x);
01186 
01187 
01188 ACE_END_VERSIONED_NAMESPACE_DECL
01189 
01190 #if defined (__ACE_INLINE__)
01191 # include "ace/CDR_Stream.inl"
01192 #else /* __ACE_INLINE__ */
01193 
01194 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
01195 
01196 // Not used by CORBA or TAO
01197 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01198                                                ACE_CDR::Char x);
01199 // CDR output operators for primitive types
01200 
01201 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01202                                                ACE_CDR::Short x);
01203 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01204                                                ACE_CDR::UShort x);
01205 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01206                                                ACE_CDR::Long x);
01207 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01208                                                ACE_CDR::ULong x);
01209 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01210                                                ACE_CDR::LongLong x);
01211 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01212                                                ACE_CDR::ULongLong x);
01213 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR& os,
01214                                                ACE_CDR::LongDouble x);
01215 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01216                                                ACE_CDR::Float x);
01217 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01218                                                ACE_CDR::Double x);
01219 
01220 // CDR output operator from helper classes
01221 
01222 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01223                                                ACE_OutputCDR::from_boolean x);
01224 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01225                                                ACE_OutputCDR::from_char x);
01226 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01227                                                ACE_OutputCDR::from_wchar x);
01228 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01229                                                ACE_OutputCDR::from_octet x);
01230 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01231                                                ACE_OutputCDR::from_string x);
01232 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01233                                                ACE_OutputCDR::from_wstring x);
01234 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01235                                                const ACE_CDR::Char* x);
01236 extern ACE_Export ACE_CDR::Boolean operator<< (ACE_OutputCDR &os,
01237                                                const ACE_CDR::WChar* x);
01238 
01239 // Not used by CORBA or TAO
01240 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01241                                                ACE_CDR::Char &x);
01242 // CDR input operators for primitive types
01243 
01244 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01245                                                ACE_CDR::Short &x);
01246 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01247                                                ACE_CDR::UShort &x);
01248 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01249                                                ACE_CDR::Long &x);
01250 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01251                                                ACE_CDR::ULong &x);
01252 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01253                                                ACE_CDR::LongLong &x);
01254 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01255                                                ACE_CDR::ULongLong &x);
01256 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01257                                                ACE_CDR::LongDouble &x);
01258 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01259                                                ACE_CDR::Float &x);
01260 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01261                                                ACE_CDR::Double &x);
01262 
01263 // CDR input operator from helper classes
01264 
01265 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01266                                                ACE_InputCDR::to_boolean x);
01267 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01268                                                ACE_InputCDR::to_char x);
01269 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01270                                                ACE_InputCDR::to_wchar x);
01271 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01272                                                ACE_InputCDR::to_octet x);
01273 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01274                                                ACE_InputCDR::to_string x);
01275 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01276                                                ACE_InputCDR::to_wstring x);
01277 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01278                                                ACE_CDR::Char*& x);
01279 extern ACE_Export ACE_CDR::Boolean operator>> (ACE_InputCDR &is,
01280                                                ACE_CDR::WChar*& x);
01281 
01282 ACE_END_VERSIONED_NAMESPACE_DECL
01283 
01284 #endif /* __ACE_INLINE__ */
01285 
01286 #include /**/ "ace/post.h"
01287 
01288 #endif /* ACE_CDR_STREAM_H */

Generated on Thu Nov 9 09:41:48 2006 for ACE by doxygen 1.3.6