Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

CDR.h

Go to the documentation of this file.
00001 // This may look like C, but it's really -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    CDR.h
00006  *
00007  *  $Id: CDR.h,v 1.1.1.3.64.1 2003/04/10 14:04:02 phil Exp $
00008  *
00009  *   Common Data Representation (CDR) marshaling streams.
00010  *
00011  *   This implementation assumes that the native numeric
00012  *   representation is two's complement for integers, IEEE
00013  *   single/double for floats.  Also that characters are in ISO
00014  *   Latin/1.
00015  *
00016  *   Note that CDR itself makes no such assumptions, but this
00017  *   implementation makes such assumptions for reasons of
00018  *   efficiency.  Careful enhancements could preserve that
00019  *   efficiency where the assumptions are true, yet still allow the
00020  *   code to work when they aren't true.
00021  *
00022  *   The implementation expects that buffers are aligned according
00023  *   to the strongest CDR alignment restriction.
00024  *
00025  *   NOTE: this does everything "CDR 1.1" does ... that is, it
00026  *   supports the five extended OMG-IDL data types in UNO Appendix
00027  *   A, which provide richer arithmetic types (64 bit integers,
00028  *   "quad precision" FP) and UNICODE-based characters and strings.
00029  *   Those types are not standard parts of OMG-IDL at this time.
00030  *
00031  *   THREADING NOTE: CDR data structures must be protected against
00032  *   concurrent access by their owning thread.
00033  *
00034  *
00035  *  @author  Copyright 1994-1995 by Sun Microsystems
00036  *  @author Inc.  Many enhancements added by Aniruddha Gokhale and Carlos O'Ryan.
00037  */
00038 //=============================================================================
00039 
00040 
00041 #ifndef TAO_CDR_H
00042 #define TAO_CDR_H
00043 #include "ace/pre.h"
00044 
00045 #include "tao/corbafwd.h"
00046 
00047 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00048 # pragma once
00049 #endif /* ACE_LACKS_PRAGMA_ONCE */
00050 
00051 #include "ace/CDR_Stream.h"
00052 
00053 class TAO_ORB_Core;
00054 
00055 /**
00056  * @class TAO_OutputCDR
00057  *
00058  * @brief A CDR stream for writing, i.e. for marshalling.
00059  *
00060  * This class is based on the the CORBA spec for Java (98-02-29),
00061  * java class omg.org.CORBA.portable.OutputStream.
00062  * It diverts in a few ways:
00063  * + Operations taking arrays don't have offsets, because in C++
00064  * it is easier to describe an array starting from x+offset.
00065  * + Operations return an error status, because exceptions are
00066  * not widely available in C++ (yet).
00067  * A particularly useful static member function for this buffer is
00068  * an interpretive encoding routine, usable as a typecode
00069  * interpreter callback.  Ditto for decoding.  These are used to
00070  * support all OMG-IDL datatypes, even those not supported
00071  * directly by put/get primitives.
00072  */
00073 class TAO_Export TAO_OutputCDR : public ACE_OutputCDR
00074 {
00075 public:
00076   /// For reading from a output CDR stream.
00077   friend class TAO_InputCDR;
00078 
00079   // The default values for the allocators and memcpy_tradeoff
00080   // in these constructors are not 0, but are generated by the
00081   // ORB. Refer to the constructor bodies in CDR.cpp for the
00082   // code that supplies these values to the base class constructor.
00083 
00084   /// Default constructor, allocates <size> bytes in the internal
00085   /// buffer, if <size> == 0 it allocates the default size.
00086   TAO_OutputCDR (size_t size = 0,
00087                  int byte_order = ACE_CDR_BYTE_ORDER,
00088                  ACE_Allocator* buffer_allocator = 0,
00089                  ACE_Allocator* data_block_allocator = 0,
00090                  ACE_Allocator* message_block_allocator = 0,
00091                  size_t memcpy_tradeoff = 0,
00092                  ACE_CDR::Octet major_version =
00093                    TAO_DEF_GIOP_MAJOR,
00094                  ACE_CDR::Octet minor_version =
00095                    TAO_DEF_GIOP_MINOR);
00096 
00097   /// Build a CDR stream with an initial buffer, it will *not* remove
00098   /// <data>, since it did not allocated it.
00099   TAO_OutputCDR (char *data,
00100                  size_t size,
00101                  int byte_order = ACE_CDR_BYTE_ORDER,
00102                  ACE_Allocator* buffer_allocator = 0,
00103                  ACE_Allocator* data_block_allocator = 0,
00104                  ACE_Allocator* message_block_allocator = 0,
00105                  size_t memcpy_tradeoff = 0,
00106                  ACE_CDR::Octet major_version =
00107                    TAO_DEF_GIOP_MAJOR,
00108                  ACE_CDR::Octet minor_version =
00109                    TAO_DEF_GIOP_MINOR);
00110 
00111   /// Build a CDR stream with an initial Message_Block chain, it will *not*
00112   /// remove <data>, since it did not allocate it.
00113   TAO_OutputCDR (ACE_Message_Block *data,
00114                  int byte_order = ACE_CDR_BYTE_ORDER,
00115                  size_t memcpy_tradeoff = 0,
00116                  ACE_CDR::Octet major_version =
00117                    TAO_DEF_GIOP_MAJOR,
00118                  ACE_CDR::Octet minor_version =
00119                    TAO_DEF_GIOP_MINOR);
00120 
00121   /// Destructor.
00122   ~TAO_OutputCDR (void);
00123 
00124   // @@ TODO: do we want a special method to write an array of
00125   // strings and wstrings?
00126 
00127   // = TAO specific methods.
00128   static void throw_stub_exception (int error_num ACE_ENV_ARG_DECL);
00129   static void throw_skel_exception (int error_num ACE_ENV_ARG_DECL);
00130 
00131 private:
00132   /// disallow copying...
00133   TAO_OutputCDR (const TAO_OutputCDR& rhs);
00134   TAO_OutputCDR& operator= (const TAO_OutputCDR& rhs);
00135 };
00136 
00137 /**
00138  * @class TAO_InputCDR
00139  *
00140  * @brief A CDR stream for reading, i.e. for demarshalling.
00141  *
00142  * This class is based on the the CORBA spec for Java (98-02-29),
00143  * java class omg.org.CORBA.portable.InputStream.
00144  * It diverts in a few ways:
00145  * + Operations to retrieve basic types take parameters by
00146  * reference.
00147  * + Operations taking arrays don't have offsets, because in C++
00148  * it is easier to describe an array starting from x+offset.
00149  * + Operations return an error status, because exceptions are
00150  * not widely available in C++ (yet).
00151  * A particularly useful static member function for this buffer is
00152  * an interpretive encoding routine, usable as a typecode
00153  * interpreter callback.  Ditto for decoding.  These are used to
00154  * support all OMG-IDL datatypes, even those not supported
00155  * directly by put/get primitives.
00156  */
00157 class TAO_Export TAO_InputCDR : public ACE_InputCDR
00158 {
00159 public:
00160   /**
00161    * Create an input stream from an arbitrary buffer, care must be
00162    * exercised wrt alignment, because this contructor will *not* work
00163    * if the buffer is unproperly aligned.
00164    */
00165   TAO_InputCDR (const char* buf,
00166                 size_t bufsiz,
00167                 int byte_order = ACE_CDR_BYTE_ORDER,
00168                 ACE_CDR::Octet major_version =
00169                   TAO_DEF_GIOP_MAJOR,
00170                 ACE_CDR::Octet minor_version =
00171                   TAO_DEF_GIOP_MINOR,
00172                 TAO_ORB_Core* orb_core = 0);
00173 
00174   /// Create an empty input stream. The caller is responsible for
00175   /// putting the right data and providing the right alignment.
00176   TAO_InputCDR (size_t bufsiz,
00177                 int byte_order = ACE_CDR_BYTE_ORDER,
00178                 ACE_CDR::Octet major_version =
00179                   TAO_DEF_GIOP_MAJOR,
00180                 ACE_CDR::Octet minor_version =
00181                   TAO_DEF_GIOP_MINOR,
00182                 TAO_ORB_Core* orb_core = 0);
00183 
00184   /// Create an input stream from an ACE_Message_Block
00185   TAO_InputCDR (const ACE_Message_Block *data,
00186                 int byte_order = ACE_CDR_BYTE_ORDER,
00187                 ACE_CDR::Octet major_version =
00188                   TAO_DEF_GIOP_MAJOR,
00189                 ACE_CDR::Octet minor_version =
00190                   TAO_DEF_GIOP_MINOR,
00191                 TAO_ORB_Core* orb_core = 0);
00192 
00193   /// Create an input stream from an ACE_Data_Block
00194   TAO_InputCDR (ACE_Data_Block *data,
00195                 ACE_Message_Block::Message_Flags flag = 0,
00196                 int byte_order = ACE_CDR_BYTE_ORDER,
00197                 ACE_CDR::Octet major_version =
00198                   TAO_DEF_GIOP_MAJOR,
00199                 ACE_CDR::Octet minor_version =
00200                   TAO_DEF_GIOP_MINOR,
00201                 TAO_ORB_Core* orb_core = 0);
00202 
00203   /// Create an input stream from an ACE_Data_Block
00204   TAO_InputCDR (ACE_Data_Block *data,
00205                 ACE_Message_Block::Message_Flags flag,
00206                 size_t read_pointer_position,
00207                 size_t write_pointer_position,
00208                 int byte_order = ACE_CDR_BYTE_ORDER,
00209                 ACE_CDR::Octet major_version =
00210                   TAO_DEF_GIOP_MAJOR,
00211                 ACE_CDR::Octet minor_version =
00212                   TAO_DEF_GIOP_MINOR,
00213                 TAO_ORB_Core* orb_core = 0);
00214 
00215   /**
00216    * Make a copy of the current stream state, but does not copy the
00217    * internal buffer; so the same stream can be read multiple times
00218    * efficiently.
00219    */
00220   TAO_InputCDR (const TAO_InputCDR& rhs);
00221 
00222   /// When interpreting indirected TypeCodes it is useful to make a
00223   /// "copy" of the stream starting in the new position.
00224   TAO_InputCDR (const TAO_InputCDR& rhs,
00225                 size_t size,
00226                 ACE_CDR::Long offset);
00227   /**
00228    * This creates an encapsulated stream, the first byte must be (per
00229    * the spec) the byte order of the encapsulation.  The default
00230    * values for the allocators in this constructor are not 0, but are
00231    * generated by the ORB. Refer to the constructor body in CDR.cpp
00232    * for the code that supplies these values to the base class
00233    * constructor.
00234    */
00235   TAO_InputCDR (const TAO_InputCDR& rhs,
00236                 size_t size);
00237 
00238   /// Create an input CDR from an output CDR.
00239   TAO_InputCDR (const TAO_OutputCDR& rhs,
00240                 ACE_Allocator* buffer_allocator = 0,
00241                 ACE_Allocator* data_block_allocator = 0,
00242                 ACE_Allocator* message_block_allocator = 0,
00243                 TAO_ORB_Core* orb_core = 0);
00244 
00245   /// Initialize the contents of one CDR from another, without data
00246   /// copying and with minimimum locking overhead.
00247   TAO_InputCDR (ACE_InputCDR::Transfer_Contents rhs,
00248                 TAO_ORB_Core* orb_core = 0);
00249 
00250   /// destructor
00251   ~TAO_InputCDR (void);
00252 
00253   // = TAO specific methods.
00254 
00255   /// Accessor
00256   TAO_ORB_Core *orb_core (void) const;
00257 
00258 
00259   // = TAO specific methods.
00260   static void throw_stub_exception (int error_num ACE_ENV_ARG_DECL);
00261   static void throw_skel_exception (int error_num ACE_ENV_ARG_DECL);
00262 
00263 private:
00264   /// The ORB_Core, required to extract object references.
00265   TAO_ORB_Core* orb_core_;
00266 };
00267 
00268 #if defined(__ACE_INLINE__)
00269 # include "tao/CDR.i"
00270 #else
00271 
00272 // CDR output operators for CORBA types
00273 
00274 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00275                                       CORBA::Short x);
00276 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00277                                       CORBA::UShort x);
00278 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00279                                       CORBA::Long x);
00280 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00281                                       CORBA::ULong x);
00282 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00283                                       CORBA::LongLong x);
00284 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00285                                       CORBA::ULongLong x);
00286 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR& os,
00287                                       CORBA::LongDouble x);
00288 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00289                                       CORBA::Float x);
00290 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00291                                       CORBA::Double x);
00292 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00293                                       const CORBA::Char* x);
00294 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00295                                       const CORBA::WChar* x);
00296 
00297 // CDR input operators for CORBA types
00298 
00299 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00300                                       CORBA::Short &x);
00301 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00302                                       CORBA::UShort &x);
00303 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00304                                       CORBA::Long &x);
00305 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00306                                       CORBA::ULong &x);
00307 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00308                                       CORBA::LongLong &x);
00309 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00310                                       CORBA::ULongLong &x);
00311 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00312                                       CORBA::LongDouble &x);
00313 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00314                                       CORBA::Float &x);
00315 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00316                                       CORBA::Double &x);
00317 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00318                                       CORBA::Char* &x);
00319 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00320                                       CORBA::WChar* &x);
00321 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &,
00322                                       const CORBA::ParameterMode &);
00323 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &,
00324                                       CORBA::ParameterMode &);
00325 #endif /* __ACE_INLINE */
00326 
00327 #include "ace/post.h"
00328 #endif /* TAO_CDR_H */

Generated on Mon Jun 16 13:48:03 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002