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

Generated on Wed Jan 2 04:11:03 2008 for libdap++ by  doxygen 1.5.4