Schnek
gridcheck.hpp
1 /*
2  * gridcheck.hpp
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_GRIDCHECK_H_
28 #define SCHNEK_GRIDCHECK_H_
29 
30 #include "array.hpp"
31 
32 #include "../util/logger.hpp"
33 #include <cassert>
34 
35 namespace schnek {
36 
37 template<int rank>
39  public:
41  static const IndexType &check(
42  const IndexType &pos,
43  const IndexType &low,
44  const IndexType &high
45  );
46 };
47 
48 
49 template<int rank>
51  public:
53  static const IndexType &check(
54  const IndexType &pos,
55  const IndexType &low,
56  const IndexType &high
57  );
58 };
59 
60 
61 
62 template<int rank>
64  public:
66  private:
67  static bool errorFlag;
68  static int errorInfo;
69  static IndexType offending;
70  public:
71  static const IndexType check(
72  const IndexType &pos,
73  const IndexType &low,
74  const IndexType &high
75  );
76 
77  static bool getErrorFlag()
78  {
79  return errorFlag;
80  }
81 
82  static int getErrorInfo()
83  {
84  return errorInfo;
85  }
86 
87  static IndexType getOffending()
88  {
89  return offending;
90  }
91  };
92 
93 template<int rank>
95  const IndexType &pos,
96  const IndexType &, const IndexType &
97  )
98 { return pos; }
99 
100 template<int rank>
102  const IndexType &pos,
103  const IndexType &low,
104  const IndexType &high
105  )
106 {
107  for (int i=0; i<rank; ++i)
108  {
109  assert(pos[i]>=low[i]);
110  assert(pos[i]<=high[i]);
111  }
112  return pos;
113 }
114 
115 
116 template<int rank>
118 
119 template<int rank>
121 
122 template<int rank>
124 
125 template<int rank>
127  const IndexType &pos,
128  const IndexType &low,
129  const IndexType &high
130  )
131 {
132  IndexType pos_copy(pos);
133  for (int i=0; i<rank; ++i)
134  {
135  if (pos_copy[i]<low[i]) {
136  SCHNEK_TRACE_ERR(1,"schnek::GridDebugCheck index out of range (dim="<<i<<"): index=" <<pos_copy[i]<<" lo="<<low[i])
137  pos_copy[i]=low[i];
138  GridDebugCheck<rank>::errorFlag = true;
139  GridDebugCheck<rank>::errorInfo = -i;
140  GridDebugCheck<rank>::offending = pos;
141  }
142  if (pos_copy[i] > high[i])
143  {
144  SCHNEK_TRACE_ERR(1,"schnek::GridDebugCheck index out of range (dim="<<i<<"): index=" <<pos_copy[i]<<" hi="<<high[i])
145  pos_copy[i] = high[i];
146  GridDebugCheck<rank>::errorFlag = true;
147  GridDebugCheck<rank>::errorInfo = i;
148  GridDebugCheck<rank>::offending = pos;
149  }
150  }
151  return pos_copy;
152 }
153 
154 }
155 
156 #endif // SCHNEK_GRIDCHECK_H_
Definition: gridcheck.hpp:63
Definition: algo.hpp:30
Definition: gridcheck.hpp:50
Definition: gridcheck.hpp:38
#define SCHNEK_TRACE_ERR(i, x)
Definition: logger.hpp:72