libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
UInt64.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) 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 "Float32.h"
32#include "Float64.h"
33#include "Int16.h"
34#include "Int32.h"
35#include "Int64.h"
36#include "Int8.h"
37#include "Str.h"
38#include "UInt16.h"
39#include "UInt32.h"
40#include "UInt64.h"
41#include "Url.h"
42
43#include "D4StreamMarshaller.h"
45#include "DMR.h"
46
47#include "DapIndent.h"
48#include "InternalErr.h"
49#include "Operators.h"
50#include "debug.h"
51#include "dods-limits.h"
52#include "parser.h"
53#include "util.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
80UInt64::UInt64(const string &n, const string &d) : BaseType(n, d, dods_uint64_c, true /*is_dap4*/), d_buf(0) {}
81
82UInt64::UInt64(const UInt64 &copy_from) : BaseType(copy_from) { d_buf = copy_from.d_buf; }
83
84BaseType *UInt64::ptr_duplicate() { return new UInt64(*this); }
85
87 if (this == &rhs)
88 return *this;
90 d_buf = rhs.d_buf;
91 return *this;
92}
93
94void UInt64::compute_checksum(Crc32 &checksum) { checksum.AddData(reinterpret_cast<uint8_t *>(&d_buf), sizeof(d_buf)); }
95
104void UInt64::serialize(D4StreamMarshaller &m, DMR &, /*ConstraintEvaluator &,*/ bool) {
105 if (!read_p())
106 read(); // read() throws Error
107
108 m.put_uint64(d_buf);
109}
110
112
113dods_uint64 UInt64::value() const { return d_buf; }
114
116 d_buf = i;
117 set_read_p(true);
118
119 return true;
120}
121
122unsigned int UInt64::buf2val(void **val)
123
124{
125 if (!val)
126 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
127
128 if (!*val)
129 *val = new dods_uint64;
130
131 *(dods_uint64 *)*val = d_buf;
132
133 return width();
134}
135
136void UInt64::print_val(ostream &out, string space, bool print_decl_p) {
137 if (print_decl_p) {
138 print_decl(out, space, false);
139 out << " = " << d_buf << ";\n";
140 } else
141 out << d_buf;
142}
143
144bool UInt64::ops(BaseType *b, int op) {
145 // Extract the Byte arg's value.
146 if (!read_p() && !read())
147 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
148
149 // Extract the second arg's value.
150 if (!b || !(b->read_p() || b->read()))
151 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
152
153 switch (b->type()) {
154 case dods_int8_c:
155 return Cmp<dods_uint64, dods_int8>(op, d_buf, static_cast<Int8 *>(b)->value());
156 case dods_byte_c:
157 return Cmp<dods_uint64, dods_byte>(op, d_buf, static_cast<Byte *>(b)->value());
158 case dods_int16_c:
159 return Cmp<dods_uint64, dods_int16>(op, d_buf, static_cast<Int16 *>(b)->value());
160 case dods_uint16_c:
161 return Cmp<dods_uint64, dods_uint16>(op, d_buf, static_cast<UInt16 *>(b)->value());
162 case dods_int32_c:
163 return Cmp<dods_uint64, dods_int32>(op, d_buf, static_cast<Int32 *>(b)->value());
164 case dods_uint32_c:
165 return Cmp<dods_uint64, dods_uint32>(op, d_buf, static_cast<UInt32 *>(b)->value());
166 case dods_int64_c:
167 return Cmp<dods_uint64, dods_int64>(op, d_buf, static_cast<Int64 *>(b)->value());
168 case dods_uint64_c:
169 return Cmp<dods_uint64, dods_uint64>(op, d_buf, static_cast<UInt64 *>(b)->value());
170 case dods_float32_c:
171 return Cmp<dods_uint64, dods_float32>(op, d_buf, static_cast<Float32 *>(b)->value());
172 case dods_float64_c:
173 return Cmp<dods_uint64, dods_float64>(op, d_buf, static_cast<Float64 *>(b)->value());
174 default:
175 return false;
176 }
177}
178
179bool UInt64::d4_ops(BaseType *b, int op) {
180 switch (b->type()) {
181 case dods_int8_c:
182 return Cmp<dods_uint64, dods_int8>(op, d_buf, static_cast<Int8 *>(b)->value());
183 case dods_byte_c:
184 return Cmp<dods_uint64, dods_byte>(op, d_buf, static_cast<Byte *>(b)->value());
185 case dods_int16_c:
186 return Cmp<dods_uint64, dods_int16>(op, d_buf, static_cast<Int16 *>(b)->value());
187 case dods_uint16_c:
188 return Cmp<dods_uint64, dods_uint16>(op, d_buf, static_cast<UInt16 *>(b)->value());
189 case dods_int32_c:
190 return Cmp<dods_uint64, dods_int32>(op, d_buf, static_cast<Int32 *>(b)->value());
191 case dods_uint32_c:
192 return Cmp<dods_uint64, dods_uint32>(op, d_buf, static_cast<UInt32 *>(b)->value());
193 case dods_int64_c:
194 return Cmp<dods_uint64, dods_int64>(op, d_buf, static_cast<Int64 *>(b)->value());
195 case dods_uint64_c:
196 return Cmp<dods_uint64, dods_uint64>(op, d_buf, static_cast<UInt64 *>(b)->value());
197 case dods_float32_c:
198 return Cmp<dods_uint64, dods_float32>(op, d_buf, static_cast<Float32 *>(b)->value());
199 case dods_float64_c:
200 return Cmp<dods_uint64, dods_float64>(op, d_buf, static_cast<Float64 *>(b)->value());
201 default:
202 return false;
203 }
204}
205
221std::vector<BaseType *> *UInt64::transform_to_dap2(AttrTable *) {
222#if 0
223 BaseType *dest = this->ptr_duplicate();
224 // convert the d4 attributes to a dap2 attribute table.
225 AttrTable *attrs = this->attributes()->get_AttrTable();
226 attrs->set_name(name());
227 dest->set_attr_table(*attrs);
228 dest->set_is_dap4(false);
229 // attrs->print(cerr,"",true);
230 return dest;
231#endif
232
233 return NULL;
234}
235
241bool UInt64::is_dap4_projected(std::vector<string> &inventory) {
242 bool has_projected_dap4 = false;
243 if (send_p()) {
244 has_projected_dap4 = true;
245 attributes()->has_dap4_types(FQN(), inventory);
246 inventory.emplace_back(type_name() + " " + FQN());
247 }
248 return has_projected_dap4;
249}
250
259void UInt64::dump(ostream &strm) const {
260 strm << DapIndent::LMarg << "UInt32::dump - (" << (void *)this << ")" << endl;
262 BaseType::dump(strm);
263 strm << DapIndent::LMarg << "value: " << d_buf << endl;
265}
266
267} // namespace libdap
Definition crc.h:43
void AddData(const uint8_t *pData, const uint32_t length)
Definition crc.h:64
Contains the attributes for a dataset.
Definition AttrTable.h:150
virtual void set_name(const string &n)
Set the name of this attribute table.
Definition AttrTable.cc:247
BaseType & operator=(const BaseType &rhs)
Definition BaseType.cc:159
virtual string type_name() const
Returns the type of the class instance as a string.
Definition BaseType.cc:335
virtual bool read()
Read data into a local buffer.
Definition BaseType.cc:775
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:296
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 void set_attr_table(const AttrTable &at)
Definition BaseType.cc:502
void dump(ostream &strm) const override
dumps information about this object
Definition BaseType.cc:269
virtual D4Attributes * attributes()
Definition BaseType.cc:507
virtual std::string FQN() const
Definition BaseType.cc:304
virtual bool send_p()
Should this variable be sent?
Definition BaseType.cc:478
virtual void set_is_dap4(const bool v)
Definition BaseType.h:182
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
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...
virtual void put_uint64(dods_uint64 val)
Read data from the stream made by D4StreamMarshaller.
virtual void get_uint64(dods_uint64 &val)
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
Holds an unsigned 16-bit integer.
Definition UInt16.h:55
Holds a 32-bit unsigned integer.
Definition UInt32.h:57
bool ops(BaseType *b, int op) override
Evaluate relational operators.
Definition UInt64.cc:144
UInt64 & operator=(const UInt64 &rhs)
Definition UInt64.cc:86
virtual dods_uint64 value() const
Definition UInt64.cc:113
void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false) override
Serialize an Int8.
Definition UInt64.cc:104
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:72
BaseType * ptr_duplicate() override
Definition UInt64.cc:84
bool d4_ops(BaseType *b, int op) override
Evaluator a relop for DAP4.
Definition UInt64.cc:179
void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override
Definition UInt64.cc:111
void dump(ostream &strm) const override
dumps information about this object
Definition UInt64.cc:259
std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table) override
DAP4 to DAP2 transform.
Definition UInt64.cc:221
dods_uint64 d_buf
Definition UInt64.h:59
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:94
virtual bool set_value(dods_uint64 val)
Definition UInt64.cc:115
bool is_dap4_projected(std::vector< string > &inventory) override
Definition UInt64.cc:241
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
uint64_t dods_uint64