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

Generated on Wed May 13 18:06:38 2009 for libdap++ by  doxygen 1.4.7