libdap
Updated for version 3.17.0
|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Int64. 00033 // 00034 // jhrg 9/7/94 00035 00036 00037 #include "config.h" 00038 00039 #include <cassert> 00040 #include <sstream> 00041 00042 #include "Byte.h" // synonymous with UInt8 and Char 00043 #include "Int8.h" 00044 #include "Int16.h" 00045 #include "UInt16.h" 00046 #include "Int32.h" 00047 #include "UInt32.h" 00048 #include "Int64.h" 00049 #include "UInt64.h" 00050 #include "Float32.h" 00051 #include "Float64.h" 00052 #include "Str.h" 00053 #include "Url.h" 00054 00055 #if 0 00056 #include "Array.h" 00057 #include "Structure.h" 00058 #include "Sequence.h" 00059 #include "Grid.h" 00060 #endif 00061 00062 #include "DMR.h" 00063 #include "D4StreamMarshaller.h" 00064 #include "D4StreamUnMarshaller.h" 00065 00066 #include "util.h" 00067 #include "parser.h" 00068 #include "Operators.h" 00069 #include "dods-limits.h" 00070 #include "debug.h" 00071 #include "InternalErr.h" 00072 00073 using std::cerr; 00074 using std::endl; 00075 00076 namespace libdap { 00077 00088 Int64::Int64(const string &n) : BaseType(n, dods_int64_c, true /*is_dap4*/), d_buf(0) 00089 {} 00090 00101 Int64::Int64(const string &n, const string &d) : BaseType(n, d, dods_int64_c, true /*is_dap4*/), d_buf(0) 00102 {} 00103 00104 Int64::Int64(const Int64 ©_from) : BaseType(copy_from) 00105 { 00106 d_buf = copy_from.d_buf; 00107 } 00108 00109 BaseType * 00110 Int64::ptr_duplicate() 00111 { 00112 return new Int64(*this); 00113 } 00114 00115 Int64::~Int64() 00116 { 00117 DBG(cerr << "~Int64" << endl); 00118 } 00119 00120 Int64 & 00121 Int64::operator=(const Int64 &rhs) 00122 { 00123 if (this == &rhs) 00124 return *this; 00125 00126 dynamic_cast<BaseType &>(*this) = rhs; 00127 00128 d_buf = rhs.d_buf; 00129 00130 return *this; 00131 } 00132 00133 unsigned int 00134 Int64::width(bool) const 00135 { 00136 return sizeof(dods_int64); 00137 } 00138 00139 void 00140 Int64::compute_checksum(Crc32 &checksum) 00141 { 00142 checksum.AddData(reinterpret_cast<uint8_t*>(&d_buf), sizeof(d_buf)); 00143 } 00144 00153 void 00154 Int64::serialize(D4StreamMarshaller &m, DMR &, /*ConstraintEvaluator &,*/ bool) 00155 { 00156 if (!read_p()) 00157 read(); // read() throws Error 00158 00159 m.put_int64( d_buf ) ; 00160 } 00161 00162 void 00163 Int64::deserialize(D4StreamUnMarshaller &um, DMR &) 00164 { 00165 um.get_int64( d_buf ) ; 00166 } 00167 00168 dods_int64 00169 Int64::value() const 00170 { 00171 return d_buf; 00172 } 00173 00174 bool 00175 Int64::set_value(dods_int64 i) 00176 { 00177 d_buf = i; 00178 set_read_p(true); 00179 00180 return true; 00181 } 00182 00183 void Int64::print_val(ostream &out, string space, bool print_decl_p) 00184 { 00185 if (print_decl_p) { 00186 print_decl(out, space, false); 00187 out << " = " << d_buf << ";\n"; 00188 } 00189 else 00190 out << d_buf; 00191 } 00192 00193 bool 00194 Int64::ops(BaseType *b, int op) 00195 { 00196 // Get the arg's value. 00197 if (!read_p() && !read()) 00198 throw InternalErr(__FILE__, __LINE__, "This value not read!"); 00199 00200 // Get the second arg's value. 00201 if (!b->read_p() && !b->read()) 00202 throw InternalErr(__FILE__, __LINE__, "This value not read!"); 00203 00204 switch (b->type()) { 00205 case dods_int8_c: 00206 return Cmp<dods_int64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value()); 00207 case dods_byte_c: 00208 return SUCmp<dods_int64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value()); 00209 case dods_int16_c: 00210 return Cmp<dods_int64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value()); 00211 case dods_uint16_c: 00212 return SUCmp<dods_int64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value()); 00213 case dods_int32_c: 00214 return Cmp<dods_int64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value()); 00215 case dods_uint32_c: 00216 return SUCmp<dods_int64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value()); 00217 case dods_int64_c: 00218 return Cmp<dods_int64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value()); 00219 case dods_uint64_c: 00220 return SUCmp<dods_int64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value()); 00221 case dods_float32_c: 00222 return Cmp<dods_int64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value()); 00223 case dods_float64_c: 00224 return Cmp<dods_int64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value()); 00225 default: 00226 return false; 00227 } 00228 00229 return false; 00230 } 00231 00240 void 00241 Int64::dump(ostream &strm) const 00242 { 00243 strm << DapIndent::LMarg << "Int64::dump - (" 00244 << (void *)this << ")" << endl ; 00245 DapIndent::Indent() ; 00246 BaseType::dump(strm) ; 00247 strm << DapIndent::LMarg << "value: " << d_buf << endl ; 00248 DapIndent::UnIndent() ; 00249 } 00250 00251 } // namespace libdap 00252