33 #include <libxml/encoding.h> 46 #include "D4EnumDefs.h" 47 #include "D4Attributes.h" 52 #include "D4StreamMarshaller.h" 53 #include "D4StreamUnMarshaller.h" 55 #include "Operators.h" 56 #include "InternalErr.h" 57 #include "dods-datatypes.h" 58 #include "dods-limits.h" 68 void 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;
90 std::vector<BaseType *> *
94 DBG(cerr << __func__ <<
"() - BEGIN" << endl;);
97 switch (d_element_type) {
106 my_pretty_pony =
var;
115 my_pretty_pony =
var;
124 my_pretty_pony =
var;
133 my_pretty_pony =
var;
142 my_pretty_pony =
var;
151 my_pretty_pony =
var;
160 my_pretty_pony =
var;
166 oss << __func__ <<
"() - ERROR! Unknown D4Enum type:"<< d_element_type <<
" name: " <<
name() << endl;
172 DBG( cerr << __func__ <<
"() - Processing Enum type:"<<
173 my_pretty_pony->
type_name() <<
" name: " << my_pretty_pony->
name() << endl;);
188 this->
value(&my_value);
189 DBG(cerr << __func__ <<
"() - value: "<< my_value << endl;);
195 D4EnumDef::D4EnumValueIter dIter = d_enum_def->value_begin();
196 D4EnumDef::D4EnumValueIter dEnd = d_enum_def->value_end();
198 long long a_value = (*dIter).value;
199 string a_label = (*dIter).label;
202 DBG(cerr << __func__ <<
"() - a_value: "<< a_value << endl;);
204 if(a_value == my_value){
205 my_label = (*dIter).label;
209 if(!my_label.empty())
213 vector<BaseType *> *result =
new vector<BaseType *>();
214 result->push_back(my_pretty_pony);
215 DBG(cerr << __func__ <<
"() - END" << endl;);
219 void D4Enum::m_check_value(int64_t v)
const 221 switch (d_element_type) {
224 if ((uint64_t)v > DODS_UCHAR_MAX || v < 0) {
226 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
227 throw Error(oss.str());
231 if ((uint64_t)v > DODS_USHRT_MAX || v < 0) {
233 oss <<
"The value " << v <<
" will not fit in an unsigned 16-bit integer. (" << __func__ <<
")";
234 throw Error(oss.str());
238 if ((uint64_t)v > DODS_UINT_MAX || v < 0) {
240 oss <<
"The value " << v <<
" will not fit in an unsigned 32-bit integer. (" << __func__ <<
")";
241 throw Error(oss.str());
249 if (v > DODS_SCHAR_MAX || v < DODS_SCHAR_MIN) {
251 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
252 throw Error(oss.str());
257 if (v > DODS_SHRT_MAX || v < DODS_SHRT_MIN) {
259 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
260 throw Error(oss.str());
264 if (v > DODS_INT_MAX || v < DODS_INT_MIN) {
266 oss <<
"The value " << v <<
" will not fit in an unsigned byte. (" << __func__ <<
")";
267 throw Error(oss.str());
274 assert(!
"illegal type for D4Enum");
278 D4Enum::D4Enum(
const string &
name,
const string &enum_type) :
279 BaseType(name, dods_enum_c,
true ), d_buf(0), d_element_type(dods_null_c), d_enum_def(0)
281 d_element_type =
get_type(enum_type.c_str());
284 set_is_signed(d_element_type);
287 D4Enum::D4Enum(
const string &name,
Type type) :
288 BaseType(name, dods_enum_c,
true ), d_buf(0), d_element_type(type), d_enum_def(0)
291 set_is_signed(d_element_type);
294 D4Enum::D4Enum(
const string &name,
const string &
dataset,
Type type) :
295 BaseType(name, dataset, dods_enum_c,
true ), d_buf(0), d_element_type(type), d_enum_def(0)
298 set_is_signed(d_element_type);
306 template void D4Enum::value<dods_byte>(dods_byte *v)
const;
307 template void D4Enum::value<dods_int16>(dods_int16 *v)
const;
308 template void D4Enum::value<dods_uint16>(dods_uint16 *v)
const;
309 template void D4Enum::value<dods_int32>(dods_int32 *v)
const;
310 template void D4Enum::value<dods_uint32>(dods_uint32 *v)
const;
311 template void D4Enum::value<dods_int64>(dods_int64 *v)
const;
312 template void D4Enum::value<dods_uint64>(dods_uint64 *v)
const;
314 template void D4Enum::set_value<dods_byte>(dods_byte v,
bool check_value);
315 template void D4Enum::set_value<dods_int16>(dods_int16 v,
bool check_value);
316 template void D4Enum::set_value<dods_uint16>(dods_uint16 v,
bool check_value);
317 template void D4Enum::set_value<dods_int32>(dods_int32 v,
bool check_value);
318 template void D4Enum::set_value<dods_uint32>(dods_uint32 v,
bool check_value);
319 template void D4Enum::set_value<dods_int64>(dods_int64 v,
bool check_value);
320 template void D4Enum::set_value<dods_uint64>(dods_uint64 v,
bool check_value);
323 D4Enum::set_enumeration(
D4EnumDef *enum_def) {
324 d_enum_def = enum_def;
325 d_element_type = enum_def->type();
331 DBG(cerr << __func__ <<
": element type: " << ::
libdap::type_name(d_element_type) << endl);
333 switch (d_element_type) {
337 dods_byte v =
static_cast<dods_byte
>(d_buf);
338 checksum.
AddData(reinterpret_cast<uint8_t*>(&v),
sizeof(uint8_t));
343 dods_int16 v =
static_cast<dods_int16
>(d_buf);
344 checksum.
AddData(reinterpret_cast<uint8_t*>(&v),
sizeof(uint16_t));
349 dods_int32 v =
static_cast<dods_int32
>(d_buf);
350 checksum.
AddData(reinterpret_cast<uint8_t*>(&v),
sizeof(uint32_t));
355 checksum.
AddData(reinterpret_cast<uint8_t*>(&d_buf),
sizeof(uint64_t));
359 assert(!
"illegal type for D4Enum");
364 D4Enum::set_is_signed(
Type t)
383 assert(!
"illegal type for D4Enum");
384 throw InternalErr(__FILE__, __LINE__,
"Illegal type");
407 switch (d_element_type) {
435 assert(!
"illegal type for D4Enum");
442 switch (d_element_type) {
450 case dods_uint16_c: {
456 case dods_uint32_c: {
462 case dods_uint64_c: {
494 assert(!
"illegal type for D4Enum");
501 throw InternalErr(
"The incoming pointer does not contain any data.");
503 switch (d_element_type) {
506 d_buf = *(dods_byte*)val;
509 d_buf = *(dods_uint16*)val;
512 d_buf = *(dods_uint32*)val;
515 d_buf = *(dods_uint64*)val;
519 d_buf = *(dods_int8*)val;
522 d_buf = *(dods_int16*)val;
525 d_buf = *(dods_int32*)val;
528 d_buf = *(dods_int64*)val;
531 assert(!
"illegal type for D4Enum");
542 switch (d_element_type) {
545 if (!*val) *val =
new dods_byte;
546 *(dods_byte *) * val = d_buf;
549 if (!*val) *val =
new dods_uint16;
550 *(dods_uint16 *) * val = d_buf;
553 if (!*val) *val =
new dods_uint32;
554 *(dods_uint32 *) * val = d_buf;
557 if (!*val) *val =
new dods_uint64;
558 *(dods_uint64 *) * val = d_buf;
562 if (!*val) *val =
new dods_int8;
563 *(dods_int8*) * val = d_buf;
566 if (!*val) *val =
new dods_int16;
567 *(dods_int16 *) * val = d_buf;
570 if (!*val) *val =
new dods_int32;
571 *(dods_int32 *) * val = d_buf;
574 if (!*val) *val =
new dods_int64;
575 *(dods_int64 *) * val = d_buf;
578 assert(!
"illegal type for D4Enum");
591 DBG(cerr <<
"Enum union value: " << hex << d_buf << dec << endl);
617 if (constrained && !
send_p())
620 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Enum") < 0)
621 throw InternalErr(__FILE__, __LINE__,
"Could not write Enum element");
624 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
625 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
628 string path = d_enum_def->name();
632 if (d_enum_def->parent()) {
634 path =
static_cast<D4Group*
>(d_enum_def->parent()->parent())->
FQN() + path;
636 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"enum", (
const xmlChar*)path.c_str()) < 0)
637 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for enum");
644 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
645 throw InternalErr(__FILE__, __LINE__,
"Could not end Enum element");
654 throw InternalErr(__FILE__, __LINE__,
"This value not read!");
658 throw InternalErr(__FILE__, __LINE__,
"This value not read!");
662 return Cmp<dods_int64, dods_int8>(op, d_buf,
static_cast<Int8*
>(b)->
value());
664 return SUCmp<dods_int64, dods_byte>(op, d_buf,
static_cast<Byte*
>(b)->
value());
666 return Cmp<dods_int64, dods_int16>(op, d_buf,
static_cast<Int16*
>(b)->
value());
668 return SUCmp<dods_int64, dods_uint16>(op, d_buf,
static_cast<UInt16*
>(b)->
value());
670 return Cmp<dods_int64, dods_int32>(op, d_buf,
static_cast<Int32*
>(b)->
value());
672 return SUCmp<dods_int64, dods_uint32>(op, d_buf,
static_cast<UInt32*
>(b)->
value());
676 return Cmp<dods_int64, dods_int64>(op, d_buf,
static_cast<D4Enum*
>(b)->
value());
678 return SUCmp<dods_int64, dods_uint64>(op, d_buf,
static_cast<D4Enum*
>(b)->
value());
681 return Cmp<dods_int64, dods_float32>(op, d_buf,
static_cast<Float32*
>(b)->
value());
683 return Cmp<dods_int64, dods_float64>(op, d_buf,
static_cast<Float64*
>(b)->
value());
702 strm << DapIndent::LMarg <<
"D4Enum::dump - (" << (
void *)
this <<
")" << endl;
705 strm << DapIndent::LMarg <<
"value: " << d_buf << endl;
706 DapIndent::UnIndent();
virtual bool read()
Read data into a local buffer.
Holds an 8-bit signed integer value.
Holds a64-bit signed integer.
virtual bool read_p()
Has this variable been read?
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.
AttrTable * get_AttrTable(const std::string name)
copy attributes from DAP4 to DAP2
virtual void dump(ostream &strm) const
dumps information about this object
unsigned int val2buf(void *, bool)
Loads class data.
Contains the attributes for a dataset.
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...
virtual string get_name() const
Get the name of this attribute table.
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.
void print_xml_writer(XMLWriter &xml)
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.
virtual std::string FQN() const
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
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 AttrTable * append_container(const string &name)
Add a container to the attribute table.
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...
virtual bool set_value(const dods_byte value)
virtual std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table)
DAP4 to DAP2 transform.
virtual D4Attributes * attributes()
Holds a 64-bit unsigned integer.
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)
virtual AttrTable & get_attr_table()
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
The basic data type for the DODS DAP types.
virtual string type_name() const
Returns the type of the class instance as a string.
Holds a 64-bit (double precision) floating point value.
virtual void set_attr_table(const AttrTable &at)
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...
A class for error processing.
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
virtual void set_name(const string &n)
Set the name of this attribute table.
Holds a 32-bit unsigned integer.
virtual bool send_p()
Should this variable be sent?
unsigned int buf2val(void **)
Reads the class data.
bool is_integer_type(Type t)
Holds a 32-bit signed integer.
virtual string dataset() const
Returns the name of the dataset used to create this instance.