54 Array::_duplicate(
const Array &a)
72 Array::update_length(
int)
75 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
76 length *= (*i).c_size > 0 ? (*i).c_size : 1;
133 DBG(cerr <<
"Entering ~Array (" <<
this <<
")" << endl);
134 DBG(cerr <<
"Exiting ~Array" << endl);
140 return new Array(*
this);
149 dynamic_cast<Vector &
>(*this) = rhs;
265 _shape.insert(_shape.begin(), d);
281 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
283 (*i).stop = (*i).size - 1;
285 (*i).c_size = (*i).size;
309 static const char *array_sss = \
310 "Invalid constraint parameters: At least one of the start, stride or stop \n\
311 specified do not match the array variable.";
341 if (start >= d.
size || stop >= d.
size || stride > d.
size || stride <= 0)
344 if (((stop - start) / stride + 1) > d.
size)
351 d.
c_size = (stop - start) / stride + 1;
353 DBG(cerr <<
"add_constraint: c_size = " << d.
c_size << endl);
362 return _shape.begin() ;
369 return _shape.end() ;
384 unsigned int dim = 0;
385 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
414 if (!_shape.empty()) {
445 return (!_shape.empty()) ? (*i).start : 0;
469 return (!_shape.empty()) ? (*i).stop : 0;
494 return (!_shape.empty()) ? (*i).stride : 0;
517 "*This* array has no dimensions.");
535 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
538 return length *
var()->
width(
false);
563 bool constraint_info,
bool constrained)
565 if (constrained && !
send_p())
569 var()->
print_decl(out, space,
false, constraint_info, constrained);
571 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
573 if ((*i).name !=
"") {
574 fprintf(out,
"%s = ",
id2www((*i).name).c_str()) ;
577 fprintf(out,
"%d]", (*i).c_size) ;
580 fprintf(out,
"%d]", (*i).size) ;
585 fprintf(out,
";\n") ;
609 bool constraint_info,
bool constrained)
611 if (constrained && !
send_p())
615 var()->
print_decl(out, space,
false, constraint_info, constrained);
617 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
619 if ((*i).name !=
"") {
620 out <<
id2www((*i).name) <<
" = " ;
623 out << (*i).c_size <<
"]" ;
626 out << (*i).size <<
"]" ;
675 class PrintArrayDim :
public unary_function<Array::dimension&, void>
681 PrintArrayDim(FILE *o,
string s,
bool c)
682 : d_out(o), d_space(s), d_constrained(c)
685 void operator()(Array::dimension &d)
687 int size = d_constrained ? d.c_size : d.size;
689 fprintf(d_out,
"%s<dimension size=\"%d\"/>\n", d_space.c_str(),
692 fprintf(d_out,
"%s<dimension name=\"%s\" size=\"%d\"/>\n",
693 d_space.c_str(),
id2xml(d.name).c_str(), size);
703 if (constrained && !
send_p())
706 fprintf(out,
"%s<%s", space.c_str(), tag.c_str());
708 fprintf(out,
" name=\"%s\"",
id2xml(
name()).c_str());
709 fprintf(out ,
">\n");
714 string tmp_name = btp->
name();
716 btp->
print_xml(out, space +
" ", constrained);
720 PrintArrayDim(out, space +
" ", constrained));
722 fprintf(out,
"%s</%s>\n", space.c_str(), tag.c_str());
726 class PrintArrayDimStrm :
public unary_function<Array::dimension&, void>
732 PrintArrayDimStrm(ostream &o,
string s,
bool c)
733 : d_out(o), d_space(s), d_constrained(c)
736 void operator()(Array::dimension &d)
738 int size = d_constrained ? d.c_size : d.size;
740 d_out << d_space <<
"<dimension size=\"" << size <<
"\"/>\n" ;
742 d_out << d_space <<
"<dimension name=\"" <<
id2xml(d.name)
743 <<
"\" size=\"" << size <<
"\"/>\n" ;
753 if (constrained && !
send_p())
756 out << space <<
"<" << tag;
764 string tmp_name = btp->
name();
766 btp->
print_xml(out, space +
" ", constrained);
769 for_each(
dim_begin(),
dim_end(), PrintArrayDimStrm(out, space +
" ", constrained));
771 out << space <<
"</" << tag <<
">\n";
786 class PrintArrayDimXMLWriter :
public unary_function<Array::dimension&, void>
791 PrintArrayDimXMLWriter(
XMLWriter &xml,
bool c) : xml(xml), d_constrained(c) {}
793 void operator()(Array::dimension &d)
795 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dimension") < 0)
796 throw InternalErr(__FILE__, __LINE__,
"Could not write dimension element");
799 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d.name.c_str()) < 0)
800 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
803 size << (d_constrained ? d.c_size : d.size);
804 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"size", (
const xmlChar*)size.str().c_str()) < 0)
805 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
807 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
808 throw InternalErr(__FILE__, __LINE__,
"Could not end dimension element");
815 if (constrained && !
send_p())
818 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)tag.c_str()) < 0)
819 throw InternalErr(__FILE__, __LINE__,
"Could not write " + tag +
" element");
822 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
823 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
828 string tmp_name = btp->
name();
835 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
836 throw InternalErr(__FILE__, __LINE__,
"Could not end " + tag +
" element");
853 unsigned int shape[])
857 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
874 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
875 index =
print_array(out, index, dims - 1, shape + 1);
878 index =
print_array(out, index, dims - 1, shape + 1);
899 unsigned int shape[])
903 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
920 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
921 index =
print_array(out, index, dims - 1, shape + 1);
924 index =
print_array(out, index, dims - 1, shape + 1);
943 fprintf(out,
" = ") ;
946 unsigned int *shape =
new unsigned int[_shape.size()];
947 unsigned int index = 0;
948 for (
Dim_iter i = _shape.begin(); i != _shape.end() && index < _shape.size(); i++)
953 delete [] shape; shape = 0;
956 fprintf(out,
";\n") ;
975 unsigned int *shape =
new unsigned int[
dimensions(
true)];
976 unsigned int index = 0;
982 delete [] shape; shape = 0;
1004 msg =
"An array variable must have dimensions";
1021 << (
void *)
this <<
")" << endl ;
1028 unsigned int dim_num = 0 ;
1029 for (; i != ie; i++) {