libdap  Updated for version 3.18.3
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 
54 using std::cerr;
55 using std::endl;
56 
57 namespace libdap {
58 
67 UInt64::UInt64(const string &n) : BaseType(n, dods_uint64_c, true /*is_dap4*/), d_buf(0)
68 {}
69 
80 UInt64::UInt64(const string &n, const string &d) : BaseType(n, d, dods_uint64_c, true /*is_dap4*/), d_buf(0)
81 {}
82 
83 UInt64::UInt64(const UInt64 &copy_from) : BaseType(copy_from)
84 {
85  d_buf = copy_from.d_buf;
86 }
87 
88 BaseType *
90 {
91  return new UInt64(*this);
92 }
93 
94 UInt64 &
95 UInt64::operator=(const UInt64 &rhs)
96 {
97  if (this == &rhs)
98  return *this;
99 
100  dynamic_cast<BaseType &>(*this) = rhs;
101 
102  d_buf = rhs.d_buf;
103 
104  return *this;
105 }
106 
107 unsigned int
108 UInt64::width(bool) const
109 {
110  return sizeof(dods_uint64);
111 }
112 
113 void
115 {
116  checksum.AddData(reinterpret_cast<uint8_t*>(&d_buf), sizeof(d_buf));
117 }
118 
127 void
128 UInt64::serialize(D4StreamMarshaller &m, DMR &, /*ConstraintEvaluator &,*/ bool)
129 {
130  if (!read_p())
131  read(); // read() throws Error
132 
133  m.put_uint64( d_buf ) ;
134 }
135 
136 void
138 {
139  um.get_uint64( d_buf ) ;
140 }
141 
142 dods_uint64
143 UInt64::value() const
144 {
145  return d_buf;
146 }
147 
148 bool
149 UInt64::set_value(dods_uint64 i)
150 {
151  d_buf = i;
152  set_read_p(true);
153 
154  return true;
155 }
156 
157 void
158 UInt64::print_val(ostream &out, string space, bool print_decl_p)
159 {
160  if (print_decl_p) {
161  print_decl(out, space, false);
162  out << " = " << d_buf << ";\n" ;
163  }
164  else
165  out << d_buf ;
166 }
167 
168 bool
170 {
171  // Extract the Byte arg's value.
172  if (!read_p() && !read())
173  throw InternalErr(__FILE__, __LINE__, "This value was not read!");
174 
175  // Extract the second arg's value.
176  if (!b || !(b->read_p() || b->read()))
177  throw InternalErr(__FILE__, __LINE__, "This value was not read!");
178 
179  switch (b->type()) {
180  case dods_int8_c:
181  return USCmp<dods_uint64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value());
182  case dods_byte_c:
183  return Cmp<dods_uint64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value());
184  case dods_int16_c:
185  return USCmp<dods_uint64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value());
186  case dods_uint16_c:
187  return Cmp<dods_uint64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value());
188  case dods_int32_c:
189  return USCmp<dods_uint64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value());
190  case dods_uint32_c:
191  return Cmp<dods_uint64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value());
192  case dods_int64_c:
193  return USCmp<dods_uint64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value());
194  case dods_uint64_c:
195  return Cmp<dods_uint64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value());
196  case dods_float32_c:
197  return USCmp<dods_uint64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value());
198  case dods_float64_c:
199  return USCmp<dods_uint64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value());
200  default:
201  return false;
202  }
203 }
204 
205 bool
207 {
208  switch (b->type()) {
209  case dods_int8_c:
210  return USCmp<dods_uint64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value());
211  case dods_byte_c:
212  return Cmp<dods_uint64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value());
213  case dods_int16_c:
214  return USCmp<dods_uint64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value());
215  case dods_uint16_c:
216  return Cmp<dods_uint64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value());
217  case dods_int32_c:
218  return USCmp<dods_uint64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value());
219  case dods_uint32_c:
220  return Cmp<dods_uint64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value());
221  case dods_int64_c:
222  return USCmp<dods_uint64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value());
223  case dods_uint64_c:
224  return Cmp<dods_uint64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value());
225  case dods_float32_c:
226  return USCmp<dods_uint64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value());
227  case dods_float64_c:
228  return USCmp<dods_uint64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value());
229  default:
230  return false;
231  }
232 }
233 
242 void
243 UInt64::dump(ostream &strm) const
244 {
245  strm << DapIndent::LMarg << "UInt32::dump - ("
246  << (void *)this << ")" << endl ;
247  DapIndent::Indent() ;
248  BaseType::dump(strm) ;
249  strm << DapIndent::LMarg << "value: " << d_buf << endl ;
250  DapIndent::UnIndent() ;
251 }
252 
253 } // namespace libdap
254 
virtual bool read()
Read data into a local buffer.
Definition: BaseType.cc:820
Holds an 8-bit signed integer value.
Definition: Int8.h:42
Holds a64-bit signed integer.
Definition: Int64.h:49
virtual bool read_p()
Has this variable been read?
Definition: BaseType.cc:425
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 void dump(ostream &strm) const
dumps information about this object
Definition: BaseType.cc:236
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
Definition: UInt64.cc:169
Read data from the stream made by D4StreamMarshaller.
Holds an unsigned 16-bit integer.
Definition: UInt16.h:57
virtual BaseType * ptr_duplicate()
Definition: UInt64.cc:89
Definition: crc.h:76
virtual bool d4_ops(BaseType *b, int op)
Evaluator a relop for DAP4.
Definition: UInt64.cc:206
Holds a 32-bit floating point value.
Definition: Float32.h:61
A class for software fault reporting.
Definition: InternalErr.h:64
UInt64(const string &n)
Definition: UInt64.cc:67
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4&#39;s receiv...
Holds a 16-bit signed integer value.
Definition: Int16.h:59
virtual Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:310
virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false)
Serialize an Int8.
Definition: UInt64.cc:128
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition: BaseType.cc:461
virtual void compute_checksum(Crc32 &checksum)
include the data for this variable in the checksum DAP4 includes a checksum with every data response...
Definition: UInt64.cc:114
virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr)
Definition: UInt64.cc:137
Holds a 64-bit unsigned integer.
Definition: UInt64.h:49
void AddData(const uint8_t *pData, const uint32_t length)
Definition: crc.h:98
virtual void dump(ostream &strm) const
dumps information about this object
Definition: UInt64.cc:243
virtual unsigned int width(bool constrained=false) const
How many bytes does this use Return the number of bytes of storage this variable uses. For scalar types, this is pretty simple (an int32 uses 4 bytes, etc.). For arrays and Constructors, it is a bit more complex. Note that a scalar String variable uses sizeof(String*) bytes, not the length of the string. In other words, the value returned is independent of the type. Also note width() of a String array returns the number of elements in the array times sizeof(String*). That is, each different array size is a different data type.
Definition: UInt64.cc:108
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
Holds a 64-bit (double precision) floating point value.
Definition: Float64.h:60
Holds a single byte.
Definition: Byte.h:60
Holds a 32-bit unsigned integer.
Definition: UInt32.h:59
Holds a 32-bit signed integer.
Definition: Int32.h:65