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 #include "../macros.hpp"
36 
37 namespace schnek {
38 
39  template<class GridType, typename TList>
40  class IndexedGrid;
41 
42  template<class IndexType>
43  struct IndexCast;
44 
45  template<class Operator, size_t Length>
46  class ArrayExpression;
47 
48 
49  namespace internal {
55  template<
56  typename T,
57  size_t rank,
58  class CheckingPolicy,
59  class StoragePolicy
60  >
61  class GridBase : public StoragePolicy, public CheckingPolicy
62  {
63  public:
64  typedef T value_type;
65  typedef CheckingPolicy CheckingPolicyType;
66  typedef StoragePolicy StoragePolicyType;
67  typedef typename CheckingPolicy::IndexType IndexType;
68  typedef typename StoragePolicy::RangeType RangeType;
70  enum {Rank = rank};
71 
75  GridBase();
76 
80  GridBase(const GridBase&) = default;
81 
82  template<template<size_t> class ArrayCheckingPolicy>
84 
85  template<template<size_t> class ArrayCheckingPolicy>
87 
88  template<template<size_t> class ArrayCheckingPolicy>
90 
92  template<template<size_t> class ArrayCheckingPolicy>
93  SCHNEK_INLINE T& operator[](const Array<int,rank,ArrayCheckingPolicy>& pos); // write
95  template<template<size_t> class ArrayCheckingPolicy>
96  SCHNEK_INLINE T operator[](const Array<int,rank,ArrayCheckingPolicy>& pos) const; // read
97 
99  template<class Operator, int Length>
100  SCHNEK_INLINE T& operator[](const ArrayExpression<Operator, Length>& pos); // write
102  template<class Operator, int Length>
103  SCHNEK_INLINE T operator[](const ArrayExpression<Operator, Length>& pos) const; // read
104 
106  SCHNEK_INLINE T& operator[](int i);
108  SCHNEK_INLINE T operator[](int i) const;
109 
111  SCHNEK_INLINE T& operator()(int i);
113  SCHNEK_INLINE T operator()(int i) const;
115  SCHNEK_INLINE T& operator()(int i, int j);
117  SCHNEK_INLINE T operator()(int i, int j) const;
119  SCHNEK_INLINE T& operator()(int i, int j, int k);
121  SCHNEK_INLINE T operator()(int i, int j, int k) const;
123  SCHNEK_INLINE T& operator()(int i, int j, int k, int l);
125  SCHNEK_INLINE T operator()(int i, int j, int k, int l) const;
127  SCHNEK_INLINE T& operator()(int i, int j, int k, int l, int m);
129  SCHNEK_INLINE T operator()(int i, int j, int k, int l, int m) const;
131  SCHNEK_INLINE T& operator()(int i, int j, int k, int l, int m, int o);
133  SCHNEK_INLINE T operator()(int i, int j, int k, int l, int m, int o) const;
135  SCHNEK_INLINE T& operator()(int i, int j, int k, int l, int m, int o, int p);
137  SCHNEK_INLINE T operator()(int i, int j, int k, int l, int m, int o, int p) const;
139  SCHNEK_INLINE T& operator()(int i, int j, int k, int l, int m, int o, int p, int q);
141  SCHNEK_INLINE T operator()(int i, int j, int k, int l, int m, int o, int p, int q) const;
143  SCHNEK_INLINE T& operator()(int i, int j, int k, int l, int m, int o, int p, int q, int r);
145  SCHNEK_INLINE T operator()(int i, int j, int k, int l, int m, int o, int p, int q, int r) const;
147  SCHNEK_INLINE T& operator()(int i, int j, int k, int l, int m, int o, int p, int q, int r, int s);
149  SCHNEK_INLINE T operator()(int i, int j, int k, int l, int m, int o, int p, int q, int r, int s) const;
150 
153  operator=(const T &val);
154 
158 
159  template<
160  typename T2,
161  class CheckingPolicy2
162  >
165 
166  template<
167  typename T2,
168  class CheckingPolicy2,
169  class StoragePolicy2
170  >
173 
174  template<
175  typename T2,
176  class CheckingPolicy2
177  >
180 
181 
182  template<
183  typename T2,
184  class CheckingPolicy2,
185  class StoragePolicy2
186  >
189 
202  void resize(const IndexType &size);
203 
218  void resize(const IndexType &low, const IndexType &high);
219 
233  void resize(const RangeType &range);
234 
236  template<
237  typename T2,
238  class CheckingPolicy2,
239  class StoragePolicy2
240  >
242  };
243  }
244 
245 
254  template<
255  typename T,
256  size_t rank,
257  template<size_t> class CheckingPolicy = GridNoArgCheck,
258  template<typename, size_t> class StoragePolicy = SingleArrayGridStorage
259  >
260  class Grid : public internal::GridBase<T, rank, CheckingPolicy<rank>, StoragePolicy<T,rank> >
261  {
262 
263  public:
264  typedef T value_type;
265  typedef Array<int,rank> IndexType;
266  typedef Range<int,rank> RangeType;
268  typedef internal::GridBase<T, rank, CheckingPolicy<rank>, StoragePolicy<T,rank> > BaseType;
269  enum {Rank = rank};
270 
274  Grid();
275 
279  Grid(const Grid&) = default;
280 
292  Grid(const IndexType &size);
293 
306  Grid(const IndexType &low, const IndexType &high);
307 
320  Grid(const RangeType &range);
321 
322  //
323  // template<typename Arg0>
324  // IndexedGrid<GridType, TYPELIST_1(Arg0) > operator()(
325  // const Arg0 &i0
326  // );
327  //
328  // template<typename Arg0, typename Arg1>
329  // IndexedGrid<GridType, TYPELIST_2(Arg0, Arg1) > operator()(
330  // const Arg0 &i0, const Arg1 &i1
331  // );
332 
333 
335  GridType& operator=(const T &val)
336  {
337  BaseType::operator=(val);
338  return *this;
339  }
340 
342  GridType& operator=(const GridType &grid)
343  {
344  BaseType::operator=(grid);
345  return *this;
346  }
347 
349  template<
350  typename T2,
351  class CheckingPolicy2,
352  class StoragePolicy2
353  >
355  {
356  BaseType::operator=(grid);
357  return *this;
358  }
359  };
360 
361 } // namespace schnek
362 
363 #include "grid.t"
364 
365 #endif // SCHNEK_GRID_H_
Definition: array.hpp:55
SCHNEK_INLINE T & operator[](const Array< int, rank, ArrayCheckingPolicy > &pos)
Definition: array.hpp:40
Definition: range.hpp:43
GridType & operator=(const GridType &grid)
Definition: grid.hpp:342
Extends from SingleArrayGridStorageBase to provide C-order indexing over the 1-dimensional data array...
Definition: single-array-storage-base.hpp:110
GridType & operator=(const T &val)
Definition: grid.hpp:335
Definition: algo.hpp:30
SCHNEK_INLINE T & operator()(int i)
The generic base class for the Grid class template.
Definition: grid.hpp:61
Definition: grid.hpp:43
Definition: gridcheck.hpp:39
GridBase()
Default constructor.
Definition: grid.hpp:40
A multidimensional grid that stores simple data.
Definition: grid.hpp:260
SCHNEK_INLINE GridBase< T, rank, CheckingPolicy, StoragePolicy > & operator=(const T &val)
GridType & operator=(const internal::GridBase< T2, rank, CheckingPolicy2, StoragePolicy2 > &grid)
Definition: grid.hpp:354
void resize(const IndexType &size)
Resize to size[0] x ... x size[rank-1].