libdap++  Updated for version 3.8.2
Float64.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 Float64.
33 //
34 // jhrg 9/7/94
35 
36 #include <iomanip>
37 
38 #include "config.h"
39 
40 static char rcsid[] not_used =
41  {"$Id: Float64.cc 21699 2009-11-05 00:06:01Z jimg $"
42  };
43 
44 #include <iomanip>
45 
46 #include "Byte.h"
47 #include "Int16.h"
48 #include "UInt16.h"
49 #include "Int32.h"
50 #include "UInt32.h"
51 #include "Float32.h"
52 #include "Float64.h"
53 #include "Str.h"
54 #include "Url.h"
55 #include "Array.h"
56 #include "Structure.h"
57 #include "Sequence.h"
58 #include "Grid.h"
59 
60 #include "DDS.h"
61 #include "util.h"
62 #include "parser.h"
63 #include "Operators.h"
64 #include "dods-limits.h"
65 #include "InternalErr.h"
66 
67 
68 using std::cerr;
69 using std::endl;
70 
71 namespace libdap {
72 
81 Float64::Float64(const string &n)
83 {}
84 
92 Float64::Float64(const string &n, const string &d)
93  : BaseType(n, d, dods_float64_c)
94 {}
95 
96 Float64::Float64(const Float64 &copy_from) : BaseType(copy_from)
97 {
98  _buf = copy_from._buf;
99 }
100 
101 BaseType *
103 {
104  return new Float64(*this);
105 }
106 
107 Float64 &
109 {
110  if (this == &rhs)
111  return *this;
112 
113  dynamic_cast<BaseType &>(*this) = rhs;
114 
115  _buf = rhs._buf;
116 
117  return *this;
118 }
119 
120 unsigned int
122 {
123  return sizeof(dods_float64);
124 }
125 
126 bool
128  Marshaller &m, bool ce_eval)
129 {
130  dds.timeout_on();
131 
132  if (!read_p())
133  read(); // read() throws Error and InternalErr
134 
135 #if EVAL
136  if (ce_eval && !eval.eval_selection(dds, dataset()))
137  return true;
138 #endif
139 
140  dds.timeout_off();
141 
142  m.put_float64( _buf ) ;
143 
144  return true;
145 }
146 
147 bool
149 {
150  um.get_float64( _buf ) ;
151 
152  return false;
153 }
154 
155 unsigned int
156 Float64::val2buf(void *val, bool)
157 {
158  // Jose Garcia
159  // This method is public therefore and I believe it has being designed
160  // to be use by read which must be implemented on the surrogated library,
161  // thus if the pointer val is NULL, is an Internal Error.
162  if (!val)
163  throw InternalErr(__FILE__, __LINE__,
164  "The incoming pointer does not contain any data.");
165 
166  _buf = *(dods_float64 *)val;
167 
168  return width();
169 }
170 
171 unsigned int
172 Float64::buf2val(void **val)
173 {
174  // Jose Garcia
175  // The same comment justifying throwing an Error in val2buf applies here.
176  if (!val)
177  throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
178 
179  if (!*val)
180  *val = new dods_float64;
181 
182  *(dods_float64 *)*val = _buf;
183 
184  return width();
185 }
186 
194 {
195  return _buf;
196 }
197 
198 bool
200 {
201  _buf = val;
202  set_read_p(true);
203 
204  return true;
205 }
206 
207 #if FILE_METHODS
208 void
209 Float64::print_val(FILE *out, string space, bool print_decl_p)
210 {
211  // FIX: need to set precision in the printing somehow.
212  // os.precision(DODS_DBL_DIG);
213 
214  if (print_decl_p) {
215  print_decl(out, space, false);
216  fprintf(out, " = %.15g;\n", _buf) ;
217  }
218  else
219  fprintf(out, "%.15g", _buf) ;
220 }
221 #endif
222 
223 void
224 Float64::print_val(ostream &out, string space, bool print_decl_p)
225 {
226  // FIX: need to set precision in the printing somehow.
227  // os.precision(DODS_DBL_DIG);
228 
229  if (print_decl_p) {
230  print_decl(out, space, false);
231  out << " = " << std::setprecision( 15 ) << _buf << ";\n" ;
232  }
233  else
234  out << std::setprecision( 15 ) << _buf ;
235 }
236 
237 bool
239 {
240  // Extract the Byte arg's value.
241  if (!read_p() && !read()) {
242  // Jose Garcia
243  // Since the read method is virtual and implemented outside
244  // libdap++ if we cannot read the data that is the problem
245  // of the user or of whoever wrote the surrogate library
246  // implemeting read therefore it is an internal error.
247  throw InternalErr(__FILE__, __LINE__, "This value not read!");
248  }
249 
250  // Extract the second arg's value.
251  if (!b->read_p() && !b->read()) {
252  // Jose Garcia
253  // Since the read method is virtual and implemented outside
254  // libdap++ if we cannot read the data that is the problem
255  // of the user or of whoever wrote the surrogate library
256  // implemeting read therefore it is an internal error.
257  throw InternalErr(__FILE__, __LINE__, "This value not read!");
258  }
259 
260  switch (b->type()) {
261  case dods_byte_c:
262  return rops<dods_float64, dods_byte, Cmp<dods_float64, dods_byte> >
263  (_buf, dynamic_cast<Byte *>(b)->_buf, op);
264  case dods_int16_c:
265  return rops<dods_float64, dods_int16, Cmp<dods_float64, dods_int16> >
266  (_buf, dynamic_cast<Int16 *>(b)->_buf, op);
267  case dods_uint16_c:
268  return rops<dods_float64, dods_uint16, Cmp<dods_float64, dods_uint16> >
269  (_buf, dynamic_cast<UInt16 *>(b)->_buf, op);
270  case dods_int32_c:
271  return rops<dods_float64, dods_int32, Cmp<dods_float64, dods_int32> >
272  (_buf, dynamic_cast<Int32 *>(b)->_buf, op);
273  case dods_uint32_c:
274  return rops<dods_float64, dods_uint32, Cmp<dods_float64, dods_uint32> >
275  (_buf, dynamic_cast<UInt32 *>(b)->_buf, op);
276  case dods_float32_c:
277  return rops<dods_float64, dods_float32, Cmp<dods_float64, dods_float32> >
278  (_buf, dynamic_cast<Float32 *>(b)->_buf, op);
279  case dods_float64_c:
280  return rops<dods_float64, dods_float64, Cmp<dods_float64, dods_float64> >
281  (_buf, dynamic_cast<Float64 *>(b)->_buf, op);
282  default:
283  return false;
284  }
285 }
286 
295 void
296 Float64::dump(ostream &strm) const
297 {
298  strm << DapIndent::LMarg << "Float64::dump - ("
299  << (void *)this << ")" << endl ;
301  BaseType::dump(strm) ;
302  strm << DapIndent::LMarg << "value: " << _buf << endl ;
304 }
305 
306 } // namespace libdap
307 
virtual bool read()
Read data into a local buffer.
Definition: BaseType.cc:790
virtual bool read_p()
Has this variable been read?
Definition: BaseType.cc:444
static void UnIndent()
Definition: DapIndent.cc:49
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:853
virtual void put_float64(dods_float64 val)=0
virtual unsigned int buf2val(void **val)
Reads the class data.
Definition: Float64.cc:172
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition: Float64.cc:148
#define not_used
Definition: config.h:850
virtual bool set_value(dods_float64 val)
Definition: Float64.cc:199
virtual BaseType * ptr_duplicate()
Definition: Float64.cc:102
Holds an unsigned 16-bit integer.
Definition: UInt16.h:59
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Move data to the net.
Definition: Float64.cc:127
void timeout_off()
Definition: DDS.cc:687
Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:238
virtual dods_float64 value() const
Definition: Float64.cc:193
Holds a 32-bit floating point value.
Definition: Float32.h:61
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:231
bool eval_selection(DDS &dds, const string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator ans is called ...
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
Definition: Float64.cc:238
Holds a 16-bit signed integer value.
Definition: Int16.h:59
double dods_float64
static void Indent()
Definition: DapIndent.cc:43
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BaseType.cc:186
Float64(const string &n)
Definition: Float64.cc:81
virtual unsigned int width()
Returns the size of the class instance data.
Definition: Float64.cc:121
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition: BaseType.cc:483
virtual unsigned int val2buf(void *val, bool reuse=false)
Loads class data.
Definition: Float64.cc:156
void timeout_on()
Definition: DDS.cc:679
Evaluate a constraint expression.
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Float64.cc:296
static ostream & LMarg(ostream &strm)
Definition: DapIndent.cc:78
The basic data type for the DODS DAP types.
Definition: BaseType.h:190
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:53
dods_float64 _buf
Definition: Float64.h:77
Holds a 64-bit (double precision) floating point value.
Definition: Float64.h:62
Holds a single byte.
Definition: Byte.h:63
Float64 & operator=(const Float64 &rhs)
Definition: Float64.cc:108
Holds a 32-bit unsigned integer.
Definition: UInt32.h:61
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: Float64.cc:209
virtual void get_float64(dods_float64 &val)=0
Holds a 32-bit signed integer.
Definition: Int32.h:62