00001 #ifdef CH_LANG_CC 00002 /* 00003 * _______ __ 00004 * / ___/ / ___ __ _ / / ___ 00005 * / /__/ _ \/ _ \/ V \/ _ \/ _ \ 00006 * \___/_//_/\___/_/_/_/_.__/\___/ 00007 * Please refer to Copyright.txt, in Chombo's root directory. 00008 */ 00009 #endif 00010 00011 #ifndef _BOXITERATOR_H_ 00012 #define _BOXITERATOR_H_ 00013 00014 #include <cstdlib> 00015 00016 #include "Box.H" 00017 #include "REAL.H" 00018 #include "SPACE.H" 00019 #include "IntVect.H" 00020 #include "NamespaceHeader.H" 00021 00023 00037 class BoxIterator 00038 { 00039 public: 00041 00045 BoxIterator(); 00046 00048 00053 BoxIterator(const Box& a_bx); 00054 00055 void setBox(const Box& a_bx); 00056 00058 00063 void define(const Box& a_bx); 00064 00066 00071 BoxIterator(const BoxIterator& a_iterIn); 00072 00074 ~BoxIterator (){} 00075 00077 00082 void begin(); 00083 00085 00090 void reset(); 00091 00093 00098 void operator ++ (); 00099 00100 void next(); 00101 00103 00107 const IntVect& operator () () const; 00108 00110 00113 bool ok(); 00114 00115 protected: 00116 IntVect m_current; 00117 IntVect m_boxLo; 00118 IntVect m_boxHi; 00119 }; 00120 00121 inline 00122 BoxIterator::BoxIterator() 00123 { 00124 m_current = IntVect::Unit; 00125 m_boxLo = IntVect::Unit; 00126 m_boxHi = IntVect::Zero; 00127 } 00128 00129 inline 00130 BoxIterator::BoxIterator(const Box& a_bx) 00131 { 00132 define(a_bx); 00133 } 00134 00135 inline 00136 BoxIterator::BoxIterator(const BoxIterator& a_iterIn) 00137 { 00138 m_current = a_iterIn.m_current; 00139 m_boxLo = a_iterIn.m_boxLo; 00140 m_boxHi = a_iterIn.m_boxHi; 00141 } 00142 00143 inline 00144 void BoxIterator::begin() 00145 { 00146 if (m_boxLo <= m_boxHi) m_current = m_boxLo; 00147 } 00148 00149 inline 00150 void BoxIterator::reset() 00151 { 00152 begin(); 00153 } 00154 00155 inline 00156 void BoxIterator::operator ++ () 00157 { 00158 next(); 00159 } 00160 00161 inline 00162 void BoxIterator::next() 00163 { 00164 m_current[0]++; 00165 #if CH_SPACEDIM >= 2 00166 if (m_current[0] > m_boxHi[0]) 00167 { 00168 m_current[0] = m_boxLo[0]; 00169 m_current[1]++; 00170 #if CH_SPACEDIM >= 3 00171 if (m_current[1] > m_boxHi[1]) 00172 { 00173 m_current[1] = m_boxLo[1]; 00174 m_current[2]++; 00175 #if CH_SPACEDIM >= 4 00176 if (m_current[2] > m_boxHi[2]) 00177 { 00178 m_current[2] = m_boxLo[2]; 00179 m_current[3]++; 00180 #if CH_SPACEDIM >= 5 00181 if (m_current[3] > m_boxHi[3]) 00182 { 00183 m_current[3] = m_boxLo[3]; 00184 m_current[4]++; 00185 #if CH_SPACEDIM == 6 00186 if (m_current[4] > m_boxHi[4]) 00187 { 00188 m_current[4] = m_boxLo[4]; 00189 m_current[5]++; 00190 } 00191 #elif CH_SPACEDIM > 6 00192 SPACEDIM > 6 undefined!; 00193 #endif 00194 } 00195 #endif 00196 } 00197 #endif 00198 } 00199 #endif 00200 } 00201 #endif 00202 } 00203 00204 inline 00205 const IntVect& BoxIterator::operator () () const 00206 { 00207 CH_assert(m_current <= m_boxHi); 00208 CH_assert(m_current >= m_boxLo); 00209 return m_current; 00210 } 00211 00212 inline 00213 bool BoxIterator::ok() 00214 { 00215 return (m_current <= m_boxHi); 00216 } 00217 00218 #include "NamespaceFooter.H" 00219 #endif