33 #include <libxml/encoding.h> 44 #include "D4EnumDefs.h" 45 #include "D4Attributes.h" 50 #include "D4StreamMarshaller.h" 51 #include "D4StreamUnMarshaller.h" 53 #include "Operators.h" 54 #include "InternalErr.h" 55 #include "dods-datatypes.h" 56 #include "dods-limits.h" 66 void D4Enum::m_duplicate(
const D4Enum &src)
69 d_element_type = src.d_element_type;
70 d_enum_def = src.d_enum_def;
74 d_enum_def = src.d_enum_def == 0 ? 0 :
new D4EnumDef(*(src.d_enum_def));
76 d_is_signed = src.d_is_signed;
79 void D4Enum::m_check_value(int64_t v)
const 81 switch (d_element_type) {
84 if ((uint64_t)v > DODS_UCHAR_MAX || v < 0) {
86 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
87 throw Error(oss.str());
91 if ((uint64_t)v > DODS_USHRT_MAX || v < 0) {
93 oss <<
"The value " << v <<
" will not fit in an unsigned 16-bit integer. (" << __func__ <<
")";
94 throw Error(oss.str());
98 if ((uint64_t)v > DODS_UINT_MAX || v < 0) {
100 oss <<
"The value " << v <<
" will not fit in an unsigned 32-bit integer. (" << __func__ <<
")";
101 throw Error(oss.str());
109 if (v > DODS_SCHAR_MAX || v < DODS_SCHAR_MIN) {
111 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
112 throw Error(oss.str());
117 if (v > DODS_SHRT_MAX || v < DODS_SHRT_MIN) {
119 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
120 throw Error(oss.str());
124 if (v > DODS_INT_MAX || v < DODS_INT_MIN) {
126 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
127 throw Error(oss.str());
134 assert(!
"illegal type for D4Enum");
138 D4Enum::D4Enum(
const string &
name,
const string &enum_type) :
139 BaseType(name, dods_enum_c, true ), d_buf(0), d_element_type(dods_null_c), d_enum_def(0)
141 d_element_type =
get_type(enum_type.c_str());
144 set_is_signed(d_element_type);
147 D4Enum::D4Enum(
const string &name,
Type type) :
148 BaseType(name, dods_enum_c, true ), d_buf(0), d_element_type(type), d_enum_def(0)
151 set_is_signed(d_element_type);
154 D4Enum::D4Enum(
const string &name,
const string &dataset,
Type type) :
155 BaseType(name, dataset, dods_enum_c, true ), d_buf(0), d_element_type(type), d_enum_def(0)
158 set_is_signed(d_element_type);
166 template void D4Enum::value<dods_byte>(dods_byte *v)
const;
167 template void D4Enum::value<dods_int16>(dods_int16 *v)
const;
168 template void D4Enum::value<dods_uint16>(dods_uint16 *v)
const;
169 template void D4Enum::value<dods_int32>(dods_int32 *v)
const;
170 template void D4Enum::value<dods_uint32>(dods_uint32 *v)
const;
171 template void D4Enum::value<dods_int64>(dods_int64 *v)
const;
172 template void D4Enum::value<dods_uint64>(dods_uint64 *v)
const;
174 template void D4Enum::set_value<dods_byte>(dods_byte v,
bool check_value);
175 template void D4Enum::set_value<dods_int16>(dods_int16 v,
bool check_value);
176 template void D4Enum::set_value<dods_uint16>(dods_uint16 v,
bool check_value);
177 template void D4Enum::set_value<dods_int32>(dods_int32 v,
bool check_value);
178 template void D4Enum::set_value<dods_uint32>(dods_uint32 v,
bool check_value);
179 template void D4Enum::set_value<dods_int64>(dods_int64 v,
bool check_value);
180 template void D4Enum::set_value<dods_uint64>(dods_uint64 v,
bool check_value);
183 D4Enum::set_enumeration(D4EnumDef *enum_def) {
184 d_enum_def = enum_def;
185 d_element_type = enum_def->type();
191 DBG(cerr << __func__ <<
": element type: " << ::
libdap::type_name(d_element_type) << endl);
193 switch (d_element_type) {
197 dods_byte v =
static_cast<dods_byte
>(d_buf);
198 checksum.
AddData(reinterpret_cast<uint8_t*>(&v),
sizeof(uint8_t));
203 dods_int16 v =
static_cast<dods_int16
>(d_buf);
204 checksum.
AddData(reinterpret_cast<uint8_t*>(&v),
sizeof(uint16_t));
209 dods_int32 v =
static_cast<dods_int32
>(d_buf);
210 checksum.
AddData(reinterpret_cast<uint8_t*>(&v),
sizeof(uint32_t));
215 checksum.
AddData(reinterpret_cast<uint8_t*>(&d_buf),
sizeof(uint64_t));
219 assert(!
"illegal type for D4Enum");
224 D4Enum::set_is_signed(
Type t)
243 assert(!
"illegal type for D4Enum");
244 throw InternalErr(__FILE__, __LINE__,
"Illegal type");
267 switch (d_element_type) {
295 assert(!
"illegal type for D4Enum");
302 switch (d_element_type) {
310 case dods_uint16_c: {
316 case dods_uint32_c: {
322 case dods_uint64_c: {
354 assert(!
"illegal type for D4Enum");
361 throw InternalErr(
"The incoming pointer does not contain any data.");
363 switch (d_element_type) {
366 d_buf = *(dods_byte*)val;
369 d_buf = *(dods_uint16*)val;
372 d_buf = *(dods_uint32*)val;
375 d_buf = *(dods_uint64*)val;
379 d_buf = *(dods_int8*)val;
382 d_buf = *(dods_int16*)val;
385 d_buf = *(dods_int32*)val;
388 d_buf = *(dods_int64*)val;
391 assert(!
"illegal type for D4Enum");
402 switch (d_element_type) {
405 if (!*val) *val =
new dods_byte;
406 *(dods_byte *) * val = d_buf;
409 if (!*val) *val =
new dods_uint16;
410 *(dods_uint16 *) * val = d_buf;
413 if (!*val) *val =
new dods_uint32;
414 *(dods_uint32 *) * val = d_buf;
417 if (!*val) *val =
new dods_uint64;
418 *(dods_uint64 *) * val = d_buf;
422 if (!*val) *val =
new dods_int8;
423 *(dods_int8*) * val = d_buf;
426 if (!*val) *val =
new dods_int16;
427 *(dods_int16 *) * val = d_buf;
430 if (!*val) *val =
new dods_int32;
431 *(dods_int32 *) * val = d_buf;
434 if (!*val) *val =
new dods_int64;
435 *(dods_int64 *) * val = d_buf;
438 assert(!
"illegal type for D4Enum");
447 print_decl(out, space,
false);
451 DBG(cerr <<
"Enum union value: " << hex << d_buf << dec << endl);
477 if (constrained && !send_p())
480 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Enum") < 0)
481 throw InternalErr(__FILE__, __LINE__,
"Could not write Enum element");
484 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)name().c_str()) < 0)
485 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
488 string path = d_enum_def->name();
492 if (d_enum_def->parent()) {
494 path =
static_cast<D4Group*
>(d_enum_def->parent()->parent())->FQN() + path;
496 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"enum", (
const xmlChar*)path.c_str()) < 0)
497 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for enum");
499 attributes()->print_dap4(xml);
501 if (get_attr_table().get_size() > 0)
502 get_attr_table().print_xml_writer(xml);
504 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
505 throw InternalErr(__FILE__, __LINE__,
"Could not end Enum element");
513 if (!read_p() && !read())
514 throw InternalErr(__FILE__, __LINE__,
"This value not read!");
518 throw InternalErr(__FILE__, __LINE__,
"This value not read!");
522 return Cmp<dods_int64, dods_int8>(op, d_buf,
static_cast<Int8*
>(b)->value());
524 return SUCmp<dods_int64, dods_byte>(op, d_buf,
static_cast<Byte*
>(b)->value());
526 return Cmp<dods_int64, dods_int16>(op, d_buf,
static_cast<Int16*
>(b)->value());
528 return SUCmp<dods_int64, dods_uint16>(op, d_buf,
static_cast<UInt16*
>(b)->value());
530 return Cmp<dods_int64, dods_int32>(op, d_buf,
static_cast<Int32*
>(b)->value());
532 return SUCmp<dods_int64, dods_uint32>(op, d_buf,
static_cast<UInt32*
>(b)->value());
536 return Cmp<dods_int64, dods_int64>(op, d_buf,
static_cast<D4Enum*
>(b)->value());
538 return SUCmp<dods_int64, dods_uint64>(op, d_buf,
static_cast<D4Enum*
>(b)->value());
541 return Cmp<dods_int64, dods_float32>(op, d_buf,
static_cast<Float32*
>(b)->value());
543 return Cmp<dods_int64, dods_float64>(op, d_buf,
static_cast<Float64*
>(b)->value());
562 strm << DapIndent::LMarg <<
"D4Enum::dump - (" << (
void *)
this <<
")" << endl;
565 strm << DapIndent::LMarg <<
"value: " << d_buf << endl;
566 DapIndent::UnIndent();
virtual bool read()
Read data into a local buffer.
Holds an 8-bit signed integer value.
virtual bool read_p()
Has this variable been read?
virtual string name() const
Returns the name of the class instance.
virtual void dump(ostream &strm) const
dumps information about this object
unsigned int val2buf(void *, bool)
Loads class data.
Read data from the stream made by D4StreamMarshaller.
Holds an unsigned 16-bit integer.
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Type
Identifies the data type.
Holds a 32-bit floating point value.
A class for software fault reporting.
Holds a DAP4 enumeration.
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...
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Holds a 16-bit signed integer value.
virtual void dump(ostream &strm) const
dumps information about this object
virtual Type type() const
Returns the type of the class instance.
ObjectType get_type(const string &value)
virtual void compute_checksum(Crc32 &checksum)
include the data for this variable in the checksum DAP4 includes a checksum with every data response...
void AddData(const uint8_t *pData, const uint32_t length)
virtual void deserialize(D4StreamUnMarshaller &um, DMR &dmr)
virtual void print_xml_writer(XMLWriter &xml, bool constrained)
The basic data type for the DODS DAP types.
Holds a 64-bit (double precision) floating point value.
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
Holds a 32-bit unsigned integer.
unsigned int buf2val(void **)
Reads the class data.
Holds a 32-bit signed integer.
bool is_integer_type(Type t)