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 _LAYOUTITERATOR_H_ 00012 #define _LAYOUTITERATOR_H_ 00013 00014 #include "DataIndex.H" 00015 #include "BoxLayout.H" 00016 00017 #include "NamespaceHeader.H" 00018 00019 ///An Iterator based on a BoxLayout object. 00020 /** 00021 An Iterator based on a BoxLayout object. It does not 00022 support a dereferencing operation(1), since it is intended 00023 to work with all of BoxLayouts, DisjointBoxLayouts, BoxLayoutDatas 00024 LevelData's, and any object that is built on top 00025 of a BoxLayout object. LayoutIterator accesses the data in a BoxLayout-based 00026 object in a NON-data-parallel manner (i.e. every processor iterates through 00027 \b all the Boxes in the BoxLayout). This differs from the DataIterator class. 00028 00029 BoxLayout-based objects can act as the Factory for the LayoutIterator. 00030 00031 (1) STL-speak. not critical for comprehension, but can help people 00032 familiar with STL iterators and expecting similar behaviour. 00033 00034 */ 00035 class LayoutIterator 00036 { 00037 public: 00038 /// a null constructed LayoutIterator will return false on ok() 00039 LayoutIterator() 00040 {} 00041 00042 // Default copy and null constructor should be fine. 00043 // Not useful to someone using the iterator. Used by 00044 // other classes in Chombo. Could make it private and 00045 // let BoxLayout have access.... 00046 00047 virtual ~LayoutIterator() 00048 {} 00049 00050 /// return the index that this iterator is at 00051 const LayoutIndex& operator () () const; 00052 00053 /// return a copy of the index that this iterator is at 00054 LayoutIndex i() const 00055 { 00056 return this->operator()(); 00057 } 00058 00059 /// move the iterator to the next Box in the layout 00060 virtual void operator ++ (); 00061 00062 /// move the iterator to the next Box in the layout 00063 void incr() 00064 { 00065 ++(*this); 00066 } 00067 00068 /// return true if this iterator is still in its Layout 00069 virtual bool ok() const; 00070 00071 /// initialize this iterator to the first Box in its Layout 00072 void begin(); 00073 00074 /// same as begin() 00075 void reset(); 00076 00077 /// move this iterator to after the last Box in the layout 00078 /** The iterator will be !ok() afterwards. */ 00079 void end(); 00080 00081 00082 00083 const LayoutIndex& operator[](int ivec) const 00084 { 00085 return (*this->m_indicies)[ivec]; 00086 } 00087 00088 LayoutIndex& operator[](int ivec) 00089 { 00090 return (*this->m_indicies)[ivec]; 00091 } 00092 00093 protected: 00094 friend class BoxLayout; 00095 friend class DisjointBoxLayout; 00096 friend class TimedDataIterator; 00097 LayoutIterator(const BoxLayout& a_boxlayout, 00098 const int* a_layoutID); 00099 00100 BoxLayout m_layout; 00101 RefCountedPtr<Vector<LayoutIndex> > m_indicies; 00102 00103 unsigned int m_current; 00104 }; 00105 00106 inline const LayoutIndex& LayoutIterator::operator () () const 00107 { 00108 CH_assert(ok()); 00109 return (*m_indicies)[m_current]; 00110 } 00111 00112 inline void LayoutIterator::operator ++ () 00113 { 00114 ++m_current; 00115 } 00116 00117 inline bool LayoutIterator::ok() const 00118 { 00119 return m_current < m_layout.size(); 00120 } 00121 00122 inline void LayoutIterator::begin() 00123 { 00124 m_current = 0; 00125 } 00126 00127 #include "NamespaceFooter.H" 00128 #endif