XDRFileUnMarshaller.cc

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

Generated on Wed May 13 18:06:39 2009 for libdap++ by  doxygen 1.4.7