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

Generated on Sat Jan 19 04:05:26 2008 for libdap++ by  doxygen 1.5.4