Chombo + EB + MF  3.2
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() << *this << endl;
87  }
88 
89  friend std::ostream& operator<< (std::ostream& os,
90  const LayoutIndex& dit);
91 private:
92  friend class DataIterator;
93  friend class LayoutIterator;
94  friend class TimedDataIterator;
95  friend class NeighborIterator;
96  friend class BoxLayout;
97  friend class DataIndex;
98  friend class DisjointBoxLayout;
99 
100  int m_index;
101  int m_datInd;
102  const int* m_layoutIntPtr;
103 
104  LayoutIndex(int a_indexIntoBoxes,
105  int a_indexIntoData,
106  const int* a_layoutID)
107  :
108  m_index (a_indexIntoBoxes),
109  m_datInd(a_indexIntoData),
110  m_layoutIntPtr(a_layoutID)
111  {}
112 };
113 
114 class DataIndex : public LayoutIndex
115 {
116 public:
117  explicit DataIndex(const LayoutIndex& a_promotion)
118  :
119  LayoutIndex(a_promotion)
120  {}
122  :
123  LayoutIndex()
124  {}
125 
126  virtual ~DataIndex()
127  {}
128 
129 private:
130  friend class LayoutIterator;
131  friend class DataIterator;
132  friend class TimedDataIterator;
133  friend class NeighborIterator;
134  friend class BoxLayout;
135  friend class Copier;
136 
137  DataIndex(int a_indexIntoBox,
138  int a_indexIntoData,
139  const int* a_layoutID)
140  :
141  LayoutIndex(a_indexIntoBox, a_indexIntoData, a_layoutID)
142  {
143  }
144 };
145 
146 
147 
148 #ifndef WRAPPER
150  :
151  m_index(0),
152  m_layoutIntPtr(NULL)
153 {
154 }
155 
156 inline bool LayoutIndex::operator == (const LayoutIndex& a_rhs) const
157 {
158  return (m_index == a_rhs.m_index);
159 }
160 
161 inline int LayoutIndex::intCode() const
162 {
163  return m_index;
164 }
165 
166 inline bool LayoutIndex::isNull() const
167 {
168  return m_layoutIntPtr == NULL;
169 }
170 #endif
171 
172 //std::ostream& operator<<(std::ostream& os, const LayoutIndex& copier);
173 
174 #include "NamespaceFooter.H"
175 #endif
std::ostream & pout()
Use this in place of std::cout for program output.
int intCode() const
Definition: DataIndex.H:161
int datInd() const
Definition: DataIndex.H:64
friend std::ostream & operator<<(std::ostream &os, const LayoutIndex &dit)
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:145
A strange but true thing to make copying from one boxlayoutdata to another fast.
Definition: Copier.H:152
LayoutIndex()
Definition: DataIndex.H:149
bool operator==(const LayoutIndex &a_rhs) const
Definition: DataIndex.H:156
DataIndex(const LayoutIndex &a_promotion)
Definition: DataIndex.H:117
virtual ~LayoutIndex()
Definition: DataIndex.H:36
Definition: DataIterator.H:190
An Iterator based on a BoxLayout object.
Definition: LayoutIterator.H:35
const int * m_layoutIntPtr
Definition: DataIndex.H:102
LayoutIndex(const LayoutIndex &a_input)
Definition: DataIndex.H:74
virtual ~DataIndex()
Definition: DataIndex.H:126
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:30
DataIndex()
Definition: DataIndex.H:121
bool eq(const LayoutIndex &a_rhs) const
Definition: DataIndex.H:44
Definition: DataIndex.H:114
DataIndex(int a_indexIntoBox, int a_indexIntoData, const int *a_layoutID)
Definition: DataIndex.H:137
bool isNull() const
returns &#39;true&#39; if this DataIndex has been null constructed.
Definition: DataIndex.H:166
virtual void output() const
Definition: DataIndex.H:84
LayoutIndex(int a_indexIntoBoxes, int a_indexIntoData, const int *a_layoutID)
Definition: DataIndex.H:104
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:100
int m_datInd
Definition: DataIndex.H:101
Definition: TimedDataIterator.H:23
bool operator!=(const LayoutIndex &a_rhs) const
Definition: DataIndex.H:50