2
/***************************************************************************
3
* blitz/veciter.h Iterator classes for Vector<P_numtype>
5
* $Id: veciter.h 1414 2005-11-01 22:04:59Z cookedm $
7
* Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License
11
* as published by the Free Software Foundation; either version 2
12
* of the License, or (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* Suggestions: blitz-dev@oonumerics.org
20
* Bugs: blitz-bugs@oonumerics.org
22
* For more information, please see the Blitz++ Home Page:
23
* http://oonumerics.org/blitz/
25
***************************************************************************/
32
#error <blitz/veciter.h> should be included via <blitz/vector.h>
37
// Declaration of class VectorIter
38
template<typename P_numtype>
41
typedef P_numtype T_numtype;
43
explicit VectorIter(Vector<P_numtype>& x)
50
VectorIter(P_numtype* restrict data, int stride, int length)
51
: data_(data), stride_(stride), length_(length)
54
#ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
55
VectorIter(const VectorIter<P_numtype>& x)
63
P_numtype operator[](int i) const
65
BZPRECONDITION(i < length_);
66
return data_[i*stride_];
69
P_numtype& restrict operator[](int i)
71
BZPRECONDITION(i < length_);
72
return data_[i*stride_];
75
P_numtype operator()(int i) const
77
BZPRECONDITION(i < length_);
78
return data_[i*stride_];
81
P_numtype& restrict operator()(int i)
83
BZPRECONDITION(i < length_);
84
return data_[i*stride_];
87
P_numtype operator*() const
90
P_numtype& operator*()
93
VectorIter<P_numtype> operator+(int i)
95
// NEEDS_WORK -- precondition checking?
96
return VectorIter<P_numtype>(data_+i*stride_, stride_, length_-i);
102
bool isUnitStride() const
103
{ return (stride_ == 1); }
105
/////////////////////////////////////////////
106
// Library-internal member functions
107
// These are undocumented and may change or
108
// disappear in future releases.
109
/////////////////////////////////////////////
112
_bz_staticLengthCount = 0,
113
_bz_dynamicLengthCount = 1,
114
_bz_staticLength = 0;
116
bool _bz_hasFastAccess() const
117
{ return isUnitStride(); }
119
P_numtype _bz_fastAccess(int i) const
122
P_numtype& restrict _bz_fastAccess(int i)
125
int _bz_suggestLength() const
130
P_numtype * restrict data_;
136
template<typename P_numtype>
137
class VectorIterConst {
139
typedef P_numtype T_numtype;
141
explicit VectorIterConst(const Vector<P_numtype>& x)
144
stride_ = x.stride();
145
length_ = x.length();
148
#ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
149
VectorIterConst(const VectorIterConst<P_numtype>& x)
157
P_numtype operator[](int i) const
159
BZPRECONDITION(i < length_);
160
return data_[i*stride_];
163
P_numtype operator()(int i) const
165
BZPRECONDITION(i < length_);
166
return data_[i*stride_];
169
int length(int) const
172
bool isUnitStride() const
173
{ return (stride_ == 1); }
175
/////////////////////////////////////////////
176
// Library-internal member functions
177
// These are undocumented and may change or
178
// disappear in future releases.
179
/////////////////////////////////////////////
182
_bz_staticLengthCount = 0,
183
_bz_dynamicLengthCount = 1,
184
_bz_staticLength = 0;
186
bool _bz_hasFastAccess() const
187
{ return isUnitStride(); }
189
P_numtype _bz_fastAccess(int i) const
194
int _bz_suggestLength() const
198
const P_numtype * restrict data_;
205
#endif // BZ_VECITER_H