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