libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
UInt32.cc
Go to the documentation of this file.
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5// Access Protocol.
6
7// Copyright (c) 2002,2003 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26// (c) COPYRIGHT URI/MIT 1999
27// Please read the full copyright statement in the file COPYRIGHT_URI.
28//
29// Authors:
30// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31
32// Implementation for Int32.
33//
34// jhrg 9/7/94
35
36#include "config.h"
37
38#include <sstream>
39
40#include "Byte.h" // synonymous with UInt8 and Char
41#include "Float32.h"
42#include "Float64.h"
43#include "Int16.h"
44#include "Int32.h"
45#include "Int64.h"
46#include "Int8.h"
47#include "Str.h"
48#include "UInt16.h"
49#include "UInt32.h"
50#include "UInt64.h"
51#include "Url.h"
52
53#include "DDS.h"
54#include "Marshaller.h"
55#include "UnMarshaller.h"
56
57#include "D4StreamMarshaller.h"
59#include "DMR.h"
60
61#include "DapIndent.h"
62#include "InternalErr.h"
63#include "Operators.h"
64#include "debug.h"
65#include "dods-limits.h"
66#include "parser.h"
67#include "util.h"
68
69using std::cerr;
70using std::endl;
71
72namespace libdap {
73
79UInt32::UInt32(const string &n) : BaseType(n, dods_uint32_c), d_buf(0) {}
80
88UInt32::UInt32(const string &n, const string &d) : BaseType(n, d, dods_uint32_c), d_buf(0) {}
89
90UInt32::UInt32(const UInt32 &copy_from) : BaseType(copy_from) { d_buf = copy_from.d_buf; }
91
92BaseType *UInt32::ptr_duplicate() { return new UInt32(*this); }
93
95 if (this == &rhs)
96 return *this;
98 d_buf = rhs.d_buf;
99 return *this;
100}
101
102bool UInt32::serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval) {
103#if USE_LOCAL_TIMEOUT_SCHEME
104 dds.timeout_on();
105#endif
106 if (!read_p())
107 read(); // read() throws Error and InternalErr
108
109 if (ce_eval && !eval.eval_selection(dds, dataset()))
110 return true;
111#if USE_LOCAL_TIMEOUT_SCHEME
112 dds.timeout_off();
113#endif
114 m.put_uint32(d_buf);
115
116 return true;
117}
118
120 um.get_uint32(d_buf);
121
122 return false;
123}
124
125void UInt32::compute_checksum(Crc32 &checksum) { checksum.AddData(reinterpret_cast<uint8_t *>(&d_buf), sizeof(d_buf)); }
126
135void UInt32::serialize(D4StreamMarshaller &m, DMR &, /*ConstraintEvaluator &,*/ bool) {
136 if (!read_p())
137 read(); // read() throws Error
138
139 m.put_uint32(d_buf);
140}
141
143
144unsigned int UInt32::val2buf(void *val, bool) {
145
146 // Jose Garcia
147 // This method is public therefore and I believe it has being designed
148 // to be use by read which must be implemented on the surrogated library,
149 // thus if the pointer val is NULL, is an Internal Error.
150 if (!val)
151 throw InternalErr(__FILE__, __LINE__, "The incoming pointer does not contain any data.");
152
153 d_buf = *(dods_uint32 *)val;
154
155 return width();
156}
157
158unsigned int UInt32::buf2val(void **val) {
159 // Jose Garcia
160 // The same comment justifying throwing an Error in val2buf applies here.
161 if (!val)
162 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
163
164 if (!*val)
165 *val = new dods_uint32;
166
167 *(dods_uint32 *)*val = d_buf;
168
169 return width();
170}
171
172dods_uint32 UInt32::value() const { return d_buf; }
173
175 d_buf = i;
176 set_read_p(true);
177
178 return true;
179}
180
181void UInt32::print_val(FILE *out, string space, bool print_decl_p) {
182 ostringstream oss;
183 print_val(oss, space, print_decl_p);
184 fwrite(oss.str().data(), sizeof(char), oss.str().length(), out);
185}
186
187void UInt32::print_val(ostream &out, string space, bool print_decl_p) {
188 if (print_decl_p) {
189 print_decl(out, space, false);
190 out << " = " << (unsigned int)d_buf << ";\n";
191 } else
192 out << (unsigned int)d_buf;
193}
194
195bool UInt32::ops(BaseType *b, int op) {
196 // Extract the Byte arg's value.
197 if (!read_p() && !read()) {
198 // Jose Garcia
199 // Since the read method is virtual and implemented outside
200 // libdap++ if we cannot read the data that is the problem
201 // of the user or of whoever wrote the surrogate library
202 // implemeting read therefore it is an internal error.
203 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
204 }
205
206 // Extract the second arg's value.
207 if (!b || !(b->read_p() || b->read())) {
208 // Jose Garcia
209 // Since the read method is virtual and implemented outside
210 // libdap++ if we cannot read the data that is the problem
211 // of the user or of whoever wrote the surrogate library
212 // implemeting read therefore it is an internal error.
213 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
214 }
215
216 switch (b->type()) {
217 case dods_int8_c:
218 return Cmp<dods_uint32, dods_int8>(op, d_buf, static_cast<Int8 *>(b)->value());
219 case dods_byte_c:
220 return Cmp<dods_uint32, dods_byte>(op, d_buf, static_cast<Byte *>(b)->value());
221 case dods_int16_c:
222 return Cmp<dods_uint32, dods_int16>(op, d_buf, static_cast<Int16 *>(b)->value());
223 case dods_uint16_c:
224 return Cmp<dods_uint32, dods_uint16>(op, d_buf, static_cast<UInt16 *>(b)->value());
225 case dods_int32_c:
226 return Cmp<dods_uint32, dods_int32>(op, d_buf, static_cast<Int32 *>(b)->value());
227 case dods_uint32_c:
228 return Cmp<dods_uint32, dods_uint32>(op, d_buf, static_cast<UInt32 *>(b)->value());
229 case dods_int64_c:
230 return Cmp<dods_uint32, dods_int64>(op, d_buf, static_cast<Int64 *>(b)->value());
231 case dods_uint64_c:
232 return Cmp<dods_uint32, dods_uint64>(op, d_buf, static_cast<UInt64 *>(b)->value());
233 case dods_float32_c:
234 return Cmp<dods_uint32, dods_float32>(op, d_buf, static_cast<Float32 *>(b)->value());
235 case dods_float64_c:
236 return Cmp<dods_uint32, dods_float64>(op, d_buf, static_cast<Float64 *>(b)->value());
237 default:
238 return false;
239 }
240}
241
250void UInt32::dump(ostream &strm) const {
251 strm << DapIndent::LMarg << "UInt32::dump - (" << (void *)this << ")" << endl;
253 BaseType::dump(strm);
254 strm << DapIndent::LMarg << "value: " << d_buf << endl;
256}
257
258} // namespace libdap
Definition crc.h:43
void AddData(const uint8_t *pData, const uint32_t length)
Definition crc.h:64
BaseType & operator=(const BaseType &rhs)
Definition BaseType.cc:159
virtual bool read()
Read data into a local buffer.
Definition BaseType.cc:775
virtual void print_decl(FILE *out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
Definition BaseType.cc:868
virtual bool read_p()
Has this variable been read?
Definition BaseType.cc:410
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition BaseType.cc:442
virtual string dataset() const
Returns the name of the dataset used to create this instance.
Definition BaseType.cc:326
void dump(ostream &strm) const override
dumps information about this object
Definition BaseType.cc:269
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition BaseType.cc:124
virtual Type type() const
Returns the type of the class instance.
Definition BaseType.cc:329
Holds a single byte.
Definition Byte.h:59
Evaluate a constraint expression.
bool eval_selection(DDS &dds, const std::string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator and is called ...
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
virtual void put_uint32(dods_uint32 val)
Read data from the stream made by D4StreamMarshaller.
virtual void get_uint32(dods_uint32 &val)
void timeout_off()
Definition DDS.cc:695
void timeout_on()
Definition DDS.cc:687
static ostream & LMarg(ostream &strm)
Definition DapIndent.cc:61
static void Indent()
Definition DapIndent.cc:44
static void UnIndent()
Definition DapIndent.cc:46
Holds a 32-bit floating point value.
Definition Float32.h:59
Holds a 64-bit (double precision) floating point value.
Definition Float64.h:58
Holds a 16-bit signed integer value.
Definition Int16.h:57
Holds a 32-bit signed integer.
Definition Int32.h:63
Holds a64-bit signed integer.
Definition Int64.h:48
Holds an 8-bit signed integer value.
Definition Int8.h:41
A class for software fault reporting.
Definition InternalErr.h:61
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
virtual void put_uint32(dods_uint32 val)=0
Holds an unsigned 16-bit integer.
Definition UInt16.h:55
UInt32(const string &n)
Definition UInt32.cc:79
BaseType * ptr_duplicate() override
Definition UInt32.cc:92
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition UInt32.cc:125
bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false) override
Receive data from the net.
Definition UInt32.cc:119
UInt32 & operator=(const UInt32 &rhs)
Definition UInt32.cc:94
bool ops(BaseType *b, int op) override
Evaluate relational operators.
Definition UInt32.cc:195
void dump(ostream &strm) const override
dumps information about this object
Definition UInt32.cc:250
unsigned int width(bool=false) const override
How many bytes does this variable use Return the number of bytes of storage this variable uses....
Definition UInt32.h:72
virtual dods_uint32 value() const
Definition UInt32.cc:172
bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true) override
Move data to the net, then remove them from the object.
Definition UInt32.cc:102
void print_val(FILE *out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
Definition UInt32.cc:181
unsigned int buf2val(void **val) override
Reads the class data.
Definition UInt32.cc:158
unsigned int val2buf(void *val, bool reuse=false) override
Loads class data.
Definition UInt32.cc:144
virtual bool set_value(dods_uint32 val)
Definition UInt32.cc:174
dods_uint32 d_buf
Definition UInt32.h:59
Holds a 64-bit unsigned integer.
Definition UInt64.h:47
abstract base class used to unmarshall/deserialize dap data objects
virtual void get_uint32(dods_uint32 &val)=0
top level DAP object to house generic methods
Definition AISConnect.cc:30
@ dods_uint32_c
Definition Type.h:100
@ dods_int16_c
Definition Type.h:97
@ dods_byte_c
Definition Type.h:96
@ dods_int32_c
Definition Type.h:99
@ dods_int8_c
Definition Type.h:115
@ dods_float32_c
Definition Type.h:101
@ dods_int64_c
Definition Type.h:118
@ dods_uint64_c
Definition Type.h:119
@ dods_uint16_c
Definition Type.h:98
@ dods_float64_c
Definition Type.h:102
bool Cmp(int op, T1 v1, T2 v2)
Definition Operators.h:52
uint32_t dods_uint32