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