62 Constructor::Constructor(
const string &n,
const Type &t)
76 Constructor::Constructor(
const string &n,
const string &d,
const Type &t)
92 dynamic_cast<BaseType &
>(*this) = rhs;
103 return _vars.begin() ;
129 string::size_type i = source->
name.find(
"_dim_");
130 if (i != string::npos && (btp =
var(source->
name.substr(0, i)))) {
137 int n = atoi(source->
name.substr(i + 5).c_str());
138 DBG(cerr <<
"Found a Grid (" << btp->
name() <<
") and "
139 << source->
name.substr(i) <<
", extracted n: " << n << endl);
140 return *(
dynamic_cast<Grid&
>(*btp).map_begin() + n);
151 Constructor::find_matching_container(AttrTable::entry *source,
152 BaseType **dest_variable)
156 throw InternalErr(__FILE__, __LINE__,
"Constructor::find_matching_container");
161 if ((btp =
var(source->name))) {
163 *dest_variable = btp;
168 else if ((btp = find_hdf4_dimension_attribute_home(source))) {
172 DBG(cerr <<
"Found a Grid" << endl);
173 *dest_variable = btp;
174 return &btp->get_attr_table();
177 string::size_type i = source->name.find(
"_dim_");
178 string ext = source->name.substr(i + 1);
179 *dest_variable = btp;
180 return btp->get_attr_table().append_container(ext);
187 at =
new AttrTable();
217 DBG(cerr <<
"Constructor::transfer_attributes, variable: " <<
name() <<
219 DBG(cerr <<
"Working on the '" << entry->
220 name <<
"' container." << endl);
222 throw InternalErr(__FILE__, __LINE__,
223 "Constructor::transfer_attributes");
225 AttrTable *source = entry->attributes;
227 AttrTable *dest = find_matching_container(entry, &dest_variable);
231 while (source_p != source->attr_end()) {
232 DBG(cerr <<
"Working on the '" << (*source_p)->
233 name <<
"' attribute" << endl);
236 if (dest_variable && dest_variable->is_constructor_type()) {
237 dynamic_cast <Constructor & >(*dest_variable).transfer_attributes(*source_p);
240 dest->append_container(
new AttrTable(*(*source_p)->attributes),
245 dest->append_attr(source->get_name(source_p),
246 source->get_type(source_p),
247 source->get_attr_vector(source_p));
273 DBG(cerr <<
"Processing the attributes for: " << (*var)->name() <<
" a " << (*var)->type_name() << endl);
274 (*var)->transfer_attributes(at);
312 return _vars.rbegin();
329 return _vars.begin() + i;
338 return *(
_vars.begin() + i);
344 bool constraint_info,
bool constrained)
346 if (constrained && !
send_p())
349 fprintf(out,
"%s%s {\n", space.c_str(),
type_name().c_str()) ;
351 (*i)->print_decl(out, space +
" ",
true,
352 constraint_info, constrained);
354 fprintf(out,
"%s} %s", space.c_str(),
id2www(
name()).c_str()) ;
356 if (constraint_info) {
358 cout <<
": Send True";
360 cout <<
": Send False";
364 fprintf(out,
";\n") ;
370 bool constraint_info,
bool constrained)
372 if (constrained && !
send_p())
377 (*i)->print_decl(out, space +
" ",
true,
378 constraint_info, constrained);
382 if (constraint_info) {
384 out <<
": Send True";
386 out <<
": Send False";
394 class PrintField :
public unary_function<BaseType *, void>
400 PrintField(FILE *o,
string s,
bool c)
401 : d_out(o), d_space(s), d_constrained(c)
404 void operator()(BaseType *btp)
406 btp->print_xml(d_out, d_space, d_constrained);
416 if (constrained && !
send_p())
419 bool has_attributes =
false;
422 fprintf(out,
"%s<%s", space.c_str(),
type_name().c_str());
424 fprintf(out,
" name=\"%s\"",
id2xml(
name()).c_str());
426 if (has_attributes || has_variables) {
432 PrintField(out, space +
" ", constrained));
434 fprintf(out,
"%s</%s>\n", space.c_str(),
type_name().c_str());
437 fprintf(out,
"/>\n");
442 class PrintFieldStrm :
public unary_function<BaseType *, void>
448 PrintFieldStrm(ostream &o,
string s,
bool c)
449 : d_out(o), d_space(s), d_constrained(c)
452 void operator()(BaseType *btp)
454 btp->print_xml(d_out, d_space, d_constrained);
464 if (constrained && !
send_p())
467 bool has_attributes =
false;
474 if (has_attributes || has_variables) {
480 PrintFieldStrm(out, space +
" ", constrained));
482 out << space <<
"</" <<
type_name() <<
">\n" ;
489 class PrintFieldXMLWriter :
public unary_function<BaseType *, void>
494 PrintFieldXMLWriter(
XMLWriter &x,
bool c)
495 : d_xml(x), d_constrained(c)
498 void operator()(BaseType *btp)
500 btp->print_xml_writer(d_xml, d_constrained);
507 if (constrained && !
send_p())
514 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
515 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
517 bool has_attributes =
false;
519 if (has_attributes || has_variables) {
525 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
559 << (
void *)
this <<
")" << endl ;
566 for (; i != ie; i++) {
std::vector< entry * >::iterator Attr_iter
virtual Attr_iter attr_end()
std::vector< BaseType * >::reverse_iterator Vars_riter
Contains the attributes for a dataset.
string get_error_message() const
virtual string get_type(const string &name)
Get the type name of an attribute within this attribute table.
std::vector< BaseType * > _vars
std::vector< BaseType * >::iterator Vars_iter
virtual void print_xml(FILE *out, string pad=" ", bool constrained=false)
virtual bool is_global_attribute() const
string id2xml(string in, const string ¬_allowed)
virtual void set_is_global_attribute(bool ga)
void print_xml_writer(XMLWriter &xml)
virtual AttrTable * find_container(const string &target)
Find an attribute with a given name.
Type
Identifies the data type.
Type type() const
Returns the type of the class instance.
virtual string get_name() const
Get the name of this attribute table.
Constructor & operator=(const Constructor &rhs)
A class for software fault reporting.
virtual bool is_vector_type()
Returns true if the instance is a vector (i.e., array) type variable.
xmlTextWriterPtr get_writer()
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
string type_name() const
Returns the type of the class instance as a string.
virtual bool is_linear()
Check to see whether this variable can be printed simply.
virtual void transfer_attributes(AttrTable *at_container)
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 void dump(ostream &strm) const
dumps information about this object
BaseType * get_var_index(int i)
virtual void dump(ostream &strm) const
dumps information about this object
string name() const
Returns the name of the class instance.
std::vector< BaseType * >::const_iterator Vars_citer
virtual Attr_iter attr_begin()
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
BaseType(const string &n, const Type &t)
The BaseType constructor.
static ostream & LMarg(ostream &strm)
virtual AttrTable & get_attr_table()
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
The basic data type for the DODS DAP types.
virtual AttrType get_attr_type(const string &name)
Get the type of an attribute.
virtual void print_decl(ostream &out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
virtual vector< string > * get_attr_vector(const string &name)
Get a vector-valued attribute.
Vars_iter get_vars_iter(int i)
A class for error processing.
virtual bool send_p()
Should this variable be sent?
string id2www(string in, const string &allowable)
void _duplicate(const Constructor &s)