OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
FSlice.h
Go to the documentation of this file.
1 #ifndef CLASSIC_FSlice_HH
2 #define CLASSIC_FSlice_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: FSlice.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1.2.2 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Template class: FSlice
13 //
14 // ------------------------------------------------------------------------
15 // Class category: FixedAlgebra
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2004/11/12 18:57:54 $
19 // $Author: adelmann $
20 //
21 // ------------------------------------------------------------------------
22 
23 #include <iterator>
24 
25 // Class FSlice.
26 // ------------------------------------------------------------------------
28 
29 template<class T, int S>
30 class FSlice {
31 
32 public:
33 
35  typedef std::random_access_iterator_tag iterator_category;
36 
38  typedef T value_type;
39 
41  typedef std::ptrdiff_t difference_type;
42 
44  typedef T *pointer;
45 
47  typedef T &reference;
48 
50  explicit FSlice(T *);
51 
52  FSlice(const FSlice &);
53  FSlice &operator=(const FSlice &);
54  bool operator==(const FSlice &rhs) const;
55  bool operator!=(const FSlice &rhs) const;
56 
58  FSlice &operator++();
59 
61  FSlice operator++(int);
62 
64  FSlice &operator--();
65 
67  FSlice operator--(int);
68 
70  FSlice &operator+=(std::ptrdiff_t);
71 
73  FSlice &operator-=(std::ptrdiff_t);
74 
76  FSlice operator+(std::ptrdiff_t);
77 
79  FSlice operator-(std::ptrdiff_t);
80 
82  difference_type operator-(const FSlice &) const;
83 
85  T &operator*() const;
86 
88  T &operator[](int) const;
89 
90 private:
91 
93 };
94 
95 
96 // Class FConstSlice.
97 // ------------------------------------------------------------------------
99 
100 template<class T, int S>
101 class FConstSlice {
102 
103 public:
104 
106  typedef std::random_access_iterator_tag iterator_category;
107 
109  typedef const T value_type;
110 
112  typedef std::ptrdiff_t difference_type;
113 
115  typedef const T *pointer;
116 
118  typedef const T &reference;
119 
121  FConstSlice(const T *);
122 
123  FConstSlice(const FConstSlice &rhs);
125  bool operator==(const FConstSlice &rhs) const;
126  bool operator!=(const FConstSlice &rhs) const;
127 
130 
132  FConstSlice operator++(int);
133 
136 
138  FConstSlice operator--(int);
139 
141  FConstSlice &operator+=(std::ptrdiff_t);
142 
144  FConstSlice &operator-=(std::ptrdiff_t);
145 
147  FConstSlice operator+(std::ptrdiff_t) const;
148 
150  FConstSlice operator-(std::ptrdiff_t) const;
151 
153  difference_type operator-(const FConstSlice &) const;
154 
156  const T &operator*() const;
157 
159  const T &operator[](int) const;
160 
161 private:
162 
163  mutable const T *cursor;
164 };
165 
166 
167 // Ancillary functions.
168 // ------------------------------------------------------------------------
169 
170 template<class T, int S>
171 inline std::random_access_iterator_tag
173  return std::random_access_iterator_tag();
174 }
175 
176 template<class T, int S>
177 inline std::random_access_iterator_tag
179  return std::random_access_iterator_tag();
180 }
181 
182 template<class T, int S>
183 inline T *value_type(const FSlice<T, S> &) {
184  return (T *)(0);
185 }
186 
187 template<class T, int S>
188 inline T *value_type(const FConstSlice<T, S> &) {
189  return (T *)(0);
190 }
191 
192 
193 // Template function implementation for FSlice.
194 // ------------------------------------------------------------------------
195 
196 template<class T, int S>
197 inline FSlice<T, S>::FSlice(T *array):
198  cursor(array)
199 {}
200 
201 template<class T, int S>
202 inline FSlice<T, S>::FSlice(const FSlice &rhs):
203  cursor(rhs.cursor)
204 {}
205 
206 template<class T, int S>
208  cursor = rhs.cursor;
209  return *this;
210 }
211 
212 template<class T, int S>
213 inline bool FSlice<T, S>::operator==(const FSlice &rhs) const {
214  return cursor == rhs.cursor;
215 }
216 
217 template<class T, int S>
218 inline bool FSlice<T, S>::operator!=(const FSlice &rhs) const {
219  return cursor != rhs.cursor;
220 }
221 
222 template<class T, int S>
224  cursor += S;
225  return *this;
226 }
227 
228 template<class T, int S>
230  FSlice tmp(*this);
231  cursor += S;
232  return tmp;
233 }
234 
235 template<class T, int S>
237  cursor -= S;
238  return *this;
239 }
240 
241 template<class T, int S>
243  FSlice tmp(*this);
244  cursor -= S;
245  return tmp;
246 }
247 
248 template<class T, int S>
249 inline FSlice<T, S> &FSlice<T, S>::operator+=(std::ptrdiff_t n) {
250  cursor += n * S;
251  return *this;
252 }
253 
254 template<class T, int S>
255 inline FSlice<T, S> &FSlice<T, S>::operator-=(std::ptrdiff_t n) {
256  cursor -= n * S;
257  return *this;
258 }
259 
260 template<class T, int S>
261 inline FSlice<T, S> FSlice<T, S>::operator+(std::ptrdiff_t n) {
262  FSlice tmp(*this);
263  return tmp += n;
264 }
265 
266 template<class T, int S>
267 inline FSlice<T, S> FSlice<T, S>::operator-(std::ptrdiff_t n) {
268  FSlice tmp(*this);
269  return tmp -= n;
270 }
271 
272 template<class T, int S>
273 inline typename FSlice<T, S>::difference_type
274 FSlice<T, S>::operator-(const FSlice &rhs) const {
275  return (cursor - rhs.cursor) / S;
276 }
277 
278 template<class T, int S>
279 inline T &FSlice<T, S>::operator*() const {
280  return *cursor;
281 }
282 
283 template<class T, int S>
284 inline T &FSlice<T, S>::operator[](int n) const {
285  return cursor[n*S];
286 }
287 
288 
289 // Template function implementation for FConstSlice.
290 // ------------------------------------------------------------------------
291 
292 template<class T, int S>
293 inline FConstSlice<T, S>::FConstSlice(const T *array):
294  cursor(array)
295 {}
296 
297 template<class T, int S>
299  cursor(rhs.cursor)
300 {}
301 
302 template<class T, int S>
304  cursor = rhs.cursor;
305  return *this;
306 }
307 
308 template<class T, int S>
309 inline bool FConstSlice<T, S>::operator==(const FConstSlice &rhs) const {
310  return cursor == rhs.cursor;
311 }
312 
313 template<class T, int S>
314 inline bool FConstSlice<T, S>::operator!=(const FConstSlice &rhs) const {
315  return cursor != rhs.cursor;
316 }
317 
318 template<class T, int S>
320  cursor += S;
321  return *this;
322 }
323 
324 template<class T, int S>
326  FConstSlice tmp(*this);
327  cursor += S;
328  return tmp;
329 }
330 
331 template<class T, int S>
333  cursor -= S;
334  return *this;
335 }
336 
337 template<class T, int S>
339  FConstSlice tmp(*this);
340  cursor -= S;
341  return tmp;
342 }
343 
344 template<class T, int S>
346  cursor += n * S;
347  return *this;
348 }
349 
350 template<class T, int S>
352  cursor -= n * S;
353  return *this;
354 }
355 
356 template<class T, int S> inline
358  FConstSlice tmp(*this);
359  return tmp += n;
360 }
361 
362 template<class T, int S> inline
364  FConstSlice tmp(*this);
365  return tmp -= n;
366 }
367 
368 template<class T, int S>
371  return (cursor - rhs.cursor) / S;
372 }
373 
374 template<class T, int S>
375 inline const T &FConstSlice<T, S>::operator*() const {
376  return *cursor;
377 }
378 
379 template<class T, int S>
380 inline const T &FConstSlice<T, S>::operator[](int n) const {
381  return cursor[n*S];
382 }
383 
384 #endif // CLASSIC_FSlice_HH
385 
FConstSlice & operator--()
Decrement (iterate backward).
Definition: FSlice.h:332
FSlice & operator=(const FSlice &)
Definition: FSlice.h:207
const T * cursor
Definition: FSlice.h:163
Definition: rbendmap.h:8
T & operator[](int) const
Delegate.
Definition: FSlice.h:284
FConstSlice & operator++()
Increment (iterate forward).
Definition: FSlice.h:319
std::ptrdiff_t difference_type
The pointer difference type.
Definition: FSlice.h:112
FConstSlice operator-(std::ptrdiff_t) const
Subtract multiple stride.
Definition: FSlice.h:363
FSlice & operator-=(std::ptrdiff_t)
Decrement by multiple stride.
Definition: FSlice.h:255
T & operator*() const
Dereference.
Definition: FSlice.h:279
std::random_access_iterator_tag iterator_category
The iterator tag, taken from the standard template library.
Definition: FSlice.h:106
FSlice operator+(std::ptrdiff_t)
Add multiple stride.
Definition: FSlice.h:261
FConstSlice operator+(std::ptrdiff_t) const
Add multiple stride.
Definition: FSlice.h:357
Constant version of FSlice.
Definition: FSlice.h:101
FSlice & operator--()
Decrement (iterate backward).
Definition: FSlice.h:236
std::random_access_iterator_tag iterator_category(const SliceIterator< T > &)
const T * pointer
The pointer type.
Definition: FSlice.h:115
FSlice operator-(std::ptrdiff_t)
Subtract multiple stride.
Definition: FSlice.h:267
const T value_type
The value type.
Definition: FSlice.h:109
bool operator!=(const FSlice &rhs) const
Definition: FSlice.h:218
const T & operator*() const
Dereference.
Definition: FSlice.h:375
bool operator==(const FSlice &rhs) const
Definition: FSlice.h:213
FConstSlice(const T *)
Constructor from array and stride.
Definition: FSlice.h:293
FConstSlice & operator=(const FConstSlice &)
Definition: FSlice.h:303
T & reference
The reference type.
Definition: FSlice.h:47
std::ptrdiff_t difference_type
The pointer difference type.
Definition: FSlice.h:41
T * value_type(const SliceIterator< T > &)
bool operator!=(const FConstSlice &rhs) const
Definition: FSlice.h:314
std::random_access_iterator_tag iterator_category
The iterator tag, taken from the standard template library.
Definition: FSlice.h:35
T * pointer
The pointer type.
Definition: FSlice.h:44
FSlice(T *)
Constructor for array.
Definition: FSlice.h:197
bool operator==(const FConstSlice &rhs) const
Definition: FSlice.h:309
const T & operator[](int) const
Delegate.
Definition: FSlice.h:380
FConstSlice & operator-=(std::ptrdiff_t)
Subtract multiple stride and assign.
Definition: FSlice.h:351
T value_type
The value type.
Definition: FSlice.h:38
An iterator permitting to iterate with a stride different from 1.
Definition: FSlice.h:30
FConstSlice & operator+=(std::ptrdiff_t)
Add multiple stride and assign.
Definition: FSlice.h:345
T * cursor
Definition: FSlice.h:92
FSlice & operator++()
Increment (iterate forward).
Definition: FSlice.h:223
FSlice & operator+=(std::ptrdiff_t)
Increment by multiple stride.
Definition: FSlice.h:249
const T & reference
The reference type.
Definition: FSlice.h:118