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

Generated on Wed Mar 5 15:27:11 2008 for libdap++ by  doxygen 1.5.4