Chombo + EB  3.0
BoxIterator.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _BOXITERATOR_H_
12 #define _BOXITERATOR_H_
13 
14 #include <cstdlib>
15 
16 #include "Box.H"
17 #include "REAL.H"
18 #include "SPACE.H"
19 #include "IntVect.H"
20 #include "NamespaceHeader.H"
21 
22 ///iterates through the IntVects of a Box
23 /**
24  BoxIterator iterates through the IntVects of a box. The actual
25  sqeuence of IntVects is implementation-specific.
26  Typical usage:
27 
28  Box b;
29  ...
30  BoxIterator bit (b);
31  for (bit.begin(); bit.ok(); ++bit)
32  {
33  IntVect iv = bit();
34  (do operations involving iv)
35  }
36 */
38 {
39 public:
40  ///
41  /**
42  Default constructor. This constructs an invalid iterator.
43  The user must call define before using.
44  */
45  BoxIterator();
46 
47  ///
48  /**
49  Constructs a BoxIterator and associates it with a Box.
50  Arguments:
51  a_bx (not modified) the Box to iterate over.
52  */
53  BoxIterator(const Box& a_bx);
54 
55  void setBox(const Box& a_bx);
56 
57  ///
58  /**
59  Associates a Box with this BoxIterator.
60  Arguments:
61  a_bx (not modified) the Box to iterate over.
62  */
63  void define(const Box& a_bx);
64 
65  ///
66  /**
67  Copy constructor.
68  Arguments:
69  a_iterIn (not modified) the BoxIterator to copy.
70  */
71  BoxIterator(const BoxIterator& a_iterIn);
72 
73  ///
75  {
76  }
77 
78  ///
79  /**
80  Sets this BoxIterator to the first IntVect in its Box. The
81  definition of the "first" IntVect is
82  implementation-dependent.
83  */
84  void begin();
85 
86  ///
87  /**
88  Sets this BoxIterator to the first IntVect in its Box. The
89  definition of the "first" IntVect is
90  implementation-dependent.
91  */
92  void reset();
93 
94  ///
95  /**
96  Modifies this BoxIterator to set it to the next location in its
97  Box. The definition of the "next location" of a Box is
98  implementation-dependent.
99  */
100  void operator ++ ();
101 
102  void next();
103 
104  ///
105  /**
106  Returns the value of the InVect for the current location of this
107  BoxIterator.
108  */
109  const IntVect& operator () () const;
110 
111  ///
112  /**
113  Returns true if this BoxIterator's location is within its Box.
114  */
115  bool ok();
116 
117 protected:
121 };
122 
123 inline
125 {
129 }
130 
131 inline
133 {
134  define(a_bx);
135 }
136 
137 inline
139 {
140  m_current = a_iterIn.m_current;
141  m_boxLo = a_iterIn.m_boxLo;
142  m_boxHi = a_iterIn.m_boxHi;
143 }
144 
145 inline
147 {
148  if (m_boxLo <= m_boxHi) m_current = m_boxLo;
149 }
150 
151 inline
153 {
154  begin();
155 }
156 
157 inline
159 {
160  next();
161 }
162 
163 inline
165 {
166  m_current[0]++;
167 #if CH_SPACEDIM >= 2
168  if (m_current[0] > m_boxHi[0])
169  {
170  m_current[0] = m_boxLo[0];
171  m_current[1]++;
172 #if CH_SPACEDIM >= 3
173  if (m_current[1] > m_boxHi[1])
174  {
175  m_current[1] = m_boxLo[1];
176  m_current[2]++;
177 #if CH_SPACEDIM >= 4
178  if (m_current[2] > m_boxHi[2])
179  {
180  m_current[2] = m_boxLo[2];
181  m_current[3]++;
182 #if CH_SPACEDIM >= 5
183  if (m_current[3] > m_boxHi[3])
184  {
185  m_current[3] = m_boxLo[3];
186  m_current[4]++;
187 #if CH_SPACEDIM == 6
188  if (m_current[4] > m_boxHi[4])
189  {
190  m_current[4] = m_boxLo[4];
191  m_current[5]++;
192  }
193 #elif CH_SPACEDIM > 6
194  SPACEDIM > 6 undefined!;
195 #endif
196  }
197 #endif
198  }
199 #endif
200  }
201 #endif
202  }
203 #endif
204 }
205 
206 inline
208 {
211  return m_current;
212 }
213 
214 inline
216 {
217  return (m_current <= m_boxHi);
218 }
219 
220 #include "NamespaceFooter.H"
221 #endif
IntVect m_boxLo
Definition: BoxIterator.H:119
bool ok()
Definition: BoxIterator.H:215
void define(const Box &a_bx)
const IntVect & operator()() const
Definition: BoxIterator.H:207
void reset()
Definition: BoxIterator.H:152
#define CH_assert(cond)
Definition: CHArray.H:37
iterates through the IntVects of a Box
Definition: BoxIterator.H:37
~BoxIterator()
Definition: BoxIterator.H:74
static const IntVect Unit
Definition: IntVect.H:632
IntVect m_current
Definition: BoxIterator.H:118
static const IntVect Zero
Definition: IntVect.H:627
void operator++()
Definition: BoxIterator.H:158
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
void begin()
Definition: BoxIterator.H:146
void setBox(const Box &a_bx)
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
void next()
Definition: BoxIterator.H:164
IntVect m_boxHi
Definition: BoxIterator.H:120
BoxIterator()
Definition: BoxIterator.H:124