Chombo + EB  3.0
DataIndex.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 _DATAINDEX_H_
12 #define _DATAINDEX_H_
13 
14 #include <cstdlib>
15 #include <iostream>
16 #include "MayDay.H"
17 #include "parstream.H"
18 #include "NamespaceHeader.H"
19 
20 #ifndef WRAPPER
21 class BoxLayout;
22 
23 class DataIterator;
24 class LayoutIterator;
25 
26 #endif /* WRAPPER */
27 
28 using std::endl;
29 ///An index for LayoutIterator
31 {
32 public:
33  ///
34  LayoutIndex();
35 
36  virtual ~LayoutIndex()
37  {}
38 
39  // default copy and assign should be fine.
40 
41  ///
42  bool operator == (const LayoutIndex& a_rhs) const;
43 
44  bool eq(const LayoutIndex& a_rhs) const
45  {
46  return *this == a_rhs;
47  }
48 
49  ///
50  bool operator != (const LayoutIndex& a_rhs) const
51  {
52  return !(*this == a_rhs);
53  }
54 
55  /// returns 'true' if this DataIndex has been null constructed.
56  bool isNull() const;
57 
58  // not user function. breaks design encapsulation. method not intended for
59  // users. The alternative is to make this class a friend of BoxLayoutData<T>,
60  // which implicitly makes this class templated, which makes no bloody sense.
61  // The behaviour of this method is undefined for users. bvs
62  int intCode() const;
63 
64  int datInd() const
65  {
66 #ifdef CH_MPI
67  return m_datInd;
68 #else
69  //no MPI means dataindex is just a layout index
70  return m_index;
71 #endif
72  }
73 
74  LayoutIndex(const LayoutIndex& a_input)
75  {
76  m_index = a_input.m_index;
77  m_datInd = a_input.m_datInd;
79  }
80  ///
81  /**
82  Print to the given output stream in ASCII.
83  */
84  virtual void output() const
85  {
86  pout() << "(" << m_index << "," << m_datInd << ")" << endl;
87  }
88 
89 private:
90  friend class DataIterator;
91  friend class LayoutIterator;
92  friend class TimedDataIterator;
93  friend class NeighborIterator;
94  friend class BoxLayout;
95  friend class DataIndex;
96  friend class DisjointBoxLayout;
97 
98  int m_index;
99  int m_datInd;
100  const int* m_layoutIntPtr;
101 
102  LayoutIndex(int a_indexIntoBoxes,
103  int a_indexIntoData,
104  const int* a_layoutID)
105  :
106  m_index (a_indexIntoBoxes),
107  m_datInd(a_indexIntoData),
108  m_layoutIntPtr(a_layoutID)
109  {}
110 };
111 
112 class DataIndex : public LayoutIndex
113 {
114 public:
115  explicit DataIndex(const LayoutIndex& a_promotion)
116  :
117  LayoutIndex(a_promotion)
118  {}
120  :
121  LayoutIndex()
122  {}
123 
124  virtual ~DataIndex()
125  {}
126 
127 private:
128  friend class LayoutIterator;
129  friend class DataIterator;
130  friend class TimedDataIterator;
131  friend class NeighborIterator;
132  friend class BoxLayout;
133  friend class Copier;
134 
135  DataIndex(int a_indexIntoBox,
136  int a_indexIntoData,
137  const int* a_layoutID)
138  :
139  LayoutIndex(a_indexIntoBox, a_indexIntoData, a_layoutID)
140  {
141  }
142 };
143 
144 #ifndef WRAPPER
146  :
147  m_index(0),
148  m_layoutIntPtr(NULL)
149 {
150 }
151 
152 inline bool LayoutIndex::operator == (const LayoutIndex& a_rhs) const
153 {
154  return (m_index == a_rhs.m_index);
155 }
156 
157 inline int LayoutIndex::intCode() const
158 {
159  return m_index;
160 }
161 
162 inline bool LayoutIndex::isNull() const
163 {
164  return m_layoutIntPtr == NULL;
165 }
166 #endif
167 
168 #include "NamespaceFooter.H"
169 #endif
std::ostream & pout()
Use this in place of std::cout for program output.
bool operator!=(const LayoutIndex &a_rhs) const
Definition: DataIndex.H:50
virtual void output() const
Definition: DataIndex.H:84
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:146
A strange but true thing to make copying from one boxlayoutdata to another fast.
Definition: Copier.H:137
LayoutIndex()
Definition: DataIndex.H:145
bool operator==(const LayoutIndex &a_rhs) const
Definition: DataIndex.H:152
DataIndex(const LayoutIndex &a_promotion)
Definition: DataIndex.H:115
virtual ~LayoutIndex()
Definition: DataIndex.H:36
Definition: DataIterator.H:140
An Iterator based on a BoxLayout object.
Definition: LayoutIterator.H:38
int datInd() const
Definition: DataIndex.H:64
const int * m_layoutIntPtr
Definition: DataIndex.H:100
bool eq(const LayoutIndex &a_rhs) const
Definition: DataIndex.H:44
LayoutIndex(const LayoutIndex &a_input)
Definition: DataIndex.H:74
virtual ~DataIndex()
Definition: DataIndex.H:124
bool isNull() const
returns 'true' if this DataIndex has been null constructed.
Definition: DataIndex.H:162
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:31
DataIndex()
Definition: DataIndex.H:119
Definition: DataIndex.H:112
DataIndex(int a_indexIntoBox, int a_indexIntoData, const int *a_layoutID)
Definition: DataIndex.H:135
LayoutIndex(int a_indexIntoBoxes, int a_indexIntoData, const int *a_layoutID)
Definition: DataIndex.H:102
An index for LayoutIterator.
Definition: DataIndex.H:30
An Iterator based on a DisjointBoxLayout object for neighboring boxes.
Definition: NeighborIterator.H:23
int m_index
Definition: DataIndex.H:98
int m_datInd
Definition: DataIndex.H:99
int intCode() const
Definition: DataIndex.H:157
Definition: TimedDataIterator.H:23