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"
#if 0
#include "InternalErr.h"
#include "dods-datatypes.h"
#include "dods-limits.h"
#include "util.h"
#endif
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;
static_cast<BaseType &>(*this) = rhs;
m_duplicate(rhs);
return *this;
}
virtual ~D4Enum() { }
virtual D4EnumDef *enumeration() const { return d_enum_def; }
virtual void set_enumeration(D4EnumDef *enum_def);
virtual BaseType *ptr_duplicate() { 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);
}
virtual unsigned int width(bool /* constrained */ = false) const { return /*sizeof(int64_t);*/ m_type_width();}
// DAP4
virtual void compute_checksum(Crc32 &checksum);
virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
virtual void print_val(ostream &out, string space = "", bool print_decl_p = true);
virtual void print_xml_writer(XMLWriter &xml, bool constrained);
virtual bool ops(BaseType *b, int op);
virtual void dump(ostream &strm) const;
unsigned int val2buf(void *, bool);
unsigned int buf2val(void **);
virtual std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table);
};
} // namespace libdap
#endif // _D4Enum_h
Crc32
Definition: crc.h:77
libdap::AttrTable
Contains the attributes for a dataset.
Definition: AttrTable.h:143
libdap::BaseType
The basic data type for the DODS DAP types.
Definition: BaseType.h:118
libdap::BaseType::name
virtual string name() const
Returns the name of the class instance.
Definition: BaseType.cc:320
libdap::BaseType::dataset
virtual string dataset() const
Returns the name of the dataset used to create this instance.
Definition: BaseType.cc:358
libdap::BaseType::BaseType
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition: BaseType.cc:126
libdap::BaseType::type
virtual Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:365
libdap::D4EnumDef
Definition: D4EnumDefs.h:42
libdap::D4Enum
Holds a DAP4 enumeration.
Definition: D4Enum.h:62
libdap::D4Enum::transform_to_dap2
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
Convert an Enum to a DAP2 int type.
Definition: D4Enum.cc:92
libdap::D4Enum::ops
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
Definition: D4Enum.cc:647
libdap::D4Enum::deserialize
virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr)
Definition: D4Enum.cc:437
libdap::D4Enum::serialize
virtual void serialize(D4StreamMarshaller &m, DMR &dmr, bool filter=false)
Serialize a D4Enum Use the (integer) data type associated with an Enumeration definition to serialize...
Definition: D4Enum.cc:399
libdap::D4Enum::compute_checksum
virtual void compute_checksum(Crc32 &checksum)
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition: D4Enum.cc:323
libdap::D4Enum::buf2val
unsigned int buf2val(void **)
Reads the class data.
Definition: D4Enum.cc:534
libdap::D4Enum::dump
virtual void dump(ostream &strm) const
dumps information about this object
Definition: D4Enum.cc:695
libdap::D4Enum::width
virtual unsigned int width(bool=false) const
Return the number of bytes in an instance of an Enum. This returns the number of bytes an instance of...
Definition: D4Enum.h:175
libdap::D4Enum::ptr_duplicate
virtual BaseType * ptr_duplicate()
Definition: D4Enum.h:124
libdap::D4Enum::print_val
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: D4Enum.cc:581
libdap::D4Enum::print_xml_writer
virtual void print_xml_writer(XMLWriter &xml, bool constrained)
Definition: D4Enum.cc:612
libdap::D4Enum::val2buf
unsigned int val2buf(void *, bool)
Loads class data.
Definition: D4Enum.cc:495
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:154
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:140
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:55
libdap::XMLWriter
Definition: XMLWriter.h:39
libdap
top level DAP object to house generic methods
Definition: AlarmHandler.h:36
libdap::Type
Type
Identifies the data type.
Definition: Type.h:94