libdap
Updated for version 3.17.0
|
00001 // XDRFileUnMarshaller.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 "config.h" 00034 00035 #include "XDRFileUnMarshaller.h" 00036 00037 #include "Byte.h" 00038 #include "Int16.h" 00039 #include "UInt16.h" 00040 #include "Int32.h" 00041 #include "UInt32.h" 00042 #include "Float32.h" 00043 #include "Float64.h" 00044 #include "Str.h" 00045 #include "Url.h" 00046 #include "Array.h" 00047 #include "Structure.h" 00048 #include "Sequence.h" 00049 #include "Grid.h" 00050 #if 0 00051 #include "Vector.h" 00052 #endif 00053 #include "util.h" 00054 #include "InternalErr.h" 00055 00056 namespace libdap { 00057 00058 XDRFileUnMarshaller::XDRFileUnMarshaller( FILE *out ) 00059 : _source( 0 ) 00060 { 00061 _source = new_xdrstdio( out, XDR_DECODE ) ; 00062 } 00063 00064 XDRFileUnMarshaller::XDRFileUnMarshaller() 00065 : UnMarshaller(), _source( 0 ) 00066 { 00067 throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented." ) ; 00068 } 00069 00070 XDRFileUnMarshaller::XDRFileUnMarshaller( const XDRFileUnMarshaller &um ) 00071 : UnMarshaller( um ), _source( 0 ) 00072 { 00073 throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented." ) ; 00074 } 00075 00076 XDRFileUnMarshaller & 00077 XDRFileUnMarshaller::operator=( const XDRFileUnMarshaller & ) 00078 { 00079 throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented." ) ; 00080 00081 return *this ; 00082 } 00083 00084 XDRFileUnMarshaller::~XDRFileUnMarshaller( ) 00085 { 00086 // Some static code analysis tools complain that delete_xdrstdio 00087 // does not close the FILE* it holds, but that's not true with 00088 // modern XDR libraries. Don't try to close that FILE*. jhrg 8/27/13 00089 00090 delete_xdrstdio( _source ) ; 00091 } 00092 00093 void 00094 XDRFileUnMarshaller::get_byte( dods_byte &val ) 00095 { 00096 if( !xdr_char( _source, (char *)&val ) ) 00097 throw Error("Network I/O Error. Could not read byte data."); 00098 } 00099 00100 void 00101 XDRFileUnMarshaller::get_int16( dods_int16 &val ) 00102 { 00103 if( !XDR_INT16( _source, &val ) ) 00104 throw Error("Network I/O Error. Could not read int 16 data."); 00105 } 00106 00107 void 00108 XDRFileUnMarshaller::get_int32( dods_int32 &val ) 00109 { 00110 if( !XDR_INT32( _source, &val ) ) 00111 throw Error("Network I/O Error. Could not read int 32 data."); 00112 } 00113 00114 void 00115 XDRFileUnMarshaller::get_float32( dods_float32 &val ) 00116 { 00117 if( !xdr_float( _source, &val ) ) 00118 throw Error("Network I/O Error. Could not read float 32 data."); 00119 } 00120 00121 void 00122 XDRFileUnMarshaller::get_float64( dods_float64 &val ) 00123 { 00124 if( !xdr_double( _source, &val ) ) 00125 throw Error("Network I/O Error.Could not read float 64 data."); 00126 } 00127 00128 void 00129 XDRFileUnMarshaller::get_uint16( dods_uint16 &val ) 00130 { 00131 if( !XDR_UINT16( _source, &val ) ) 00132 throw Error("Network I/O Error. Could not read uint 16 data."); 00133 } 00134 00135 void 00136 XDRFileUnMarshaller::get_uint32( dods_uint32 &val ) 00137 { 00138 if( !XDR_UINT32( _source, &val ) ) 00139 throw Error("Network I/O Error. Could not read uint 32 data."); 00140 } 00141 00142 void 00143 XDRFileUnMarshaller::get_str( string &val ) 00144 { 00145 char *in_tmp = NULL ; 00146 00147 if( !xdr_string( _source, &in_tmp, max_str_len ) ) 00148 throw Error("Network I/O Error. Could not read string data."); 00149 00150 val = in_tmp ; 00151 00152 free( in_tmp ) ; 00153 } 00154 00155 void 00156 XDRFileUnMarshaller::get_url( string &val ) 00157 { 00158 get_str( val ) ; 00159 } 00160 00161 void 00162 XDRFileUnMarshaller::get_opaque( char *val, unsigned int len ) 00163 { 00164 xdr_opaque( _source, val, len ) ; 00165 } 00166 00167 void 00168 XDRFileUnMarshaller::get_int( int &val ) 00169 { 00170 if( !xdr_int( _source, &val ) ) 00171 throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection."); 00172 } 00173 00174 void 00175 XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, Vector & ) 00176 { 00177 if( !xdr_bytes( _source, val, &num, DODS_MAX_ARRAY) ) 00178 throw Error("Network I/O error (1)."); 00179 } 00180 00181 void 00182 XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, int width, Vector &vec ) 00183 { 00184 BaseType *var = vec.var() ; 00185 00186 if( !xdr_array( _source, val, &num, DODS_MAX_ARRAY, width, 00187 XDRUtils::xdr_coder( var->type() ) ) ) 00188 { 00189 throw Error("Network I/O error (2)."); 00190 } 00191 } 00192 00193 void 00194 XDRFileUnMarshaller::dump(ostream &strm) const 00195 { 00196 strm << DapIndent::LMarg << "XDRFileUnMarshaller::dump - (" 00197 << (void *)this << ")" << endl ; 00198 } 00199 00200 } // namespace libdap 00201