libdap Updated for version 3.20.8
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#if 0
35#include "InternalErr.h"
36#include "dods-datatypes.h"
37#include "dods-limits.h"
38#include "util.h"
39#endif
40
41namespace libdap
42{
43
44class D4EnumDef;
45class ConstraintEvaluator;
46class Marshaller;
47class UnMarshaller;
48
61class D4Enum: public BaseType
62{
63 friend class D4EnumTest;
64
65protected:
66 // Use an unsigned 64-bit int. the value() and set_value()
67 // accessors cast to other types as needed, including signed ones.
68 uint64_t d_buf;
69
70private:
71 Type d_element_type;
72 D4EnumDef *d_enum_def; // This is a weak pointer; don't delete
73 bool d_is_signed;
74
75 void m_duplicate(const D4Enum &src);
76 void m_check_value(int64_t v) const;
77
78 unsigned int m_type_width() const {
79 switch(d_element_type) {
80 case dods_byte_c:
81 case dods_int8_c:
82 case dods_uint8_c:
83 return 1;
84 case dods_int16_c:
85 case dods_uint16_c:
86 return 2;
87 case dods_int32_c:
88 case dods_uint32_c:
89 return 4;
90 case dods_int64_c:
91 case dods_uint64_c:
92 return 8;
93 case dods_null_c:
94 default:
95 assert(!"illegal type for D4Enum");
96 return 0;
97 }
98 }
99
100 D4Enum(); // No empty constructor
101
102public:
103 D4Enum(const string &name, const string &enum_type);
104
105 D4Enum(const string &name, Type type);
106
107 D4Enum(const string &name, const string &dataset, Type type);
108
109 D4Enum(const D4Enum &src) : BaseType(src) { m_duplicate(src); }
110
111 D4Enum &operator=(const D4Enum &rhs) {
112 if (this == &rhs)
113 return *this;
114 static_cast<BaseType &>(*this) = rhs;
115 m_duplicate(rhs);
116 return *this;
117 }
118
119 virtual ~D4Enum() { }
120
121 virtual D4EnumDef *enumeration() const { return d_enum_def; }
122 virtual void set_enumeration(D4EnumDef *enum_def);
123
124 virtual BaseType *ptr_duplicate() { return new D4Enum(*this); }
125
126 Type element_type() { return d_element_type; }
127 void set_element_type(Type type) { d_element_type = type; }
128
129 bool is_signed() const { return d_is_signed; }
130 void set_is_signed(Type t);
131
140 template<typename T> void value(T *v) const {
141 *v = static_cast<T>(d_buf);
142 }
143
154 template <typename T> void set_value(T v, bool check_value = true)
155 {
156 if (check_value) m_check_value(v);
157 d_buf = static_cast<int64_t>(v);
158 }
159
175 virtual unsigned int width(bool /* constrained */ = false) const { return /*sizeof(int64_t);*/ m_type_width();}
176
177 // DAP4
178 virtual void compute_checksum(Crc32 &checksum);
179 virtual void serialize(D4StreamMarshaller &m, DMR &dmr, /*ConstraintEvaluator &eval,*/ bool filter = false);
180 virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr);
181
182 virtual void print_val(ostream &out, string space = "", bool print_decl_p = true);
183
184 virtual void print_xml_writer(XMLWriter &xml, bool constrained);
185
186 virtual bool ops(BaseType *b, int op);
187
188 virtual void dump(ostream &strm) const;
189
190 unsigned int val2buf(void *, bool);
191 unsigned int buf2val(void **);
192
193 virtual std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table);
194
195};
196
197} // namespace libdap
198
199#endif // _D4Enum_h
200
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:320
virtual string dataset() const
Returns the name of the dataset used to create this instance.
Definition BaseType.cc:358
virtual Type type() const
Returns the type of the class instance.
Definition BaseType.cc:365
Holds a DAP4 enumeration.
Definition D4Enum.h:62
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
Convert an Enum to a DAP2 int type.
Definition D4Enum.cc:92
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:175
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:124
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
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
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
Type
Identifies the data type.
Definition Type.h:94