libdap Updated for version 3.21.0
libdap4 is an implementation of OPeNDAP's DAP protocol.
Int64.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) 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 1994-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 Int64.
33//
34// jhrg 9/7/94
35
36
37#include "config.h"
38
39#include <cassert>
40#include <sstream>
41
42#include "Byte.h" // synonymous with UInt8 and Char
43#include "Int8.h"
44#include "Int16.h"
45#include "UInt16.h"
46#include "Int32.h"
47#include "UInt32.h"
48#include "Int64.h"
49#include "UInt64.h"
50#include "Float32.h"
51#include "Float64.h"
52#include "Str.h"
53#include "Url.h"
54
55#if 0
56#include "Array.h"
57#include "Structure.h"
58#include "Sequence.h"
59#include "Grid.h"
60#endif
61
62#include "DMR.h"
63#include "D4StreamMarshaller.h"
64#include "D4StreamUnMarshaller.h"
65
66#include "util.h"
67#include "parser.h"
68#include "Operators.h"
69#include "dods-limits.h"
70#include "debug.h"
71#include "InternalErr.h"
72#include "DapIndent.h"
73
74using std::cerr;
75using std::endl;
76
77namespace libdap {
78
89Int64::Int64(const string &n) : BaseType(n, dods_int64_c, true /*is_dap4*/), d_buf(0)
90{}
91
102Int64::Int64(const string &n, const string &d) : BaseType(n, d, dods_int64_c, true /*is_dap4*/), d_buf(0)
103{}
104
105Int64::Int64(const Int64 &copy_from) : BaseType(copy_from)
106{
107 d_buf = copy_from.d_buf;
108}
109
110BaseType *
112{
113 return new Int64(*this);
114}
115
116Int64::~Int64()
117{
118 DBG(cerr << "~Int64" << endl);
119}
120
121Int64 &
122Int64::operator=(const Int64 &rhs)
123{
124 if (this == &rhs)
125 return *this;
126 BaseType::operator=(rhs);
127 d_buf = rhs.d_buf;
128 return *this;
129}
130
131void
133{
134 checksum.AddData(reinterpret_cast<uint8_t*>(&d_buf), sizeof(d_buf));
135}
136
145void
146Int64::serialize(D4StreamMarshaller &m, DMR &, /*ConstraintEvaluator &,*/ bool)
147{
148 if (!read_p())
149 read(); // read() throws Error
150
151 m.put_int64( d_buf ) ;
152}
153
154void
156{
157 um.get_int64( d_buf ) ;
158}
159
160dods_int64
161Int64::value() const
162{
163 return d_buf;
164}
165
166bool
167Int64::set_value(dods_int64 i)
168{
169 d_buf = i;
170 set_read_p(true);
171
172 return true;
173}
174
175unsigned int
176Int64::buf2val(void **val)
177{
178 if (!val)
179 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
180
181 if (!*val)
182 *val = new dods_int64;
183
184 *(dods_int64 *)*val = d_buf;
185
186 return width();
187}
188void Int64::print_val(ostream &out, string space, bool print_decl_p)
189{
190 if (print_decl_p) {
191 print_decl(out, space, false);
192 out << " = " << d_buf << ";\n";
193 }
194 else
195 out << d_buf;
196}
197
198bool
200{
201 // Get the arg's value.
202 if (!read_p() && !read())
203 throw InternalErr(__FILE__, __LINE__, "This value not read!");
204
205 // Get the second arg's value.
206 if (!b || !(b->read_p() || b->read()))
207 throw InternalErr(__FILE__, __LINE__, "This value not read!");
208
209 return d4_ops(b, op);
210}
211
215bool Int64::d4_ops(BaseType *b, int op)
216{
217 switch (b->type()) {
218 case dods_int8_c:
219 return Cmp<dods_int64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value());
220 case dods_byte_c:
221 return Cmp<dods_int64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value());
222 case dods_int16_c:
223 return Cmp<dods_int64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value());
224 case dods_uint16_c:
225 return Cmp<dods_int64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value());
226 case dods_int32_c:
227 return Cmp<dods_int64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value());
228 case dods_uint32_c:
229 return Cmp<dods_int64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value());
230 case dods_int64_c:
231 return Cmp<dods_int64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value());
232 case dods_uint64_c:
233 return Cmp<dods_int64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value());
234 case dods_float32_c:
235 return Cmp<dods_int64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value());
236 case dods_float64_c:
237 return Cmp<dods_int64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value());
238 case dods_str_c:
239 case dods_url_c:
240 throw Error(malformed_expr, "Relational operators can only compare compatible types (number, string).");
241 default:
242 throw Error(malformed_expr, "Relational operators only work with scalar types.");
243 }
244}
245
252vector<BaseType *> *
254{
255#if 0
256 BaseType *dest = this->ptr_duplicate();
257 // convert the d4 attributes to a dap2 attribute table.
258 AttrTable *attrs = this->attributes()->get_AttrTable();
259 attrs->set_name(name());
260 dest->set_attr_table(*attrs);
261 dest->set_is_dap4(false);
262 // attrs->print(cerr,"",true);
263 return dest;
264#endif
265
266 return NULL;
267}
268
274bool Int64::is_dap4_projected(std::vector<string> &inventory)
275{
276 bool has_projected_dap4 = false;
277 if(send_p()) {
278 has_projected_dap4 = true;
279 attributes()->has_dap4_types(FQN(), inventory);
280 inventory.emplace_back(type_name() + " " + FQN());
281 }
282 return has_projected_dap4;
283}
284
285
294void
295Int64::dump(ostream &strm) const
296{
297 strm << DapIndent::LMarg << "Int64::dump - ("
298 << (void *)this << ")" << endl ;
299 DapIndent::Indent() ;
300 BaseType::dump(strm) ;
301 strm << DapIndent::LMarg << "value: " << d_buf << endl ;
302 DapIndent::UnIndent() ;
303}
304
305} // namespace libdap
306
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
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
Holds a single byte.
Definition Byte.h:61
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.
A class for error processing.
Definition Error.h:94
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
BaseType * ptr_duplicate() override
Definition Int64.cc:111
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 Int64.h:74
bool d4_ops(BaseType *b, int op) override
Definition Int64.cc:215
Int64(const string &n)
Definition Int64.cc:89
void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override
Definition Int64.cc:155
bool ops(BaseType *b, int op) override
Evaluate relational operators.
Definition Int64.cc:199
void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false) override
Serialize an Int8.
Definition Int64.cc:146
bool is_dap4_projected(std::vector< string > &inventory) override
Definition Int64.cc:274
void dump(ostream &strm) const override
dumps information about this object
Definition Int64.cc:295
std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table) override
DAP4 to DAP2 transform.
Definition Int64.cc:253
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition Int64.cc:132
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
top level DAP object to house generic methods
Definition AISConnect.cc:30