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) 2012 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 #include "config.h" 00027 00028 #include <sstream> 00029 00030 #include "Byte.h" // synonymous with UInt8 and Char 00031 #include "Int8.h" 00032 #include "Int16.h" 00033 #include "UInt16.h" 00034 #include "Int32.h" 00035 #include "UInt32.h" 00036 #include "Int64.h" 00037 #include "UInt64.h" 00038 #include "Float32.h" 00039 #include "Float64.h" 00040 #include "Str.h" 00041 #include "Url.h" 00042 00043 #include "DMR.h" 00044 #include "D4StreamMarshaller.h" 00045 #include "D4StreamUnMarshaller.h" 00046 00047 #include "util.h" 00048 #include "parser.h" 00049 #include "Operators.h" 00050 #include "dods-limits.h" 00051 #include "debug.h" 00052 #include "InternalErr.h" 00053 00054 using std::cerr; 00055 using std::endl; 00056 00057 namespace libdap { 00058 00067 UInt64::UInt64(const string &n) : BaseType(n, dods_uint64_c, true /*is_dap4*/), d_buf(0) 00068 {} 00069 00080 UInt64::UInt64(const string &n, const string &d) : BaseType(n, d, dods_uint64_c, true /*is_dap4*/), d_buf(0) 00081 {} 00082 00083 UInt64::UInt64(const UInt64 ©_from) : BaseType(copy_from) 00084 { 00085 d_buf = copy_from.d_buf; 00086 } 00087 00088 BaseType * 00089 UInt64::ptr_duplicate() 00090 { 00091 return new UInt64(*this); 00092 } 00093 00094 UInt64 & 00095 UInt64::operator=(const UInt64 &rhs) 00096 { 00097 if (this == &rhs) 00098 return *this; 00099 00100 dynamic_cast<BaseType &>(*this) = rhs; 00101 00102 d_buf = rhs.d_buf; 00103 00104 return *this; 00105 } 00106 00107 unsigned int 00108 UInt64::width(bool) const 00109 { 00110 return sizeof(dods_uint64); 00111 } 00112 00113 void 00114 UInt64::compute_checksum(Crc32 &checksum) 00115 { 00116 checksum.AddData(reinterpret_cast<uint8_t*>(&d_buf), sizeof(d_buf)); 00117 } 00118 00127 void 00128 UInt64::serialize(D4StreamMarshaller &m, DMR &, /*ConstraintEvaluator &,*/ bool) 00129 { 00130 if (!read_p()) 00131 read(); // read() throws Error 00132 00133 m.put_uint64( d_buf ) ; 00134 } 00135 00136 void 00137 UInt64::deserialize(D4StreamUnMarshaller &um, DMR &) 00138 { 00139 um.get_uint64( d_buf ) ; 00140 } 00141 00142 dods_uint64 00143 UInt64::value() const 00144 { 00145 return d_buf; 00146 } 00147 00148 bool 00149 UInt64::set_value(dods_uint64 i) 00150 { 00151 d_buf = i; 00152 set_read_p(true); 00153 00154 return true; 00155 } 00156 00157 void 00158 UInt64::print_val(ostream &out, string space, bool print_decl_p) 00159 { 00160 if (print_decl_p) { 00161 print_decl(out, space, false); 00162 out << " = " << d_buf << ";\n" ; 00163 } 00164 else 00165 out << d_buf ; 00166 } 00167 00168 bool 00169 UInt64::ops(BaseType *b, int op) 00170 { 00171 // Extract the Byte arg's value. 00172 if (!read_p() && !read()) 00173 throw InternalErr(__FILE__, __LINE__, "This value was not read!"); 00174 00175 // Extract the second arg's value. 00176 if (!b || !(b->read_p() || b->read())) 00177 throw InternalErr(__FILE__, __LINE__, "This value was not read!"); 00178 00179 switch (b->type()) { 00180 case dods_int8_c: 00181 return USCmp<dods_uint64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value()); 00182 case dods_byte_c: 00183 return Cmp<dods_uint64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value()); 00184 case dods_int16_c: 00185 return USCmp<dods_uint64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value()); 00186 case dods_uint16_c: 00187 return Cmp<dods_uint64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value()); 00188 case dods_int32_c: 00189 return USCmp<dods_uint64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value()); 00190 case dods_uint32_c: 00191 return Cmp<dods_uint64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value()); 00192 case dods_int64_c: 00193 return USCmp<dods_uint64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value()); 00194 case dods_uint64_c: 00195 return Cmp<dods_uint64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value()); 00196 case dods_float32_c: 00197 return USCmp<dods_uint64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value()); 00198 case dods_float64_c: 00199 return USCmp<dods_uint64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value()); 00200 default: 00201 return false; 00202 } 00203 } 00204 00213 void 00214 UInt64::dump(ostream &strm) const 00215 { 00216 strm << DapIndent::LMarg << "UInt32::dump - (" 00217 << (void *)this << ")" << endl ; 00218 DapIndent::Indent() ; 00219 BaseType::dump(strm) ; 00220 strm << DapIndent::LMarg << "value: " << d_buf << endl ; 00221 DapIndent::UnIndent() ; 00222 } 00223 00224 } // namespace libdap 00225