D4Enum.h
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2013 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
#ifndef _D4Enum_h
#define _D4Enum_h 1
#include <cassert>
#include "BaseType.h"
#include "dods-datatypes.h"
namespace libdap {
class D4EnumDef;
class ConstraintEvaluator;
class Marshaller;
class UnMarshaller;
class D4Enum : public BaseType {
friend class D4EnumTest;
protected:
// Use an unsigned 64-bit int. the value() and set_value()
// accessors cast to other types as needed, including signed ones.
uint64_t d_buf;
private:
Type d_element_type;
D4EnumDef *d_enum_def; // This is a weak pointer; don't delete
bool d_is_signed;
void m_duplicate(const D4Enum &src);
void m_check_value(int64_t v) const;
unsigned int m_type_width() const {
switch (d_element_type) {
case dods_byte_c:
case dods_int8_c:
case dods_uint8_c:
return 1;
case dods_int16_c:
case dods_uint16_c:
return 2;
case dods_int32_c:
case dods_uint32_c:
return 4;
case dods_int64_c:
case dods_uint64_c:
return 8;
case dods_null_c:
default:
assert(!"illegal type for D4Enum");
return 0;
}
}
D4Enum(); // No empty constructor
public:
D4Enum(const string &name, const string &enum_type);
D4Enum(const string &name, Type type);
D4Enum(const string &name, const string &dataset, Type type);
D4Enum(const D4Enum &src) : BaseType(src) { m_duplicate(src); }
D4Enum &operator=(const D4Enum &rhs) {
if (this == &rhs)
return *this;
BaseType::operator=(rhs);
m_duplicate(rhs);
return *this;
}
virtual ~D4Enum() {}
virtual D4EnumDef *enumeration() const { return d_enum_def; }
virtual void set_enumeration(D4EnumDef *enum_def);
BaseType *ptr_duplicate() override { return new D4Enum(*this); }
Type element_type() { return d_element_type; }
void set_element_type(Type type) { d_element_type = type; }
bool is_signed() const { return d_is_signed; }
void set_is_signed(Type t);
template <typename T> void value(T *v) const { *v = static_cast<T>(d_buf); }
template <typename T> void set_value(T v, bool check_value = true) {
if (check_value)
m_check_value(v);
d_buf = static_cast<int64_t>(v);
}
unsigned int width(bool /* constrained */ = false) const override { return (int)m_type_width(); }
int64_t width_ll(bool /* constrained */ = false) const override { return (int64_t)m_type_width(); }
// DAP4
void compute_checksum(Crc32 &checksum) override;
void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false) override;
void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override;
void print_val(ostream &out, string space = "", bool print_decl_p = true) override;
void print_xml_writer(XMLWriter &xml, bool constrained) override;
bool ops(BaseType *b, int op) override;
void dump(ostream &strm) const override;
unsigned int val2buf(void *, bool) override;
unsigned int buf2val(void **) override;
std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table) override;
};
} // namespace libdap
#endif // _D4Enum_h
BaseType
Crc32
Definition crc.h:45
libdap::ConstraintEvaluator
Evaluate a constraint expression.
Definition ConstraintEvaluator.h:41
libdap::D4EnumDef
Definition D4EnumDefs.h:42
libdap::D4Enum::print_xml_writer
void print_xml_writer(XMLWriter &xml, bool constrained) override
Definition D4Enum.cc:602
libdap::D4Enum::transform_to_dap2
std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table) override
Convert an Enum to a DAP2 int type.
Definition D4Enum.cc:90
libdap::D4Enum::width
unsigned int width(bool=false) const override
Return the number of bytes in an instance of an Enum. This returns the number of bytes an instance of...
Definition D4Enum.h:164
libdap::D4Enum::serialize
void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false) override
Serialize a D4Enum Use the (integer) data type associated with an Enumeration definition to serialize...
Definition D4Enum.cc:389
libdap::D4Enum::set_value
void set_value(T v, bool check_value=true)
Set the value of the Enum Template member function to set the value of the Enum. The libdap library c...
Definition D4Enum.h:143
libdap::D4Enum::value
void value(T *v) const
Get the value of an Enum Get the value of this instance. The caller is responsible for using a type T...
Definition D4Enum.h:131
libdap::D4Enum::dump
void dump(ostream &strm) const override
dumps information about this object
Definition D4Enum.cc:679
libdap::Marshaller
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
libdap::UnMarshaller
abstract base class used to unmarshall/deserialize dap data objects
Definition UnMarshaller.h:53
libdap
top level DAP object to house generic methods
Definition AlarmHandler.h:35
libdap::ptr_duplicate
virtual BaseType * ptr_duplicate()=0
libdap::Type
Type
Identifies the data type.
Definition Type.h:94
libdap::width_ll
virtual int64_t width_ll(bool constrained=false) const
Return the number of bytes needed to hold the array data.
Definition Vector.h:203
libdap::dataset
virtual string dataset() const
Returns the name of the dataset used to create this instance.
Definition BaseType.cc:326