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