libdap Updated for version 3.18.1
XDRFileUnMarshaller.cc
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 "config.h"
34
35#include "XDRFileUnMarshaller.h"
36
37#include "Byte.h"
38#include "Int16.h"
39#include "UInt16.h"
40#include "Int32.h"
41#include "UInt32.h"
42#include "Float32.h"
43#include "Float64.h"
44#include "Str.h"
45#include "Url.h"
46#include "Array.h"
47#include "Structure.h"
48#include "Sequence.h"
49#include "Grid.h"
50#if 0
51#include "Vector.h"
52#endif
53#include "util.h"
54#include "InternalErr.h"
55
56namespace libdap {
57
58XDRFileUnMarshaller::XDRFileUnMarshaller( FILE *out )
59 : _source( 0 )
60{
61 _source = new_xdrstdio( out, XDR_DECODE ) ;
62}
63
64XDRFileUnMarshaller::XDRFileUnMarshaller()
65 : UnMarshaller(), _source( 0 )
66{
67 throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented." ) ;
68}
69
70XDRFileUnMarshaller::XDRFileUnMarshaller( const XDRFileUnMarshaller &um )
71 : UnMarshaller( um ), _source( 0 )
72{
73 throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented." ) ;
74}
75
76XDRFileUnMarshaller &
77XDRFileUnMarshaller::operator=( const XDRFileUnMarshaller & )
78{
79 throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented." ) ;
80
81 return *this ;
82}
83
84XDRFileUnMarshaller::~XDRFileUnMarshaller( )
85{
86 // Some static code analysis tools complain that delete_xdrstdio
87 // does not close the FILE* it holds, but that's not true with
88 // modern XDR libraries. Don't try to close that FILE*. jhrg 8/27/13
89
90 delete_xdrstdio( _source ) ;
91}
92
93void
94XDRFileUnMarshaller::get_byte( dods_byte &val )
95{
96 if( !xdr_char( _source, (char *)&val ) )
97 throw Error("Network I/O Error. Could not read byte data.");
98}
99
100void
101XDRFileUnMarshaller::get_int16( dods_int16 &val )
102{
103 if( !XDR_INT16( _source, &val ) )
104 throw Error("Network I/O Error. Could not read int 16 data.");
105}
106
107void
108XDRFileUnMarshaller::get_int32( dods_int32 &val )
109{
110 if( !XDR_INT32( _source, &val ) )
111 throw Error("Network I/O Error. Could not read int 32 data.");
112}
113
114void
115XDRFileUnMarshaller::get_float32( dods_float32 &val )
116{
117 if( !xdr_float( _source, &val ) )
118 throw Error("Network I/O Error. Could not read float 32 data.");
119}
120
121void
122XDRFileUnMarshaller::get_float64( dods_float64 &val )
123{
124 if( !xdr_double( _source, &val ) )
125 throw Error("Network I/O Error.Could not read float 64 data.");
126}
127
128void
129XDRFileUnMarshaller::get_uint16( dods_uint16 &val )
130{
131 if( !XDR_UINT16( _source, &val ) )
132 throw Error("Network I/O Error. Could not read uint 16 data.");
133}
134
135void
136XDRFileUnMarshaller::get_uint32( dods_uint32 &val )
137{
138 if( !XDR_UINT32( _source, &val ) )
139 throw Error("Network I/O Error. Could not read uint 32 data.");
140}
141
142void
143XDRFileUnMarshaller::get_str( string &val )
144{
145 char *in_tmp = NULL ;
146
147 if( !xdr_string( _source, &in_tmp, max_str_len ) )
148 throw Error("Network I/O Error. Could not read string data.");
149
150 val = in_tmp ;
151
152 free( in_tmp ) ;
153}
154
155void
156XDRFileUnMarshaller::get_url( string &val )
157{
158 get_str( val ) ;
159}
160
161void
162XDRFileUnMarshaller::get_opaque( char *val, unsigned int len )
163{
164 xdr_opaque( _source, val, len ) ;
165}
166
167void
168XDRFileUnMarshaller::get_int( int &val )
169{
170 if( !xdr_int( _source, &val ) )
171 throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
172}
173
174void
175XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, Vector & )
176{
177 if( !xdr_bytes( _source, val, &num, DODS_MAX_ARRAY) )
178 throw Error("Network I/O error (1).");
179}
180
181void
182XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, int width, Vector &vec )
183{
184 BaseType *var = vec.var() ;
185
186 if( !xdr_array( _source, val, &num, DODS_MAX_ARRAY, width,
187 XDRUtils::xdr_coder( var->type() ) ) )
188 {
189 throw Error("Network I/O error (2).");
190 }
191}
192
193void
194XDRFileUnMarshaller::dump(ostream &strm) const
195{
196 strm << DapIndent::LMarg << "XDRFileUnMarshaller::dump - ("
197 << (void *)this << ")" << endl ;
198}
199
200} // namespace libdap
201