Chombo + EB  3.0
LayoutIterator.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 _LAYOUTITERATOR_H_
12 #define _LAYOUTITERATOR_H_
13 
14 
15 
16 #include "DataIndex.H"
17 #include "BoxLayout.H"
18 
19 
20 #include "NamespaceHeader.H"
21 
22 ///An Iterator based on a BoxLayout object.
23 /**
24  An Iterator based on a BoxLayout object. It does not
25  support a dereferencing operation(1), since it is intended
26  to work with all of BoxLayouts, DisjointBoxLayouts, BoxLayoutDatas
27  LevelData's, and any object that is built on top
28  of a BoxLayout object. LayoutIterator accesses the data in a BoxLayout-based
29  object in a NON-data-parallel manner (i.e. every processor iterates through
30  \b all the Boxes in the BoxLayout). This differs from the DataIterator class.
31 
32  BoxLayout-based objects can act as the Factory for the LayoutIterator.
33 
34  (1) STL-speak. not critical for comprehension, but can help people
35  familiar with STL iterators and expecting similar behaviour.
36 
37 */
39 {
40 public:
41  /// a null constructed LayoutIterator will return false on ok()
43  {}
44 
45  // Default copy and null constructor should be fine.
46  // Not useful to someone using the iterator. Used by
47  // other classes in Chombo. Could make it private and
48  // let BoxLayout have access....
49 
50  virtual ~LayoutIterator()
51  {}
52 
53  /// return the index that this iterator is at
54  const LayoutIndex& operator () () const;
55 
56  /// return a copy of the index that this iterator is at
57  LayoutIndex i() const
58  {
59  return this->operator()();
60  }
61 
62  /// move the iterator to the next Box in the layout
63  virtual void operator ++ ();
64 
65  /// move the iterator to the next Box in the layout
66  void incr()
67  {
68  ++(*this);
69  }
70 
71  /// return true if this iterator is still in its Layout
72  virtual bool ok() const;
73 
74  /// initialize this iterator to the first Box in its Layout
75  void begin();
76 
77  /// same as begin()
78  void reset();
79 
80  /// move this iterator to after the last Box in the layout
81  /** The iterator will be !ok() afterwards. */
82  void end();
83 
84 
85 protected:
86  friend class BoxLayout;
87  friend class DisjointBoxLayout;
88  friend class TimedDataIterator;
89  LayoutIterator(const BoxLayout& a_boxlayout,
90  const int* a_layoutID);
91 
94 
95  int m_current;
96 };
97 
98 
100 {
101  CH_assert(ok());
102  return (*m_indicies)[m_current];
103 }
104 
106 {
107  ++m_current;
108 }
109 
110 inline bool LayoutIterator::ok() const
111 {
112  return m_current < m_layout.size();
113 }
114 
116 {
117  m_current = 0;
118 }
119 
120 
121 #include "NamespaceFooter.H"
122 #endif
A reference-counting handle class.
Definition: RefCountedPtr.H:66
void incr()
move the iterator to the next Box in the layout
Definition: LayoutIterator.H:66
#define CH_assert(cond)
Definition: CHArray.H:37
const LayoutIndex & operator()() const
return the index that this iterator is at
Definition: LayoutIterator.H:99
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:146
void end()
move this iterator to after the last Box in the layout
void begin()
initialize this iterator to the first Box in its Layout
Definition: LayoutIterator.H:115
int m_current
Definition: LayoutIterator.H:95
unsigned int size() const
Returns the total number of boxes in the BoxLayout.
An Iterator based on a BoxLayout object.
Definition: LayoutIterator.H:38
void reset()
same as begin()
LayoutIterator()
a null constructed LayoutIterator will return false on ok()
Definition: LayoutIterator.H:42
BoxLayout m_layout
Definition: LayoutIterator.H:92
virtual void operator++()
move the iterator to the next Box in the layout
Definition: LayoutIterator.H:105
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:31
LayoutIndex i() const
return a copy of the index that this iterator is at
Definition: LayoutIterator.H:57
An index for LayoutIterator.
Definition: DataIndex.H:30
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:110
virtual ~LayoutIterator()
Definition: LayoutIterator.H:50
Definition: TimedDataIterator.H:23
RefCountedPtr< Vector< LayoutIndex > > m_indicies
Definition: LayoutIterator.H:93