Float64.cc

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

Generated on Tue Mar 4 18:01:54 2008 for libdap++ by  doxygen 1.5.1