00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef SINDEX_H
00012 #define SINDEX_H
00013
00014
00015 #include "Index/NDIndex.h"
00016 #include "Index/SOffset.h"
00017 #include "Index/LSIndex.h"
00018 #include "FieldLayout/FieldLayoutUser.h"
00019 #include "Utility/RefCounted.h"
00020 #include "Utility/Inform.h"
00021
00022 #ifdef IPPL_STDSTL
00023 #include <vector>
00024 using std::vector;
00025 #else
00026 #include <vector.h>
00027 #endif
00028
00029 #ifdef IPPL_USE_STANDARD_HEADERS
00030 #include <iostream>
00031 using namespace std;
00032 #else
00033 #include <iostream.h>
00034 #endif
00035
00036
00037 template <unsigned Dim> class FieldLayout;
00038 template <unsigned Dim> class SIndex;
00039 template <unsigned Dim, unsigned Brackets> class IndexedSIndex;
00040 template <unsigned Dim>
00041 ostream& operator<<(ostream&, const SIndex<Dim>&);
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 template <unsigned Dim>
00075 class SIndex : public FieldLayoutUser {
00076
00077 public:
00078
00079 typedef vector< RefCountedP<LSIndex<Dim> > > container_t;
00080 typedef unsigned int size_type;
00081 typedef typename container_t::iterator iterator_iv;
00082 typedef typename container_t::const_iterator const_iterator_iv;
00083 typedef typename container_t::size_type size_type_iv;
00084 typedef typename LSIndex<Dim>::iterator iterator_indx;
00085 typedef typename LSIndex<Dim>::const_iterator const_iterator_indx;
00086
00087
00088
00089 SIndex();
00090
00091
00092 SIndex(FieldLayout<Dim>&);
00093
00094
00095 SIndex(const SIndex<Dim>&);
00096
00097
00098 virtual ~SIndex();
00099
00100
00101
00102 void initialize(FieldLayout<Dim>&);
00103
00104
00105 bool needInitialize() const { return (Layout == 0); }
00106
00107
00108 template<class T1>
00109 SIndex<Dim>& operator=(const PETE_Expr<T1>& rhs) {
00110 assign(*this, rhs);
00111 return *this;
00112 }
00113
00114
00115
00116 SIndex<Dim>& operator=(const SIndex<Dim>&);
00117 SIndex<Dim>& operator=(const SOffset<Dim>&);
00118 SIndex<Dim>& operator=(const NDIndex<Dim>&);
00119
00120
00121
00122
00123 SIndex<Dim>& operator&=(const SIndex<Dim>&);
00124 SIndex<Dim>& operator&=(const SOffset<Dim>&);
00125 SIndex<Dim>& operator&=(const NDIndex<Dim>&);
00126
00127
00128
00129 SIndex<Dim>& operator|=(const SIndex<Dim>&);
00130 SIndex<Dim>& operator|=(const SOffset<Dim>&);
00131 SIndex<Dim>& operator|=(const NDIndex<Dim>&);
00132
00133
00134
00135 bool addIndex(const SOffset<Dim>&);
00136 bool addIndex(iterator_iv&, const SOffset<Dim>&);
00137 void addIndex(const NDIndex<Dim>&);
00138
00139
00140
00141 bool removeIndex(const SOffset<Dim>&);
00142 bool removeIndex(iterator_iv&, const SOffset<Dim>&);
00143 void removeIndex(const NDIndex<Dim>&);
00144
00145
00146
00147 void reserve(double = 1.0);
00148
00149
00150 void clear();
00151
00152
00153
00154 SOffset<Dim>& getOffset() { return Offset; }
00155 const SOffset<Dim>& getOffset() const { return Offset; }
00156
00157
00158 FieldLayout<Dim>& getFieldLayout() const { return *Layout; };
00159
00160
00161 void setFieldLayout(FieldLayout<Dim>&);
00162
00163
00164 const NDIndex<Dim> &getDomain() const { return BoundingBox; }
00165 void setDomain(const NDIndex<Dim> &ndi) { BoundingBox = ndi; }
00166
00167
00168
00169
00170
00171
00172
00173
00174 friend
00175 SIndex<Dim> operator+(const SIndex<Dim>& si, const SOffset<Dim>& so) {
00176 return SIndex(si, so);
00177 }
00178
00179 friend
00180 SIndex<Dim> operator+(const SOffset<Dim> &so, const SIndex<Dim>& si) {
00181 return SIndex(si, so);
00182 }
00183
00184 friend
00185 SIndex<Dim> operator+(const SIndex<Dim>& si, const int *so) {
00186 return SIndex(si, so);
00187 }
00188
00189 friend
00190 SIndex<Dim> operator+(const int *so, const SIndex<Dim>& si) {
00191 return SIndex(si, so);
00192 }
00193
00194 friend
00195 SIndex<Dim> operator-(const SIndex<Dim>& si, const SOffset<Dim>& so) {
00196 return SIndex(si, -so);
00197 }
00198
00199 friend
00200 SIndex<Dim> operator-(const SOffset<Dim> &so, const SIndex<Dim>& si) {
00201 return SIndex(si, -so);
00202 }
00203
00204 friend
00205 SIndex<Dim> operator-(const SIndex<Dim>& si, const int *so) {
00206 return SIndex(si, -SOffset<Dim>(so));
00207 }
00208
00209 friend
00210 SIndex<Dim> operator-(const int *so, const SIndex<Dim>& si) {
00211 return SIndex(si, -SOffset<Dim>(so));
00212 }
00213
00214
00215
00216
00217 SIndex<Dim> operator()(int);
00218 SIndex<Dim> operator()(int,int);
00219 SIndex<Dim> operator()(int,int,int);
00220 SIndex<Dim> operator()(int,int,int,int);
00221 SIndex<Dim> operator()(int,int,int,int,int);
00222 SIndex<Dim> operator()(int,int,int,int,int,int);
00223 SIndex<Dim> operator()(const SOffset<Dim>&);
00224 SIndex<Dim> operator()(const int *);
00225
00226
00227
00228
00229
00230 IndexedSIndex<Dim,1> operator[](const Index &);
00231
00232 template<unsigned int Dim2>
00233 IndexedSIndex<Dim,Dim2> operator[](const NDIndex<Dim2> &ndi) {
00234 TAU_TYPE_STRING(taustr, CT(*this) + " (NDIndex)");
00235 TAU_PROFILE("SIndex::operator[]", taustr, TAU_SPARSE);
00236
00237 CTAssert(Dim >= Dim2);
00238 NDIndex<Dim> dom;
00239 for (int i=0; i < Dim2; ++i)
00240 dom[i] = ndi[i];
00241 return IndexedSIndex<Dim,Dim2>(*this, dom);
00242 }
00243
00244
00245
00246
00247
00248
00249 void toNDIndex(const SOffset<Dim>&, NDIndex<Dim>&);
00250
00251
00252
00253
00254
00255
00256 iterator_iv begin_iv() { return IndexList.begin(); }
00257 iterator_iv end_iv() { return IndexList.end(); }
00258 const_iterator_iv begin_iv() const { return IndexList.begin(); }
00259 const_iterator_iv end_iv() const { return IndexList.end(); }
00260 size_type_iv size_iv() const { return IndexList.size(); }
00261
00262
00263 size_type_iv size() const;
00264
00265
00266 bool hasIndex(const SOffset<Dim>&) const;
00267
00268
00269
00270
00271
00272
00273 virtual void Repartition(UserList *);
00274
00275
00276 virtual void notifyUserOfDelete(UserList *);
00277
00278
00279
00280
00281
00282
00283 void printDebug(Inform&) const;
00284
00285 private:
00286
00287 FieldLayout<Dim>* Layout;
00288
00289
00290
00291 SOffset<Dim> Offset;
00292
00293
00294
00295
00296 NDIndex<Dim> BoundingBox;
00297
00298
00299 container_t IndexList;
00300
00301
00302
00303
00304 SIndex(const SIndex<Dim>&, const SOffset<Dim>&);
00305 SIndex(const SIndex<Dim>&, const int *);
00306
00307
00308
00309 void setup();
00310 };
00311
00312 #include "Index/SIndex.cpp"
00313
00314 #endif // SINDEX_H
00315
00316
00317
00318
00319
00320