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++) {