libdap++ Updated for version 3.8.2

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