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

Generated on Fri Nov 30 10:49:12 2007 for libdap++ by  doxygen 1.5.1