AFF --- A container for numbers (array) by Friederich and Forbriger.
slice.h
Go to the documentation of this file.
1 
48 // include guard
49 #ifndef AFF_SLICE_H_VERSION
50 
51 #define AFF_SLICE_H_VERSION \
52  "AFF_SLICE_H V1.4"
53 
54 #include<aff/array.h>
55 
56 namespace aff {
57 namespace util {
58 
66  template<class C>
67  class Slice
68  {
69  public:
71  typedef C Tarray;
73  typedef C Tcontainer;
75  typedef typename Tarray::Tconst_value Tconst_value;
77  typedef typename Tarray::Tconst_reference Tconst_reference;
79  typedef typename Tarray::Tconst_pointer Tconst_pointer;
81  typedef typename Tarray::Tshape Tshape;
83  typedef typename Tarray::Trepresentation Trepresentation;
85  Slice(const Tarray& array)
86  {
87  // notice: a const Array does not return its representation
88  // thus me create a local (non-const) copy
89  // that's truely inefficient (copying the shape twice)
90  Tarray copy=array;
91  Mshape=copy.shape();
92  Mrepresentation=copy.representation();
93  Mdim=0;
94  }
97  {
98  ++Mdim;
99  return(*this);
100  }
102  Slice& operator()(const Tsubscript& index)
103  {
104  this->check_dim();
105  Mshape.collapse(Mdim, index);
106  ++Mdim;
107  return(*this);
108  }
110  Slice& operator()(const Tdim& dim, const Tsubscript& index)
111  {
112  Mshape.collapse(dim, index);
113  return(*this);
114  }
117  {
118  typename Tshape::Tstepper st(Mshape);
119  for(st.tofirst(); st.valid(); st.incr())
120  { Mrepresentation[st.current()]=value; }
121  return(*this);
122  }
124  Tarray array() const
125  { return(Tarray(Mshape,Mrepresentation)); }
127  operator Tarray() const
128  { return(Tarray(Mshape,Mrepresentation)); }
129  private:
131  void check_dim() const
132  {
133  AFF_assert((Mdim<Tshape::Mmax_dimen),
134  "ERROR (Slice): you use too many dimension-brackets!");
135  }
142  }; // class Slice
143 
144 } // namespace util
145 
146 /*----------------------------------------------------------------------*/
147 
156 template<class C>
157 inline
159 { return(aff::util::Slice<C>(c)); }
160 
161 } // namespace aff
162 
163 #endif // AFF_SLICE_H_VERSION (includeguard)
164 
165 /* ----- END OF slice.h ----- */
Slice & operator()()
skip this dimension
Definition: slice.h:96
Root namespace of library.
Definition: array.h:148
Slice & operator()(const Tdim &dim, const Tsubscript &index)
slice dimention dim
Definition: slice.h:110
Trepresentation Mrepresentation
Representation to use.
Definition: slice.h:139
aff::util::Slice< C > slice(const C &c)
Wrapper function to select correct type.
Definition: slice.h:158
Slice(const Tarray &array)
Constructor takes a reference to an array.
Definition: slice.h:85
C Tcontainer
Type of array to be handled.
Definition: slice.h:73
Tarray::Tconst_pointer Tconst_pointer
Type of pointer to const element.
Definition: slice.h:79
Slice & operator()(const Tsubscript &index)
slice next dimension
Definition: slice.h:102
Slice & operator=(Tconst_reference value)
provide value assignment to a slice
Definition: slice.h:116
void check_dim() const
check dimension
Definition: slice.h:131
Tarray::Tshape Tshape
Type of shape to be used.
Definition: slice.h:81
C Tarray
Type of array to be handled.
Definition: slice.h:71
Tarray::Trepresentation Trepresentation
Type of reference to be used.
Definition: slice.h:83
full template array class headers (prototypes)
Tarray array() const
return an array
Definition: slice.h:124
Tarray::Tconst_reference Tconst_reference
Type of reference to const element.
Definition: slice.h:77
#define AFF_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:162
Tshape Mshape
Shape to process.
Definition: slice.h:137
Tarray::Tconst_value Tconst_value
Type of const element.
Definition: slice.h:75
Create slices.
Definition: slice.h:67
Tdim Mdim
Next dimension to collapse.
Definition: slice.h:141
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