XDRUtils.cc

Go to the documentation of this file.
00001 // XDRUtils.cc
00002 
00003 #include "XDRUtils.h"
00004 #include "debug.h"
00005 #include "Str.h"
00006 
00007 // This function is used to allocate memory for, and initialize, a new XDR
00008 // pointer. It sets the stream associated with the (XDR *) to STREAM.
00009 //
00010 // NB: STREAM is not one of the C++/libg++ iostream classes; it is a (FILE
00011 // *).
00012 
00013 //  These func's moved to xdrutil_ppc.* under the PPC as explained there
00014 #ifndef __POWERPC__
00015 XDR *
00016 new_xdrstdio(FILE *stream, enum xdr_op xop)
00017 {
00018     XDR *xdr = new XDR;
00019 
00020     xdrstdio_create(xdr, stream, xop);
00021 
00022     return xdr;
00023 }
00024 
00025 XDR *
00026 set_xdrstdio(XDR *xdr, FILE *stream, enum xdr_op xop)
00027 {
00028     xdrstdio_create(xdr, stream, xop);
00029 
00030     return xdr;
00031 }
00032 
00033 // Delete an XDR pointer allocated using the above function. Do not close the
00034 // associated FILE pointer.
00035 
00036 void
00037 delete_xdrstdio(XDR *xdr)
00038 {
00039     xdr_destroy(xdr);
00040 
00041     delete xdr; xdr = 0;
00042 }
00043 #endif
00044 
00045 // This function is used to en/decode Str and Url type variables. It is
00046 // defined as extern C since it is passed via function pointers to routines
00047 // in the xdr library where it is executed. This function is defined so
00048 // that Str and Url have an en/decoder which takes exactly two argumnets: an
00049 // XDR * and a string reference.
00050 //
00051 // NB: this function is *not* used for arrays (i.e., it is not the function
00052 // referenced by BaseType's _xdr_coder field when the object is a Str or Url.
00053 // Also note that \e max_str_len is an obese number but that really does not
00054 // matter; xdr_string() would never actually allocate that much memory unless
00055 // a string that size was sent from the server.
00056 // Returns: XDR's bool_t; TRUE if no errors are detected, FALSE
00057 // otherwise. The formal parameter BUF is modified as a side effect.
00058 
00059 extern "C" bool_t
00060 xdr_str(XDR *xdrs, string &buf)
00061 {
00062     DBG(cerr << "In xdr_str, xdrs: " << xdrs << endl);
00063 
00064     switch (xdrs->x_op) {
00065     case XDR_ENCODE: { // BUF is a pointer to a (string *)
00066             const char *out_tmp = buf.c_str();
00067 
00068             return xdr_string(xdrs, (char **)&out_tmp, max_str_len);
00069         }
00070 
00071     case XDR_DECODE: {
00072             char *in_tmp = NULL;
00073 
00074             bool_t stat = xdr_string(xdrs, &in_tmp, max_str_len);
00075             if (!stat)
00076                 return stat;
00077 
00078             buf = in_tmp;
00079 
00080             free(in_tmp);
00081 
00082             return stat;
00083         }
00084 
00085     default:
00086 #if 0
00087         // Removed; build fails on FC6. jhrg 8/28/07
00088         assert(false);
00089 #endif
00090         return 0;
00091     }
00092 }
00093 
00112 xdrproc_t
00113 XDRUtils::xdr_coder( const Type &t )
00114 {
00115     switch( t )
00116     {
00117         case dods_int16_c:
00118             return (xdrproc_t)XDR_INT16 ;
00119             break ;
00120         case dods_uint16_c:
00121             return (xdrproc_t)XDR_UINT16 ;
00122             break ;
00123         case dods_int32_c:
00124             return (xdrproc_t)XDR_INT32 ;
00125             break ;
00126         case dods_uint32_c:
00127             return (xdrproc_t)XDR_UINT32 ;
00128             break ;
00129         case dods_float32_c:
00130             return (xdrproc_t)XDR_FLOAT32 ;
00131             break ;
00132         case dods_float64_c:
00133             return (xdrproc_t)XDR_FLOAT64 ;
00134             break ;
00135         case dods_byte_c:
00136         case dods_str_c:
00137         case dods_url_c:
00138         case dods_array_c:
00139         case dods_structure_c:
00140         case dods_sequence_c:
00141         case dods_grid_c:
00142         default:
00143             return NULL ;
00144             break ;
00145     }
00146 }
00147 

Generated on Wed Nov 14 03:15:44 2007 for libdap++ by  doxygen 1.5.1