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;
245 _shape.insert(_shape.begin(), d);
261 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
263 (*i).stop = (*i).size - 1;
265 (*i).c_size = (*i).size;
289 static const char *array_sss = \
290 "Invalid constraint parameters: At least one of the start, stride or stop \n\
291 specified do not match the array variable.";
321 if (start >= d.
size || stop >= d.
size || stride > d.
size || stride <= 0)
324 if (((stop - start) / stride + 1) > d.
size)
331 d.
c_size = (stop - start) / stride + 1;
333 DBG(cerr <<
"add_constraint: c_size = " << d.
c_size << endl);
342 return _shape.begin() ;
349 return _shape.end() ;
364 unsigned int dim = 0;
365 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
394 if (!_shape.empty()) {
425 return (!_shape.empty()) ? (*i).start : 0;
449 return (!_shape.empty()) ? (*i).stop : 0;
474 return (!_shape.empty()) ? (*i).stride : 0;
497 "*This* array has no dimensions.");
515 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
518 return length *
var()->
width(
false);
543 bool constraint_info,
bool constrained)
545 if (constrained && !
send_p())
549 var()->
print_decl(out, space,
false, constraint_info, constrained);
551 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
553 if ((*i).name !=
"") {
554 fprintf(out,
"%s = ",
id2www((*i).name).c_str()) ;
557 fprintf(out,
"%d]", (*i).c_size) ;
560 fprintf(out,
"%d]", (*i).size) ;
565 fprintf(out,
";\n") ;
589 bool constraint_info,
bool constrained)
591 if (constrained && !
send_p())
595 var()->
print_decl(out, space,
false, constraint_info, constrained);
597 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
599 if ((*i).name !=
"") {
600 out <<
id2www((*i).name) <<
" = " ;
603 out << (*i).c_size <<
"]" ;
606 out << (*i).size <<
"]" ;
655 class PrintArrayDim :
public unary_function<Array::dimension&, void>
661 PrintArrayDim(FILE *o,
string s,
bool c)
662 : d_out(o), d_space(s), d_constrained(c)
665 void operator()(Array::dimension &d)
667 int size = d_constrained ? d.c_size : d.size;
669 fprintf(d_out,
"%s<dimension size=\"%d\"/>\n", d_space.c_str(),
672 fprintf(d_out,
"%s<dimension name=\"%s\" size=\"%d\"/>\n",
673 d_space.c_str(),
id2xml(d.name).c_str(), size);
683 if (constrained && !
send_p())
686 fprintf(out,
"%s<%s", space.c_str(), tag.c_str());
688 fprintf(out,
" name=\"%s\"",
id2xml(
name()).c_str());
689 fprintf(out ,
">\n");
694 string tmp_name = btp->
name();
696 btp->
print_xml(out, space +
" ", constrained);
700 PrintArrayDim(out, space +
" ", constrained));
702 fprintf(out,
"%s</%s>\n", space.c_str(), tag.c_str());
706 class PrintArrayDimStrm :
public unary_function<Array::dimension&, void>
712 PrintArrayDimStrm(ostream &o,
string s,
bool c)
713 : d_out(o), d_space(s), d_constrained(c)
716 void operator()(Array::dimension &d)
718 int size = d_constrained ? d.c_size : d.size;
720 d_out << d_space <<
"<dimension size=\"" << size <<
"\"/>\n" ;
722 d_out << d_space <<
"<dimension name=\"" <<
id2xml(d.name)
723 <<
"\" size=\"" << size <<
"\"/>\n" ;
733 if (constrained && !
send_p())
736 out << space <<
"<" << tag;
744 string tmp_name = btp->
name();
746 btp->
print_xml(out, space +
" ", constrained);
749 for_each(
dim_begin(),
dim_end(), PrintArrayDimStrm(out, space +
" ", constrained));
751 out << space <<
"</" << tag <<
">\n";
766 class PrintArrayDimXMLWriter :
public unary_function<Array::dimension&, void>
771 PrintArrayDimXMLWriter(
XMLWriter &xml,
bool c) : xml(xml), d_constrained(c) {}
773 void operator()(Array::dimension &d)
775 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dimension") < 0)
776 throw InternalErr(__FILE__, __LINE__,
"Could not write dimension element");
779 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d.name.c_str()) < 0)
780 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
783 size << (d_constrained ? d.c_size : d.size);
784 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"size", (
const xmlChar*)size.str().c_str()) < 0)
785 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
787 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
788 throw InternalErr(__FILE__, __LINE__,
"Could not end dimension element");
795 if (constrained && !
send_p())
798 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)tag.c_str()) < 0)
799 throw InternalErr(__FILE__, __LINE__,
"Could not write " + tag +
" element");
802 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
803 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
808 string tmp_name = btp->
name();
815 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
816 throw InternalErr(__FILE__, __LINE__,
"Could not end " + tag +
" element");
833 unsigned int shape[])
837 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
854 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
855 index =
print_array(out, index, dims - 1, shape + 1);
858 index =
print_array(out, index, dims - 1, shape + 1);
879 unsigned int shape[])
883 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
900 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
901 index =
print_array(out, index, dims - 1, shape + 1);
904 index =
print_array(out, index, dims - 1, shape + 1);
923 fprintf(out,
" = ") ;
926 unsigned int *shape =
new unsigned int[_shape.size()];
927 unsigned int index = 0;
928 for (
Dim_iter i = _shape.begin(); i != _shape.end() && index < _shape.size(); i++)
933 delete [] shape; shape = 0;
936 fprintf(out,
";\n") ;
955 unsigned int *shape =
new unsigned int[
dimensions(
true)];
956 unsigned int index = 0;
962 delete [] shape; shape = 0;
984 msg =
"An array variable must have dimensions";
1001 << (
void *)
this <<
")" << endl ;
1005 DapIndent::Indent() ;
1008 unsigned int dim_num = 0 ;
1009 for (; i != ie; i++) {
1012 DapIndent::Indent() ;