Schnek
grid.hpp
1 /*
2  * grid.h
3  *
4  * Created on: 23 Jan 2007
5  * Author: Holger Schmitz
6  * Email: holger@notjustphysics.com
7  *
8  * Copyright 2012 Holger Schmitz
9  *
10  * This file is part of Schnek.
11  *
12  * Schnek is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * Schnek is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with Schnek. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef SCHNEK_GRID_H_
28 #define SCHNEK_GRID_H_
29 
30 #include "array.hpp"
31 #include "range.hpp"
32 #include "gridcheck.hpp"
33 #include "gridstorage.hpp"
34 #include "../typetools.hpp"
35 
36 namespace schnek {
37 
38 template<class GridType, typename TList>
40 
41 template<class IndexType>
42 struct IndexCast;
43 
44 template<class Operator, int Length>
45 class ArrayExpression;
46 
48 template<
49  typename T,
50  int rank,
51  class CheckingPolicy,
52  class StoragePolicy
53 >
54 class GridBase : public StoragePolicy, public CheckingPolicy
55 {
56  public:
57  typedef T value_type;
58  typedef CheckingPolicy CheckingPolicyType;
59  typedef StoragePolicy StoragePolicyType;
60  typedef typename CheckingPolicy::IndexType IndexType;
62  enum {Rank = rank};
63 
64  GridBase();
65 
66  template<template<int> class ArrayCheckingPolicy>
68 
69  template<template<int> class ArrayCheckingPolicy>
71 
73  template<template<int> class ArrayCheckingPolicy>
74  T& operator[](const Array<int,rank,ArrayCheckingPolicy>& pos); // write
76  template<template<int> class ArrayCheckingPolicy>
77  T operator[](const Array<int,rank,ArrayCheckingPolicy>& pos) const; // read
78 
80  template<class Operator, int Length>
81  T& operator[](const ArrayExpression<Operator, Length>& pos); // write
83  template<class Operator, int Length>
84  T operator[](const ArrayExpression<Operator, Length>& pos) const; // read
85 
87  T& operator[](int i);
89  T operator[](int i) const;
90 
92  T& operator()(int i);
94  T operator()(int i) const;
96  T& operator()(int i, int j);
98  T operator()(int i, int j) const;
100  T& operator()(int i, int j, int k);
102  T operator()(int i, int j, int k) const;
104  T& operator()(int i, int j, int k, int l);
106  T operator()(int i, int j, int k, int l) const;
108  T& operator()(int i, int j, int k, int l, int m);
110  T operator()(int i, int j, int k, int l, int m) const;
112  T& operator()(int i, int j, int k, int l, int m, int o);
114  T operator()(int i, int j, int k, int l, int m, int o) const;
116  T& operator()(int i, int j, int k, int l, int m, int o, int p);
118  T operator()(int i, int j, int k, int l, int m, int o, int p) const;
120  T& operator()(int i, int j, int k, int l, int m, int o, int p, int q);
122  T operator()(int i, int j, int k, int l, int m, int o, int p, int q) const;
124  T& operator()(int i, int j, int k, int l, int m, int o, int p, int q, int r);
126  T operator()(int i, int j, int k, int l, int m, int o, int p, int q, int r) const;
128  T& operator()(int i, int j, int k, int l, int m, int o, int p, int q, int r, int s);
130  T operator()(int i, int j, int k, int l, int m, int o, int p, int q, int r, int s) const;
131 
135 
137  template<
138  typename T2,
139  class CheckingPolicy2,
140  class StoragePolicy2
141  >
144 
147  operator=(const T &val);
148 
149  template<
150  typename T2,
151  class CheckingPolicy2
152  >
155 
156  template<
157  typename T2,
158  class CheckingPolicy2,
159  class StoragePolicy2
160  >
163 
164  template<
165  typename T2,
166  class CheckingPolicy2
167  >
170 
171 
172  template<
173  typename T2,
174  class CheckingPolicy2,
175  class StoragePolicy2
176  >
179 
191  void resize(const IndexType &size);
192 
206  void resize(const IndexType &low, const IndexType &high);
207 
209  template<
210  typename T2,
211  class CheckingPolicy2,
212  class StoragePolicy2
213  >
215 
216  protected:
217  // assumes that the sizes are already set properly
218  template<typename T2, class CheckingPolicy2>
219  void copyFromGrid(const GridBase<T2, rank, CheckingPolicy2, StoragePolicy>& grid);
220 
221 };
222 
223 
224 
229 template<
230  typename T,
231  int rank,
232  template<int> class CheckingPolicy = GridNoArgCheck,
233  template<typename, int> class StoragePolicy = SingleArrayGridStorage
234 >
235 class Grid : public GridBase<T, rank, CheckingPolicy<rank>, StoragePolicy<T,rank> >
236 {
237 
238  public:
239  typedef T value_type;
240  typedef Array<int,rank> IndexType;
241  typedef Range<int,rank> RangeType;
243  typedef GridBase<T, rank, CheckingPolicy<rank>, StoragePolicy<T,rank> > BaseType;
244  enum {Rank = rank};
245 
247  Grid();
248 
259  Grid(const IndexType &size);
260 
273  Grid(const IndexType &low, const IndexType &high);
274 
287  Grid(const RangeType &range);
288 
291 
292 //
293 // template<typename Arg0>
294 // IndexedGrid<GridType, TYPELIST_1(Arg0) > operator()(
295 // const Arg0 &i0
296 // );
297 //
298 // template<typename Arg0, typename Arg1>
299 // IndexedGrid<GridType, TYPELIST_2(Arg0, Arg1) > operator()(
300 // const Arg0 &i0, const Arg1 &i1
301 // );
302 
303 
305  GridType& operator=(const T &val)
306  {
307  BaseType::operator=(val);
308  return *this;
309  }
310 
312  GridType& operator=(const GridType &grid)
313  {
314  BaseType::operator=(grid);
315  return *this;
316  }
317 
319  template<
320  typename T2,
321  class CheckingPolicy2,
322  class StoragePolicy2
323  >
325  {
326  BaseType::operator=(grid);
327  return *this;
328  }
329 };
330 
331 } // namespace schnek
332 
333 #include "grid.t"
334 
335 #endif // SCHNEK_GRID_H_
Definition: array.hpp:49
T & operator[](const Array< int, rank, ArrayCheckingPolicy > &pos)
Definition: grid.hpp:54
Definition: array.hpp:34
Definition: gridstorage.hpp:232
GridType & operator=(const GridType &grid)
Definition: grid.hpp:312
GridType & operator=(const T &val)
Definition: grid.hpp:305
GridBase< T, rank, CheckingPolicy, StoragePolicy > & operator=(const GridBase< T, rank, CheckingPolicy, StoragePolicy > &)
Definition: algo.hpp:30
void resize(const IndexType &size)
GridType & operator=(const GridBase< T2, rank, CheckingPolicy2, StoragePolicy2 > &grid)
Definition: grid.hpp:324
T & operator()(int i)
Definition: grid.hpp:42
Definition: gridcheck.hpp:38
Definition: grid.hpp:39
Definition: grid.hpp:235