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 _NEIGHBORITERATOR_H_ 00012 #define _NEIGHBORITERATOR_H_ 00013 00014 #include "DataIndex.H" 00015 #include "ProblemDomain.H" 00016 #include "DisjointBoxLayout.H" 00017 #include "NamespaceHeader.H" 00018 00019 ///An Iterator based on a DisjointBoxLayout object for neighboring boxes. 00020 /** 00021 00022 */ 00023 class NeighborIterator 00024 { 00025 public: 00026 00027 NeighborIterator():m_dblPtr(NULL) 00028 { 00029 } 00030 00031 /// 00032 NeighborIterator(const DisjointBoxLayout& dbl); 00033 00034 /// return the index that this iterator is at 00035 /** Aborts if the iterator is not ok() */ 00036 inline const LayoutIndex& operator()() const ; 00037 00038 Box box() const ; 00039 00040 /// move the iterator to the next index in the neighbor list 00041 inline void operator++(); 00042 00043 /// return true if this iterator is still in the neighbor list 00044 inline bool ok() const; 00045 00046 /// initialize this iterator to the first index in the neighbor list 00047 void begin(const DataIndex& a_dataIndex); 00048 00049 /// OK, this one requires a little explanation 00050 /** 00051 if the *current* box is a periodic image box, then this operation returns the unmapping 00052 of a_box. 00053 */ 00054 Box unshift(const Box& a_box) const ; 00055 00056 private: 00057 00058 const DisjointBoxLayout* m_dblPtr; 00059 std::vector<std::pair<int, LayoutIndex> >::const_iterator m_current, m_end; 00060 LayoutIndex m_lindex; 00061 }; 00062 00063 inline bool NeighborIterator::ok() const 00064 { 00065 CH_assert(m_dblPtr!=NULL); 00066 return m_current != m_end; 00067 } 00068 00069 inline void NeighborIterator::operator++() 00070 { 00071 ++m_current; 00072 if (m_current != m_end) 00073 m_lindex = m_current->second; 00074 } 00075 00076 inline const LayoutIndex& NeighborIterator::operator()() const 00077 { 00078 CH_assert(m_dblPtr!= NULL); 00079 CH_assert(this->ok()); 00080 return m_lindex; 00081 } 00082 00083 #include "NamespaceFooter.H" 00084 #endif