29 #include "D4Attributes.h" 30 #include "D4AttributeType.h" 31 #include "InternalErr.h" 33 #include "AttrTable.h" 97 case attr_container_c:
100 case attr_otherxml_c:
104 throw InternalErr(__FILE__, __LINE__,
"Unsupported attribute type");
108 D4AttributeType StringToD4AttributeType(
string s)
112 if (s ==
"container")
113 return attr_container_c;
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")
124 return attr_uint16_c;
125 else if (s ==
"int32")
127 else if (s ==
"uint32")
128 return attr_uint32_c;
129 else if (s ==
"int64")
131 else if (s ==
"uint64")
132 return attr_uint64_c;
134 else if (s ==
"float32")
135 return attr_float32_c;
136 else if (s ==
"float64")
137 return attr_float64_c;
139 else if (s ==
"string")
143 else if (s ==
"otherxml")
144 return attr_otherxml_c;
154 d_values = src.d_values;
155 if (src.d_attributes)
166 D4Attribute::~D4Attribute()
174 if (
this == &rhs)
return *
this;
180 D4Attribute::attributes()
202 case Attr_container: {
206 add_attribute_nocopy(a);
212 add_attribute_nocopy(a);
218 add_attribute_nocopy(a);
224 add_attribute_nocopy(a);
230 add_attribute_nocopy(a);
236 add_attribute_nocopy(a);
242 add_attribute_nocopy(a);
248 add_attribute_nocopy(a);
254 add_attribute_nocopy(a);
260 add_attribute_nocopy(a);
263 case Attr_other_xml: {
266 add_attribute_nocopy(a);
270 throw InternalErr(__FILE__, __LINE__,
"Unknown DAP2 attribute type in D4Attributes::copy_from_dap2()");
276 D4Attributes::find_depth_first(
const string &name, D4AttributesIter i)
278 if (i == attribute_end())
280 else if ((*i)->name() == name)
282 else if ((*i)->type() == attr_container_c)
283 return find_depth_first(name, (*i)->attributes()->attribute_begin());
285 return find_depth_first(name, ++i);
289 D4Attributes::find(
const string &name)
291 return find_depth_first(name, attribute_begin());
303 size_t pos = fqn.find(
'.');
304 string part = fqn.substr(0, pos);
307 if (pos != string::npos)
308 rest = fqn.substr(pos + 1);
310 DBG(cerr <<
"part: '" << part <<
"'; rest: '" << rest <<
"'" << endl);
314 D4AttributesIter i = attribute_begin();
315 while (i != attribute_end()) {
316 if ((*i)->name() == part && (*i)->type() == attr_container_c)
317 return (*i)->attributes()->get(rest);
322 D4AttributesIter i = attribute_begin();
323 while (i != attribute_end()) {
324 if ((*i)->name() == part)
335 D4Attribute::print_dap4(
XMLWriter &xml)
const 337 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Attribute") < 0)
338 throw InternalErr(__FILE__, __LINE__,
"Could not write Attribute element");
339 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)name().c_str()) < 0)
340 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
341 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"type", (
const xmlChar*)
D4AttributeTypeToString(type()).c_str()) < 0)
342 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for type");
345 case attr_container_c:
347 throw InternalErr(__FILE__, __LINE__,
"Null Attribute container");
348 d_attributes->print_dap4(xml);
351 case attr_otherxml_c:
352 if (num_values() != 1)
353 throw Error(
"OtherXML attributes cannot be vector-valued.");
354 if (xmlTextWriterWriteRaw(xml.get_writer(), (
const xmlChar*) value(0).c_str()) < 0)
355 throw InternalErr(__FILE__, __LINE__,
"Could not write OtherXML value");
360 D4AttributeCIter i = d_values.begin();
361 while (i != d_values.end()) {
362 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Value") < 0)
363 throw InternalErr(__FILE__, __LINE__,
"Could not write value element");
365 if (xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*) (*i++).c_str()) < 0)
366 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute value");
368 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
369 throw InternalErr(__FILE__, __LINE__,
"Could not end value element");
376 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
377 throw InternalErr(__FILE__, __LINE__,
"Could not end Attribute element");
391 strm << DapIndent::LMarg <<
"D4Attribute::dump - (" << (
void *)
this <<
")" << endl;
393 DapIndent::Indent() ;
397 strm << DapIndent::LMarg << xml.get_doc() << flush;
399 DapIndent::UnIndent() ;
404 D4Attributes::print_dap4(
XMLWriter &xml)
const 409 D4AttributesCIter i = d_attrs.begin();
410 while (i != d_attrs.end()) {
411 (*i++)->print_dap4(xml);
426 strm << DapIndent::LMarg <<
"D4Attributes::dump - (" << (
void *)
this <<
")" << endl;
428 DapIndent::Indent() ;
432 strm << DapIndent::LMarg << xml.get_doc() << flush;
434 DapIndent::UnIndent() ;
virtual void dump(ostream &strm) const
dumps information about this object
virtual Attr_iter attr_end()
Contains the attributes for a dataset.
virtual string get_name() const
Get the name of this attribute table.
A class for software fault reporting.
virtual AttrTable * get_attr_table(const string &name)
Get an attribute container.
virtual Attr_iter attr_begin()
virtual AttrType get_attr_type(const string &name)
Get the type of an attribute.
virtual vector< string > * get_attr_vector(const string &name)
Get a vector-valued attribute.
D4Attribute * get(const string &fqn)
A class for error processing.
string D4AttributeTypeToString(D4AttributeType at)
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
virtual void dump(ostream &strm) const
dumps information about this object