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)
00094 {
00095
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 #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
00149 VectorIterConst(const VectorIterConst<P_numtype>& x)
00150 {
00151 data_ = x.data_;
00152 stride_ = x.stride_;
00153 length_ = x.length_;
00154 }
00155 #endif
00156
00157 P_numtype operator[](int i) const
00158 {
00159 BZPRECONDITION(i < length_);
00160 return data_[i*stride_];
00161 }
00162
00163 P_numtype operator()(int i) const
00164 {
00165 BZPRECONDITION(i < length_);
00166 return data_[i*stride_];
00167 }
00168
00169 int length(int) const
00170 { return length_; }
00171
00172 bool isUnitStride() const
00173 { return (stride_ == 1); }
00174
00176
00177
00178
00180
00181 static const int
00182 _bz_staticLengthCount = 0,
00183 _bz_dynamicLengthCount = 1,
00184 _bz_staticLength = 0;
00185
00186 bool _bz_hasFastAccess() const
00187 { return isUnitStride(); }
00188
00189 P_numtype _bz_fastAccess(int i) const
00190 {
00191 return data_[i];
00192 }
00193
00194 int _bz_suggestLength() const
00195 { return length_; }
00196
00197 private:
00198 const P_numtype * restrict data_;
00199 int stride_;
00200 int length_;
00201 };
00202
00203 BZ_NAMESPACE_END
00204
00205 #endif // BZ_VECITER_H