libdap++  Updated for version 3.13.3
UInt64.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) 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 "DAP4StreamMarshaller.h"
44 #include "DAP4StreamUnMarshaller.h"
45 
46 #include "DDS.h"
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 
64 UInt64::UInt64(const string &n)
66 {}
67 
75 UInt64::UInt64(const string &n, const string &d)
76  : BaseType(n, d, dods_uint64_c)
77 {}
78 
79 UInt64::UInt64(const UInt64 &copy_from) : BaseType(copy_from)
80 {
81  d_buf = copy_from.d_buf;
82 }
83 
84 BaseType *
86 {
87  return new UInt64(*this);
88 }
89 
90 UInt64 &
92 {
93  if (this == &rhs)
94  return *this;
95 
96  dynamic_cast<BaseType &>(*this) = rhs;
97 
98  d_buf = rhs.d_buf;
99 
100  return *this;
101 }
102 
103 unsigned int
105 {
106  return sizeof(dods_uint64);
107 }
108 
109 bool
111  Marshaller &m, bool ce_eval)
112 {
113  dds.timeout_on();
114 
115  if (!read_p())
116  read(); // read() throws Error and InternalErr
117 
118 #if EVAL
119  if (ce_eval && !eval.eval_selection(dds, dataset()))
120  return true;
121 #endif
122 
123  dds.timeout_off();
124 
125  static_cast<DAP4StreamMarshaller*>(&m)->put_uint64( d_buf ) ;
126 
127  return true;
128 }
129 
130 bool
132 {
133  // TODO assert
134  static_cast<DAP4StreamUnMarshaller*>(&um)->get_uint64( d_buf ) ;
135 
136  return false;
137 }
138 
141 {
142  return d_buf;
143 }
144 
145 bool
147 {
148  d_buf = i;
149  set_read_p(true);
150 
151  return true;
152 }
153 
154 void
155 UInt64::print_val(FILE *out, string space, bool print_decl_p)
156 {
157  ostringstream oss;
158  print_val(oss, space, print_decl_p);
159  fwrite(oss.str().data(), sizeof(char), oss.str().length(), out);
160 }
161 
162 void
163 UInt64::print_val(ostream &out, string space, bool print_decl_p)
164 {
165  if (print_decl_p) {
166  print_decl(out, space, false);
167  out << " = " << (unsigned int)d_buf << ";\n" ;
168  }
169  else
170  out << (unsigned int)d_buf ;
171 }
172 
173 bool
175 {
176  // Extract the Byte arg's value.
177  if (!read_p() && !read())
178  throw InternalErr(__FILE__, __LINE__, "This value was not read!");
179 
180  // Extract the second arg's value.
181  if (!b || !(b->read_p() || b->read()))
182  throw InternalErr(__FILE__, __LINE__, "This value was not read!");
183 
184  switch (b->type()) {
185  case dods_int8_c:
186  return USCmp<dods_uint64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value());
187  case dods_byte_c:
188  return Cmp<dods_uint64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value());
189  case dods_int16_c:
190  return USCmp<dods_uint64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value());
191  case dods_uint16_c:
192  return Cmp<dods_uint64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value());
193  case dods_int32_c:
194  return USCmp<dods_uint64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value());
195  case dods_uint32_c:
196  return Cmp<dods_uint64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value());
197  case dods_int64_c:
198  return USCmp<dods_uint64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value());
199  case dods_uint64_c:
200  return Cmp<dods_uint64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value());
201  case dods_float32_c:
202  return USCmp<dods_uint64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value());
203  case dods_float64_c:
204  return USCmp<dods_uint64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value());
205  default:
206  return false;
207  }
208 }
209 
218 void
219 UInt64::dump(ostream &strm) const
220 {
221  strm << DapIndent::LMarg << "UInt32::dump - ("
222  << (void *)this << ")" << endl ;
224  BaseType::dump(strm) ;
225  strm << DapIndent::LMarg << "value: " << d_buf << endl ;
227 }
228 
229 } // namespace libdap
230 
virtual bool read()
Read data into a local buffer.
Definition: BaseType.cc:923
Holds a 16-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:579
static void UnIndent()
Definition: DapIndent.cc:51
abstract base class used to unmarshall/deserialize dap data objects
Definition: UnMarshaller.h:54
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:985
Read data from the stream made by DAP4StreamMarshaller.
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
Definition: UInt64.cc:174
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Move data to the net.
Definition: UInt64.cc:110
Holds an unsigned 16-bit integer.
Definition: UInt16.h:57
virtual BaseType * ptr_duplicate()
Definition: UInt64.cc:85
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: UInt64.cc:155
dods_uint64 d_buf
Definition: UInt64.h:55
virtual dods_uint64 value() const
Definition: UInt64.cc:140
void timeout_off()
Definition: DDS.cc:862
Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:282
Holds a 32-bit floating point value.
Definition: Float32.h:59
uint64_t dods_uint64
A class for software fault reporting.
Definition: InternalErr.h:64
string dataset() const
Returns the name of the dataset used to create this instance.
Definition: BaseType.cc:275
bool eval_selection(DDS &dds, const string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator ans is called ...
UInt64(const string &n)
Definition: UInt64.cc:64
Holds a 16-bit signed integer value.
Definition: Int16.h:57
static void Indent()
Definition: DapIndent.cc:45
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BaseType.cc:230
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition: BaseType.cc:618
Holds a 64-bit unsigned integer.
Definition: UInt64.h:49
virtual unsigned int width(bool constrained=false)
Definition: UInt64.cc:104
void timeout_on()
Definition: DDS.cc:854
virtual bool set_value(dods_uint64 val)
Definition: UInt64.cc:146
Evaluate a constraint expression.
UInt64 & operator=(const UInt64 &rhs)
Definition: UInt64.cc:91
static ostream & LMarg(ostream &strm)
Definition: DapIndent.cc:80
The basic data type for the DODS DAP types.
Definition: BaseType.h:199
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:53
Holds a 64-bit (double precision) floating point value.
Definition: Float64.h:60
Holds a single byte.
Definition: Byte.h:60
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
virtual void dump(ostream &strm) const
dumps information about this object
Definition: UInt64.cc:219
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition: UInt64.cc:131
Holds a 32-bit unsigned integer.
Definition: UInt32.h:59
Holds a 32-bit signed integer.
Definition: Int32.h:64