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