libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4Enum.h
Go to the documentation of this file.
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5// Access Protocol.
6
7// Copyright (c) 2013 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26#ifndef _D4Enum_h
27#define _D4Enum_h 1
28
29#include <cassert>
30
31#include "BaseType.h"
32#include "dods-datatypes.h"
33
34namespace libdap {
35
36class D4EnumDef;
38class Marshaller;
39class UnMarshaller;
40
53class D4Enum : public BaseType {
54 friend class D4EnumTest;
55
56protected:
57 // Use an unsigned 64-bit int. the value() and set_value()
58 // accessors cast to other types as needed, including signed ones.
59 uint64_t d_buf;
60
61private:
62 Type d_element_type;
63 D4EnumDef *d_enum_def; // This is a weak pointer; don't delete
64 bool d_is_signed;
65
66 void m_duplicate(const D4Enum &src);
67 void m_check_value(int64_t v) const;
68
69 unsigned int m_type_width() const {
70 switch (d_element_type) {
71 case dods_byte_c:
72 case dods_int8_c:
73 case dods_uint8_c:
74 return 1;
75 case dods_int16_c:
76 case dods_uint16_c:
77 return 2;
78 case dods_int32_c:
79 case dods_uint32_c:
80 return 4;
81 case dods_int64_c:
82 case dods_uint64_c:
83 return 8;
84 case dods_null_c:
85 default:
86 assert(!"illegal type for D4Enum");
87 return 0;
88 }
89 }
90
91 D4Enum(); // No empty constructor
92
93public:
94 D4Enum(const string &name, const string &enum_type);
95
96 D4Enum(const string &name, Type type);
97
98 D4Enum(const string &name, const string &dataset, Type type);
99
100 D4Enum(const D4Enum &src) : BaseType(src) { m_duplicate(src); }
101
102 D4Enum &operator=(const D4Enum &rhs) {
103 if (this == &rhs)
104 return *this;
106 m_duplicate(rhs);
107 return *this;
108 }
109
110 virtual ~D4Enum() {}
111
112 virtual D4EnumDef *enumeration() const { return d_enum_def; }
113 virtual void set_enumeration(D4EnumDef *enum_def);
114
115 BaseType *ptr_duplicate() override { return new D4Enum(*this); }
116
117 Type element_type() { return d_element_type; }
118 void set_element_type(Type type) { d_element_type = type; }
119
120 bool is_signed() const { return d_is_signed; }
121 void set_is_signed(Type t);
122
131 template <typename T> void value(T *v) const { *v = static_cast<T>(d_buf); }
132
143 template <typename T> void set_value(T v, bool check_value = true) {
144 if (check_value)
145 m_check_value(v);
146 d_buf = static_cast<int64_t>(v);
147 }
148
164 unsigned int width(bool /* constrained */ = false) const override { return (int)m_type_width(); }
165
166 int64_t width_ll(bool /* constrained */ = false) const override { return (int64_t)m_type_width(); }
167
168 // DAP4
169 void compute_checksum(Crc32 &checksum) override;
170 void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false) override;
171 void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override;
172
173 void print_val(ostream &out, string space = "", bool print_decl_p = true) override;
174
175 void print_xml_writer(XMLWriter &xml, bool constrained) override;
176
177 bool ops(BaseType *b, int op) override;
178
179 void dump(ostream &strm) const override;
180
181 unsigned int val2buf(void *, bool) override;
182 unsigned int buf2val(void **) override;
183
184 std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table) override;
185};
186
187} // namespace libdap
188
189#endif // _D4Enum_h
Definition crc.h:43
Contains the attributes for a dataset.
Definition AttrTable.h:150
The basic data type for the DODS DAP types.
Definition BaseType.h:118
BaseType & operator=(const BaseType &rhs)
Definition BaseType.cc:159
virtual string name() const
Returns the name of the class instance.
Definition BaseType.cc:296
virtual string dataset() const
Returns the name of the dataset used to create this instance.
Definition BaseType.cc:326
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition BaseType.cc:124
virtual Type type() const
Returns the type of the class instance.
Definition BaseType.cc:329
Evaluate a constraint expression.
virtual D4EnumDef * enumeration() const
Definition D4Enum.h:112
Type element_type()
Definition D4Enum.h:117
void print_xml_writer(XMLWriter &xml, bool constrained) override
Definition D4Enum.cc:602
bool ops(BaseType *b, int op) override
Evaluate relational operators.
Definition D4Enum.cc:633
virtual ~D4Enum()
Definition D4Enum.h:110
std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table) override
Convert an Enum to a DAP2 int type.
Definition D4Enum.cc:90
friend class D4EnumTest
Definition D4Enum.h:54
void set_element_type(Type type)
Definition D4Enum.h:118
uint64_t d_buf
Definition D4Enum.h:59
BaseType * ptr_duplicate() override
Definition D4Enum.h:115
void print_val(ostream &out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
Definition D4Enum.cc:574
unsigned int buf2val(void **) override
Reads the class data.
Definition D4Enum.cc:520
unsigned int val2buf(void *, bool) override
Loads class data.
Definition D4Enum.cc:482
void set_is_signed(Type t)
Definition D4Enum.cc:350
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
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
Definition D4Enum.cc:317
D4Enum & operator=(const D4Enum &rhs)
Definition D4Enum.h:102
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
int64_t width_ll(bool=false) const override
Definition D4Enum.h:166
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
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
virtual void set_enumeration(D4EnumDef *enum_def)
Definition D4Enum.cc:312
D4Enum(const D4Enum &src)
Definition D4Enum.h:100
bool is_signed() const
Definition D4Enum.h:120
void dump(ostream &strm) const override
dumps information about this object
Definition D4Enum.cc:679
void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override
Definition D4Enum.cc:425
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Read data from the stream made by D4StreamMarshaller.
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
abstract base class used to unmarshall/deserialize dap data objects
top level DAP object to house generic methods
Definition AISConnect.cc:30
Type
Identifies the data type.
Definition Type.h:94
@ dods_uint32_c
Definition Type.h:100
@ dods_int16_c
Definition Type.h:97
@ dods_byte_c
Definition Type.h:96
@ dods_int32_c
Definition Type.h:99
@ dods_int8_c
Definition Type.h:115
@ dods_int64_c
Definition Type.h:118
@ dods_uint64_c
Definition Type.h:119
@ dods_uint16_c
Definition Type.h:98
@ dods_null_c
Definition Type.h:95
@ dods_uint8_c
Definition Type.h:116