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