libdap++ Updated for version 3.8.2
|
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 "Byte.h" 00036 #include "Int16.h" 00037 #include "UInt16.h" 00038 #include "Int32.h" 00039 #include "UInt32.h" 00040 #include "Float32.h" 00041 #include "Float64.h" 00042 #include "Str.h" 00043 #include "Url.h" 00044 #include "Array.h" 00045 #include "Structure.h" 00046 #include "Sequence.h" 00047 #include "Grid.h" 00048 00049 #include "util.h" 00050 #include "InternalErr.h" 00051 00052 namespace libdap { 00053 00054 XDRFileMarshaller::XDRFileMarshaller( FILE *out ) 00055 : _sink( 0 ) 00056 { 00057 _sink = new_xdrstdio( out, XDR_ENCODE ) ; 00058 } 00059 00060 XDRFileMarshaller::XDRFileMarshaller() 00061 : Marshaller(), 00062 _sink( 0 ) 00063 { 00064 throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented." ) ; 00065 } 00066 00067 XDRFileMarshaller::XDRFileMarshaller( const XDRFileMarshaller &m ) 00068 : Marshaller( m ), 00069 _sink( 0 ) 00070 { 00071 throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented." ) ; 00072 } 00073 00074 XDRFileMarshaller & 00075 XDRFileMarshaller::operator=( const XDRFileMarshaller & ) 00076 { 00077 throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented." ) ; 00078 00079 return *this ; 00080 } 00081 00082 XDRFileMarshaller::~XDRFileMarshaller( ) 00083 { 00084 delete_xdrstdio( _sink ) ; 00085 } 00086 00087 void 00088 XDRFileMarshaller::put_byte( dods_byte val ) 00089 { 00090 if( !xdr_char( _sink, (char *)&val ) ) 00091 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."); 00092 } 00093 00094 void 00095 XDRFileMarshaller::put_int16( dods_int16 val ) 00096 { 00097 if( !XDR_INT16( _sink, &val ) ) 00098 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."); 00099 } 00100 00101 void 00102 XDRFileMarshaller::put_int32( dods_int32 val ) 00103 { 00104 if( !XDR_INT32( _sink, &val ) ) 00105 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."); 00106 } 00107 00108 void 00109 XDRFileMarshaller::put_float32( dods_float32 val ) 00110 { 00111 if( !xdr_float( _sink, &val ) ) 00112 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."); 00113 } 00114 00115 void 00116 XDRFileMarshaller::put_float64( dods_float64 val ) 00117 { 00118 if( !xdr_double( _sink, &val ) ) 00119 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."); 00120 } 00121 00122 void 00123 XDRFileMarshaller::put_uint16( dods_uint16 val ) 00124 { 00125 if( !XDR_UINT16( _sink, &val ) ) 00126 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."); 00127 } 00128 00129 void 00130 XDRFileMarshaller::put_uint32( dods_uint32 val ) 00131 { 00132 if( !XDR_UINT32( _sink, &val ) ) 00133 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."); 00134 } 00135 00136 void 00137 XDRFileMarshaller::put_str( const string &val ) 00138 { 00139 const char *out_tmp = val.c_str() ; 00140 00141 if( !xdr_string( _sink, (char **)&out_tmp, max_str_len) ) 00142 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."); 00143 } 00144 00145 void 00146 XDRFileMarshaller::put_url( const string &val ) 00147 { 00148 put_str( val ) ; 00149 } 00150 00151 void 00152 XDRFileMarshaller::put_opaque( char *val, unsigned int len ) 00153 { 00154 if( !xdr_opaque( _sink, val, len ) ) 00155 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."); 00156 } 00157 00158 void 00159 XDRFileMarshaller::put_int( int val ) 00160 { 00161 if( !xdr_int( _sink, &val) ) 00162 throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection."); 00163 } 00164 00165 void 00166 XDRFileMarshaller::put_vector( char *val, int num, Vector & ) 00167 { 00168 if (!val) 00169 throw InternalErr(__FILE__, __LINE__, 00170 "Buffer pointer is not set."); 00171 00172 put_int( num ) ; 00173 00174 if( !xdr_bytes( _sink, (char **)&val, 00175 (unsigned int *) &num, 00176 DODS_MAX_ARRAY) ) 00177 { 00178 throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection."); 00179 } 00180 } 00181 00182 void 00183 XDRFileMarshaller::put_vector( char *val, int num, int width, Vector &vec ) 00184 { 00185 if (!val) 00186 throw InternalErr(__FILE__, __LINE__, 00187 "Buffer pointer is not set."); 00188 00189 put_int( num ) ; 00190 00191 BaseType *var = vec.var() ; 00192 if( !xdr_array( _sink, (char **)&val, 00193 (unsigned int *) & num, 00194 DODS_MAX_ARRAY, width, 00195 XDRUtils::xdr_coder( var->type() ) ) ) 00196 { 00197 throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection."); 00198 } 00199 } 00200 00201 void 00202 XDRFileMarshaller::dump(ostream &strm) const 00203 { 00204 strm << DapIndent::LMarg << "XDRFileMarshaller::dump - (" 00205 << (void *)this << ")" << endl ; 00206 } 00207 00208 } // namespace libdap 00209