libdap Updated for version 3.21.0
libdap4 is an implementation of OPeNDAP's DAP protocol.
UInt64.cc
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) 2012 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#include "config.h"
27
28#include <sstream>
29
30#include "Byte.h" // synonymous with UInt8 and Char
31#include "Int8.h"
32#include "Int16.h"
33#include "UInt16.h"
34#include "Int32.h"
35#include "UInt32.h"
36#include "Int64.h"
37#include "UInt64.h"
38#include "Float32.h"
39#include "Float64.h"
40#include "Str.h"
41#include "Url.h"
42
43#include "DMR.h"
44#include "D4StreamMarshaller.h"
45#include "D4StreamUnMarshaller.h"
46
47#include "util.h"
48#include "parser.h"
49#include "Operators.h"
50#include "dods-limits.h"
51#include "debug.h"
52#include "InternalErr.h"
53#include "DapIndent.h"
54
55using std::cerr;
56using std::endl;
57
58namespace libdap {
59
68UInt64::UInt64(const string &n) : BaseType(n, dods_uint64_c, true /*is_dap4*/), d_buf(0)
69{}
70
81UInt64::UInt64(const string &n, const string &d) : BaseType(n, d, dods_uint64_c, true /*is_dap4*/), d_buf(0)
82{}
83
84UInt64::UInt64(const UInt64 &copy_from) : BaseType(copy_from)
85{
86 d_buf = copy_from.d_buf;
87}
88
89BaseType *
91{
92 return new UInt64(*this);
93}
94
95UInt64 &
96UInt64::operator=(const UInt64 &rhs)
97{
98 if (this == &rhs)
99 return *this;
100 BaseType::operator=(rhs);
101 d_buf = rhs.d_buf;
102 return *this;
103}
104
105void
107{
108 checksum.AddData(reinterpret_cast<uint8_t*>(&d_buf), sizeof(d_buf));
109}
110
119void
120UInt64::serialize(D4StreamMarshaller &m, DMR &, /*ConstraintEvaluator &,*/ bool)
121{
122 if (!read_p())
123 read(); // read() throws Error
124
125 m.put_uint64( d_buf ) ;
126}
127
128void
130{
131 um.get_uint64( d_buf ) ;
132}
133
134dods_uint64
135UInt64::value() const
136{
137 return d_buf;
138}
139
140bool
141UInt64::set_value(dods_uint64 i)
142{
143 d_buf = i;
144 set_read_p(true);
145
146 return true;
147}
148
149unsigned int
150UInt64::buf2val(void **val)
151
152{
153 if (!val)
154 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
155
156 if (!*val)
157 *val = new dods_uint64;
158
159 *(dods_uint64 *)*val = d_buf;
160
161 return width();
162}
163
164void
165UInt64::print_val(ostream &out, string space, bool print_decl_p)
166{
167 if (print_decl_p) {
168 print_decl(out, space, false);
169 out << " = " << d_buf << ";\n" ;
170 }
171 else
172 out << d_buf ;
173}
174
175bool
177{
178 // Extract the Byte arg's value.
179 if (!read_p() && !read())
180 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
181
182 // Extract the second arg's value.
183 if (!b || !(b->read_p() || b->read()))
184 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
185
186 switch (b->type()) {
187 case dods_int8_c:
188 return Cmp<dods_uint64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value());
189 case dods_byte_c:
190 return Cmp<dods_uint64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value());
191 case dods_int16_c:
192 return Cmp<dods_uint64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value());
193 case dods_uint16_c:
194 return Cmp<dods_uint64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value());
195 case dods_int32_c:
196 return Cmp<dods_uint64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value());
197 case dods_uint32_c:
198 return Cmp<dods_uint64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value());
199 case dods_int64_c:
200 return Cmp<dods_uint64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value());
201 case dods_uint64_c:
202 return Cmp<dods_uint64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value());
203 case dods_float32_c:
204 return Cmp<dods_uint64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value());
205 case dods_float64_c:
206 return Cmp<dods_uint64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value());
207 default:
208 return false;
209 }
210}
211
212bool
214{
215 switch (b->type()) {
216 case dods_int8_c:
217 return Cmp<dods_uint64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value());
218 case dods_byte_c:
219 return Cmp<dods_uint64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value());
220 case dods_int16_c:
221 return Cmp<dods_uint64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value());
222 case dods_uint16_c:
223 return Cmp<dods_uint64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value());
224 case dods_int32_c:
225 return Cmp<dods_uint64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value());
226 case dods_uint32_c:
227 return Cmp<dods_uint64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value());
228 case dods_int64_c:
229 return Cmp<dods_uint64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value());
230 case dods_uint64_c:
231 return Cmp<dods_uint64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value());
232 case dods_float32_c:
233 return Cmp<dods_uint64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value());
234 case dods_float64_c:
235 return Cmp<dods_uint64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value());
236 default:
237 return false;
238 }
239}
240
241
242
258std::vector<BaseType *> *
260{
261#if 0
262 BaseType *dest = this->ptr_duplicate();
263 // convert the d4 attributes to a dap2 attribute table.
264 AttrTable *attrs = this->attributes()->get_AttrTable();
265 attrs->set_name(name());
266 dest->set_attr_table(*attrs);
267 dest->set_is_dap4(false);
268 // attrs->print(cerr,"",true);
269 return dest;
270#endif
271
272 return NULL;
273}
274
275
281bool UInt64::is_dap4_projected(std::vector<string> &inventory)
282{
283 bool has_projected_dap4 = false;
284 if(send_p()) {
285 has_projected_dap4 = true;
286 attributes()->has_dap4_types(FQN(), inventory);
287 inventory.emplace_back(type_name() + " " + FQN());
288 }
289 return has_projected_dap4;
290}
291
292
301void
302UInt64::dump(ostream &strm) const
303{
304 strm << DapIndent::LMarg << "UInt32::dump - ("
305 << (void *)this << ")" << endl ;
306 DapIndent::Indent() ;
307 BaseType::dump(strm) ;
308 strm << DapIndent::LMarg << "value: " << d_buf << endl ;
309 DapIndent::UnIndent() ;
310}
311
312} // namespace libdap
313
Definition crc.h:77
void AddData(const uint8_t *pData, const uint32_t length)
Definition crc.h:98
Contains the attributes for a dataset.
Definition AttrTable.h:154
virtual void set_name(const string &n)
Set the name of this attribute table.
Definition AttrTable.cc:273
The basic data type for the DODS DAP types.
Definition BaseType.h:120
virtual string type_name() const
Returns the type of the class instance as a string.
Definition BaseType.cc:376
virtual bool read()
Read data into a local buffer.
Definition BaseType.cc:905
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:317
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:1009
virtual bool read_p()
Has this variable been read?
Definition BaseType.cc:477
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition BaseType.cc:513
virtual void set_attr_table(const AttrTable &at)
Definition BaseType.cc:587
void dump(ostream &strm) const override
dumps information about this object
Definition BaseType.cc:287
virtual D4Attributes * attributes()
Definition BaseType.cc:596
virtual std::string FQN() const
Definition BaseType.cc:329
virtual bool send_p()
Should this variable be sent?
Definition BaseType.cc:551
virtual Type type() const
Returns the type of the class instance.
Definition BaseType.cc:362
Holds a single byte.
Definition Byte.h:61
bool has_dap4_types(const std::string &path, std::vector< std::string > &inventory) const
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Read data from the stream made by D4StreamMarshaller.
Holds a 32-bit floating point value.
Definition Float32.h:62
Holds a 64-bit (double precision) floating point value.
Definition Float64.h:61
Holds a 16-bit signed integer value.
Definition Int16.h:60
Holds a 32-bit signed integer.
Definition Int32.h:66
Holds a64-bit signed integer.
Definition Int64.h:50
Holds an 8-bit signed integer value.
Definition Int8.h:43
A class for software fault reporting.
Definition InternalErr.h:65
Holds an unsigned 16-bit integer.
Definition UInt16.h:58
Holds a 32-bit unsigned integer.
Definition UInt32.h:60
Holds a 64-bit unsigned integer.
Definition UInt64.h:50
bool ops(BaseType *b, int op) override
Evaluate relational operators.
Definition UInt64.cc:176
void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false) override
Serialize an Int8.
Definition UInt64.cc:120
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 UInt64.h:74
BaseType * ptr_duplicate() override
Definition UInt64.cc:90
bool d4_ops(BaseType *b, int op) override
Evaluator a relop for DAP4.
Definition UInt64.cc:213
void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override
Definition UInt64.cc:129
void dump(ostream &strm) const override
dumps information about this object
Definition UInt64.cc:302
std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table) override
DAP4 to DAP2 transform.
Definition UInt64.cc:259
UInt64(const string &n)
Definition UInt64.cc:68
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition UInt64.cc:106
bool is_dap4_projected(std::vector< string > &inventory) override
Definition UInt64.cc:281
top level DAP object to house generic methods
Definition AISConnect.cc:30
bool Cmp(int op, T1 v1, T2 v2)
Definition Operators.h:53