33#include <libxml/encoding.h>
59#include "dods-datatypes.h"
69void D4Enum::m_duplicate(
const D4Enum &src) {
71 d_element_type = src.d_element_type;
72 d_enum_def = src.d_enum_def;
76 d_enum_def = src.d_enum_def == 0 ? 0 :
new D4EnumDef(*(src.d_enum_def));
78 d_is_signed = src.d_is_signed;
93 DBG(cerr << __func__ <<
"() - BEGIN" << endl;);
95 switch (d_element_type) {
156 oss <<
"Unknown D4Enum type:" << d_element_type <<
", name: " <<
name() << endl;
161 DBG(cerr << __func__ <<
"() - Processing Enum type:" << btp->
type_name() <<
" name: " << btp->
name() << endl;);
176 this->
value(&my_value);
178 DBG(cerr << __func__ <<
"() - value: " << my_value << endl;);
180 string my_label =
"";
186 while (dIter != dEnd) {
187 long long a_value = (*dIter).value;
188 string a_label = (*dIter).label;
191 DBG(cerr << __func__ <<
"() - a_value: " << a_value << endl;);
193 if (a_value == my_value) {
194 my_label = (*dIter).label;
199 if (!my_label.empty())
204 vector<BaseType *> *result =
new vector<BaseType *>();
205 result->push_back(btp);
206 DBG(cerr << __func__ <<
"() - END" << endl;);
210void D4Enum::m_check_value(int64_t v)
const {
211 switch (d_element_type) {
216 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
217 throw Error(oss.str());
223 oss <<
"The value " << v <<
" will not fit in an unsigned 16-bit integer. (" << __func__ <<
")";
224 throw Error(oss.str());
230 oss <<
"The value " << v <<
" will not fit in an unsigned 32-bit integer. (" << __func__ <<
")";
231 throw Error(oss.str());
241 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
242 throw Error(oss.str());
249 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
250 throw Error(oss.str());
256 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
257 throw Error(oss.str());
264 assert(!
"illegal type for D4Enum");
268D4Enum::D4Enum(
const string &
name,
const string &enum_type)
270 d_element_type =
get_type(enum_type.c_str());
313 d_enum_def = enum_def;
314 d_element_type = enum_def->
type();
320 switch (d_element_type) {
325 checksum.
AddData(
reinterpret_cast<uint8_t *
>(&v),
sizeof(uint8_t));
331 checksum.
AddData(
reinterpret_cast<uint8_t *
>(&v),
sizeof(uint16_t));
337 checksum.
AddData(
reinterpret_cast<uint8_t *
>(&v),
sizeof(uint32_t));
342 checksum.
AddData(
reinterpret_cast<uint8_t *
>(&
d_buf),
sizeof(uint64_t));
346 assert(!
"illegal type for D4Enum");
371 assert(!
"illegal type for D4Enum");
373 throw InternalErr(__FILE__, __LINE__,
"Illegal type");
393 switch (d_element_type) {
421 assert(!
"illegal type for D4Enum");
426 switch (d_element_type) {
478 assert(!
"illegal type for D4Enum");
484 throw InternalErr(
"The incoming pointer does not contain any data.");
486 switch (d_element_type) {
514 assert(!
"illegal type for D4Enum");
524 switch (d_element_type) {
568 assert(!
"illegal type for D4Enum");
580 DBG(cerr <<
"Enum union value: " << hex <<
d_buf << dec << endl);
603 if (constrained && !
send_p())
606 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar *)
"Enum") < 0)
607 throw InternalErr(__FILE__, __LINE__,
"Could not write Enum element");
610 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"name", (
const xmlChar *)
name().c_str()) < 0)
611 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
613 string path = d_enum_def->name();
617 if (d_enum_def->parent()) {
619 path =
static_cast<D4Group *
>(d_enum_def->parent()->parent())->
FQN() + path;
621 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"enum", (
const xmlChar *)path.c_str()) < 0)
622 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for enum");
629 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
630 throw InternalErr(__FILE__, __LINE__,
"Could not end Enum element");
636 throw InternalErr(__FILE__, __LINE__,
"This value not read!");
640 throw InternalErr(__FILE__, __LINE__,
"This value not read!");
680 strm <<
DapIndent::LMarg <<
"D4Enum::dump - (" << (
void *)
this <<
")" << endl;
void AddData(const uint8_t *pData, const uint32_t length)
Contains the attributes for a dataset.
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
virtual void set_name(const string &n)
Set the name of this attribute table.
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
virtual string get_name() const
Get the name of this attribute table.
void print_xml_writer(XMLWriter &xml)
virtual unsigned int get_size() const
Get the number of entries in this attribute table.
virtual string type_name() const
Returns the type of the class instance as a string.
virtual bool read()
Read data into a local buffer.
virtual AttrTable & get_attr_table()
virtual string name() const
Returns the name of the class instance.
virtual void print_decl(FILE *out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
virtual bool read_p()
Has this variable been read?
virtual string dataset() const
Returns the name of the dataset used to create this instance.
virtual void set_attr_table(const AttrTable &at)
void dump(ostream &strm) const override
dumps information about this object
virtual D4Attributes * attributes()
virtual bool send_p()
Should this variable be sent?
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr)
Returns a pointer to a member of a constructor class.
virtual Type type() const
Returns the type of the class instance.
void print_dap4(XMLWriter &xml) const
void transform_attrs_to_dap2(AttrTable *d2_attr_table)
Copy the attributes from this D4Attributes object to a DAP2 AttrTable.
vector< tuple >::iterator D4EnumValueIter
Holds a DAP4 enumeration.
void print_xml_writer(XMLWriter &xml, bool constrained) override
bool ops(BaseType *b, int op) override
Evaluate relational operators.
std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table) override
Convert an Enum to a DAP2 int type.
void print_val(ostream &out, string space="", bool print_decl_p=true) override
Prints the value of the variable.
unsigned int buf2val(void **) override
Reads the class data.
unsigned int val2buf(void *, bool) override
Loads class data.
void set_is_signed(Type t)
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...
void compute_checksum(Crc32 &checksum) override
include the data for this variable in the checksum DAP4 includes a checksum with every data response....
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...
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...
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...
virtual void set_enumeration(D4EnumDef *enum_def)
void dump(ostream &strm) const override
dumps information about this object
void deserialize(D4StreamUnMarshaller &um, DMR &dmr) override
std::string FQN() const override
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
virtual void put_uint16(dods_uint16 val)
virtual void put_int32(dods_int32 val)
virtual void put_uint64(dods_uint64 val)
virtual void put_byte(dods_byte val)
virtual void put_int8(dods_int8 val)
virtual void put_int64(dods_int64 val)
virtual void put_int16(dods_int16 val)
virtual void put_uint32(dods_uint32 val)
Read data from the stream made by D4StreamMarshaller.
virtual void get_byte(dods_byte &val)
virtual void get_uint64(dods_uint64 &val)
virtual void get_int32(dods_int32 &val)
virtual void get_uint16(dods_uint16 &val)
virtual void get_int16(dods_int16 &val)
virtual void get_int8(dods_int8 &val)
virtual void get_int64(dods_int64 &val)
virtual void get_uint32(dods_uint32 &val)
static ostream & LMarg(ostream &strm)
A class for error processing.
Holds a 32-bit floating point value.
Holds a 64-bit (double precision) floating point value.
Holds a 16-bit signed integer value.
Holds a 32-bit signed integer.
Holds a64-bit signed integer.
Holds an 8-bit signed integer value.
A class for software fault reporting.
Holds an unsigned 16-bit integer.
Holds a 32-bit unsigned integer.
Holds a 64-bit unsigned integer.
xmlTextWriterPtr get_writer() const
unsigned long long get_size(D4Group *grp, bool constrained=false)
top level DAP object to house generic methods
Type
Identifies the data type.
bool Cmp(int op, T1 v1, T2 v2)
bool is_integer_type(Type t)
ObjectType get_type(const string &value)