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 1994-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 Float64. 00033 // 00034 // jhrg 9/7/94 00035 00036 #include <iomanip> 00037 00038 #include "config.h" 00039 00040 static char rcsid[] not_used = 00041 {"$Id: Float64.cc 19948 2008-12-03 23:51:12Z 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 00079 Float64::Float64(const string &n, const string &d) 00080 : BaseType(n, d, dods_float64_c) 00081 {} 00082 00083 Float64::Float64(const Float64 ©_from) : BaseType(copy_from) 00084 { 00085 _buf = copy_from._buf; 00086 } 00087 00088 BaseType * 00089 Float64::ptr_duplicate() 00090 { 00091 return new Float64(*this); 00092 } 00093 00094 Float64 & 00095 Float64::operator=(const Float64 &rhs) 00096 { 00097 if (this == &rhs) 00098 return *this; 00099 00100 dynamic_cast<BaseType &>(*this) = rhs; 00101 00102 _buf = rhs._buf; 00103 00104 return *this; 00105 } 00106 00107 unsigned int 00108 Float64::width() 00109 { 00110 return sizeof(dods_float64); 00111 } 00112 00113 bool 00114 Float64::serialize(ConstraintEvaluator &eval, DDS &dds, 00115 Marshaller &m, bool ce_eval) 00116 { 00117 dds.timeout_on(); 00118 00119 if (!read_p()) 00120 read(); // read() throws Error and InternalErr 00121 00122 #if EVAL 00123 if (ce_eval && !eval.eval_selection(dds, dataset())) 00124 return true; 00125 #endif 00126 00127 dds.timeout_off(); 00128 00129 m.put_float64( _buf ) ; 00130 00131 return true; 00132 } 00133 00134 bool 00135 Float64::deserialize(UnMarshaller &um, DDS *, bool) 00136 { 00137 um.get_float64( _buf ) ; 00138 00139 return false; 00140 } 00141 00142 unsigned int 00143 Float64::val2buf(void *val, bool) 00144 { 00145 // Jose Garcia 00146 // This method is public therefore and I believe it has being designed 00147 // to be use by read which must be implemented on the surrogated library, 00148 // thus if the pointer val is NULL, is an Internal Error. 00149 if (!val) 00150 throw InternalErr(__FILE__, __LINE__, 00151 "The incoming pointer does not contain any data."); 00152 00153 _buf = *(dods_float64 *)val; 00154 00155 return width(); 00156 } 00157 00158 unsigned int 00159 Float64::buf2val(void **val) 00160 { 00161 // Jose Garcia 00162 // The same comment justifying throwing an Error in val2buf applies here. 00163 if (!val) 00164 throw InternalErr(__FILE__, __LINE__, "NULL pointer."); 00165 00166 if (!*val) 00167 *val = new dods_float64; 00168 00169 *(dods_float64 *)*val = _buf; 00170 00171 return width(); 00172 } 00173 00179 dods_float64 00180 Float64::value() const 00181 { 00182 return _buf; 00183 } 00184 00185 bool 00186 Float64::set_value(dods_float64 val) 00187 { 00188 _buf = val; 00189 set_read_p(true); 00190 00191 return true; 00192 } 00193 //#if FILE_METHODS 00194 void 00195 Float64::print_val(FILE *out, string space, bool print_decl_p) 00196 { 00197 // FIX: need to set precision in the printing somehow. 00198 // os.precision(DODS_DBL_DIG); 00199 00200 if (print_decl_p) { 00201 print_decl(out, space, false); 00202 fprintf(out, " = %.15g;\n", _buf) ; 00203 } 00204 else 00205 fprintf(out, "%.15g", _buf) ; 00206 } 00207 //#endif 00208 void 00209 Float64::print_val(ostream &out, string space, bool print_decl_p) 00210 { 00211 // FIX: need to set precision in the printing somehow. 00212 // os.precision(DODS_DBL_DIG); 00213 00214 if (print_decl_p) { 00215 print_decl(out, space, false); 00216 out << " = " << std::setprecision( 15 ) << _buf << ";\n" ; 00217 } 00218 else 00219 out << std::setprecision( 15 ) << _buf ; 00220 } 00221 00222 bool 00223 Float64::ops(BaseType *b, int op) 00224 { 00225 // Extract the Byte arg's value. 00226 if (!read_p() && !read()) { 00227 // Jose Garcia 00228 // Since the read method is virtual and implemented outside 00229 // libdap++ if we cannot read the data that is the problem 00230 // of the user or of whoever wrote the surrogate library 00231 // implemeting read therefore it is an internal error. 00232 throw InternalErr(__FILE__, __LINE__, "This value not read!"); 00233 } 00234 00235 // Extract the second arg's value. 00236 if (!b->read_p() && !b->read()) { 00237 // Jose Garcia 00238 // Since the read method is virtual and implemented outside 00239 // libdap++ if we cannot read the data that is the problem 00240 // of the user or of whoever wrote the surrogate library 00241 // implemeting read therefore it is an internal error. 00242 throw InternalErr(__FILE__, __LINE__, "This value not read!"); 00243 } 00244 00245 switch (b->type()) { 00246 case dods_byte_c: 00247 return rops<dods_float64, dods_byte, Cmp<dods_float64, dods_byte> > 00248 (_buf, dynamic_cast<Byte *>(b)->_buf, op); 00249 case dods_int16_c: 00250 return rops<dods_float64, dods_int16, Cmp<dods_float64, dods_int16> > 00251 (_buf, dynamic_cast<Int16 *>(b)->_buf, op); 00252 case dods_uint16_c: 00253 return rops<dods_float64, dods_uint16, Cmp<dods_float64, dods_uint16> > 00254 (_buf, dynamic_cast<UInt16 *>(b)->_buf, op); 00255 case dods_int32_c: 00256 return rops<dods_float64, dods_int32, Cmp<dods_float64, dods_int32> > 00257 (_buf, dynamic_cast<Int32 *>(b)->_buf, op); 00258 case dods_uint32_c: 00259 return rops<dods_float64, dods_uint32, Cmp<dods_float64, dods_uint32> > 00260 (_buf, dynamic_cast<UInt32 *>(b)->_buf, op); 00261 case dods_float32_c: 00262 return rops<dods_float64, dods_float32, Cmp<dods_float64, dods_float32> > 00263 (_buf, dynamic_cast<Float32 *>(b)->_buf, op); 00264 case dods_float64_c: 00265 return rops<dods_float64, dods_float64, Cmp<dods_float64, dods_float64> > 00266 (_buf, dynamic_cast<Float64 *>(b)->_buf, op); 00267 default: 00268 return false; 00269 } 00270 } 00271 00280 void 00281 Float64::dump(ostream &strm) const 00282 { 00283 strm << DapIndent::LMarg << "Float64::dump - (" 00284 << (void *)this << ")" << endl ; 00285 DapIndent::Indent() ; 00286 BaseType::dump(strm) ; 00287 strm << DapIndent::LMarg << "value: " << _buf << endl ; 00288 DapIndent::UnIndent() ; 00289 } 00290 00291 } // namespace libdap 00292