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