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 18315 2008-03-03 20:14:44Z 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
00072 Float64::Float64(const Float64 ©_from) : BaseType(copy_from)
00073 {
00074 _buf = copy_from._buf;
00075 }
00076
00077 BaseType *
00078 Float64::ptr_duplicate()
00079 {
00080 return new Float64(*this);
00081 }
00082
00083 Float64 &
00084 Float64::operator=(const Float64 &rhs)
00085 {
00086 if (this == &rhs)
00087 return *this;
00088
00089 dynamic_cast<BaseType &>(*this) = rhs;
00090
00091 _buf = rhs._buf;
00092
00093 return *this;
00094 }
00095
00096 unsigned int
00097 Float64::width()
00098 {
00099 return sizeof(dods_float64);
00100 }
00101
00102 bool
00103 Float64::serialize(const string &dataset, ConstraintEvaluator &eval, DDS &dds,
00104 Marshaller &m, bool ce_eval)
00105 {
00106 dds.timeout_on();
00107
00108 if (!read_p())
00109 read(dataset);
00110
00111 #if EVAL
00112 if (ce_eval && !eval.eval_selection(dds, dataset))
00113 return true;
00114 #endif
00115
00116 dds.timeout_off();
00117
00118 m.put_float64( _buf ) ;
00119
00120 return true;
00121 }
00122
00123 bool
00124 Float64::deserialize(UnMarshaller &um, DDS *, bool)
00125 {
00126 um.get_float64( _buf ) ;
00127
00128 return false;
00129 }
00130
00131 unsigned int
00132 Float64::val2buf(void *val, bool)
00133 {
00134
00135
00136
00137
00138 if (!val)
00139 throw InternalErr(__FILE__, __LINE__,
00140 "The incoming pointer does not contain any data.");
00141
00142 _buf = *(dods_float64 *)val;
00143
00144 return width();
00145 }
00146
00147 unsigned int
00148 Float64::buf2val(void **val)
00149 {
00150
00151
00152 if (!val)
00153 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
00154
00155 if (!*val)
00156 *val = new dods_float64;
00157
00158 *(dods_float64 *)*val = _buf;
00159
00160 return width();
00161 }
00162
00168 dods_float64
00169 Float64::value() const
00170 {
00171 return _buf;
00172 }
00173
00174 bool
00175 Float64::set_value(dods_float64 val)
00176 {
00177 _buf = val;
00178 set_read_p(true);
00179
00180 return true;
00181 }
00182
00183 void
00184 Float64::print_val(FILE *out, string space, bool print_decl_p)
00185 {
00186
00187
00188
00189 if (print_decl_p) {
00190 print_decl(out, space, false);
00191 fprintf(out, " = %.15g;\n", _buf) ;
00192 }
00193 else
00194 fprintf(out, "%.15g", _buf) ;
00195 }
00196
00197 void
00198 Float64::print_val(ostream &out, string space, bool print_decl_p)
00199 {
00200
00201
00202
00203 if (print_decl_p) {
00204 print_decl(out, space, false);
00205 out << " = " << std::setprecision( 15 ) << _buf << ";\n" ;
00206 }
00207 else
00208 out << std::setprecision( 15 ) << _buf ;
00209 }
00210
00211 bool
00212 Float64::ops(BaseType *b, int op, const string &dataset)
00213 {
00214
00215 if (!read_p() && !read(dataset)) {
00216
00217
00218
00219
00220
00221 throw InternalErr(__FILE__, __LINE__, "This value not read!");
00222 }
00223
00224
00225 if (!b->read_p() && !b->read(dataset)) {
00226
00227
00228
00229
00230
00231 throw InternalErr(__FILE__, __LINE__, "This value not read!");
00232 }
00233
00234 switch (b->type()) {
00235 case dods_byte_c:
00236 return rops<dods_float64, dods_byte, Cmp<dods_float64, dods_byte> >
00237 (_buf, dynamic_cast<Byte *>(b)->_buf, op);
00238 case dods_int16_c:
00239 return rops<dods_float64, dods_int16, Cmp<dods_float64, dods_int16> >
00240 (_buf, dynamic_cast<Int16 *>(b)->_buf, op);
00241 case dods_uint16_c:
00242 return rops<dods_float64, dods_uint16, Cmp<dods_float64, dods_uint16> >
00243 (_buf, dynamic_cast<UInt16 *>(b)->_buf, op);
00244 case dods_int32_c:
00245 return rops<dods_float64, dods_int32, Cmp<dods_float64, dods_int32> >
00246 (_buf, dynamic_cast<Int32 *>(b)->_buf, op);
00247 case dods_uint32_c:
00248 return rops<dods_float64, dods_uint32, Cmp<dods_float64, dods_uint32> >
00249 (_buf, dynamic_cast<UInt32 *>(b)->_buf, op);
00250 case dods_float32_c:
00251 return rops<dods_float64, dods_float32, Cmp<dods_float64, dods_float32> >
00252 (_buf, dynamic_cast<Float32 *>(b)->_buf, op);
00253 case dods_float64_c:
00254 return rops<dods_float64, dods_float64, Cmp<dods_float64, dods_float64> >
00255 (_buf, dynamic_cast<Float64 *>(b)->_buf, op);
00256 default:
00257 return false;
00258 }
00259 }
00260
00269 void
00270 Float64::dump(ostream &strm) const
00271 {
00272 strm << DapIndent::LMarg << "Float64::dump - ("
00273 << (void *)this << ")" << endl ;
00274 DapIndent::Indent() ;
00275 BaseType::dump(strm) ;
00276 strm << DapIndent::LMarg << "value: " << _buf << endl ;
00277 DapIndent::UnIndent() ;
00278 }
00279
00280 }
00281