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);
289 _array_var->
serialize(eval, dds, m,
false);
291 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
292 if ((*i)->send_p()) {
293 (*i)->serialize(eval, dds, m,
false);
305 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
306 (*i)->deserialize(um, dds, reuse);
337 return var(n,
true, &s);
351 s->push(static_cast<BaseType *>(
this));
355 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
356 if ((*i)->name() ==
name) {
358 s->push(static_cast<BaseType *>(
this));
383 "Passing NULL pointer as variable to be added.");
386 if (part ==
array && _array_var) {
388 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
402 "Grid::add_var(): with Part==array: object is not an Array!");
406 set_array(static_cast<Array*>(bt_clone));
413 _map_vars.push_back(bt_clone);
424 "Grid::add_var(): with Part==array: object is not an Array!");
428 set_array(static_cast<Array*>(bt_clone));
433 _map_vars.push_back(bt_clone);
443 _vars.push_back(bt_clone);
467 "Passing NULL pointer as variable to be added.");
470 if (part ==
array && _array_var) {
472 throw InternalErr(__FILE__, __LINE__,
"Error: Grid::add_var called with part==Array, but the array was already set!");
485 "Grid::add_var(): with Part==array: object is not an Array!");
493 _map_vars.push_back(bt);
504 "Grid::add_var(): with Part==array: object is not an Array!");
509 _map_vars.push_back(bt);
537 "Grid::set_array(): Cannot set to null!");
540 if (p_new_arr == _array_var) {
544 delete _array_var; _array_var = 0;
546 _array_var = p_new_arr;
581 "Grid::add_map(): cannot have p_new_map null!");
589 _map_vars.push_back(p_new_map);
590 _vars.push_back(p_new_map);
617 _map_vars.insert(_map_vars.begin(), p_new_map);
650 return _map_vars.begin() ;
658 return _map_vars.end() ;
665 return _map_vars.rbegin() ;
673 return _map_vars.rend() ;
682 return _map_vars.begin() + i;
706 comp = _array_var->
send_p() ? 1 : 0;
708 for (
Map_iter i = _map_vars.begin(); i != _map_vars.end(); i++) {
709 if ((*i)->send_p()) {
715 comp = 1 + _map_vars.size();
732 (*map)->transfer_attributes(at);
829 bool constraint_info,
bool constrained)
831 if (constrained && !
send_p())
840 fprintf(out,
"%sStructure {\n", space.c_str()) ;
842 _array_var->
print_decl(out, space +
" ",
true, constraint_info,
845 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end(); i++) {
846 (*i)->print_decl(out, space +
" ",
true,
847 constraint_info, constrained);
850 fprintf(out,
"%s} %s", space.c_str(),
id2www(
name()).c_str()) ;
855 fprintf(out,
"%s%s {\n", space.c_str(),
type_name().c_str()) ;
857 fprintf(out,
"%s Array:\n", space.c_str()) ;
858 _array_var->
print_decl(out, space +
" ",
true, constraint_info,
861 fprintf(out,
"%s Maps:\n", space.c_str()) ;
862 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end(); i++) {
863 (*i)->print_decl(out, space +
" ",
true,
864 constraint_info, constrained);
867 fprintf(out,
"%s} %s", space.c_str(),
id2www(
name()).c_str()) ;
870 if (constraint_info) {
872 fprintf( out,
": Send True");
874 fprintf( out,
": Send False");
878 fprintf(out,
";\n") ;
886 bool constraint_info,
bool constrained)
888 if (constrained && !
send_p())
893 out << space <<
"Structure {\n" ;
895 _array_var->
print_decl(out, space +
" ",
true, constraint_info,
898 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end(); i++) {
899 (*i)->print_decl(out, space +
" ",
true,
900 constraint_info, constrained);
910 out << space <<
" Array:\n" ;
911 _array_var->
print_decl(out, space +
" ",
true, constraint_info,
914 out << space <<
" Maps:\n" ;
915 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end(); i++) {
916 (*i)->print_decl(out, space +
" ",
true,
917 constraint_info, constrained);
923 if (constraint_info) {
925 out <<
": Send True";
927 out <<
": Send False";
937 class PrintMapField :
public unary_function<BaseType *, void>
944 PrintMapField(FILE *o,
string s,
bool c,
const string &t =
"Map")
945 : d_out(o), d_space(s), d_constrained(c), d_tag(t)
948 void operator()(BaseType *btp)
950 Array *a =
dynamic_cast<Array*
>(btp);
952 throw InternalErr(__FILE__, __LINE__,
"Expected an Array.");
953 a->print_xml_core(d_out, d_space, d_constrained, d_tag);
963 if (constrained && !
send_p())
967 fprintf(out,
"%s<Structure", space.c_str());
969 fprintf(out,
" name=\"%s\"",
id2xml(
name()).c_str());
978 PrintMapField(out, space +
" ", constrained,
"Array"));
980 fprintf(out,
"%s</Structure>\n", space.c_str());
985 fprintf(out,
"%s<Grid", space.c_str());
987 fprintf(out,
" name=\"%s\"",
id2xml(
name()).c_str());
996 PrintMapField(out, space +
" ", constrained));
998 fprintf(out,
"%s</Grid>\n", space.c_str());
1003 class PrintMapFieldStrm :
public unary_function<BaseType *, void>
1010 PrintMapFieldStrm(ostream &o,
string s,
bool c,
const string &t =
"Map")
1011 : d_out(o), d_space(s), d_constrained(c), d_tag(t)
1014 void operator()(BaseType *btp)
1016 Array *a =
dynamic_cast<Array*
>(btp);
1018 throw InternalErr(__FILE__, __LINE__,
"Expected an Array.");
1019 a->print_xml_core(d_out, d_space, d_constrained, d_tag);
1029 if (constrained && !
send_p())
1033 out << space <<
"<Structure" ;
1034 if (!
name().empty())
1035 out <<
" name=\"" <<
id2xml(
name()) <<
"\"" ;
1044 PrintMapFieldStrm(out, space +
" ", constrained,
"Array"));
1046 out << space <<
"</Structure>\n" ;
1051 out << space <<
"<Grid" ;
1052 if (!
name().empty())
1053 out <<
" name=\"" <<
id2xml(
name()) <<
"\"" ;
1062 PrintMapFieldStrm(out, space +
" ", constrained));
1064 out << space <<
"</Grid>\n" ;
1069 class PrintGridFieldXMLWriter :
public unary_function<BaseType *, void>
1075 PrintGridFieldXMLWriter(
XMLWriter &x,
bool c,
const string &t =
"Map")
1076 : d_xml(x), d_constrained(c), d_tag(t)
1079 void operator()(BaseType *btp)
1081 Array *a =
dynamic_cast<Array*
>(btp);
1083 throw InternalErr(__FILE__, __LINE__,
"Expected an Array.");
1084 a->print_xml_writer_core(d_xml, d_constrained, d_tag);
1091 if (constrained && !
send_p())
1095 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)
"Structure") < 0)
1096 throw InternalErr(__FILE__, __LINE__,
"Could not write Structure element");
1098 if (!
name().empty())
1099 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
1100 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1107 PrintGridFieldXMLWriter(xml, constrained,
"Array"));
1109 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
1110 throw InternalErr(__FILE__, __LINE__,
"Could not end Structure element");
1115 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)
"Grid") < 0)
1116 throw InternalErr(__FILE__, __LINE__,
"Could not write Grid element");
1118 if (!
name().empty())
1119 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
1120 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1127 PrintGridFieldXMLWriter(xml, constrained,
"Map"));
1129 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
1130 throw InternalErr(__FILE__, __LINE__,
"Could not end Grid element");
1140 fprintf(out,
" = ") ;
1149 fprintf(out,
"{ Array: ") ;
1154 fprintf(out,
" Maps: ") ;
1155 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end();
1156 i++, (void)(i != _map_vars.end() && fprintf(out,
", "))) {
1157 (*i)->print_val(out,
"",
false);
1159 fprintf(out,
" }") ;
1162 fprintf(out,
";\n") ;
1180 out <<
"{ Array: " ;
1186 for (
Map_citer i = _map_vars.begin(); i != _map_vars.end();
1187 i++, (void)(i != _map_vars.end() && out <<
", ")) {
1188 (*i)->print_val(out,
"",
false);
1211 msg +=
"Null grid base array in `" +
name() +
"'\n";
1217 msg +=
"Grid `" +
name() +
"'s' member `" + _array_var->
name() +
"' must be an array\n";
1225 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
1230 if ((
unsigned)_map_vars.size() != av->
dimensions()) {
1231 msg +=
"The number of map variables for grid `" + this->
name() +
"' does not match the number of dimensions of `";
1232 msg += av->
name() +
"'\n";
1236 const string array_var_name = av->
name();
1238 for (
Map_iter mvi = _map_vars.begin();
1239 mvi != _map_vars.end(); mvi++, asi++) {
1244 if (array_var_name == mv->
name()) {
1245 msg +=
"Grid map variable `" + mv->
name() +
"' conflicts with the grid array name in grid `" +
name() +
"'\n";
1250 msg +=
"Grid map variable `" + mv->
name() +
"' is not an array\n";
1258 msg +=
"The field variable `" + this->
name() +
"' must be an array of simple type elements (e.g., int32, String)\n";
1264 msg +=
"Grid map variable `" + mv_a->
name() +
"' must be only one dimension\n";
1271 if (mv_a_size != av_size) {
1272 msg +=
"Grid map variable `" + mv_a->
name() +
"'s' size does not match the size of array variable '";
1273 msg += _array_var->
name() +
"'s' cooresponding dimension\n";
1281 for (
Map_iter mvi = _map_vars.begin(); mvi != _map_vars.end(); mvi++) {
1282 if (!(*mvi)->check_semantics(msg,
true)) {
1303 << (
void *)
this <<
")" << endl ;
1308 DapIndent::Indent() ;
1309 _array_var->
dump(strm) ;
1316 DapIndent::Indent() ;
1319 for (; i != ie; i++) {