libdap++  Updated for version 3.8.2
XDRFileUnMarshaller.cc
Go to the documentation of this file.
1 // XDRFileUnMarshaller.cc
2 
3 // -*- mode: c++; c-basic-offset:4 -*-
4 
5 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
6 // Access Protocol.
7 
8 // Copyright (c) 2002,2003 OPeNDAP, Inc.
9 // Author: Patrick West <pwest@ucar.edu>
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 //
25 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
26 
27 // (c) COPYRIGHT URI/MIT 1994-1999
28 // Please read the full copyright statement in the file COPYRIGHT_URI.
29 //
30 // Authors:
31 // pwest Patrick West <pwest@ucar.edu>
32 
33 #include "XDRFileUnMarshaller.h"
34 
35 #include "Byte.h"
36 #include "Int16.h"
37 #include "UInt16.h"
38 #include "Int32.h"
39 #include "UInt32.h"
40 #include "Float32.h"
41 #include "Float64.h"
42 #include "Str.h"
43 #include "Url.h"
44 #include "Array.h"
45 #include "Structure.h"
46 #include "Sequence.h"
47 #include "Grid.h"
48 #if 0
49 #include "Vector.h"
50 #endif
51 #include "util.h"
52 #include "InternalErr.h"
53 
54 namespace libdap {
55 
56 XDRFileUnMarshaller::XDRFileUnMarshaller( FILE *out )
57  : _source( 0 )
58 {
59  _source = new_xdrstdio( out, XDR_DECODE ) ;
60 }
61 
62 XDRFileUnMarshaller::XDRFileUnMarshaller()
63  : UnMarshaller(),
64  _source( 0 )
65 {
66  throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented." ) ;
67 }
68 
69 XDRFileUnMarshaller::XDRFileUnMarshaller( const XDRFileUnMarshaller &um )
70  : UnMarshaller( um ),
71  _source( 0 )
72 {
73  throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented." ) ;
74 }
75 
76 XDRFileUnMarshaller &
77 XDRFileUnMarshaller::operator=( const XDRFileUnMarshaller & )
78 {
79  throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented." ) ;
80 
81  return *this ;
82 }
83 
85 {
86  delete_xdrstdio( _source ) ;
87 }
88 
89 void
91 {
92  if( !xdr_char( _source, (char *)&val ) )
93  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.");
94 }
95 
96 void
98 {
99  if( !XDR_INT16( _source, &val ) )
100  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.");
101 }
102 
103 void
105 {
106  if( !XDR_INT32( _source, &val ) )
107  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.");
108 }
109 
110 void
112 {
113  if( !xdr_float( _source, &val ) )
114  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.");
115 }
116 
117 void
119 {
120  if( !xdr_double( _source, &val ) )
121  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.");
122 }
123 
124 void
126 {
127  if( !XDR_UINT16( _source, &val ) )
128  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.");
129 }
130 
131 void
133 {
134  if( !XDR_UINT32( _source, &val ) )
135  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.");
136 }
137 
138 void
140 {
141  char *in_tmp = NULL ;
142 
143  if( !xdr_string( _source, &in_tmp, max_str_len ) )
144  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.");
145 
146  val = in_tmp ;
147 
148  free( in_tmp ) ;
149 }
150 
151 void
153 {
154  get_str( val ) ;
155 }
156 
157 void
158 XDRFileUnMarshaller::get_opaque( char *val, unsigned int len )
159 {
160  xdr_opaque( _source, val, len ) ;
161 }
162 
163 void
165 {
166  if( !xdr_int( _source, &val ) )
167  throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
168 }
169 
170 void
171 XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, Vector & )
172 {
173  if( !xdr_bytes( _source, val, &num, DODS_MAX_ARRAY) )
174  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.");
175 }
176 
177 void
178 XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, int width, Vector &vec )
179 {
180  BaseType *var = vec.var() ;
181 
182  if( !xdr_array( _source, val, &num, DODS_MAX_ARRAY, width,
183  XDRUtils::xdr_coder( var->type() ) ) )
184  {
185  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.");
186  }
187 }
188 
189 void
190 XDRFileUnMarshaller::dump(ostream &strm) const
191 {
192  strm << DapIndent::LMarg << "XDRFileUnMarshaller::dump - ("
193  << (void *)this << ")" << endl ;
194 }
195 
196 } // namespace libdap
197