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