UInt64.cc
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2012 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
#include "config.h"
#include <sstream>
#include "Byte.h" // synonymous with UInt8 and Char
#include "Int8.h"
#include "Int16.h"
#include "UInt16.h"
#include "Int32.h"
#include "UInt32.h"
#include "Int64.h"
#include "UInt64.h"
#include "Float32.h"
#include "Float64.h"
#include "Str.h"
#include "Url.h"
#include "DMR.h"
#include "D4StreamMarshaller.h"
#include "D4StreamUnMarshaller.h"
#include "util.h"
#include "parser.h"
#include "Operators.h"
#include "dods-limits.h"
#include "debug.h"
#include "InternalErr.h"
#include "DapIndent.h"
using std::cerr;
using std::endl;
namespace libdap {
UInt64::UInt64(const string &n) : BaseType(n, dods_uint64_c, true /*is_dap4*/), d_buf(0)
{}
UInt64::UInt64(const string &n, const string &d) : BaseType(n, d, dods_uint64_c, true /*is_dap4*/), d_buf(0)
{}
UInt64::UInt64(const UInt64 &copy_from) : BaseType(copy_from)
{
d_buf = copy_from.d_buf;
}
BaseType *
UInt64::ptr_duplicate()
{
return new UInt64(*this);
}
UInt64 &
UInt64::operator=(const UInt64 &rhs)
{
if (this == &rhs)
return *this;
BaseType::operator=(rhs);
d_buf = rhs.d_buf;
return *this;
}
void
UInt64::compute_checksum(Crc32 &checksum)
{
checksum.AddData(reinterpret_cast<uint8_t*>(&d_buf), sizeof(d_buf));
}
void
UInt64::serialize(D4StreamMarshaller &m, DMR &, /*ConstraintEvaluator &,*/ bool)
{
if (!read_p())
read(); // read() throws Error
m.put_uint64( d_buf ) ;
}
void
UInt64::deserialize(D4StreamUnMarshaller &um, DMR &)
{
um.get_uint64( d_buf ) ;
}
dods_uint64
UInt64::value() const
{
return d_buf;
}
bool
UInt64::set_value(dods_uint64 i)
{
d_buf = i;
set_read_p(true);
return true;
}
unsigned int
UInt64::buf2val(void **val)
{
if (!val)
throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
if (!*val)
*val = new dods_uint64;
*(dods_uint64 *)*val = d_buf;
return width();
}
void
UInt64::print_val(ostream &out, string space, bool print_decl_p)
{
if (print_decl_p) {
print_decl(out, space, false);
out << " = " << d_buf << ";\n" ;
}
else
out << d_buf ;
}
bool
UInt64::ops(BaseType *b, int op)
{
// Extract the Byte arg's value.
if (!read_p() && !read())
throw InternalErr(__FILE__, __LINE__, "This value was not read!");
// Extract the second arg's value.
if (!b || !(b->read_p() || b->read()))
throw InternalErr(__FILE__, __LINE__, "This value was not read!");
switch (b->type()) {
case dods_int8_c:
return Cmp<dods_uint64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value());
case dods_byte_c:
return Cmp<dods_uint64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value());
case dods_int16_c:
return Cmp<dods_uint64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value());
case dods_uint16_c:
return Cmp<dods_uint64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value());
case dods_int32_c:
return Cmp<dods_uint64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value());
case dods_uint32_c:
return Cmp<dods_uint64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value());
case dods_int64_c:
return Cmp<dods_uint64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value());
case dods_uint64_c:
return Cmp<dods_uint64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value());
case dods_float32_c:
return Cmp<dods_uint64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value());
case dods_float64_c:
return Cmp<dods_uint64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value());
default:
return false;
}
}
bool
UInt64::d4_ops(BaseType *b, int op)
{
switch (b->type()) {
case dods_int8_c:
return Cmp<dods_uint64, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value());
case dods_byte_c:
return Cmp<dods_uint64, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value());
case dods_int16_c:
return Cmp<dods_uint64, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value());
case dods_uint16_c:
return Cmp<dods_uint64, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value());
case dods_int32_c:
return Cmp<dods_uint64, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value());
case dods_uint32_c:
return Cmp<dods_uint64, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value());
case dods_int64_c:
return Cmp<dods_uint64, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value());
case dods_uint64_c:
return Cmp<dods_uint64, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value());
case dods_float32_c:
return Cmp<dods_uint64, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value());
case dods_float64_c:
return Cmp<dods_uint64, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value());
default:
return false;
}
}
std::vector<BaseType *> *
UInt64::transform_to_dap2(AttrTable *)
{
#if 0
BaseType *dest = this->ptr_duplicate();
// convert the d4 attributes to a dap2 attribute table.
AttrTable *attrs = this->attributes()->get_AttrTable();
attrs->set_name(name());
dest->set_attr_table(*attrs);
dest->set_is_dap4(false);
// attrs->print(cerr,"",true);
return dest;
#endif
return NULL;
}
bool UInt64::is_dap4_projected(std::vector<string> &inventory)
{
bool has_projected_dap4 = false;
if(send_p()) {
has_projected_dap4 = true;
attributes()->has_dap4_types(FQN(), inventory);
inventory.emplace_back(type_name() + " " + FQN());
}
return has_projected_dap4;
}
void
UInt64::dump(ostream &strm) const
{
strm << DapIndent::LMarg << "UInt32::dump - ("
<< (void *)this << ")" << endl ;
DapIndent::Indent() ;
BaseType::dump(strm) ;
strm << DapIndent::LMarg << "value: " << d_buf << endl ;
DapIndent::UnIndent() ;
}
} // namespace libdap
Crc32
Definition crc.h:79
Crc32::AddData
void AddData(const uint8_t *pData, const uint32_t length)
Definition crc.h:100
libdap::AttrTable
Contains the attributes for a dataset.
Definition AttrTable.h:154
libdap::AttrTable::set_name
virtual void set_name(const string &n)
Set the name of this attribute table.
Definition AttrTable.cc:273
libdap::BaseType
The basic data type for the DODS DAP types.
Definition BaseType.h:120
libdap::BaseType::type_name
virtual string type_name() const
Returns the type of the class instance as a string.
Definition BaseType.cc:376
libdap::BaseType::read
virtual bool read()
Read data into a local buffer.
Definition BaseType.cc:905
libdap::BaseType::name
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:317
libdap::BaseType::print_decl
virtual void print_decl(FILE *out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
Definition BaseType.cc:1009
libdap::BaseType::read_p
virtual bool read_p()
Has this variable been read?
Definition BaseType.cc:477
libdap::BaseType::set_read_p
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition BaseType.cc:513
libdap::BaseType::set_attr_table
virtual void set_attr_table(const AttrTable &at)
Definition BaseType.cc:587
libdap::BaseType::dump
void dump(ostream &strm) const override
dumps information about this object
Definition BaseType.cc:287
libdap::BaseType::attributes
virtual D4Attributes * attributes()
Definition BaseType.cc:596
libdap::BaseType::FQN
virtual std::string FQN() const
Definition BaseType.cc:329
libdap::BaseType::send_p
virtual bool send_p()
Should this variable be sent?
Definition BaseType.cc:551
libdap::BaseType::type
virtual Type type() const
Returns the type of the class instance.
Definition BaseType.cc:362
libdap::Byte
Holds a single byte.
Definition Byte.h:61
libdap::D4Attributes::has_dap4_types
bool has_dap4_types(const std::string &path, std::vector< std::string > &inventory) const
Definition D4Attributes.cc:661
libdap::D4StreamMarshaller
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Definition D4StreamMarshaller.h:71
libdap::D4StreamUnMarshaller
Read data from the stream made by D4StreamMarshaller.
Definition D4StreamUnMarshaller.h:65
libdap::DMR
Definition DMR.h:58
libdap::Float32
Holds a 32-bit floating point value.
Definition Float32.h:62
libdap::Float64
Holds a 64-bit (double precision) floating point value.
Definition Float64.h:61
libdap::Int16
Holds a 16-bit signed integer value.
Definition Int16.h:60
libdap::Int32
Holds a 32-bit signed integer.
Definition Int32.h:66
libdap::Int64
Holds a64-bit signed integer.
Definition Int64.h:50
libdap::Int8
Holds an 8-bit signed integer value.
Definition Int8.h:43
libdap::InternalErr
A class for software fault reporting.
Definition InternalErr.h:65
libdap::UInt16
Holds an unsigned 16-bit integer.
Definition UInt16.h:58
libdap::UInt32
Holds a 32-bit unsigned integer.
Definition UInt32.h:60
libdap::UInt64
Holds a 64-bit unsigned integer.
Definition UInt64.h:50
libdap::UInt64::ops
bool ops(BaseType *b, int op) override
Evaluate relational operators.
Definition UInt64.cc:176
libdap::UInt64::serialize
void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false) override
Serialize an Int8.
Definition UInt64.cc:120
libdap::UInt64::width
unsigned int width(bool=false) const override
How many bytes does this variable use Return the number of bytes of storage this variable uses....
Definition UInt64.h:74
libdap::UInt64::ptr_duplicate
BaseType * ptr_duplicate() override
Definition UInt64.cc:90
libdap::UInt64::d4_ops
bool d4_ops(BaseType *b, int op) override
Evaluator a relop for DAP4.
Definition UInt64.cc:213
libdap::UInt64::deserialize
void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override
Definition UInt64.cc:129
libdap::UInt64::dump
void dump(ostream &strm) const override
dumps information about this object
Definition UInt64.cc:302
libdap::UInt64::transform_to_dap2
std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table) override
DAP4 to DAP2 transform.
Definition UInt64.cc:259
libdap::UInt64::UInt64
UInt64(const string &n)
Definition UInt64.cc:68
libdap::UInt64::compute_checksum
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition UInt64.cc:106
libdap::UInt64::is_dap4_projected
bool is_dap4_projected(std::vector< string > &inventory) override
Definition UInt64.cc:281
libdap
top level DAP object to house generic methods
Definition AlarmHandler.h:36