libdap++  Updated for version 3.14.0
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 
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 
73 using std::cerr;
74 using std::endl;
75 
76 namespace libdap {
77 
85 Int64::Int64(const string &n) : BaseType(n, dods_int64_c, true /*is_dap4*/), d_buf(0)
86 {}
87 
95 Int64::Int64(const string &n, const string &d) : BaseType(n, d, dods_int64_c, true /*is_dap4*/), d_buf(0)
96 {}
97 
98 Int64::Int64(const Int64 &copy_from) : BaseType(copy_from)
99 {
100  d_buf = copy_from.d_buf;
101 }
102 
103 BaseType *
105 {
106  return new Int64(*this);
107 }
108 
110 {
111  DBG(cerr << "~Int64" << endl);
112 }
113 
114 Int64 &
116 {
117  if (this == &rhs)
118  return *this;
119 
120  dynamic_cast<BaseType &>(*this) = rhs;
121 
122  d_buf = rhs.d_buf;
123 
124  return *this;
125 }
126 
127 unsigned int
128 Int64::width(bool) const
129 {
130  return sizeof(dods_int64);
131 }
132 
133 void
135 {
136  checksum.AddData(reinterpret_cast<uint8_t*>(&d_buf), sizeof(d_buf));
137 }
138 
147 void
148 Int64::serialize(D4StreamMarshaller &m, DMR &, /*ConstraintEvaluator &,*/ bool)
149 {
150  if (!read_p())
151  read(); // read() throws Error
152 
153  m.put_int64( d_buf ) ;
154 }
155 
156 void
158 {
159  um.get_int64( d_buf ) ;
160 }
161 
164 {
165  return d_buf;
166 }
167 
168 bool
170 {
171  d_buf = i;
172  set_read_p(true);
173 
174  return true;
175 }
176 
177 void Int64::print_val(ostream &out, string space, bool print_decl_p)
178 {
179  if (print_decl_p) {
180  print_decl(out, space, false);
181  out << " = " << d_buf << ";\n";
182  }
183  else
184  out << d_buf;
185 }
186 
187 bool
188 Int64::ops(BaseType *b, int op)
189 {
190  // Get the arg's value.
191  if (!read_p() && !read())
192  throw InternalErr(__FILE__, __LINE__, "This value not read!");
193 
194  // Get the second arg's value.
195  if (!b->read_p() && !b->read())
196  throw InternalErr(__FILE__, __LINE__, "This value not read!");
197 
198  switch (b->type()) {
199  case dods_int8_c:
200  return Cmp<dods_int64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value());
201  case dods_byte_c:
202  return SUCmp<dods_int64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value());
203  case dods_int16_c:
204  return Cmp<dods_int64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value());
205  case dods_uint16_c:
206  return SUCmp<dods_int64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value());
207  case dods_int32_c:
208  return Cmp<dods_int64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value());
209  case dods_uint32_c:
210  return SUCmp<dods_int64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value());
211  case dods_int64_c:
212  return Cmp<dods_int64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value());
213  case dods_uint64_c:
214  return SUCmp<dods_int64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value());
215  case dods_float32_c:
216  return Cmp<dods_int64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value());
217  case dods_float64_c:
218  return Cmp<dods_int64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value());
219  default:
220  return false;
221  }
222 
223  return false;
224 }
225 
234 void
235 Int64::dump(ostream &strm) const
236 {
237  strm << DapIndent::LMarg << "Int64::dump - ("
238  << (void *)this << ")" << endl ;
240  BaseType::dump(strm) ;
241  strm << DapIndent::LMarg << "value: " << d_buf << endl ;
243 }
244 
245 } // namespace libdap
246 
virtual bool read()
Read data into a local buffer.
Definition: BaseType.cc:805
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:421
static void UnIndent()
Definition: DapIndent.cc:51
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:905
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: Int64.cc:128
int64_t dods_int64
Int64 & operator=(const Int64 &rhs)
Definition: Int64.cc:115
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
Definition: Int64.cc:188
Read data from the stream made by D4StreamMarshaller.
virtual void get_int64(dods_int64 &val)
Holds an unsigned 16-bit integer.
Definition: UInt16.h:57
Definition: crc.h:76
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Int64.cc:235
Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:306
Holds a 32-bit floating point value.
Definition: Float32.h:61
A class for software fault reporting.
Definition: InternalErr.h:64
virtual dods_int64 value() const
Definition: Int64.cc:163
#define DBG(x)
Definition: debug.h:58
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Holds a 16-bit signed integer value.
Definition: Int16.h:59
static void Indent()
Definition: DapIndent.cc:45
dods_int64 d_buf
Definition: Int64.h:59
virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false)
Serialize an Int8.
Definition: Int64.cc:148
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BaseType.cc:237
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition: BaseType.cc:454
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:134
virtual bool set_value(dods_int64 i)
Definition: Int64.cc:169
Holds a 64-bit unsigned integer.
Definition: UInt64.h:49
virtual BaseType * ptr_duplicate()
Definition: Int64.cc:104
void AddData(const uint8_t *pData, const uint32_t length)
Definition: crc.h:84
Int64(const string &n)
Definition: Int64.cc:85
static ostream & LMarg(ostream &strm)
Definition: DapIndent.cc:80
virtual ~Int64()
Definition: Int64.cc:109
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
virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr)
Definition: Int64.cc:157
virtual void put_int64(dods_int64 val)
Holds a 32-bit signed integer.
Definition: Int32.h:65