57 Grid::_duplicate(
const Grid &s)
64 _vars.push_back(_array_var);
68 for (
Map_iter i = cs._map_vars.begin(); i != cs._map_vars.end(); i++) {
71 _map_vars.push_back(btp);
112 delete _array_var; _array_var = 0;
114 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
116 delete btp ; btp = 0;
123 return new Grid(*
this);
132 delete _array_var; _array_var = 0;
134 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
152 return _map_vars.size() + 1;
155 for (
Map_iter j = _map_vars.begin(); j != _map_vars.end(); j++) {
156 j += (*j)->element_count(leaves);
160 throw InternalErr(__FILE__, __LINE__,
"No Grid arry!");
172 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
173 (*i)->set_send_p(state);
184 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
185 (*i)->set_read_p(state);
196 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
197 (*i)->set_in_selection(state);
206 unsigned int sz = _array_var->
width();
208 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
229 sz = _array_var->
width(constrained);
232 sz = _array_var->
width(constrained);
235 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
238 sz += (*i)->width(constrained);
241 sz += (*i)->width(constrained);
261 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
262 if ((*i)->send_p()) {
263 (*i)->intern_data(eval, dds);
271 DBG(cerr <<
"In Grid::serialize()" << endl);
278 DBG(cerr <<
"In Grid::serialize(), before read() - read_p() returned: " <<
read_p() << endl);
283 DBG(cerr <<
"In Grid::serialize(), past read() - read_p() returned: " <<
read_p() << endl);
292 if (_array_var->
send_p()) {
297 _array_var->
serialize(eval, dds, m,
false);
302 DBG(cerr <<
"About to call Array::serialize() in Grid::serialize" << endl);
303 _array_var->
serialize(eval, dds, m,
false);
307 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
308 if ((*i)->send_p()) {
313 (*i)->serialize(eval, dds, m,
false);
318 (*i)->serialize(eval, dds, m,
false);
331 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
332 (*i)->deserialize(um, dds, reuse);
363 return var(n,
true, &s);
377 s->push(static_cast<BaseType *>(
this));
381 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
382 if ((*i)->name() ==
name) {
384 s->push(static_cast<BaseType *>(
this));
409 "Passing NULL pointer as variable to be added.");
412 if (part ==
array && _array_var) {
414 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
428 "Grid::add_var(): with Part==array: object is not an Array!");
432 set_array(static_cast<Array*>(bt_clone));
439 _map_vars.push_back(bt_clone);
450 "Grid::add_var(): with Part==array: object is not an Array!");
454 set_array(static_cast<Array*>(bt_clone));
459 _map_vars.push_back(bt_clone);
469 _vars.push_back(bt_clone);
493 "Passing NULL pointer as variable to be added.");
496 if (part ==
array && _array_var) {
498 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
511 "Grid::add_var(): with Part==array: object is not an Array!");
519 _map_vars.push_back(bt);
530 "Grid::add_var(): with Part==array: object is not an Array!");
535 _map_vars.push_back(bt);
563 "Grid::set_array(): Cannot set to null!");
566 if (p_new_arr == _array_var) {
570 delete _array_var; _array_var = 0;
572 _array_var = p_new_arr;
607 "Grid::add_map(): cannot have p_new_map null!");
615 _map_vars.push_back(p_new_map);
616 _vars.push_back(p_new_map);
643 _map_vars.insert(_map_vars.begin(), p_new_map);
676 return _map_vars.begin() ;
684 return _map_vars.end() ;
691 return _map_vars.rbegin() ;
699 return _map_vars.rend() ;
708 return _map_vars.begin() + i;
732 comp = _array_var->
send_p() ? 1 : 0;
734 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
735 if ((*i)->send_p()) {
741 comp = 1 + _map_vars.size();
758 (*map)->transfer_attributes(at);
855 bool constraint_info,
bool constrained)
857 if (constrained && !
send_p())
866 fprintf(out,
"%sStructure {\n", space.c_str()) ;
868 _array_var->
print_decl(out, space +
" ",
true, constraint_info,
871 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end(); i++) {
872 (*i)->print_decl(out, space +
" ",
true,
873 constraint_info, constrained);
876 fprintf(out,
"%s} %s", space.c_str(),
id2www(
name()).c_str()) ;
881 fprintf(out,
"%s%s {\n", space.c_str(),
type_name().c_str()) ;
883 fprintf(out,
"%s Array:\n", space.c_str()) ;
884 _array_var->
print_decl(out, space +
" ",
true, constraint_info,
887 fprintf(out,
"%s Maps:\n", space.c_str()) ;
888 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end(); i++) {
889 (*i)->print_decl(out, space +
" ",
true,
890 constraint_info, constrained);
893 fprintf(out,
"%s} %s", space.c_str(),
id2www(
name()).c_str()) ;
896 if (constraint_info) {
898 fprintf( out,
": Send True");
900 fprintf( out,
": Send False");
904 fprintf(out,
";\n") ;
912 bool constraint_info,
bool constrained)
914 if (constrained && !
send_p())
919 out << space <<
"Structure {\n" ;
921 _array_var->
print_decl(out, space +
" ",
true, constraint_info,
924 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end(); i++) {
925 (*i)->print_decl(out, space +
" ",
true,
926 constraint_info, constrained);
936 out << space <<
" Array:\n" ;
937 _array_var->
print_decl(out, space +
" ",
true, constraint_info,
940 out << space <<
" Maps:\n" ;
941 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end(); i++) {
942 (*i)->print_decl(out, space +
" ",
true,
943 constraint_info, constrained);
949 if (constraint_info) {
951 out <<
": Send True";
953 out <<
": Send False";
963 class PrintMapField :
public unary_function<BaseType *, void>
970 PrintMapField(FILE *o,
string s,
bool c,
const string &t =
"Map")
971 : d_out(o), d_space(s), d_constrained(c), d_tag(t)
974 void operator()(BaseType *btp)
976 Array *a =
dynamic_cast<Array*
>(btp);
978 throw InternalErr(__FILE__, __LINE__,
"Expected an Array.");
979 a->print_xml_core(d_out, d_space, d_constrained, d_tag);
989 if (constrained && !
send_p())
993 fprintf(out,
"%s<Structure", space.c_str());
995 fprintf(out,
" name=\"%s\"",
id2xml(
name()).c_str());
1004 PrintMapField(out, space +
" ", constrained,
"Array"));
1006 fprintf(out,
"%s</Structure>\n", space.c_str());
1011 fprintf(out,
"%s<Grid", space.c_str());
1012 if (!
name().empty())
1013 fprintf(out,
" name=\"%s\"",
id2xml(
name()).c_str());
1015 fprintf(out,
">\n");
1022 PrintMapField(out, space +
" ", constrained));
1024 fprintf(out,
"%s</Grid>\n", space.c_str());
1029 class PrintMapFieldStrm :
public unary_function<BaseType *, void>
1036 PrintMapFieldStrm(ostream &o,
string s,
bool c,
const string &t =
"Map")
1037 : d_out(o), d_space(s), d_constrained(c), d_tag(t)
1040 void operator()(BaseType *btp)
1042 Array *a =
dynamic_cast<Array*
>(btp);
1044 throw InternalErr(__FILE__, __LINE__,
"Expected an Array.");
1045 a->print_xml_core(d_out, d_space, d_constrained, d_tag);
1055 if (constrained && !
send_p())
1059 out << space <<
"<Structure" ;
1060 if (!
name().empty())
1061 out <<
" name=\"" <<
id2xml(
name()) <<
"\"" ;
1070 PrintMapFieldStrm(out, space +
" ", constrained,
"Array"));
1072 out << space <<
"</Structure>\n" ;
1077 out << space <<
"<Grid" ;
1078 if (!
name().empty())
1079 out <<
" name=\"" <<
id2xml(
name()) <<
"\"" ;
1088 PrintMapFieldStrm(out, space +
" ", constrained));
1090 out << space <<
"</Grid>\n" ;
1095 class PrintGridFieldXMLWriter :
public unary_function<BaseType *, void>
1101 PrintGridFieldXMLWriter(
XMLWriter &x,
bool c,
const string &t =
"Map")
1102 : d_xml(x), d_constrained(c), d_tag(t)
1105 void operator()(BaseType *btp)
1107 Array *a =
dynamic_cast<Array*
>(btp);
1109 throw InternalErr(__FILE__, __LINE__,
"Expected an Array.");
1110 a->print_xml_writer_core(d_xml, d_constrained, d_tag);
1117 if (constrained && !
send_p())
1121 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)
"Structure") < 0)
1122 throw InternalErr(__FILE__, __LINE__,
"Could not write Structure element");
1124 if (!
name().empty())
1125 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
1126 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1133 PrintGridFieldXMLWriter(xml, constrained,
"Array"));
1135 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
1136 throw InternalErr(__FILE__, __LINE__,
"Could not end Structure element");
1141 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)
"Grid") < 0)
1142 throw InternalErr(__FILE__, __LINE__,
"Could not write Grid element");
1144 if (!
name().empty())
1145 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
1146 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1153 PrintGridFieldXMLWriter(xml, constrained,
"Map"));
1155 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
1156 throw InternalErr(__FILE__, __LINE__,
"Could not end Grid element");
1166 fprintf(out,
" = ") ;
1175 fprintf(out,
"{ Array: ") ;
1180 fprintf(out,
" Maps: ") ;
1181 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end();
1182 i++, (void)(i != _map_vars.end() && fprintf(out,
", "))) {
1183 (*i)->print_val(out,
"",
false);
1185 fprintf(out,
" }") ;
1188 fprintf(out,
";\n") ;
1206 out <<
"{ Array: " ;
1212 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end();
1213 i++, (void)(i != _map_vars.end() && out <<
", ")) {
1214 (*i)->print_val(out,
"",
false);
1237 msg +=
"Null grid base array in `" +
name() +
"'\n";
1243 msg +=
"Grid `" +
name() +
"'s' member `" + _array_var->
name() +
"' must be an array\n";
1251 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
1256 if ((
unsigned)_map_vars.size() != av->
dimensions()) {
1257 msg +=
"The number of map variables for grid `" + this->
name() +
"' does not match the number of dimensions of `";
1258 msg += av->
name() +
"'\n";
1262 const string array_var_name = av->
name();
1264 for (
Map_iter mvi = _map_vars.begin();
1265 mvi != _map_vars.end(); mvi++, asi++) {
1270 if (array_var_name == mv->
name()) {
1271 msg +=
"Grid map variable `" + mv->
name() +
"' conflicts with the grid array name in grid `" +
name() +
"'\n";
1276 msg +=
"Grid map variable `" + mv->
name() +
"' is not an array\n";
1284 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
1290 msg +=
"Grid map variable `" + mv_a->
name() +
"' must be only one dimension\n";
1297 if (mv_a_size != av_size) {
1298 msg +=
"Grid map variable `" + mv_a->
name() +
"'s' size does not match the size of array variable '";
1299 msg += _array_var->
name() +
"'s' cooresponding dimension\n";
1307 for (
Map_iter mvi = _map_vars.begin(); mvi != _map_vars.end(); mvi++) {
1308 if (!(*mvi)->check_semantics(msg,
true)) {
1329 << (
void *)
this <<
")" << endl ;
1335 _array_var->
dump(strm) ;
1345 for (; i != ie; i++) {
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
std::vector< entry * >::iterator Attr_iter
virtual bool read()
Read data into a local buffer.
virtual bool read_p()
Has this variable been read?
abstract base class used to unmarshall/deserialize dap data objects
virtual void print_decl(FILE *out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
virtual Attr_iter attr_end()
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
virtual Array * prepend_map(Array *p_new_map, bool add_copy)
virtual void add_var_nocopy(BaseType *bt, Part part)
Part
Names the parts of multi-section constructor data types.
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Move data to the net.
virtual void dump(ostream &strm) const
dumps information about this object
Contains the attributes for a dataset.
virtual unsigned int width()
Returns the size of the class instance data.
Grid & operator=(const Grid &rhs)
virtual string get_type(const string &name)
Get the type name of an attribute within this attribute table.
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)=0
Receive data from the net.
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
std::vector< BaseType * > _vars
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 bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)=0
Move data to the net.
virtual unsigned int width()=0
Returns the size of the class instance data.
virtual void set_in_selection(bool state)
virtual int element_count(bool leaves)
Count the members of constructor types.
virtual void set_is_global_attribute(bool ga)
void print_xml_writer(XMLWriter &xml)
virtual void set_send_p(bool state)
virtual void reset_checksum()
Type type() const
Returns the type of the class instance.
virtual unsigned int val2buf(void *buf, bool reuse=false)
Returns the size of the Grid type.
virtual string get_name() const
Get the name of this attribute table.
virtual void set_in_selection(bool state)
stack< BaseType * > btp_stack
virtual void set_parent(BaseType *parent)
A class for software fault reporting.
std::vector< BaseType * >::const_iterator Map_citer
virtual int components(bool constrained=false)
Returns the number of components in the Grid object.
Map_riter map_rbegin()
Returns an iterator referencing the first Map vector.
virtual void set_array(Array *p_new_arr)
string dataset() const
Returns the name of the dataset used to create this instance.
bool eval_selection(DDS &dds, const string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator ans is called ...
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
xmlTextWriterPtr get_writer()
virtual int element_count(bool leaves=false)
Count the members of constructor types.
virtual bool projection_yields_grid()
Map_iter map_begin()
Returns an iterator referencing the first Map vector.
string type_name() const
Returns the type of the class instance as a string.
virtual int dimension_size(Dim_iter i, bool constrained=false)
Returns the size of the dimension.
virtual BaseType * ptr_duplicate()
virtual string get_checksum()
Map_iter get_map_iter(int i)
virtual void intern_data(ConstraintEvaluator &eval, DDS &dds)
virtual void set_send_p(bool state)
virtual void add_var(BaseType *bt, Part part)
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
virtual void transfer_attributes(AttrTable *at_container)
virtual void clear_constraint()
virtual AttrTable * get_attr_table(const string &name)
Get an attribute container.
std::vector< dimension >::iterator Dim_iter
virtual void dump(ostream &strm) const
dumps information about this object
virtual void set_read_p(bool state)
Sets the value of the read_p property.
virtual BaseType * ptr_duplicate()
virtual int dimension_stride(Dim_iter i, bool constrained=false)
Returns the stride value of the constraint.
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Holds the Grid data type.
virtual void dump(ostream &strm) const
dumps information about this object
virtual void print_val(ostream &out, string space="", bool print_decl_p=true)
Prints the value of the variable.
virtual Array * add_map(Array *p_new_map, bool add_copy)
Array * get_array()
Returns the Grid Array. This method returns the array using an Array*, so no cast is required...
std::vector< BaseType * >::iterator Map_iter
std::vector< BaseType * >::reverse_iterator Map_riter
string name() const
Returns the name of the class instance.
virtual void print_xml(ostream &out, string space=" ", bool constrained=false)
virtual Attr_iter attr_begin()
virtual BaseType * ptr_duplicate()=0
string www2id(const string &in, const string &escape, const string &except)
virtual int dimension_stop(Dim_iter i, bool constrained=false)
Return the stop index of the constraint.
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.
Evaluate a constraint expression.
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
static ostream & LMarg(ostream &strm)
virtual int dimension_start(Dim_iter i, bool constrained=false)
Return the start index of a dimension.
virtual AttrTable & get_attr_table()
virtual BaseType * var(const string &n, bool exact=true, btp_stack *s=0)
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.
abstract base class used to marshal/serialize dap data objects
virtual unsigned int buf2val(void **val)
virtual bool check_semantics(string &msg, bool all=false)
Return true if this Grid is well formed.
virtual vector< string > * get_attr_vector(const string &name)
Get a vector-valued attribute.
virtual bool is_simple_type()
Returns true if the instance is a numeric, string or URL type variable.
void _duplicate(const Grid &s)
BaseType * array_var()
Returns the Grid Array.
virtual void transfer_attributes(AttrTable *at)
marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using XDR ...
A multidimensional array of identical data types.
virtual bool send_p()
Should this variable be sent?
virtual void print_xml_writer(XMLWriter &xml, bool constrained=false)
Grid(const string &n)
The Grid constructor.
string id2www(string in, const string &allowable)
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)=0
Prints the value of the variable.
virtual void clear_constraint()
Clears the projection; add each projected dimension explicitly using add_constraint.
virtual bool check_semantics(string &msg, bool all=false)
Compare an object's current state with the semantics of its type.