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 19948 2008-12-03 23:51:12Z jimg $"
00042 };
00043
00044 #include <iomanip>
00045
00046 #include "Float64.h"
00047 #include "DDS.h"
00048 #include "util.h"
00049 #include "parser.h"
00050 #include "Operators.h"
00051 #include "dods-limits.h"
00052 #include "InternalErr.h"
00053
00054
00055 using std::cerr;
00056 using std::endl;
00057
00058 namespace libdap {
00059
00068 Float64::Float64(const string &n)
00069 : BaseType(n, dods_float64_c)
00070 {}
00071
00079 Float64::Float64(const string &n, const string &d)
00080 : BaseType(n, d, dods_float64_c)
00081 {}
00082
00083 Float64::Float64(const Float64 ©_from) : BaseType(copy_from)
00084 {
00085 _buf = copy_from._buf;
00086 }
00087
00088 BaseType *
00089 Float64::ptr_duplicate()
00090 {
00091 return new Float64(*this);
00092 }
00093
00094 Float64 &
00095 Float64::operator=(const Float64 &rhs)
00096 {
00097 if (this == &rhs)
00098 return *this;
00099
00100 dynamic_cast<BaseType &>(*this) = rhs;
00101
00102 _buf = rhs._buf;
00103
00104 return *this;
00105 }
00106
00107 unsigned int
00108 Float64::width()
00109 {
00110 return sizeof(dods_float64);
00111 }
00112
00113 bool
00114 Float64::serialize(ConstraintEvaluator &eval, DDS &dds,
00115 Marshaller &m, bool ce_eval)
00116 {
00117 dds.timeout_on();
00118
00119 if (!read_p())
00120 read();
00121
00122 #if EVAL
00123 if (ce_eval && !eval.eval_selection(dds, dataset()))
00124 return true;
00125 #endif
00126
00127 dds.timeout_off();
00128
00129 m.put_float64( _buf ) ;
00130
00131 return true;
00132 }
00133
00134 bool
00135 Float64::deserialize(UnMarshaller &um, DDS *, bool)
00136 {
00137 um.get_float64( _buf ) ;
00138
00139 return false;
00140 }
00141
00142 unsigned int
00143 Float64::val2buf(void *val, bool)
00144 {
00145
00146
00147
00148
00149 if (!val)
00150 throw InternalErr(__FILE__, __LINE__,
00151 "The incoming pointer does not contain any data.");
00152
00153 _buf = *(dods_float64 *)val;
00154
00155 return width();
00156 }
00157
00158 unsigned int
00159 Float64::buf2val(void **val)
00160 {
00161
00162
00163 if (!val)
00164 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
00165
00166 if (!*val)
00167 *val = new dods_float64;
00168
00169 *(dods_float64 *)*val = _buf;
00170
00171 return width();
00172 }
00173
00179 dods_float64
00180 Float64::value() const
00181 {
00182 return _buf;
00183 }
00184
00185 bool
00186 Float64::set_value(dods_float64 val)
00187 {
00188 _buf = val;
00189 set_read_p(true);
00190
00191 return true;
00192 }
00193
00194 void
00195 Float64::print_val(FILE *out, string space, bool print_decl_p)
00196 {
00197
00198
00199
00200 if (print_decl_p) {
00201 print_decl(out, space, false);
00202 fprintf(out, " = %.15g;\n", _buf) ;
00203 }
00204 else
00205 fprintf(out, "%.15g", _buf) ;
00206 }
00207
00208 void
00209 Float64::print_val(ostream &out, string space, bool print_decl_p)
00210 {
00211
00212
00213
00214 if (print_decl_p) {
00215 print_decl(out, space, false);
00216 out << " = " << std::setprecision( 15 ) << _buf << ";\n" ;
00217 }
00218 else
00219 out << std::setprecision( 15 ) << _buf ;
00220 }
00221
00222 bool
00223 Float64::ops(BaseType *b, int op)
00224 {
00225
00226 if (!read_p() && !read()) {
00227
00228
00229
00230
00231
00232 throw InternalErr(__FILE__, __LINE__, "This value not read!");
00233 }
00234
00235
00236 if (!b->read_p() && !b->read()) {
00237
00238
00239
00240
00241
00242 throw InternalErr(__FILE__, __LINE__, "This value not read!");
00243 }
00244
00245 switch (b->type()) {
00246 case dods_byte_c:
00247 return rops<dods_float64, dods_byte, Cmp<dods_float64, dods_byte> >
00248 (_buf, dynamic_cast<Byte *>(b)->_buf, op);
00249 case dods_int16_c:
00250 return rops<dods_float64, dods_int16, Cmp<dods_float64, dods_int16> >
00251 (_buf, dynamic_cast<Int16 *>(b)->_buf, op);
00252 case dods_uint16_c:
00253 return rops<dods_float64, dods_uint16, Cmp<dods_float64, dods_uint16> >
00254 (_buf, dynamic_cast<UInt16 *>(b)->_buf, op);
00255 case dods_int32_c:
00256 return rops<dods_float64, dods_int32, Cmp<dods_float64, dods_int32> >
00257 (_buf, dynamic_cast<Int32 *>(b)->_buf, op);
00258 case dods_uint32_c:
00259 return rops<dods_float64, dods_uint32, Cmp<dods_float64, dods_uint32> >
00260 (_buf, dynamic_cast<UInt32 *>(b)->_buf, op);
00261 case dods_float32_c:
00262 return rops<dods_float64, dods_float32, Cmp<dods_float64, dods_float32> >
00263 (_buf, dynamic_cast<Float32 *>(b)->_buf, op);
00264 case dods_float64_c:
00265 return rops<dods_float64, dods_float64, Cmp<dods_float64, dods_float64> >
00266 (_buf, dynamic_cast<Float64 *>(b)->_buf, op);
00267 default:
00268 return false;
00269 }
00270 }
00271
00280 void
00281 Float64::dump(ostream &strm) const
00282 {
00283 strm << DapIndent::LMarg << "Float64::dump - ("
00284 << (void *)this << ")" << endl ;
00285 DapIndent::Indent() ;
00286 BaseType::dump(strm) ;
00287 strm << DapIndent::LMarg << "value: " << _buf << endl ;
00288 DapIndent::UnIndent() ;
00289 }
00290
00291 }
00292