46 #include "InternalErr.h"
77 Dim_iter p = bt->dim_begin();
78 while ( p != bt->dim_end() ) {
79 append_dim(bt->dimension_size(p,
true), bt->dimension_name(p));
87 set_send_p(bt->send_p());
96 Array *bt = dynamic_cast < Array * >(_redirect);
101 if (bt->var()->is_simple_type()) {
102 if (dimensions(
true) > 1) {
103 print_array(strm, print_name);
105 print_vector(strm, print_name);
108 print_complex_array(strm, print_name);
113 void AsciiArray::print_vector(ostream &strm,
bool print_name)
115 Array *bt = dynamic_cast < Array * >(
_redirect);
121 strm << dynamic_cast<AsciiOutput*>(
this)->
get_full_name() <<
", " ;
124 int end = dimension_size(dim_begin(),
true) - 1;
126 for (
int i = 0; i < end; ++i) {
152 Array *bt = dynamic_cast < Array * >(
_redirect);
160 for (
int i = 0; i < number; ++i) {
167 for (
int i = 0; i < number; ++i) {
187 if (indices.size() != dimensions(
true)) {
188 throw InternalErr(__FILE__, __LINE__,
189 "Index vector is the wrong size!");
196 vector < int >shape = get_shape_vector(indices.size());
199 reverse(indices.begin(), indices.end());
200 reverse(shape.begin(), shape.end());
202 vector < int >::iterator indices_iter = indices.begin();
203 vector < int >::iterator shape_iter = shape.begin();
205 int index = *indices_iter++;
207 while (indices_iter != indices.end()) {
208 multiplier *= *shape_iter++;
209 index += multiplier * *indices_iter++;
220 if (n < 1 || n > dimensions(
true)) {
221 string msg =
"Attempt to get ";
222 msg += long_to_string(n) +
" dimensions from " + name()
223 +
" which has only " + long_to_string(dimensions(
true))
226 throw InternalErr(__FILE__, __LINE__, msg);
230 Array::Dim_iter p = dim_begin();
231 for (
unsigned i = 0; i < n && p != dim_end(); ++i, ++p) {
232 shape.push_back(dimension_size(p,
true));
243 if (n > dimensions(
true) - 1) {
244 string msg =
"Attempt to get dimension ";
246 long_to_string(n + 1) +
" from `" + name() +
247 "' which has " + long_to_string(dimensions(
true)) +
249 throw InternalErr(__FILE__, __LINE__, msg);
252 return dimension_size(dim_begin() + n,
true);
255 void AsciiArray::print_array(ostream &strm,
bool )
257 DBG(cerr <<
"Entering AsciiArray::print_array" << endl);
259 int dims = dimensions(
true);
261 throw InternalErr(__FILE__, __LINE__,
262 "Dimension count is <= 1 while printing multidimensional array.");
273 vector < int >state(dims - 1, 0);
279 strm << dynamic_cast <AsciiOutput *>(
this)->
get_full_name() ;
281 for (
int i = 0; i < dims - 1; ++i) {
282 strm <<
"[" << state[i] <<
"]" ;
286 index =
print_row(strm, index, rightmost_dim_size - 1);
291 }
while (more_indices);
293 DBG(cerr <<
"ExitingAsciiArray::print_array" << endl);
296 void AsciiArray::print_complex_array(ostream &strm,
bool )
298 DBG(cerr <<
"Entering AsciiArray::print_complex_array" << endl);
300 Array *bt = dynamic_cast < Array * >(
_redirect);
304 int dims = dimensions(
true);
306 throw InternalErr(__FILE__, __LINE__,
307 "Dimension count is <= 1 while printing multidimensional array.");
313 vector < int >state(dims, 0);
318 strm << dynamic_cast <AsciiOutput *>(
this)->
get_full_name() ;
320 for (
int i = 0; i < dims; ++i) {
321 strm <<
"[" << state[i] <<
"]" ;
335 }
while (more_indices);
337 DBG(cerr <<
"ExitingAsciiArray::print_complex_array" << endl);
bool increment_state(vector< int > *state, const vector< int > &shape)
Increment #state# to the next value given #shape#.
virtual BaseType * ptr_duplicate()
virtual void print_ascii(ostream &strm, bool print_name=true)
Print an ASCII representation for an instance of BaseType's children.
int get_index(vector< int > indices)
int get_nth_dim_size(size_t n)
Get the size of dimension #n#.
BaseType * basetype_to_asciitype(BaseType *bt)
int print_row(ostream &strm, int index, int number)
Print a single row of values for a N-dimensional array.
vector< int > get_shape_vector(size_t n)
Get the sizes of the first N dimensions of this array.
virtual void print_ascii(ostream &strm, bool print_name=true)
Print an ASCII representation for an instance of BaseType's children.
string get_full_name()
Get the fully qualified name of this object.
AsciiArray(const string &n, BaseType *v)