00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef COMPRESSED_BRICK_ITERATOR_H
00012 #define COMPRESSED_BRICK_ITERATOR_H
00013
00014
00015 #include "Field/BrickIterator.h"
00016
00017 #ifdef IPPL_USE_STANDARD_HEADERS
00018 #include <iostream>
00019 using namespace std;
00020 #else
00021 #include <iostream.h>
00022 #endif
00023
00024 template<class T, unsigned Dim>
00025 class CompressedBrickIterator;
00026
00028
00029
00030 template<class T, unsigned D1, unsigned D2>
00031 CompressedBrickIterator<T,D2>
00032 permute(const CompressedBrickIterator<T,D1>&,
00033 const NDIndex<D1>&, const NDIndex<D2>&);
00034
00036
00037
00038
00039
00040
00041
00043
00044
00045
00046
00047
00048
00049
00051
00052 template<class T, unsigned Dim>
00053 class CompressedBrickIterator : public BrickIterator<T,Dim>
00054 {
00055 public:
00056
00057
00058
00059
00060
00061
00062
00063 CompressedBrickIterator(T* t, const NDIndex<Dim>& c, const NDIndex<Dim>& a,
00064 T& compressed)
00065 : BrickIterator<T,Dim>(t,c,a), CompressedData(&compressed)
00066 {
00067 if (!t) {
00068 BrickIterator<T,Dim>::Current = CompressedData;
00069 for (unsigned d=0; d<Dim; d++)
00070 BrickIterator<T,Dim>::Strides[d] = 0;
00071 }
00072 }
00073
00074
00075
00076
00077
00078 CompressedBrickIterator(T* t, const vec<int,Dim>& v, T& compressed)
00079 : BrickIterator<T,Dim>(t,v),CompressedData(&compressed)
00080 {
00081 if (!t) {
00082 BrickIterator<T,Dim>::Current = CompressedData;
00083 for (unsigned d=0; d<Dim; d++)
00084 BrickIterator<T,Dim>::Strides[d] = 0;
00085 }
00086 }
00087
00088
00089 CompressedBrickIterator(T& t) : CompressedData(&t) {}
00090
00091
00092
00093 CompressedBrickIterator() : CompressedData(0) {}
00094
00095
00096
00097 CompressedBrickIterator(const NDIndex<Dim>& a, T& compressed);
00098
00099
00100
00101 CompressedBrickIterator(const BrickIterator<T,Dim>& x, T& compressed)
00102 : BrickIterator<T,Dim>(x), CompressedData(&compressed) {}
00103
00104
00105 bool IsCompressed() const
00106 {
00107 return BrickIterator<T,Dim>::Current == CompressedData;
00108 }
00109
00110
00111 bool CanCompress(const T&) const;
00112
00113
00114 void Compress(T& val);
00115
00116
00117
00118
00119 bool TryCompress() { return TryCompress(**this); }
00120
00121
00122
00123 bool TryCompress(T val);
00124
00125
00126
00127 const CompressedBrickIterator<T,Dim>&
00128 operator=(const CompressedBrickIterator<T,Dim>& rhs);
00129
00130 CompressedBrickIterator(const CompressedBrickIterator<T,Dim>& X);
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 Message& putMessage(Message& m, bool makecopy = true);
00142
00143
00144 Message& getMessage(Message& m);
00145
00146
00147
00148
00149
00150 CompressedBrickIterator<T,1>
00151 permute(NDIndex<Dim>& current, NDIndex<1>& permuted) const
00152 { return ::permute(*this,current,permuted); }
00153 CompressedBrickIterator<T,2>
00154 permute(NDIndex<Dim>& current, NDIndex<2>& permuted) const
00155 { return ::permute(*this,current,permuted); }
00156 CompressedBrickIterator<T,3>
00157 permute(NDIndex<Dim>& current, NDIndex<3>& permuted) const
00158 { return ::permute(*this,current,permuted); }
00159 CompressedBrickIterator<T,4>
00160 permute(NDIndex<Dim>& current, NDIndex<4>& permuted) const
00161 { return ::permute(*this,current,permuted); }
00162 CompressedBrickIterator<T,5>
00163 permute(NDIndex<Dim>& current, NDIndex<5>& permuted) const
00164 { return ::permute(*this,current,permuted); }
00165 CompressedBrickIterator<T,6>
00166 permute(NDIndex<Dim>& current, NDIndex<6>& permuted) const
00167 { return ::permute(*this,current,permuted); }
00168
00169 void SetCurrent(T* p) { BrickIterator<T,Dim>::Current = p; }
00170 void SetCount(int d, int count) { BrickCounter<Dim>::Counts[d] = count; }
00171 void ResetCounter(int d) { BrickCounter<Dim>::Counters[d] = 0; }
00172 void SetStride(int d, int stride) { BrickIterator<T,Dim>::Strides[d] = stride; }
00173 int GetStride(int d) const { return BrickIterator<T,Dim>::Strides[d]; }
00174 T& GetCompressedData() const { return *CompressedData; }
00175 void SetCompressedData(T *newData)
00176 {
00177 CompressedData = newData;
00178 }
00179
00180 private:
00181
00182 T* CompressedData;
00183
00184 };
00185
00186
00187 #include "Field/CompressedBrickIterator.cpp"
00188
00189 #endif // COMPRESSED_BRICK_ITERATOR_H
00190
00191
00192
00193
00194
00195
00196