00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef INDEXED_FIELD_H
00012 #define INDEXED_FIELD_H
00013
00014
00015 #include "Field/IndexedBareField.h"
00016 #include "Utility/PAssert.h"
00017
00018 #ifdef IPPL_USE_STANDARD_HEADERS
00019 #include <iostream>
00020 using namespace std;
00021 #else
00022 #include <iostream.h>
00023 #endif
00024
00025
00026 template<class T, unsigned D, class M, class C> class Field;
00027
00028
00029
00030 template < class T, unsigned Dim, unsigned Brackets, class M, class C>
00031 class IndexedField : public IndexedBareField<T,Dim,Brackets>
00032 {
00033
00034 friend class IndexedField<T,Dim,Brackets-1,M,C>;
00035 friend class Field<T,Dim,M,C>;
00036
00037 public:
00038
00039 IndexedField<T,Dim,Brackets+1,M,C> operator[](const Index& idx)
00040 {
00041 CTAssert(Brackets<Dim);
00042 return IndexedField<T,Dim,Brackets+1,M,C> (F,IndexedBareField<T,Dim,Brackets>::Indexes,idx);
00043 }
00044 IndexedField<T,Dim,Brackets+1,M,C> operator[](int i)
00045 {
00046 CTAssert(Brackets<Dim);
00047 return IndexedField<T,Dim,Brackets+1,M,C> (F,IndexedBareField<T,Dim,Brackets>::Indexes,Index(i,i));
00048 }
00049
00050 IndexedField<T,Dim,Dim,M,C> operator[](const NDIndex<Dim>& ndidx)
00051 {
00052 CTAssert(Brackets<Dim);
00053 return IndexedField<T,Dim,Dim,M,C> (F,IndexedBareField<T,Dim,Brackets>::Indexes,ndidx);
00054 }
00055
00056 void operator=(T x)
00057 {
00058 assign(*this,x);
00059 }
00060
00061 IndexedField<T,Dim,Brackets,M,C>&
00062 operator=(const IndexedField<T,Dim,Brackets,M,C>& x)
00063 {
00064 CTAssert(Dim==Brackets);
00065 assign(*this,x);
00066 return *this;
00067 }
00068
00069 IndexedField<T,Dim,Brackets,M,C>&
00070 operator=(const Index& x)
00071 {
00072 assign(*this,x);
00073 return *this;
00074 }
00075
00076 template<class T1, unsigned Dim1, unsigned Brackets1, class M1, class C1>
00077 IndexedField<T,Dim,Brackets,M,C>&
00078 operator=(const IndexedField<T1,Dim1,Brackets1,M1,C1>& x)
00079 {
00080 CTAssert(Dim1==Brackets1);
00081 assign(*this,x);
00082 return *this;
00083 }
00084
00085 template<class B>
00086 IndexedField<T,Dim,Brackets,M,C>&
00087 operator=(const PETE_Expr<B>& x)
00088 {
00089 assign(*this,x);
00090 return *this;
00091 }
00092
00093
00094 Field<T,Dim,M,C>& getField() { return F; }
00095 const Field<T,Dim,M,C>& getField() const { return F; }
00096
00097 protected:
00098
00099 Field<T,Dim,M,C> &F;
00100
00101
00102
00103 IndexedField(Field<T,Dim,M,C> &f, const Index& idx)
00104 : IndexedBareField<T,Dim,Brackets>(f,idx), F(f) {}
00105 IndexedField(Field<T,Dim,M,C> &f, int i)
00106 : IndexedBareField<T,Dim,Brackets>(f,i), F(f) {}
00107 IndexedField(Field<T,Dim,M,C> &f, const NDIndex<Brackets-1>& idx, const Index& i)
00108 : IndexedBareField<T,Dim,Brackets>(f,idx,i), F(f) {}
00109
00110 IndexedField(Field<T,Dim,M,C> &f, const NDIndex<Dim>& ndidx)
00111 : IndexedBareField<T,Dim,Dim>(f,ndidx), F(f) {}
00112
00113 };
00114
00116
00117 #endif // INDEXED_FIELD_H
00118
00119
00120
00121
00122
00123