00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <iomanip>
00037
00038 #include "config.h"
00039
00040 static char rcsid[] not_used =
00041 {"$Id: Float64.cc 21699 2009-11-05 00:06:01Z jimg $"
00042 };
00043
00044 #include <iomanip>
00045
00046 #include "Byte.h"
00047 #include "Int16.h"
00048 #include "UInt16.h"
00049 #include "Int32.h"
00050 #include "UInt32.h"
00051 #include "Float32.h"
00052 #include "Float64.h"
00053 #include "Str.h"
00054 #include "Url.h"
00055 #include "Array.h"
00056 #include "Structure.h"
00057 #include "Sequence.h"
00058 #include "Grid.h"
00059
00060 #include "DDS.h"
00061 #include "util.h"
00062 #include "parser.h"
00063 #include "Operators.h"
00064 #include "dods-limits.h"
00065 #include "InternalErr.h"
00066
00067
00068 using std::cerr;
00069 using std::endl;
00070
00071 namespace libdap {
00072
00081 Float64::Float64(const string &n)
00082 : BaseType(n, dods_float64_c)
00083 {}
00084
00092 Float64::Float64(const string &n, const string &d)
00093 : BaseType(n, d, dods_float64_c)
00094 {}
00095
00096 Float64::Float64(const Float64 ©_from) : BaseType(copy_from)
00097 {
00098 _buf = copy_from._buf;
00099 }
00100
00101 BaseType *
00102 Float64::ptr_duplicate()
00103 {
00104 return new Float64(*this);
00105 }
00106
00107 Float64 &
00108 Float64::operator=(const Float64 &rhs)
00109 {
00110 if (this == &rhs)
00111 return *this;
00112
00113 dynamic_cast<BaseType &>(*this) = rhs;
00114
00115 _buf = rhs._buf;
00116
00117 return *this;
00118 }
00119
00120 unsigned int
00121 Float64::width()
00122 {
00123 return sizeof(dods_float64);
00124 }
00125
00126 bool
00127 Float64::serialize(ConstraintEvaluator &eval, DDS &dds,
00128 Marshaller &m, bool ce_eval)
00129 {
00130 dds.timeout_on();
00131
00132 if (!read_p())
00133 read();
00134
00135 #if EVAL
00136 if (ce_eval && !eval.eval_selection(dds, dataset()))
00137 return true;
00138 #endif
00139
00140 dds.timeout_off();
00141
00142 m.put_float64( _buf ) ;
00143
00144 return true;
00145 }
00146
00147 bool
00148 Float64::deserialize(UnMarshaller &um, DDS *, bool)
00149 {
00150 um.get_float64( _buf ) ;
00151
00152 return false;
00153 }
00154
00155 unsigned int
00156 Float64::val2buf(void *val, bool)
00157 {
00158
00159
00160
00161
00162 if (!val)
00163 throw InternalErr(__FILE__, __LINE__,
00164 "The incoming pointer does not contain any data.");
00165
00166 _buf = *(dods_float64 *)val;
00167
00168 return width();
00169 }
00170
00171 unsigned int
00172 Float64::buf2val(void **val)
00173 {
00174
00175
00176 if (!val)
00177 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
00178
00179 if (!*val)
00180 *val = new dods_float64;
00181
00182 *(dods_float64 *)*val = _buf;
00183
00184 return width();
00185 }
00186
00192 dods_float64
00193 Float64::value() const
00194 {
00195 return _buf;
00196 }
00197
00198 bool
00199 Float64::set_value(dods_float64 val)
00200 {
00201 _buf = val;
00202 set_read_p(true);
00203
00204 return true;
00205 }
00206
00207 #if FILE_METHODS
00208 void
00209 Float64::print_val(FILE *out, string space, bool print_decl_p)
00210 {
00211
00212
00213
00214 if (print_decl_p) {
00215 print_decl(out, space, false);
00216 fprintf(out, " = %.15g;\n", _buf) ;
00217 }
00218 else
00219 fprintf(out, "%.15g", _buf) ;
00220 }
00221 #endif
00222
00223 void
00224 Float64::print_val(ostream &out, string space, bool print_decl_p)
00225 {
00226
00227
00228
00229 if (print_decl_p) {
00230 print_decl(out, space, false);
00231 out << " = " << std::setprecision( 15 ) << _buf << ";\n" ;
00232 }
00233 else
00234 out << std::setprecision( 15 ) << _buf ;
00235 }
00236
00237 bool
00238 Float64::ops(BaseType *b, int op)
00239 {
00240
00241 if (!read_p() && !read()) {
00242
00243
00244
00245
00246
00247 throw InternalErr(__FILE__, __LINE__, "This value not read!");
00248 }
00249
00250
00251 if (!b->read_p() && !b->read()) {
00252
00253
00254
00255
00256
00257 throw InternalErr(__FILE__, __LINE__, "This value not read!");
00258 }
00259
00260 switch (b->type()) {
00261 case dods_byte_c:
00262 return rops<dods_float64, dods_byte, Cmp<dods_float64, dods_byte> >
00263 (_buf, dynamic_cast<Byte *>(b)->_buf, op);
00264 case dods_int16_c:
00265 return rops<dods_float64, dods_int16, Cmp<dods_float64, dods_int16> >
00266 (_buf, dynamic_cast<Int16 *>(b)->_buf, op);
00267 case dods_uint16_c:
00268 return rops<dods_float64, dods_uint16, Cmp<dods_float64, dods_uint16> >
00269 (_buf, dynamic_cast<UInt16 *>(b)->_buf, op);
00270 case dods_int32_c:
00271 return rops<dods_float64, dods_int32, Cmp<dods_float64, dods_int32> >
00272 (_buf, dynamic_cast<Int32 *>(b)->_buf, op);
00273 case dods_uint32_c:
00274 return rops<dods_float64, dods_uint32, Cmp<dods_float64, dods_uint32> >
00275 (_buf, dynamic_cast<UInt32 *>(b)->_buf, op);
00276 case dods_float32_c:
00277 return rops<dods_float64, dods_float32, Cmp<dods_float64, dods_float32> >
00278 (_buf, dynamic_cast<Float32 *>(b)->_buf, op);
00279 case dods_float64_c:
00280 return rops<dods_float64, dods_float64, Cmp<dods_float64, dods_float64> >
00281 (_buf, dynamic_cast<Float64 *>(b)->_buf, op);
00282 default:
00283 return false;
00284 }
00285 }
00286
00295 void
00296 Float64::dump(ostream &strm) const
00297 {
00298 strm << DapIndent::LMarg << "Float64::dump - ("
00299 << (void *)this << ")" << endl ;
00300 DapIndent::Indent() ;
00301 BaseType::dump(strm) ;
00302 strm << DapIndent::LMarg << "value: " << _buf << endl ;
00303 DapIndent::UnIndent() ;
00304 }
00305
00306 }
00307