libdap Updated for version 3.20.11
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4Enum.h
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
34
35namespace libdap
36{
37
38class D4EnumDef;
39class ConstraintEvaluator;
40class Marshaller;
41class UnMarshaller;
42
55class D4Enum: public BaseType
56{
57 friend class D4EnumTest;
58
59protected:
60 // Use an unsigned 64-bit int. the value() and set_value()
61 // accessors cast to other types as needed, including signed ones.
62 uint64_t d_buf;
63
64private:
65 Type d_element_type;
66 D4EnumDef *d_enum_def; // This is a weak pointer; don't delete
67 bool d_is_signed;
68
69 void m_duplicate(const D4Enum &src);
70 void m_check_value(int64_t v) const;
71
72 unsigned int m_type_width() const {
73 switch(d_element_type) {
74 case dods_byte_c:
75 case dods_int8_c:
76 case dods_uint8_c:
77 return 1;
78 case dods_int16_c:
79 case dods_uint16_c:
80 return 2;
81 case dods_int32_c:
82 case dods_uint32_c:
83 return 4;
84 case dods_int64_c:
85 case dods_uint64_c:
86 return 8;
87 case dods_null_c:
88 default:
89 assert(!"illegal type for D4Enum");
90 return 0;
91 }
92 }
93
94 D4Enum(); // No empty constructor
95
96public:
97 D4Enum(const string &name, const string &enum_type);
98
99 D4Enum(const string &name, Type type);
100
101 D4Enum(const string &name, const string &dataset, Type type);
102
103 D4Enum(const D4Enum &src) : BaseType(src) { m_duplicate(src); }
104
105 D4Enum &operator=(const D4Enum &rhs) {
106 if (this == &rhs)
107 return *this;
108 BaseType::operator=(rhs);
109 m_duplicate(rhs);
110 return *this;
111 }
112
113 virtual ~D4Enum() { }
114
115 virtual D4EnumDef *enumeration() const { return d_enum_def; }
116 virtual void set_enumeration(D4EnumDef *enum_def);
117
118 virtual BaseType *ptr_duplicate() { return new D4Enum(*this); }
119
120 Type element_type() { return d_element_type; }
121 void set_element_type(Type type) { d_element_type = type; }
122
123 bool is_signed() const { return d_is_signed; }
124 void set_is_signed(Type t);
125
134 template<typename T> void value(T *v) const {
135 *v = static_cast<T>(d_buf);
136 }
137
148 template <typename T> void set_value(T v, bool check_value = true)
149 {
150 if (check_value) m_check_value(v);
151 d_buf = static_cast<int64_t>(v);
152 }
153
169 virtual unsigned int width(bool /* constrained */ = false) const { return /*sizeof(int64_t);*/ m_type_width();}
170
171 // DAP4
172 virtual void compute_checksum(Crc32 &checksum);
173 virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
174 virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
175
176 virtual void print_val(ostream &out, string space = "", bool print_decl_p = true);
177
178 virtual void print_xml_writer(XMLWriter &xml, bool constrained);
179
180 virtual bool ops(BaseType *b, int op);
181
182 virtual void dump(ostream &strm) const;
183
184 unsigned int val2buf(void *, bool);
185 unsigned int buf2val(void **);
186
187 virtual std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table);
188
189};
190
191} // namespace libdap
192
193#endif // _D4Enum_h
194
Definition: crc.h:77
Contains the attributes for a dataset.
Definition: AttrTable.h:143
The basic data type for the DODS DAP types.
Definition: BaseType.h:118
virtual string name() const
Returns the name of the class instance.
Definition: BaseType.cc:316
virtual string dataset() const
Returns the name of the dataset used to create this instance.
Definition: BaseType.cc:354
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
Definition: BaseType.cc:126
virtual Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:361
Holds a DAP4 enumeration.
Definition: D4Enum.h:56
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
Convert an Enum to a DAP2 int type.
Definition: D4Enum.cc:92
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
Definition: D4Enum.cc:647
virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr)
Definition: D4Enum.cc:437
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
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
unsigned int buf2val(void **)
Reads the class data.
Definition: D4Enum.cc:534
virtual void dump(ostream &strm) const
dumps information about this object
Definition: D4Enum.cc:695
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:169
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: D4Enum.cc:581
virtual void print_xml_writer(XMLWriter &xml, bool constrained)
Definition: D4Enum.cc:612
unsigned int val2buf(void *, bool)
Loads class data.
Definition: D4Enum.cc:495
virtual BaseType * ptr_duplicate()
Definition: D4Enum.h:118
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:148
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:134
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.
top level DAP object to house generic methods
Definition: AlarmHandler.h:36
Type
Identifies the data type.
Definition: Type.h:94