29 #include "D4Attributes.h" 30 #include "D4AttributeType.h" 31 #include "InternalErr.h" 33 #include "AttrTable.h" 37 #include "DapIndent.h" 98 case attr_container_c:
101 case attr_otherxml_c:
105 throw InternalErr(__FILE__, __LINE__,
"Unsupported attribute type");
109 D4AttributeType StringToD4AttributeType(
string s)
113 if (s ==
"container")
114 return attr_container_c;
116 else if (s ==
"byte")
118 else if (s ==
"int8")
120 else if (s ==
"uint8")
122 else if (s ==
"int16")
124 else if (s ==
"uint16")
125 return attr_uint16_c;
126 else if (s ==
"int32")
128 else if (s ==
"uint32")
129 return attr_uint32_c;
130 else if (s ==
"int64")
132 else if (s ==
"uint64")
133 return attr_uint64_c;
135 else if (s ==
"float32")
136 return attr_float32_c;
137 else if (s ==
"float64")
138 return attr_float64_c;
140 else if (s ==
"string")
144 else if (s ==
"otherxml")
145 return attr_otherxml_c;
155 d_values = src.d_values;
156 if (src.d_attributes)
167 D4Attribute::~D4Attribute()
175 if (
this == &rhs)
return *
this;
181 D4Attribute::attributes()
204 case Attr_container: {
208 add_attribute_nocopy(a);
214 add_attribute_nocopy(a);
220 add_attribute_nocopy(a);
226 add_attribute_nocopy(a);
232 add_attribute_nocopy(a);
238 add_attribute_nocopy(a);
244 add_attribute_nocopy(a);
250 add_attribute_nocopy(a);
256 add_attribute_nocopy(a);
262 add_attribute_nocopy(a);
265 case Attr_other_xml: {
268 add_attribute_nocopy(a);
272 throw InternalErr(__FILE__, __LINE__,
"Unknown DAP2 attribute type in D4Attributes::copy_from_dap2()");
278 AttrType get_dap2_AttrType(D4AttributeType d4_type){
280 case attr_container_c: {
return Attr_container; }
281 case attr_byte_c: {
return Attr_byte; }
282 case attr_int16_c: {
return Attr_int16; }
283 case attr_uint16_c: {
return Attr_uint16; }
284 case attr_int32_c: {
return Attr_int32; }
285 case attr_uint32_c: {
return Attr_uint32; }
286 case attr_float32_c: {
return Attr_float32; }
287 case attr_float64_c: {
return Attr_float64; }
288 case attr_str_c: {
return Attr_string; }
289 case attr_url_c: {
return Attr_url; }
290 case attr_otherxml_c: {
return Attr_other_xml; }
292 throw InternalErr(__FILE__, __LINE__,
"Unknown DAP4 attribute");
304 string name = (*i)->name();
305 D4AttributeType d4_attr_type = (*i)->type();
306 AttrType d2_attr_type = get_dap2_AttrType(d4_attr_type);
309 D4Attribute::D4AttributeIter vitr =(*i)->value_begin();
310 D4Attribute::D4AttributeIter end =(*i)->value_end();
312 vector<string> values;
313 for(;vitr!=end; vitr++){
314 values.push_back((*vitr));
317 switch (d4_attr_type) {
318 case attr_container_c: {
323 load_AttrTable(child_attr_table,(*i)->attributes());
329 d2_attr_table->
append_attr(name,d2_attr_type_name, &values);
347 load_AttrTable(my_pretty_pony,
this);
349 return my_pretty_pony;
354 D4Attributes::find_depth_first(
const string &name, D4AttributesIter i)
356 if (i == attribute_end())
358 else if ((*i)->name() == name)
360 else if ((*i)->type() == attr_container_c)
361 return find_depth_first(name, (*i)->attributes()->attribute_begin());
363 return find_depth_first(name, ++i);
367 D4Attributes::find(
const string &name)
369 return find_depth_first(name, attribute_begin());
381 size_t pos = fqn.find(
'.');
382 string part = fqn.substr(0, pos);
385 if (pos != string::npos)
386 rest = fqn.substr(pos + 1);
388 DBG(cerr <<
"part: '" << part <<
"'; rest: '" << rest <<
"'" << endl);
392 D4AttributesIter i = attribute_begin();
393 while (i != attribute_end()) {
394 if ((*i)->name() == part && (*i)->type() == attr_container_c)
395 return (*i)->attributes()->get(rest);
400 D4AttributesIter i = attribute_begin();
401 while (i != attribute_end()) {
402 if ((*i)->name() == part)
413 D4Attribute::print_dap4(
XMLWriter &xml)
const 415 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Attribute") < 0)
416 throw InternalErr(__FILE__, __LINE__,
"Could not write Attribute element");
417 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)name().c_str()) < 0)
418 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
419 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"type", (
const xmlChar*)
D4AttributeTypeToString(type()).c_str()) < 0)
420 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for type");
423 case attr_container_c:
425 throw InternalErr(__FILE__, __LINE__,
"Null Attribute container");
426 d_attributes->print_dap4(xml);
429 case attr_otherxml_c:
430 if (num_values() != 1)
431 throw Error(
"OtherXML attributes cannot be vector-valued.");
432 if (xmlTextWriterWriteRaw(xml.get_writer(), (
const xmlChar*) value(0).c_str()) < 0)
433 throw InternalErr(__FILE__, __LINE__,
"Could not write OtherXML value");
438 D4AttributeCIter i = d_values.begin();
439 while (i != d_values.end()) {
440 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Value") < 0)
441 throw InternalErr(__FILE__, __LINE__,
"Could not write value element");
443 if (xmlTextWriterWriteString(xml.get_writer(), (
const xmlChar*) (*i++).c_str()) < 0)
444 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute value");
446 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
447 throw InternalErr(__FILE__, __LINE__,
"Could not end value element");
454 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
455 throw InternalErr(__FILE__, __LINE__,
"Could not end Attribute element");
469 strm << DapIndent::LMarg <<
"D4Attribute::dump - (" << (
void *)
this <<
")" << endl;
471 DapIndent::Indent() ;
475 strm << DapIndent::LMarg << xml.get_doc() << flush;
477 DapIndent::UnIndent() ;
482 D4Attributes::print_dap4(
XMLWriter &xml)
const 487 D4AttributesCIter i = d_attrs.begin();
488 while (i != d_attrs.end()) {
489 (*i++)->print_dap4(xml);
504 strm << DapIndent::LMarg <<
"D4Attributes::dump - (" << (
void *)
this <<
")" << endl;
506 DapIndent::Indent() ;
510 strm << DapIndent::LMarg << xml.get_doc() << flush;
512 DapIndent::UnIndent() ;
AttrTable * get_AttrTable(const std::string name)
copy attributes from DAP4 to DAP2
virtual void dump(ostream &strm) const
dumps information about this object
virtual Attr_iter attr_end()
D4AttributesIter attribute_begin()
Get an iterator to the start of the enumerations.
Contains the attributes for a dataset.
string AttrType_to_String(const AttrType at)
virtual string get_name() const
Get the name of this attribute table.
top level DAP object to house generic methods
A class for software fault reporting.
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
virtual AttrTable * get_attr_table(const string &name)
Get an attribute container.
virtual Attr_iter attr_begin()
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
virtual AttrType get_attr_type(const string &name)
Get the type of an attribute.
D4AttributesIter attribute_end()
Get an iterator to the end of the enumerations.
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)
virtual void set_name(const string &n)
Set the name of this attribute table.
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
virtual void dump(ostream &strm) const
dumps information about this object