libdap++ Updated for version 3.8.2
|
00001 00002 // -*- mode: c++; c-basic-offset:4 -*- 00003 00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data 00005 // Access Protocol. 00006 00007 // Copyright (c) 2002,2003 OPeNDAP, Inc. 00008 // Author: James Gallagher <jgallagher@opendap.org> 00009 // 00010 // This library is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU Lesser General Public 00012 // License as published by the Free Software Foundation; either 00013 // version 2.1 of the License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 // 00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00025 00026 // (c) COPYRIGHT URI/MIT 1999 00027 // Please read the full copyright statement in the file COPYRIGHT_URI. 00028 // 00029 // Authors: 00030 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu> 00031 00032 // Implementation for Float32. 00033 // 00034 // 3/22/99 jhrg 00035 00036 00037 #include <iomanip> 00038 00039 #include "config.h" 00040 00041 static char rcsid[] not_used = 00042 {"$Id: Float32.cc 21699 2009-11-05 00:06:01Z jimg $" 00043 }; 00044 00045 #include "Byte.h" 00046 #include "Int16.h" 00047 #include "UInt16.h" 00048 #include "Int32.h" 00049 #include "UInt32.h" 00050 #include "Float32.h" 00051 #include "Float64.h" 00052 #include "Str.h" 00053 #include "Url.h" 00054 #include "Array.h" 00055 #include "Structure.h" 00056 #include "Sequence.h" 00057 #include "Grid.h" 00058 00059 #include "DDS.h" 00060 #include "util.h" 00061 #include "parser.h" 00062 #include "Operators.h" 00063 #include "dods-limits.h" 00064 #include "InternalErr.h" 00065 00066 00067 using std::cerr; 00068 using std::endl; 00069 00070 namespace libdap { 00071 00079 Float32::Float32(const string &n) 00080 : BaseType(n, dods_float32_c) 00081 {} 00082 00090 Float32::Float32(const string &n, const string &d) 00091 : BaseType(n, d, dods_float32_c) 00092 {} 00093 00094 Float32::Float32(const Float32 ©_from) : BaseType(copy_from) 00095 { 00096 _buf = copy_from._buf; 00097 } 00098 00099 BaseType * 00100 Float32::ptr_duplicate() 00101 { 00102 return new Float32(*this); 00103 } 00104 00105 Float32 & 00106 Float32::operator=(const Float32 &rhs) 00107 { 00108 if (this == &rhs) 00109 return *this; 00110 00111 dynamic_cast<BaseType &>(*this) = rhs; 00112 00113 _buf = rhs._buf; 00114 00115 return *this; 00116 } 00117 00118 unsigned int 00119 Float32::width() 00120 { 00121 return sizeof(dods_float32); 00122 } 00123 00124 bool 00125 Float32::serialize(ConstraintEvaluator &eval, DDS &dds, 00126 Marshaller &m, bool ce_eval) 00127 { 00128 dds.timeout_on(); 00129 00130 if (!read_p()) 00131 read(); // read() throws Error and InternalErr 00132 00133 #if EVAL 00134 if (ce_eval && !eval.eval_selection(dds, dataset())) 00135 return true; 00136 #endif 00137 00138 dds.timeout_off(); 00139 00140 m.put_float32( _buf ) ; 00141 00142 return true; 00143 } 00144 00145 bool 00146 Float32::deserialize(UnMarshaller &um, DDS *, bool) 00147 { 00148 um.get_float32( _buf ) ; 00149 00150 return false; 00151 } 00152 00153 unsigned int 00154 Float32::val2buf(void *val, bool) 00155 { 00156 // Jose Garcia This method is public I believe it has been 00157 // designed to be used by read which must be implemented in a 00158 // subclass, thus if the pointer val is NULL, is an Internal 00159 // Error. 00160 // Changed to InternalErr. jhrg 00161 if (!val) 00162 throw InternalErr(__FILE__, __LINE__, 00163 "The incoming pointer does not contain any data."); 00164 00165 _buf = *(dods_float32 *)val; 00166 00167 return width(); 00168 } 00169 00170 unsigned int 00171 Float32::buf2val(void **val) 00172 { 00173 // Jose Garcia 00174 // The same comment justifying throwing an Error in val2buf applies here. 00175 if (!val) 00176 throw InternalErr(__FILE__, __LINE__, "NULL pointer."); 00177 00178 if (!*val) 00179 *val = new dods_float32; 00180 00181 *(dods_float32 *)*val = _buf; 00182 00183 return width(); 00184 } 00185 00186 bool 00187 Float32::set_value(dods_float32 f) 00188 { 00189 _buf = f; 00190 set_read_p(true); 00191 00192 return true; 00193 } 00194 00200 dods_float32 00201 Float32::value() const 00202 { 00203 return _buf; 00204 } 00205 00206 #if FILE_METHODS 00207 void 00208 Float32::print_val(FILE *out, string space, bool print_decl_p) 00209 { 00210 // FIX: need to set precision in the printing somehow. 00211 // os.precision(DODS_FLT_DIG); 00212 00213 if (print_decl_p) { 00214 print_decl(out, space, false); 00215 fprintf(out, " = %.6g;\n", _buf) ; 00216 } 00217 else 00218 fprintf(out, "%.6g", _buf) ; 00219 } 00220 #endif 00221 00222 void 00223 Float32::print_val(ostream &out, string space, bool print_decl_p) 00224 { 00225 // FIX: need to set precision in the printing somehow. 00226 // os.precision(DODS_FLT_DIG); 00227 00228 if (print_decl_p) { 00229 print_decl(out, space, false); 00230 out << " = " << std::setprecision( 6 ) << _buf << ";\n" ; 00231 } 00232 else 00233 out << std::setprecision( 6 ) << _buf ; 00234 } 00235 00236 bool 00237 Float32::ops(BaseType *b, int op) 00238 { 00239 // Get this instance's value 00240 if (!read_p() && !read()) { 00241 // Jose Garcia Since the read method is virtual and 00242 // implemented outside libdap++ if we cannot read the data 00243 // that is the problem of whomever wrote the implementation of 00244 // read and therefore it is an internal error. 00245 throw InternalErr(__FILE__, __LINE__, "This value not read!"); 00246 } 00247 00248 // Extract the second arg's value. 00249 if (!b || !(b->read_p() || b->read())) { 00250 throw InternalErr(__FILE__, __LINE__, "This value not read!"); 00251 } 00252 00253 switch (b->type()) { 00254 case dods_byte_c: 00255 return rops<dods_float32, dods_byte, Cmp<dods_float32, dods_byte> > 00256 (_buf, dynamic_cast<Byte *>(b)->_buf, op); 00257 case dods_int16_c: 00258 return rops<dods_float32, dods_int16, Cmp<dods_float32, dods_int16> > 00259 (_buf, dynamic_cast<Int16 *>(b)->_buf, op); 00260 case dods_uint16_c: 00261 return rops<dods_float32, dods_uint16, Cmp<dods_float32, dods_uint16> > 00262 (_buf, dynamic_cast<UInt16 *>(b)->_buf, op); 00263 case dods_int32_c: 00264 return rops<dods_float32, dods_int32, Cmp<dods_float32, dods_int32> > 00265 (_buf, dynamic_cast<Int32 *>(b)->_buf, op); 00266 case dods_uint32_c: 00267 return rops<dods_float32, dods_uint32, Cmp<dods_float32, dods_uint32> > 00268 (_buf, dynamic_cast<UInt32 *>(b)->_buf, op); 00269 case dods_float32_c: 00270 return rops<dods_float32, dods_float32, Cmp<dods_float32, dods_float32> > 00271 (_buf, dynamic_cast<Float32 *>(b)->_buf, op); 00272 case dods_float64_c: 00273 return rops<dods_float32, dods_float64, Cmp<dods_float32, dods_float64> > 00274 (_buf, dynamic_cast<Float64 *>(b)->_buf, op); 00275 default: 00276 return false; 00277 } 00278 } 00279 00288 void 00289 Float32::dump(ostream &strm) const 00290 { 00291 strm << DapIndent::LMarg << "Float32::dump - (" << (void *)this << ")" 00292 << endl ; 00293 DapIndent::Indent() ; 00294 BaseType::dump(strm) ; 00295 strm << DapIndent::LMarg << "value: " << _buf << endl ; 00296 DapIndent::UnIndent() ; 00297 } 00298 00299 } // namespace libdap 00300