File: XDRFileUnMarshaller.cc

package info (click to toggle)
libdap 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,256 kB
  • sloc: cpp: 46,310; sh: 44,047; xml: 23,535; ansic: 19,973; yacc: 2,505; exp: 1,544; makefile: 581; lex: 309; fortran: 8
file content (152 lines) | stat: -rw-r--r-- 4,988 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// XDRFileUnMarshaller.cc

// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: Patrick West <pwest@ucar.edu>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

// (c) COPYRIGHT URI/MIT 1994-1999
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
//      pwest       Patrick West <pwest@ucar.edu>

#include "config.h"

#include "XDRFileUnMarshaller.h"

#include "Array.h"
#include "Byte.h"
#include "Float32.h"
#include "Float64.h"
#include "Grid.h"
#include "Int16.h"
#include "Int32.h"
#include "Sequence.h"
#include "Str.h"
#include "Structure.h"
#include "UInt16.h"
#include "UInt32.h"
#include "Url.h"

#include "DapIndent.h"
#include "InternalErr.h"
#include "util.h"

namespace libdap {

XDRFileUnMarshaller::XDRFileUnMarshaller(FILE *out) : _source(0) { _source = new_xdrstdio(out, XDR_DECODE); }

XDRFileUnMarshaller::XDRFileUnMarshaller() : UnMarshaller(), _source(0) {
    throw InternalErr(__FILE__, __LINE__, "Default constructor not implemented.");
}

XDRFileUnMarshaller::XDRFileUnMarshaller(const XDRFileUnMarshaller &um) : UnMarshaller(um), _source(0) {
    throw InternalErr(__FILE__, __LINE__, "Copy constructor not implemented.");
}

XDRFileUnMarshaller &XDRFileUnMarshaller::operator=(const XDRFileUnMarshaller &) {
    throw InternalErr(__FILE__, __LINE__, "Copy operator not implemented.");
}

XDRFileUnMarshaller::~XDRFileUnMarshaller() {
    // Some static code analysis tools complain that delete_xdrstdio
    // does not close the FILE* it holds, but that's not true with
    // modern XDR libraries. Don't try to close that FILE*. jhrg 8/27/13

    delete_xdrstdio(_source);
}

void XDRFileUnMarshaller::get_byte(dods_byte &val) {
    if (!xdr_char(_source, (char *)&val))
        throw Error("Network I/O Error. Could not read byte data.");
}

void XDRFileUnMarshaller::get_int16(dods_int16 &val) {
    if (!XDR_INT16(_source, &val))
        throw Error("Network I/O Error. Could not read int 16 data.");
}

void XDRFileUnMarshaller::get_int32(dods_int32 &val) {
    if (!XDR_INT32(_source, &val))
        throw Error("Network I/O Error. Could not read int 32 data.");
}

void XDRFileUnMarshaller::get_float32(dods_float32 &val) {
    if (!xdr_float(_source, &val))
        throw Error("Network I/O Error. Could not read float 32 data.");
}

void XDRFileUnMarshaller::get_float64(dods_float64 &val) {
    if (!xdr_double(_source, &val))
        throw Error("Network I/O Error.Could not read float 64 data.");
}

void XDRFileUnMarshaller::get_uint16(dods_uint16 &val) {
    if (!XDR_UINT16(_source, &val))
        throw Error("Network I/O Error. Could not read uint 16 data.");
}

void XDRFileUnMarshaller::get_uint32(dods_uint32 &val) {
    if (!XDR_UINT32(_source, &val))
        throw Error("Network I/O Error. Could not read uint 32 data.");
}

void XDRFileUnMarshaller::get_str(string &val) {
    char *in_tmp = NULL;

    if (!xdr_string(_source, &in_tmp, max_str_len))
        throw Error("Network I/O Error. Could not read string data.");

    val = in_tmp;

    free(in_tmp);
}

void XDRFileUnMarshaller::get_url(string &val) { get_str(val); }

void XDRFileUnMarshaller::get_opaque(char *val, unsigned int len) { xdr_opaque(_source, val, len); }

void XDRFileUnMarshaller::get_int(int &val) {
    if (!xdr_int(_source, &val))
        throw Error(
            "Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
}

void XDRFileUnMarshaller::get_vector(char **val, unsigned int &num, Vector &) {
    if (!xdr_bytes(_source, val, &num, DODS_MAX_ARRAY))
        throw Error("Network I/O error (1).");
}

void XDRFileUnMarshaller::get_vector(char **val, unsigned int &num, int width, Vector &vec) {
    BaseType *var = vec.var();

    if (!xdr_array(_source, val, &num, DODS_MAX_ARRAY, width, XDRUtils::xdr_coder(var->type()))) {
        throw Error("Network I/O error (2).");
    }
}

void XDRFileUnMarshaller::dump(ostream &strm) const {
    strm << DapIndent::LMarg << "XDRFileUnMarshaller::dump - (" << (void *)this << ")" << endl;
}

} // namespace libdap