libdap Updated for version 3.18.1
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
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{}
90
101Int64::Int64(const string &n, const string &d) : BaseType(n, d, dods_int64_c, true /*is_dap4*/), d_buf(0)
102{}
103
104Int64::Int64(const Int64 &copy_from) : BaseType(copy_from)
105{
106 d_buf = copy_from.d_buf;
107}
108
109BaseType *
111{
112 return new Int64(*this);
113}
114
115Int64::~Int64()
116{
117 DBG(cerr << "~Int64" << endl);
118}
119
120Int64 &
121Int64::operator=(const Int64 &rhs)
122{
123 if (this == &rhs)
124 return *this;
125
126 dynamic_cast<BaseType &>(*this) = rhs;
127
128 d_buf = rhs.d_buf;
129
130 return *this;
131}
132
133unsigned int
134Int64::width(bool) const
135{
136 return sizeof(dods_int64);
137}
138
139void
141{
142 checksum.AddData(reinterpret_cast<uint8_t*>(&d_buf), sizeof(d_buf));
143}
144
153void
154Int64::serialize(D4StreamMarshaller &m, DMR &, /*ConstraintEvaluator &,*/ bool)
155{
156 if (!read_p())
157 read(); // read() throws Error
158
159 m.put_int64( d_buf ) ;
160}
161
162void
164{
165 um.get_int64( d_buf ) ;
166}
167
168dods_int64
169Int64::value() const
170{
171 return d_buf;
172}
173
174bool
175Int64::set_value(dods_int64 i)
176{
177 d_buf = i;
178 set_read_p(true);
179
180 return true;
181}
182
183void Int64::print_val(ostream &out, string space, bool print_decl_p)
184{
185 if (print_decl_p) {
186 print_decl(out, space, false);
187 out << " = " << d_buf << ";\n";
188 }
189 else
190 out << d_buf;
191}
192
193bool
195{
196 // Get the arg's value.
197 if (!read_p() && !read())
198 throw InternalErr(__FILE__, __LINE__, "This value not read!");
199
200 // Get the second arg's value.
201 if (!b->read_p() && !b->read())
202 throw InternalErr(__FILE__, __LINE__, "This value not read!");
203
204 return d4_ops(b, op);
205
206 return false;
207}
208
212bool Int64::d4_ops(BaseType *b, int op)
213{
214 switch (b->type()) {
215 case dods_int8_c:
216 return Cmp<dods_int64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value());
217 case dods_byte_c:
218 return SUCmp<dods_int64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value());
219 case dods_int16_c:
220 return Cmp<dods_int64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value());
221 case dods_uint16_c:
222 return SUCmp<dods_int64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value());
223 case dods_int32_c:
224 return Cmp<dods_int64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value());
225 case dods_uint32_c:
226 return SUCmp<dods_int64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value());
227 case dods_int64_c:
228 return Cmp<dods_int64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value());
229 case dods_uint64_c:
230 return SUCmp<dods_int64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value());
231 case dods_float32_c:
232 return Cmp<dods_int64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value());
233 case dods_float64_c:
234 return Cmp<dods_int64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value());
235 case dods_str_c:
236 case dods_url_c:
237 throw Error(malformed_expr, "Relational operators can only compare compatible types (number, string).");
238 default:
239 throw Error(malformed_expr, "Relational operators only work with scalar types.");
240 }
241}
242
251void
252Int64::dump(ostream &strm) const
253{
254 strm << DapIndent::LMarg << "Int64::dump - ("
255 << (void *)this << ")" << endl ;
256 DapIndent::Indent() ;
257 BaseType::dump(strm) ;
258 strm << DapIndent::LMarg << "value: " << d_buf << endl ;
259 DapIndent::UnIndent() ;
260}
261
262} // namespace libdap
263
Definition: crc.h:77
void AddData(const uint8_t *pData, const uint32_t length)
Definition: crc.h:98
The basic data type for the DODS DAP types.
Definition: BaseType.h:118
virtual bool read()
Read data into a local buffer.
Definition: BaseType.cc:820
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:924
virtual bool read_p()
Has this variable been read?
Definition: BaseType.cc:425
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition: BaseType.cc:461
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BaseType.cc:236
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition: BaseType.cc:125
virtual Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:310
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:91
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
virtual unsigned int width(bool constrained=false) const
How many bytes does this use Return the number of bytes of storage this variable uses....
Definition: Int64.cc:134
Int64(const string &n)
Definition: Int64.cc:88
virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false)
Serialize an Int8.
Definition: Int64.cc:154
virtual BaseType * ptr_duplicate()
Definition: Int64.cc:110
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Int64.cc:252
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
Definition: Int64.cc:194
virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr)
Definition: Int64.cc:163
virtual void compute_checksum(Crc32 &checksum)
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition: Int64.cc:140
virtual bool d4_ops(BaseType *b, int op)
Definition: Int64.cc:212
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