libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
Int64.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 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#include "config.h"
37
38#include <cassert>
39#include <sstream>
40
41#include "Byte.h" // synonymous with UInt8 and Char
42#include "Float32.h"
43#include "Float64.h"
44#include "Int16.h"
45#include "Int32.h"
46#include "Int64.h"
47#include "Int8.h"
48#include "Str.h"
49#include "UInt16.h"
50#include "UInt32.h"
51#include "UInt64.h"
52#include "Url.h"
53
54#if 0
55#include "Array.h"
56#include "Grid.h"
57#include "Sequence.h"
58#include "Structure.h"
59#endif
60
61#include "D4StreamMarshaller.h"
63#include "DMR.h"
64
65#include "DapIndent.h"
66#include "InternalErr.h"
67#include "Operators.h"
68#include "debug.h"
69#include "dods-limits.h"
70#include "parser.h"
71#include "util.h"
72
73using std::cerr;
74using std::endl;
75
76namespace libdap {
77
88Int64::Int64(const string &n) : BaseType(n, dods_int64_c, true /*is_dap4*/), d_buf(0) {}
89
100Int64::Int64(const string &n, const string &d) : BaseType(n, d, dods_int64_c, true /*is_dap4*/), d_buf(0) {}
101
102Int64::Int64(const Int64 &copy_from) : BaseType(copy_from) { d_buf = copy_from.d_buf; }
103
104BaseType *Int64::ptr_duplicate() { return new Int64(*this); }
105
106Int64::~Int64() { DBG(cerr << "~Int64" << endl); }
107
109 if (this == &rhs)
110 return *this;
112 d_buf = rhs.d_buf;
113 return *this;
114}
115
116void Int64::compute_checksum(Crc32 &checksum) { checksum.AddData(reinterpret_cast<uint8_t *>(&d_buf), sizeof(d_buf)); }
117
126void Int64::serialize(D4StreamMarshaller &m, DMR &, /*ConstraintEvaluator &,*/ bool) {
127 if (!read_p())
128 read(); // read() throws Error
129
130 m.put_int64(d_buf);
131}
132
134
135dods_int64 Int64::value() const { return d_buf; }
136
138 d_buf = i;
139 set_read_p(true);
140
141 return true;
142}
143
144unsigned int Int64::buf2val(void **val) {
145 if (!val)
146 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
147
148 if (!*val)
149 *val = new dods_int64;
150
151 *(dods_int64 *)*val = d_buf;
152
153 return width();
154}
155void Int64::print_val(ostream &out, string space, bool print_decl_p) {
156 if (print_decl_p) {
157 print_decl(out, space, false);
158 out << " = " << d_buf << ";\n";
159 } else
160 out << d_buf;
161}
162
163bool Int64::ops(BaseType *b, int op) {
164 // Get the arg's value.
165 if (!read_p() && !read())
166 throw InternalErr(__FILE__, __LINE__, "This value not read!");
167
168 // Get the second arg's value.
169 if (!b || !(b->read_p() || b->read()))
170 throw InternalErr(__FILE__, __LINE__, "This value not read!");
171
172 return d4_ops(b, op);
173}
174
178bool Int64::d4_ops(BaseType *b, int op) {
179 switch (b->type()) {
180 case dods_int8_c:
181 return Cmp<dods_int64, dods_int8>(op, d_buf, static_cast<Int8 *>(b)->value());
182 case dods_byte_c:
183 return Cmp<dods_int64, dods_byte>(op, d_buf, static_cast<Byte *>(b)->value());
184 case dods_int16_c:
185 return Cmp<dods_int64, dods_int16>(op, d_buf, static_cast<Int16 *>(b)->value());
186 case dods_uint16_c:
187 return Cmp<dods_int64, dods_uint16>(op, d_buf, static_cast<UInt16 *>(b)->value());
188 case dods_int32_c:
189 return Cmp<dods_int64, dods_int32>(op, d_buf, static_cast<Int32 *>(b)->value());
190 case dods_uint32_c:
191 return Cmp<dods_int64, dods_uint32>(op, d_buf, static_cast<UInt32 *>(b)->value());
192 case dods_int64_c:
193 return Cmp<dods_int64, dods_int64>(op, d_buf, static_cast<Int64 *>(b)->value());
194 case dods_uint64_c:
195 return Cmp<dods_int64, dods_uint64>(op, d_buf, static_cast<UInt64 *>(b)->value());
196 case dods_float32_c:
197 return Cmp<dods_int64, dods_float32>(op, d_buf, static_cast<Float32 *>(b)->value());
198 case dods_float64_c:
199 return Cmp<dods_int64, dods_float64>(op, d_buf, static_cast<Float64 *>(b)->value());
200 case dods_str_c:
201 case dods_url_c:
202 throw Error(malformed_expr, "Relational operators can only compare compatible types (number, string).");
203 default:
204 throw Error(malformed_expr, "Relational operators only work with scalar types.");
205 }
206}
207
214vector<BaseType *> *Int64::transform_to_dap2(AttrTable *) {
215#if 0
216 BaseType *dest = this->ptr_duplicate();
217 // convert the d4 attributes to a dap2 attribute table.
218 AttrTable *attrs = this->attributes()->get_AttrTable();
219 attrs->set_name(name());
220 dest->set_attr_table(*attrs);
221 dest->set_is_dap4(false);
222 // attrs->print(cerr,"",true);
223 return dest;
224#endif
225
226 return NULL;
227}
228
234bool Int64::is_dap4_projected(std::vector<string> &inventory) {
235 bool has_projected_dap4 = false;
236 if (send_p()) {
237 has_projected_dap4 = true;
238 attributes()->has_dap4_types(FQN(), inventory);
239 inventory.emplace_back(type_name() + " " + FQN());
240 }
241 return has_projected_dap4;
242}
243
252void Int64::dump(ostream &strm) const {
253 strm << DapIndent::LMarg << "Int64::dump - (" << (void *)this << ")" << endl;
255 BaseType::dump(strm);
256 strm << DapIndent::LMarg << "value: " << d_buf << endl;
258}
259
260} // namespace libdap
#define malformed_expr
(400)
Definition Error.h:66
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_int64(dods_int64 val)
Read data from the stream made by D4StreamMarshaller.
virtual void get_int64(dods_int64 &val)
static ostream & LMarg(ostream &strm)
Definition DapIndent.cc:61
static void Indent()
Definition DapIndent.cc:44
static void UnIndent()
Definition DapIndent.cc:46
A class for error processing.
Definition Error.h:92
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
BaseType * ptr_duplicate() override
Definition Int64.cc:104
Int64 & operator=(const Int64 &rhs)
Definition Int64.cc:108
virtual bool set_value(dods_int64 i)
Definition Int64.cc:137
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:178
Int64(const string &n)
Definition Int64.cc:88
void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override
Definition Int64.cc:133
virtual ~Int64()
Definition Int64.cc:106
bool ops(BaseType *b, int op) override
Evaluate relational operators.
Definition Int64.cc:163
void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false) override
Serialize an Int8.
Definition Int64.cc:126
bool is_dap4_projected(std::vector< string > &inventory) override
Definition Int64.cc:234
void dump(ostream &strm) const override
dumps information about this object
Definition Int64.cc:252
virtual dods_int64 value() const
Definition Int64.cc:135
std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table) override
DAP4 to DAP2 transform.
Definition Int64.cc:214
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:116
dods_int64 d_buf
Definition Int64.h:60
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
Holds a 64-bit unsigned integer.
Definition UInt64.h:47
#define DBG(x)
Definition debug.h:58
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_url_c
Definition Type.h:104
@ 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
@ dods_str_c
Definition Type.h:103
bool Cmp(int op, T1 v1, T2 v2)
Definition Operators.h:52