Proto  3.2
Proto_DataIterator.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_DATA_ITERATOR_
3 #define _PROTO_DATA_ITERATOR_
4 #include <vector>
5 #include "Proto_DataIndex.H"
6 //#include "Proto_BoxPartition.H"
7 
8 namespace Proto
9 {
10  // Implementation Details
11  // DataIterator is templated on an object which defines "layout-ness".
12  // In Proto, this was historically encoded in the deprecated DBLInternals object
13  // (which has been refactored into BoxPartition).
14  //
15  // Valid implementations of the class P must implement the following interface:
16  //
17  // class P {
18  // public:
19  // unsigned int numBoxes(); // total number of patches in the layout
20  // unsigned int procStartIndex(int a_proc); // return the global index of the first patch on a specified processor
21  // unsigned int procEndIndex(int a_proc); // return the global index of the first patch on a specified processor
22  // bool compatible(const P& a_p); // determine if two instances of P are compatible (e.g. if they have the layout-ness)
23  // };
24 
25  /// Distributed Data Iterator
26  /**
27  Iterate through the local contents of a data layout specified by the template class P.
28  Unlike normal iterators, DataIterator<P> dereferences into a DataIndex<P> which can
29  be used to index into various data holders that are specifically designed to work
30  in tandem with it.
31 
32  Supported objects:
33  DisjointBoxLayout (P = BoxPartition)
34  LevelBoxData (P = BoxPartition)
35 
36  Proto objects are specifically designed to use STL-like iteration syntax which
37  makes the specific implementation of DataIterator (and it's template argument)
38  invisible to the end user. See the code below for sample usage:
39 
40  @code
41  DisjointBoxLayout layout(...);
42  LevelBoxData<double> data(layout, ...);
43 
44  for (auto iter : layout)
45  {
46  // iter is a DataIndex object which can be used to index into data holders
47  Box b = layout[iter];
48  BoxData<double>& patch = data[iter];
49  // etc
50  }
51  @endcode
52  */
53  template<typename P>
54  class DataIterator
55  {
56  public:
57 
58  /// Manual Constructor
59  /**
60  Construct a DataIterator from an existing DisjointBoxLayout.
61  This constructor is mostly used internally. Users can rely on
62  the STL style iteration syntax of container objects
63  (e.g. LevelBoxData or DisjointBoxLayout)
64  */
65  inline DataIterator(std::shared_ptr<P> a_partition);
66 
67  /// Set To Start
68  /**
69  Modifies the *this and returns it
70  */
72 
73  /// Set To End
74  /**
75  modifies *this and returns it
76  */
77  inline DataIterator<P>& end();
78 
79  /// Continue Query
80  /**
81  Shortcut to check if *this has reached its end.
82  */
83  inline bool ok() const;
84 
85  /// Size
86  /** Number of iterates on this processor
87  */
88  inline unsigned int localSize() const;
89 
90  /// Increment
91  inline DataIterator<P>& operator++();
92 
93  /// Equality
94  inline bool operator==(const DataIterator<P>& a_rhs) const
95  { return m_current == a_rhs.m_current; }
96 
97  /// Equality
98  inline bool operator==(const DataIndex<P>& a_rhs) const
99  { return m_current == a_rhs; }
100 
101  /// Inquality
102  inline bool operator!=(const DataIterator<P>& a_rhs) const
103  { return m_current != a_rhs.m_current; }
104 
105  /// Inquality
106  inline bool operator!=(const DataIndex<P>& a_rhs) const
107  { return m_current != a_rhs; }
109  /// Integer Dereference (code is in implem file)
110  inline const DataIndex<P> operator[](unsigned int a_index) const;
111 
112  /// Dereference
113  /**
114  Unlike normal iterators, dereferencing a DataIterator returns a DataIndex.
115  DataIndex is accepted by all "level scope" data holders (e.g. LevelBoxData or DisjointBoxLayout).
116  */
117  inline const DataIndex<P>& operator*() const;
118 
119  inline bool compatible(const P& a_partition) const;
120 
121  inline bool compatible(const DataIndex<P>& a_index) const;
122 
123  inline bool compatible(const DataIterator<P>& a_iter) const;
124 
125  protected:
126 
127  std::shared_ptr<P> m_partition;
130  };
131 
132 
133 #include "implem/Proto_DataIteratorImplem.H"
134 } // end Proto namespace.
135 #endif
136 
std::shared_ptr< P > m_partition
Definition: Proto_DataIterator.H:127
DataIterator< P > & end()
Set To End.
Definition: Proto_DataIterator.H:22
Distributed Data Iterator.
Definition: Proto_DataIndex.H:10
DataIterator(std::shared_ptr< P > a_partition)
Manual Constructor.
Definition: Proto_DataIterator.H:3
bool operator!=(const DataIndex< P > &a_rhs) const
Inquality.
Definition: Proto_DataIterator.H:106
bool compatible(const P &a_partition) const
Definition: Proto_DataIterator.H:88
bool operator==(const DataIndex< P > &a_rhs) const
Equality.
Definition: Proto_DataIterator.H:98
DataIterator< P > & begin()
Set To Start.
Definition: Proto_DataIterator.H:13
DataIndex< P > m_end
Definition: Proto_DataIterator.H:129
DataIndex< P > m_current
Definition: Proto_DataIterator.H:128
const DataIndex< P > & operator*() const
Dereference.
Definition: Proto_DataIterator.H:81
Definition: Proto_Array.H:17
DataIterator< P > & operator++()
Increment.
Definition: Proto_DataIterator.H:45
bool operator==(const DataIterator< P > &a_rhs) const
Equality.
Definition: Proto_DataIterator.H:94
Data Index.
Definition: Proto_DataIndex.H:20
bool ok() const
Continue Query.
Definition: Proto_DataIterator.H:30
const DataIndex< P > operator[](unsigned int a_index) const
Integer Dereference (code is in implem file)
Definition: Proto_DataIterator.H:71
bool operator!=(const DataIterator< P > &a_rhs) const
Inquality.
Definition: Proto_DataIterator.H:102
unsigned int localSize() const
Size.
Definition: Proto_DataIterator.H:37