AFF --- A container for numbers (array) by Friederich and Forbriger.
subarray.h
Go to the documentation of this file.
1 
46 // include guard
47 #ifndef AFF_SUBARRAY_H_VERSION
48 
49 #define AFF_SUBARRAY_H_VERSION \
50  "AFF_SUBARRAY_H V1.3"
51 
52 #include<aff/array.h>
53 
54 namespace aff {
55 namespace util {
56 
71  template<class C>
72  class Subarray
73  {
74  public:
76  typedef C Tarray;
78  typedef C Tcontainer;
80  typedef typename Tarray::Tconst_value Tconst_value;
82  typedef typename Tarray::Tconst_reference Tconst_reference;
84  typedef typename Tarray::Tconst_pointer Tconst_pointer;
86  typedef typename Tarray::Tshape Tshape;
88  typedef typename Tarray::Trepresentation Trepresentation;
91  {
92  // notice: a const Array does not return its representation
93  // thus we create a local (non-const) copy
94  // that's truely inefficient (copying the shape twice)
95  Tarray copy=array;
96  Mshape=copy.shape();
97  Mrepresentation=copy.representation();
98  Mdim=0;
99  }
102  { ++Mdim; return(*this); }
105  {
106  this->check_dim();
107  Mshape.shrink(Mdim, last);
108  ++Mdim;
109  return(*this);
110  }
113  const Tsubscript& last)
114  {
115  this->check_dim();
116  Mshape.shrink(Mdim, first, last);
117  ++Mdim;
118  return(*this);
119  }
122  {
123  typename Tshape::Tstepper st(Mshape);
124  for(st.tofirst(); st.valid(); st.incr())
125  { Mrepresentation[st.current()]=value; }
126  return(*this);
127  }
129  Tarray array() const
130  { return(Tarray(Mshape,Mrepresentation)); }
132  operator Tarray() const
133  { return(Tarray(Mshape,Mrepresentation)); }
134  private:
136  void check_dim() const
137  {
138  AFF_assert((Mdim<Tshape::Mmax_dimen),
139  "ERROR (Subarray): you use too many dimension-brackets!");
140  }
147  }; // class Subarray
148 
149 } // namespace util
150 
151 /*----------------------------------------------------------------------*/
152 
161 template<class C>
162 inline
164 { return(aff::util::Subarray<C>(c)); }
165 
166 } // namespace aff
167 
168 #endif // AFF_SUBARRAY_H_VERSION (includeguard)
169 
170 /* ----- END OF subarray.h ----- */
Root namespace of library.
Definition: array.h:148
Tshape Mshape
Shape to process.
Definition: subarray.h:142
Create subarrays.
Definition: subarray.h:72
Tarray::Tconst_pointer Tconst_pointer
Type of pointer to const element.
Definition: subarray.h:84
aff::util::Subarray< C > subarray(const C &c)
Wrapper function to select correct type.
Definition: subarray.h:163
Tdim Mdim
Dimension to specify.
Definition: subarray.h:146
Trepresentation Mrepresentation
Representation to use.
Definition: subarray.h:144
Subarray & operator=(Tconst_reference value)
provide value assignment to a subarray
Definition: subarray.h:121
full template array class headers (prototypes)
Tarray array() const
return an array
Definition: subarray.h:129
C Tcontainer
Type of array to be handled.
Definition: subarray.h:78
#define AFF_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:162
C Tarray
Type of array to be handled.
Definition: subarray.h:76
Tarray::Tconst_reference Tconst_reference
Type of reference to const element.
Definition: subarray.h:82
Subarray & operator()()
use full range of this dimension
Definition: subarray.h:101
Subarray & operator()(const Tsubscript &first, const Tsubscript &last)
set first and last index of this dimension
Definition: subarray.h:112
Tarray::Tshape Tshape
Type of shape to be used.
Definition: subarray.h:86
unsigned short int Tdim
Type to hold an array dimensionality.
Definition: types.h:49
ptrdiff_t Tsubscript
Type to hold an array&#39;s subscript value.
Definition: types.h:53
Subarray(const Tarray &array)
Constructor takes a reference to an array.
Definition: subarray.h:90
Tarray::Tconst_value Tconst_value
Type of const element.
Definition: subarray.h:80
Tarray::Trepresentation Trepresentation
Type of reference to be used.
Definition: subarray.h:88
void check_dim() const
check dimensions
Definition: subarray.h:136
Subarray & operator()(const Tsubscript &last)
set last index of this dimension
Definition: subarray.h:104