AFF --- A container for numbers (array) by Friederich and Forbriger.
dump_array.h
Go to the documentation of this file.
1 
46 // include guard
47 #ifndef AFF_DUMP_ARRAY_H_VERSION
48 
49 #define AFF_DUMP_ARRAY_H_VERSION \
50  "AFF_DUMP_ARRAY_H V1.3"
51 
52 #include<iostream>
53 #include<aff/array.h>
55 
56 namespace aff {
57 
58 using std::endl;
59 
60 namespace {
61 
66  template<class T>
68  const Tdim& i, const Tdim& j,
69  Strided::TIndexVec& index,
70  std::ostream& os)
71  {
72  if (i>1)
73  {
74  for (index[i]=array.f(i); index[i]<=array.l(i); index[i]++)
75  {
76  os << " dimension ";
77  os << i << ": [" << index[i] << "]";
78  dump_array_helper(array, i-1, j, index, os);
79  }
80  }
81  else if (i>0)
82  {
83  if (i<j) os << endl;
84  os.width(5); os << " ";
85  for (int k=array.f(1); k<=array.l(1); k++)
86  {
87  os.width(6); os << k;
88  }
89  os << endl;
90  for (index[0]=array.f(0); index[0]<=array.l(0); index[0]++)
91  {
92  os.width(5); os << index[0];
93  for (index[1]=array.f(1); index[1]<=array.l(1); index[1]++)
94  {
95  os.width(5);
96  if (j==0)
97  { os << array(index[0]); }
98  else if (j==1)
99  { os << array(index[0], index[1]); }
100  else if (j==2)
101  { os << array(index[0], index[1], index[2]); }
102  else if (j==3)
103  { os << array(index[0], index[1], index[2], index[3]); }
104  else
105  { os << array(index); }
106  os << "#";
107  }
108  os << endl;
109  }
110  }
111  else
112  {
113  for (index[0]=array.f(0); index[0]<=array.l(0); index[0]++)
114  {
115  os.width(5); os << index[0];
116  os.width(5);
117  if (j==0)
118  { os << array(index[0]); }
119  else if (j==1)
120  { os << array(index[0], index[1]); }
121  else if (j==2)
122  { os << array(index[0], index[1], index[2]); }
123  else if (j==3)
124  { os << array(index[0], index[1], index[2], index[3]); }
125  else
126  { os << array(index); }
127  os << "#" << endl;
128  }
129  }
130  }
131 }
132 
133 /*----------------------------------------------------------------------*/
134 
139 template<class T>
140 void dump_array_values(const ConstArray<T>& array,
141  const Tdim& i=(Strided::Mmax_dimen-1),
142  std::ostream& os=std::cout)
143 {
145  "ERROR (dump_map): illegal dimensionality");
146  Strided::TIndexVec index(array.first());
147  dump_array_helper(array, i, i, index, os);
148 }
149 
150 /*----------------------------------------------------------------------*/
151 
156 template<class T>
157 void dump_array(const ConstArray<T>& array,
158  const Tdim& i=(Strided::Mmax_dimen-1),
159  std::ostream& os=std::cout)
160 {
162  "ERROR (dump_map): illegal dimensionality");
163  dump(array);
164  os << "Array elements through " << i+1 << " dimensional access:" << endl;
165  dump_array_values(array, i, os);
166 }
167 
168 /*----------------------------------------------------------------------*/
169 
174 template<class T>
175 void dump(const ConstArray<T>& array, std::ostream& os=std::cout)
176 {
177  os << "dump of a Array object layout:" << endl;
178  os << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
179  dump(array.shape());
180  dump_layout(array.representation());
181 }
182 
183 } // namespace aff
184 
185 #endif // AFF_DUMP_ARRAY_H_VERSION (includeguard)
186 
187 /* ----- END OF dump_array.h ----- */
Root namespace of library.
Definition: array.h:148
factored out SharedHeap dump function (prototypes)
const Trepresentation & representation() const
provide restricted access representation
Definition: array.h:324
void dump(const Strided &shape, std::ostream &os)
dump shape
Definition: dump.cc:49
void dump_array_values(const ConstArray< T > &array, const Tdim &i=(Strided::Mmax_dimen-1), std::ostream &os=std::cout)
Dump array values only.
Definition: dump_array.h:140
full template array class headers (prototypes)
void dump_array(const ConstArray< T > &array, const Tdim &i=(Strided::Mmax_dimen-1), std::ostream &os=std::cout)
Dump array values.
Definition: dump_array.h:157
static const Tdim Mmax_dimen
instantiate static member (otherwise the linker won&#39;t find it)
Definition: strided.h:123
#define AFF_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:162
const Tshape & shape() const
provide access to const shape
Definition: array.h:318
void dump_layout(const aff::ConstSharedHeap< T > &sharedheap, std::ostream &os=std::cout)
Dump heap layout.
unsigned short int Tdim
Type to hold an array dimensionality.
Definition: types.h:49
const Tsubscript & l(const Tsubscript &i) const
return last index of dimension i
Definition: array.h:285
void dump_array_helper(const aff::ConstArray< T > &array, const Tdim &i, const Tdim &j, Strided::TIndexVec &index, std::ostream &os)
recursive usage tests all access functions
Definition: dump_array.h:67
Array base classThis is a multidimensional (array) container that uses a strided memory layout (Fortr...
Definition: array.h:172
const Tsubscript & f(const Tsubscript &i) const
return first index of dimension i
Definition: array.h:282
const Tsubscript & first(const Tsubscript &i) const
access to base class function
Definition: strided.h:194