105 throw InternalErr(__FILE__, __LINE__,
"Unsupported attribute type");
112 if (s ==
"container")
115 else if (s ==
"byte")
117 else if (s ==
"int8")
119 else if (s ==
"uint8")
121 else if (s ==
"int16")
123 else if (s ==
"uint16")
125 else if (s ==
"int32")
127 else if (s ==
"uint32")
129 else if (s ==
"int64")
131 else if (s ==
"uint64")
134 else if (s ==
"float32")
136 else if (s ==
"float64")
139 else if (s ==
"string")
143 else if (s ==
"otherxml")
149void D4Attribute::m_duplicate(
const D4Attribute &src) {
152 d_values = src.d_values;
153 if (src.d_attributes)
154 d_attributes =
new D4Attributes(*src.d_attributes);
260 throw InternalErr(__FILE__, __LINE__,
"Unknown DAP2 attribute type in D4Attributes::copy_from_dap2()");
322 throw InternalErr(__FILE__, __LINE__,
"Unknown DAP4 attribute.");
334 string name = (*i)->name();
335 D4AttributeType d4_attr_type = (*i)->type();
339 switch (d4_attr_type) {
344 (*i)->attributes()->transform_attrs_to_dap2(child_attr_table);
350 d2_attr_table->
append_attr(name, d2_attr_type_name, *vi, (*i)->get_utf8_str_flag());
373 string name = (*i)->name();
374 D4AttributeType d4_attr_type = (*i)->type();
381 vector<string> values;
382 for (; vitr != end; vitr++) {
383 values.push_back((*vitr));
387 switch (d4_attr_type) {
390 AttrTable *child_attr_table =
new AttrTable();
391 child_attr_table->set_name(name);
393 load_AttrTable(child_attr_table, (*i)->attributes());
399 d2_attr_table->
append_attr(name, d2_attr_type_name, *vi);
416AttrTable *D4Attributes::get_AttrTable(
const string name)
418 AttrTable *at =
new AttrTable();
421 load_AttrTable(at,
this);
428D4Attribute *D4Attributes::find_depth_first(
const string &name, D4AttributesIter i) {
431 else if ((*i)->name() == name)
434 return find_depth_first(name, (*i)->attributes()->attribute_begin());
436 return find_depth_first(name, ++i);
448 size_t pos = fqn.find(
'.');
449 string part = fqn.substr(0, pos);
452 if (pos != string::npos)
453 rest = fqn.substr(pos + 1);
455 DBG(cerr <<
"part: '" << part <<
"'; rest: '" << rest <<
"'" << endl);
462 return (*i)->attributes()->get(rest);
468 if ((*i)->name() == part)
487 for (
auto &attr : d_attrs) {
488 if (attr->name() == name) {
493 d_attrs.erase(remove(d_attrs.begin(), d_attrs.end(),
nullptr), d_attrs.end());
504 size_t pos = fqn.find(
'.');
505 string part = fqn.substr(0, pos);
508 if (pos != string::npos)
509 rest = fqn.substr(pos + 1);
515 for (
auto &a : d_attrs) {
517 a->attributes()->erase(rest);
527 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar *)
"Attribute") < 0)
528 throw InternalErr(__FILE__, __LINE__,
"Could not write Attribute element");
529 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"name", (
const xmlChar *)
name().c_str()) < 0)
530 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
531 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"type",
533 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for type");
539 d_attributes->print_dap4(xml);
544 throw Error(
"OtherXML attributes cannot be vector-valued.");
545 if (xmlTextWriterWriteRaw(xml.
get_writer(), (
const xmlChar *)
value(0).c_str()) < 0)
546 throw InternalErr(__FILE__, __LINE__,
"Could not write OtherXML value");
558 auto i = d_values.begin();
559 while (i != d_values.end()) {
560 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar *)
"Value") < 0)
561 throw InternalErr(__FILE__, __LINE__,
"Could not write value element");
563 if (xmlTextWriterWriteString(xml.
get_writer(), (
const xmlChar*) (*i++).c_str()) < 0)
566 if (xmlTextWriterWriteString(xml.
get_writer(), (
const xmlChar *)s.c_str()) < 0)
567 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute value");
569 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
570 throw InternalErr(__FILE__, __LINE__,
"Could not end value element");
578 while (i != d_values.end()) {
579 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar *)
"Value") < 0)
580 throw InternalErr(__FILE__, __LINE__,
"Could not write value element");
582 if (xmlTextWriterWriteString(xml.
get_writer(), (
const xmlChar *)(*i++).c_str()) < 0)
583 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute value");
585 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
586 throw InternalErr(__FILE__, __LINE__,
"Could not end value element");
593 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
594 throw InternalErr(__FILE__, __LINE__,
"Could not end Attribute element");
606 strm <<
DapIndent::LMarg <<
"D4Attribute::dump - (" << (
void *)
this <<
")" << endl;
622 while (i != d_attrs.end()) {
634 bool ima_d4_attr =
false;
657 bool has_d4_attr =
false;
659 string attr_fqn = path +
"@" + attr->name();
660 bool isa_d4_attr = attr->is_dap4_type(attr_fqn, inventory);
664 has_d4_attr |= isa_d4_attr;
678 strm <<
DapIndent::LMarg <<
"D4Attributes::dump - (" << (
void *)
this <<
")" << endl;
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 AttrTable * get_attr_table(const string &name)
Get an attribute container.
virtual Attr_iter attr_end()
virtual vector< string > * get_attr_vector(const string &name)
Get a vector-valued attribute.
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
virtual Attr_iter attr_begin()
virtual string get_name() const
Get the name of this attribute table.
std::vector< entry * >::iterator Attr_iter
virtual AttrType get_attr_type(const string &name)
Get the type of an attribute.
D4Attributes * attributes()
bool is_dap4_type(const std::string &path, std::vector< std::string > &inventory)
void add_value_vector(const vector< string > &values)
void print_dap4(XMLWriter &xml) const
vector< string >::const_iterator D4AttributeCIter
D4Attribute & operator=(const D4Attribute &rhs)
unsigned int num_values() const
bool get_utf8_str_flag() const
string value(unsigned int i) const
vector< string >::iterator D4AttributeIter
void set_utf8_str_flag(bool utf8_str_flag)
virtual void dump(ostream &strm) const
dumps information about this object
D4AttributeType type() const
void erase(const string &fqn)
Erase the given attribute.
D4Attribute * find(const string &name)
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
D4Attribute * get(const string &fqn)
void add_attribute_nocopy(D4Attribute *attr)
const vector< D4Attribute * > & attributes() const
D4AttributesIter attribute_begin()
Get an iterator to the start of the enumerations.
D4AttributesIter attribute_end()
Get an iterator to the end of the enumerations.
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.
bool has_dap4_types(const std::string &path, std::vector< std::string > &inventory) const
virtual void dump(ostream &strm) const
dumps information about this object
void erase_named_attribute(const string &name)
Erase an attribute from a specific container This method expects to find 'name' in the D4Attributes o...
vector< D4Attribute * >::iterator D4AttributesIter
vector< D4Attribute * >::const_iterator D4AttributesCIter
static ostream & LMarg(ostream &strm)
A class for error processing.
A class for software fault reporting.
xmlTextWriterPtr get_writer() const
top level DAP object to house generic methods
string escattr_xml(string s)
D4AttributeType StringToD4AttributeType(string s)
string AttrType_to_String(const AttrType at)
string D4AttributeTypeToString(D4AttributeType at)
AttrType get_dap2_AttrType(D4AttributeType d4_type)