30#include <libxml/encoding.h>
31#include <libxml/xmlwriter.h>
42#include <libdap/BaseType.h>
43#include <libdap/debug.h>
45#include <BESInternalFatalError.h>
49#include "get_xml_data.h"
55void XDOutput::start_xml_declaration(XMLWriter *writer,
const char *element)
57 BaseType *btp =
dynamic_cast<BaseType *
>(
this);
59 throw InternalErr(__FILE__, __LINE__,
"Expected a BaseType instance");
61 if (xmlTextWriterStartElement(writer->get_writer(),
62 (element != 0) ? (
const xmlChar*) element : (
const xmlChar*) btp->type_name().c_str()) < 0)
63 throw InternalErr(__FILE__, __LINE__,
"Could not write element for " + btp->name());
65 if (xmlTextWriterWriteAttribute(writer->get_writer(), (
const xmlChar*)
"name",
66 (
const xmlChar*) (btp->name().c_str())) < 0)
67 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute 'name' for " + btp->name());
70void XDOutput::end_xml_declaration(XMLWriter *writer)
72 BaseType *btp =
dynamic_cast<BaseType *
>(
this);
74 throw InternalErr(__FILE__, __LINE__,
"Expected a BaseType instance");
76 if (xmlTextWriterEndElement(writer->get_writer()) < 0)
77 throw InternalErr(__FILE__, __LINE__,
"Could not end element for " + btp->name());
80void XDOutput::print_xml_data(XMLWriter *writer,
bool show_type)
82 BESDEBUG(
"xd",
"Entering XDOutput::print_xml_data" << endl);
84 BaseType *btp = d_redirect;
85 if (!btp) btp =
dynamic_cast<BaseType *
>(
this);
89 start_xml_declaration(writer);
93 btp->print_val(oss,
"",
false);
94 BESDEBUG(
"xd",
"XDOutput::print_xml_data, value = '" << oss.str() <<
"'." << endl);
95 if (xmlTextWriterWriteElement(writer->get_writer(), (
const xmlChar*)
"value", (
const xmlChar*) oss.str().c_str())
97 throw InternalErr(__FILE__, __LINE__,
"Could not write value element for " + btp->name());
100 end_xml_declaration(writer);
127 DBG(cerr <<
"Entering increment_state" << endl);
129 vector<int>::reverse_iterator state_riter;
130 vector<int>::const_reverse_iterator shape_riter;
131 for (state_riter = state->rbegin(), shape_riter = shape.rbegin(); state_riter < state->rend();
132 state_riter++, shape_riter++) {
133 if (*state_riter == *shape_riter - 1) {
137 *state_riter = *state_riter + 1;
139 cerr <<
"New value of state: ";
140 copy(state->begin(), state->end(),
141 ostream_iterator<int>(cerr,
", "));
exception thrown if an internal error is found and is fatal to the BES
virtual bool increment_state(vector< int > *state, const vector< int > &shape)