Proto  3.2
Proto_DataIndex.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_DATA_INDEX_
3 #define _PROTO_DATA_INDEX_
4 #include <vector>
5 #include <iostream>
6 
7 namespace Proto
8 {
9  class DisjointBoxLayout;
10  template<typename PP> class DataIterator;
11 
12  /// Data Index
13  /**
14  * Data Index is a special object used in tandem with DataIterator.
15  * See DataIterator for further documentation.
16  *
17  * \tparam P A "Partition" object which defines "layoutness" of the iterable object (see BoxPartition)
18  */
19  template<typename P>
20  class DataIndex
21  {
22  friend class DisjointBoxLayout;
23  template<typename PP> friend class DataIterator;
24  template<typename PP>
25  friend std::ostream& operator<<(std::ostream& a_os, const DataIndex<PP>& a_index);
26 
27  public:
28 
29  /// Default Constructor
30  DataIndex() : m_partition(nullptr), m_currentInt(0) {}
31 
32  /// Explicit Constructor
33  inline DataIndex(const std::shared_ptr<P> a_partition, unsigned int a_index)
34  {
35  PROTO_ASSERT(a_partition != nullptr,
36  "DataIndex::Constructor | Error: Partition object pointer is null.");
37  m_partition = a_partition;
38  m_currentInt = a_index;
39  };
40 
41  /// Copy constructor
42  DataIndex(const DataIndex& other)
44 
45  /// Copy assignment
46  DataIndex& operator=(const DataIndex& other) {
47  if (this != &other) {
48  m_partition = other.m_partition;
49  m_currentInt = other.m_currentInt;
50  }
51  return *this;
52  }
53 
54  /// Destructor
56 
57  /// Equality Operator
58  inline bool operator==(const DataIndex<P>& a_di) const {return (m_partition == a_di.m_partition) && (m_currentInt == a_di.m_currentInt);};
59 
60  /// Equality Operator (Overload)
61  /**
62  * Provided to increase expressiveness and backwards compatibility
63  */
64  inline bool operator==(const DataIterator<P>& a_iter) const;
65 
66  /// Inequality Operator
67  inline bool operator!=(const DataIndex<P>& a_di) const {return !(*this==a_di);};
68 
69  /// Inequality Operator (Overload)
70  /**
71  * Provided to increase expressiveness and backwards compatibility
72  */
73  inline bool operator!=(const DataIterator<P>& a_iter) const;
74 
75  /// Integer Cast
76  /**
77  Data Index implicitly casts to the LOCAL index of the iterable.
78  This behavior is used internally to increase code clarity.
79  */
80  inline operator int() const { return local(); };
81 
82  /// Local Value
83  /**
84  * Returns the integer value associated with the LOCAL (in the sense of MPI process) index of the iterate.
85  */
86  inline int local() const
87  {
88  return m_partition->localIndex(m_currentInt, procID());
89  //return m_currentInt - m_partition->procStartIndex(procID());
90  }
91 
92  /// Local Value
93  /**
94  * Returns the integer value associated with the GLOBAL (in the sense of MPI process) index of the iterate.
95  */
96  inline int global() const { return m_currentInt; }
97 
98  /// Compatibility Query
99  /**
100  * Returns true if the partition associated with <code>*this</code> is compatible
101  * with that associated with another index.
102  */
103  bool compatible(const DataIndex<P>& a_index) const
104  { return m_partition->compatible(*a_index.m_partition); }
105 
106  /// Compatibility Query
107  /**
108  * Returns true if the partition associated with <code>*this</code> is compatible
109  * with another partition.
110  */
111  bool compatible(const P& a_partition) const
112  { return m_partition->compatible(a_partition); }
113 
114  const P& partition() const {return *m_partition;}
115 
116  protected:
117 
118  shared_ptr<P> m_partition;
120 
121  }; // end class DataIndex;
122 }
123 #endif
bool operator!=(const DataIndex< P > &a_di) const
Inequality Operator.
Definition: Proto_DataIndex.H:67
int local() const
Local Value.
Definition: Proto_DataIndex.H:86
Distributed Data Iterator.
Definition: Proto_DataIndex.H:10
bool compatible(const DataIndex< P > &a_index) const
Compatibility Query.
Definition: Proto_DataIndex.H:103
~DataIndex()
Destructor.
Definition: Proto_DataIndex.H:55
Disjoint Box Layout.
Definition: Proto_DisjointBoxLayout.H:30
DataIndex(const DataIndex &other)
Copy constructor.
Definition: Proto_DataIndex.H:42
DataIndex & operator=(const DataIndex &other)
Copy assignment.
Definition: Proto_DataIndex.H:46
const P & partition() const
Definition: Proto_DataIndex.H:114
int procID()
Get Local Process ID.
Definition: Proto_SPMD.H:39
#define PROTO_ASSERT(stmt, args...)
Definition: Proto_PAssert.H:48
Definition: Proto_Array.H:17
int m_currentInt
Definition: Proto_DataIndex.H:119
Data Index.
Definition: Proto_DataIndex.H:20
DataIndex()
Default Constructor.
Definition: Proto_DataIndex.H:30
bool operator==(const DataIndex< P > &a_di) const
Equality Operator.
Definition: Proto_DataIndex.H:58
shared_ptr< P > m_partition
Definition: Proto_DataIndex.H:118
DataIndex(const std::shared_ptr< P > a_partition, unsigned int a_index)
Explicit Constructor.
Definition: Proto_DataIndex.H:33
bool compatible(const P &a_partition) const
Compatibility Query.
Definition: Proto_DataIndex.H:111
int global() const
Local Value.
Definition: Proto_DataIndex.H:96