00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef BZ_VECITER_H
00029 #define BZ_VECITER_H
00030
00031 #ifndef BZ_VECTOR_H
00032 #error <blitz/veciter.h> should be included via <blitz/vector.h>
00033 #endif
00034
00035 BZ_NAMESPACE(blitz)
00036
00037
00038 template<typename P_numtype>
00039 class VectorIter {
00040 public:
00041 typedef P_numtype T_numtype;
00042
00043 explicit VectorIter(Vector<P_numtype>& x)
00044 : data_(x.data())
00045 {
00046 stride_ = x.stride();
00047 length_ = x.length();
00048 }
00049
00050 VectorIter(P_numtype* restrict data, int stride, int length)
00051 : data_(data), stride_(stride), length_(length)
00052 { }
00053
00054 #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
00055 VectorIter(const VectorIter<P_numtype>& x)
00056 {
00057 data_ = x.data_;
00058 stride_ = x.stride_;
00059 length_ = x.length_;
00060 }
00061 #endif
00062
00063 P_numtype operator[](int i) const
00064 {
00065 BZPRECONDITION(i < length_);
00066 return data_[i*stride_];
00067 }
00068
00069 P_numtype& restrict operator[](int i)
00070 {
00071 BZPRECONDITION(i < length_);
00072 return data_[i*stride_];
00073 }
00074
00075 P_numtype operator()(int i) const
00076 {
00077 BZPRECONDITION(i < length_);
00078 return data_[i*stride_];
00079 }
00080
00081 P_numtype& restrict operator()(int i)
00082 {
00083 BZPRECONDITION(i < length_);
00084 return data_[i*stride_];
00085 }
00086
00087 P_numtype operator*() const
00088 { return *data_; }
00089
00090 P_numtype& operator*()
00091 { return *data_; }
00092
00093 VectorIter<P_numtype> operator+(int i) const
00094 {
00095 BZPRECONDITION(i <= length_);
00096 return VectorIter<P_numtype>(data_+i*stride_, stride_, length_-i);
00097 }
00098
00099 int length(int) const
00100 { return length_; }
00101
00102 bool isUnitStride() const
00103 { return (stride_ == 1); }
00104
00106
00107
00108
00110
00111 static const int
00112 _bz_staticLengthCount = 0,
00113 _bz_dynamicLengthCount = 1,
00114 _bz_staticLength = 0;
00115
00116 bool _bz_hasFastAccess() const
00117 { return isUnitStride(); }
00118
00119 P_numtype _bz_fastAccess(int i) const
00120 { return data_[i]; }
00121
00122 P_numtype& restrict _bz_fastAccess(int i)
00123 { return data_[i]; }
00124
00125 int _bz_suggestLength() const
00126 { return length_; }
00127
00128 private:
00129 VectorIter() { }
00130 P_numtype * restrict data_;
00131 int stride_;
00132 int length_;
00133 };
00134
00135
00136 template<typename P_numtype>
00137 class VectorIterConst {
00138 public:
00139 typedef P_numtype T_numtype;
00140
00141 explicit VectorIterConst(const Vector<P_numtype>& x)
00142 : data_(x.data())
00143 {
00144 stride_ = x.stride();
00145 length_ = x.length();
00146 }
00147
00148 VectorIterConst(P_numtype* restrict data, int stride, int length)
00149 : data_(data), stride_(stride), length_(length)
00150 { }
00151
00152 #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
00153 VectorIterConst(const VectorIterConst<P_numtype>& x)
00154 {
00155 data_ = x.data_;
00156 stride_ = x.stride_;
00157 length_ = x.length_;
00158 }
00159 #endif
00160
00161 P_numtype operator[](int i) const
00162 {
00163 BZPRECONDITION(i < length_);
00164 return data_[i*stride_];
00165 }
00166
00167 P_numtype operator()(int i) const
00168 {
00169 BZPRECONDITION(i < length_);
00170 return data_[i*stride_];
00171 }
00172
00173 P_numtype operator*() const
00174 { return *data_; }
00175
00176 VectorIterConst<P_numtype> operator+(int i) const
00177 {
00178 BZPRECONDITION(i <= length_);
00179 return VectorIterConst<P_numtype>(data_+i*stride_, stride_, length_-i);
00180 }
00181
00182 int length(int) const
00183 { return length_; }
00184
00185 bool isUnitStride() const
00186 { return (stride_ == 1); }
00187
00189
00190
00191
00193
00194 static const int
00195 _bz_staticLengthCount = 0,
00196 _bz_dynamicLengthCount = 1,
00197 _bz_staticLength = 0;
00198
00199 bool _bz_hasFastAccess() const
00200 { return isUnitStride(); }
00201
00202 P_numtype _bz_fastAccess(int i) const
00203 {
00204 return data_[i];
00205 }
00206
00207 int _bz_suggestLength() const
00208 { return length_; }
00209
00210 private:
00211 const P_numtype * restrict data_;
00212 int stride_;
00213 int length_;
00214 };
00215
00216 BZ_NAMESPACE_END
00217
00218 #endif // BZ_VECITER_H