OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
IndexedSIndex.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef INDEXED_SINDEX_H
12 #define INDEXED_SINDEX_H
13 
14 // include files
15 #include "Index/SIndex.h"
16 #include "Index/NDIndex.h"
17 #include "Index/SIndexAssign.h"
18 #include "Utility/PAssert.h"
19 
20 
21 /***********************************************************************
22  *
23  * IndexedSIndex represents an SIndex object + an NDIndex object which
24  * selects just a subset of the original field domain of the SIndex
25  * object. When the user uses the [] operator on an SIndex object, it
26  * returns an IndexedSIndex object which knows it should refer to points
27  * only in the index space of the Index objects provided in the [] operator.
28  * This is used to modify the original SIndex to let it know that it refers
29  * only to a subset, and so when it is used in an SIndex assignment or
30  * expression, only that subset should be looped over.
31  *
32  * The first template parameter is the dimension of the SIndex object; the
33  * second is the number of dimensions worth of bracket operators which have
34  * been applied so far. This is the sum of the dimensions which have been
35  * specified by Index or NDIndex objects inside the bracket operators of
36  * SIndex or IndexedSIndex. By the time the SIndex object is needed, this
37  * should have Dim == Brackets. If not, it is an error.
38  *
39  ***********************************************************************/
40 
41 
42 template <unsigned Dim, unsigned Brackets>
44 
45 public:
46  // Initialize this object with the SIndex it refers to, and the NDIndex
47  // it should use.
49  : sIndex(s), domain(i) { }
50 
52  : sIndex(const_cast<SIndex<Dim> &>(isi.sIndex)), domain(isi.domain) { }
53 
54  // destructor: nothing to do
56 
57  // get the SIndex we are using
58  const SIndex<Dim> &getSIndex() const { return sIndex; }
59 
60  // get the domain we're Indexing
61  const NDIndex<Dim> &getDomain() const { return domain; }
62 
63  // assignment operators. First make sure we have fully specified
64  // what domain to use by checking that Dim == Brackets, then call
65  // assign but with the smaller domain.
66  template<class T>
68  CTAssert(Brackets == Dim);
69  assign(sIndex, rhs, domain);
70  return *this;
71  }
72 
73  // operator[], which is used with Index or NDIndex objects to further
74  // subset the data. This will only work if the dimension of the Index
75  // arguments + Brackets is <= Dim. Otherwise, too many dimensions worth
76  // of Index objects are being applied
78  operator[](const Index &i) {
79  CTAssert((Brackets + 1) <= Dim);
80  NDIndex<Dim> dom = domain;
81  dom[Brackets] = i;
83  }
84 
85  template<unsigned Dim2>
87  operator[](const NDIndex<Dim2> &ndi) {
88  CTAssert((Brackets + Dim2) <= Dim);
89  NDIndex<Dim> dom = domain;
90  for (unsigned int i=0; i < Dim2; ++i)
91  dom[Brackets + i] = ndi[i];
93  }
94 
95 private:
96  // the SIndex we refer to
98 
99  // the NDIndex we are subsetting to
101 
102  // copy constructor and operator=, made private since we do not want them
104 };
105 
106 #endif // INDEXED_SINDEX_H
107 
108 /***************************************************************************
109  * $RCSfile: IndexedSIndex.h,v $ $Author: adelmann $
110  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:27 $
111  * IPPL_VERSION_ID: $Id: IndexedSIndex.h,v 1.1.1.1 2003/01/23 07:40:27 adelmann Exp $
112  ***************************************************************************/
const unsigned Dim
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)
#define CTAssert(c)
Definition: PAssert.h:35
Definition: Index.h:237
const SIndex< Dim > & getSIndex() const
Definition: IndexedSIndex.h:58
NDIndex< Dim > domain
IndexedSIndex< Dim, Brackets > & operator=(const PETE_Expr< T > &rhs)
Definition: IndexedSIndex.h:67
const NDIndex< Dim > & getDomain() const
Definition: IndexedSIndex.h:61
IndexedSIndex< Dim, Brackets+1 > operator[](const Index &i)
Definition: IndexedSIndex.h:78
IndexedSIndex(SIndex< Dim > &s, const NDIndex< Dim > &i)
Definition: IndexedSIndex.h:48
SIndex< Dim > & sIndex
Definition: IndexedSIndex.h:97
IndexedSIndex< Dim, Brackets > & operator=(const IndexedSIndex< Dim, Brackets > &)
IndexedSIndex(const IndexedSIndex< Dim, Brackets > &isi)
Definition: IndexedSIndex.h:51
IndexedSIndex< Dim, Brackets+Dim2 > operator[](const NDIndex< Dim2 > &ndi)
Definition: IndexedSIndex.h:87
Definition: SIndex.h:64
Definition: PETE.h:77