29#include "D4Dimensions.h"
34#include "InternalErr.h"
38void D4Dimension::set_size(
const string &size) {
39 unsigned long value = 0;
40 istringstream iss(size);
45 if (!iss || !iss.eof())
46 throw Error(
"Invalid value '" + size +
"' passed to D4Dimension::set_size.");
59 D4Group *grp = d_parent->parent();
62 name = (grp->
name() ==
"/") ?
"/" + name : grp->
name() +
"/" + name;
80 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar *)
"Dimension") < 0)
81 throw InternalErr(__FILE__, __LINE__,
"Could not write Dimension element");
83 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar *)
"name", (
const xmlChar *)d_name.c_str()) < 0)
84 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
87 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
fully_qualified_name().c_str()) < 0)
88 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
92 oss << (d_c_stop - d_c_start) / d_c_stride + 1;
95 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar *)
"size", (
const xmlChar *)oss.str().c_str()) < 0)
96 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for size");
98 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
99 throw InternalErr(__FILE__, __LINE__,
"Could not end Dimension element");
108 return d->name() == name;
112D4Dimension *D4Dimensions::find_dim(
const string &name) {
114 D4DimensionsIter d = find_if(d_dims.begin(), d_dims.end(), bind2nd(ptr_fun(dim_name_eq), name));
116 auto d = find_if(d_dims.begin(), d_dims.end(), [name](
const D4Dimension *dim) { return name == dim->name(); });
117 return (d != d_dims.end()) ? *d : 0;
120void D4Dimensions::print_dap4(
XMLWriter &xml,
bool constrained)
const {
121 D4DimensionsCIter i = d_dims.begin();
122 while (i != d_dims.end()) {
124 if (!constrained || parent()->find_first_var_that_uses_dimension(*i))
125 (*i)->print_dap4(xml);
128 if ((*i)->used_by_projected_var())
129 (*i)->print_dap4(xml);
131 (*i)->print_dap4(xml);
virtual string name() const
Returns the name of the class instance.
virtual BaseType * get_parent() const
void print_dap4(XMLWriter &xml) const
Print the Dimension declaration. Print the Dimension in a form suitable for use in a Group definition...
string fully_qualified_name() const
Get the FQN for the dimension.
vector< D4Dimension * >::iterator D4DimensionsIter
Iterator used for D4Dimensions.
A class for software fault reporting.
top level DAP object to house generic methods