XDRFileMarshaller.cc

Go to the documentation of this file.
00001 // XDRFileMarshaller.cc
00002 
00003 // -*- mode: c++; c-basic-offset:4 -*-
00004 
00005 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
00006 // Access Protocol.
00007 
00008 // Copyright (c) 2002,2003 OPeNDAP, Inc.
00009 // Author: Patrick West <pwest@ucar.edu>
00010 //
00011 // This library is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU Lesser General Public
00013 // License as published by the Free Software Foundation; either
00014 // version 2.1 of the License, or (at your option) any later version.
00015 //
00016 // This library is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 //
00025 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00026 
00027 // (c) COPYRIGHT URI/MIT 1994-1999
00028 // Please read the full copyright statement in the file COPYRIGHT_URI.
00029 //
00030 // Authors:
00031 //      pwest       Patrick West <pwest@ucar.edu>
00032 
00033 #include "XDRFileMarshaller.h"
00034 
00035 #include "Vector.h"
00036 #include "util.h"
00037 #include "InternalErr.h"
00038 
00039 namespace libdap {
00040 
00041 XDRFileMarshaller::XDRFileMarshaller( FILE *out )
00042     : _sink( 0 )
00043 {
00044     _sink = new_xdrstdio( out, XDR_ENCODE ) ;
00045 }
00046 
00047 XDRFileMarshaller::XDRFileMarshaller()
00048     : Marshaller(),
00049       _sink( 0 )
00050 {
00051     throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented." ) ;
00052 }
00053 
00054 XDRFileMarshaller::XDRFileMarshaller( const XDRFileMarshaller &m )
00055     : Marshaller( m ),
00056       _sink( 0 )
00057 {
00058     throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented." ) ;
00059 }
00060 
00061 XDRFileMarshaller &
00062 XDRFileMarshaller::operator=( const XDRFileMarshaller & )
00063 {
00064     throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented." ) ;
00065 
00066     return *this ;
00067 }
00068 
00069 XDRFileMarshaller::~XDRFileMarshaller( )
00070 {
00071     delete_xdrstdio( _sink ) ;
00072 }
00073 
00074 void
00075 XDRFileMarshaller::put_byte( dods_byte val )
00076 {
00077     if( !xdr_char( _sink, (char *)&val ) )
00078         throw Error("Network I/O Error. Could not send byte data.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
00079 }
00080 
00081 void
00082 XDRFileMarshaller::put_int16( dods_int16 val )
00083 {
00084     if( !XDR_INT16( _sink, &val ) )
00085         throw Error("Network I/O Error. Could not send int 16 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00086 }
00087 
00088 void
00089 XDRFileMarshaller::put_int32( dods_int32 val )
00090 {
00091 #if 0
00092 #ifdef _MSC_VER
00093     if( !XDR_INT32( _sink, (int *)&val ) )
00094 #else
00095     if( !XDR_INT32( _sink, &val ) )
00096 #endif
00097 #endif
00098     if( !XDR_INT32( _sink, &val ) )
00099         throw Error("Network I/O Error. Could not read int 32 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00100 }
00101 
00102 void
00103 XDRFileMarshaller::put_float32( dods_float32 val )
00104 {
00105     if( !xdr_float( _sink, &val ) )
00106         throw Error("Network I/O Error. Could not send float 32 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00107 }
00108 
00109 void
00110 XDRFileMarshaller::put_float64( dods_float64 val )
00111 {
00112     if( !xdr_double( _sink, &val ) )
00113         throw Error("Network I/O Error. Could not send float 64 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00114 }
00115 
00116 void
00117 XDRFileMarshaller::put_uint16( dods_uint16 val )
00118 {
00119     if( !XDR_UINT16( _sink, &val ) )
00120         throw Error("Network I/O Error. Could not send uint 16 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00121 }
00122 
00123 void
00124 XDRFileMarshaller::put_uint32( dods_uint32 val )
00125 {
00126 #if 0
00127 #ifdef _MSC_VER
00128     if( !XDR_UINT32( _sink, (unsigned int *)&val ) )
00129 #else
00130         if( !XDR_UINT32( _sink, &val ) )
00131 #endif
00132 #endif
00133     if( !XDR_UINT32( _sink, &val ) )
00134         throw Error("Network I/O Error. Could not send uint 32 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00135 }
00136 
00137 void
00138 XDRFileMarshaller::put_str( const string &val )
00139 {
00140     const char *out_tmp = val.c_str() ;
00141 
00142     if( !xdr_string( _sink, (char **)&out_tmp, max_str_len) )
00143         throw Error("Network I/O Error. Could not send string data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00144 }
00145 
00146 void
00147 XDRFileMarshaller::put_url( const string &val )
00148 {
00149     put_str( val ) ;
00150 }
00151 
00152 void
00153 XDRFileMarshaller::put_opaque( char *val, unsigned int len )
00154 {
00155     if( !xdr_opaque( _sink, val, len ) )
00156         throw Error("Network I/O Error. Could not send opaque data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00157 }
00158 
00159 void
00160 XDRFileMarshaller::put_int( int val )
00161 {
00162     if( !xdr_int( _sink, &val) )
00163         throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
00164 }
00165 
00166 void
00167 XDRFileMarshaller::put_vector( char *val, int num, Vector & )
00168 {
00169     if (!val)
00170         throw InternalErr(__FILE__, __LINE__,
00171                           "Buffer pointer is not set.");
00172 
00173     put_int( num ) ;
00174 
00175     if( !xdr_bytes( _sink, (char **)&val,
00176                     (unsigned int *) &num,
00177                     DODS_MAX_ARRAY) )
00178     {
00179         throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection.");
00180     }
00181 }
00182 
00183 void
00184 XDRFileMarshaller::put_vector( char *val, int num, int width, Vector &vec )
00185 {
00186     if (!val)
00187         throw InternalErr(__FILE__, __LINE__,
00188                           "Buffer pointer is not set.");
00189 
00190     put_int( num ) ;
00191 
00192     BaseType *var = vec.var() ;
00193     if( !xdr_array( _sink, (char **)&val,
00194                     (unsigned int *) & num,
00195                     DODS_MAX_ARRAY, width,
00196                     XDRUtils::xdr_coder( var->type() ) ) )
00197     {
00198         throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection.");
00199     }
00200 }
00201 
00202 void
00203 XDRFileMarshaller::dump(ostream &strm) const
00204 {
00205     strm << DapIndent::LMarg << "XDRFileMarshaller::dump - ("
00206          << (void *)this << ")" << endl ;
00207 }
00208 
00209 } // namespace libdap
00210 

Generated on Wed Mar 5 15:27:11 2008 for libdap++ by  doxygen 1.5.4