source: Sophya/trunk/Poubelle/DPC:FitsIOServer/Blitz/blitz/veciter.h

Last change on this file was 658, checked in by ansari, 26 years ago

no message

File size: 5.4 KB
RevLine 
[658]1/***************************************************************************
2 * blitz/veciter.h Iterator classes for Vector<P_numtype>
3 *
4 * $Id: veciter.h,v 1.1.1.1 1999-11-26 16:37:05 ansari Exp $
5 *
6 * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * Suggestions: blitz-suggest@cybervision.com
19 * Bugs: blitz-bugs@cybervision.com
20 *
21 * For more information, please see the Blitz++ Home Page:
22 * http://seurat.uwaterloo.ca/blitz/
23 *
24 ***************************************************************************
25 * $Log: not supported by cvs2svn $
26 * Revision 1.1.1.1 1999/04/09 17:59:00 ansari
27 * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99
28 *
29 * Revision 1.6 1998/03/14 00:04:47 tveldhui
30 * 0.2-alpha-05
31 *
32 * Revision 1.5 1997/07/16 14:51:20 tveldhui
33 * Update: Alpha release 0.2 (Arrays)
34 *
35 * Revision 1.4 1997/01/24 14:42:00 tveldhui
36 * Periodic RCS update
37 *
38 * Revision 1.3 1997/01/23 03:28:28 tveldhui
39 * Periodic RCS update
40 *
41 * Revision 1.2 1997/01/13 22:19:58 tveldhui
42 * Periodic RCS update
43 *
44 *
45 */
46
47
48#ifndef BZ_VECITER_H
49#define BZ_VECITER_H
50
51#ifndef BZ_VECTOR_H
52 #error <blitz/veciter.h> should be included via <blitz/vector.h>
53#endif
54
55BZ_NAMESPACE(blitz)
56
57// Declaration of class VectorIter
58template<class P_numtype>
59class VectorIter {
60public:
61 typedef P_numtype T_numtype;
62
63 _bz_explicit VectorIter(Vector<P_numtype>& x)
64 : data_(x.data())
65 {
66 stride_ = x.stride();
67 length_ = x.length();
68 }
69
70 VectorIter(P_numtype* _bz_restrict data, int stride, int length)
71 : data_(data), stride_(stride), length_(length)
72 { }
73
74#ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
75 VectorIter(const VectorIter<P_numtype>& x)
76 {
77 data_ = x.data_;
78 stride_ = x.stride_;
79 length_ = x.length_;
80 }
81#endif
82
83 P_numtype operator[](int i) const
84 {
85 BZPRECONDITION(i < length_);
86 return data_[i*stride_];
87 }
88
89 P_numtype& _bz_restrict operator[](int i)
90 {
91 BZPRECONDITION(i < length_);
92 return data_[i*stride_];
93 }
94
95 P_numtype operator()(int i) const
96 {
97 BZPRECONDITION(i < length_);
98 return data_[i*stride_];
99 }
100
101 P_numtype& _bz_restrict operator()(int i)
102 {
103 BZPRECONDITION(i < length_);
104 return data_[i*stride_];
105 }
106
107 P_numtype operator*() const
108 { return *data_; }
109
110 P_numtype& operator*()
111 { return *data_; }
112
113 VectorIter<P_numtype> operator+(int i)
114 {
115 // NEEDS_WORK -- precondition checking?
116 return VectorIter<P_numtype>(data_+i*stride_, stride_, length_-i);
117 }
118
119 int length(int) const
120 { return length_; }
121
122 _bz_bool isUnitStride() const
123 { return (stride_ == 1); }
124
125 /////////////////////////////////////////////
126 // Library-internal member functions
127 // These are undocumented and may change or
128 // disappear in future releases.
129 /////////////////////////////////////////////
130
131 enum { _bz_staticLengthCount = 0,
132 _bz_dynamicLengthCount = 1,
133 _bz_staticLength = 0 };
134
135 _bz_bool _bz_hasFastAccess() const
136 { return isUnitStride(); }
137
138 P_numtype _bz_fastAccess(int i) const
139 { return data_[i]; }
140
141 P_numtype& _bz_restrict _bz_fastAccess(int i)
142 { return data_[i]; }
143
144 int _bz_suggestLength() const
145 { return length_; }
146
147private:
148 VectorIter() { }
149 P_numtype * _bz_restrict data_;
150 int stride_;
151 int length_;
152};
153
154
155template<class P_numtype>
156class VectorIterConst {
157public:
158 typedef P_numtype T_numtype;
159
160 _bz_explicit VectorIterConst(const Vector<P_numtype>& x)
161 : data_(x.data())
162 {
163 stride_ = x.stride();
164 length_ = x.length();
165 }
166
167#ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
168 VectorIterConst(const VectorIterConst<P_numtype>& x)
169 {
170 data_ = x.data_;
171 stride_ = x.stride_;
172 length_ = x.length_;
173 }
174#endif
175
176 P_numtype operator[](int i) const
177 {
178 BZPRECONDITION(i < length_);
179 return data_[i*stride_];
180 }
181
182 P_numtype operator()(int i) const
183 {
184 BZPRECONDITION(i < length_);
185 return data_[i*stride_];
186 }
187
188 int length(int) const
189 { return length_; }
190
191 _bz_bool isUnitStride() const
192 { return (stride_ == 1); }
193
194 /////////////////////////////////////////////
195 // Library-internal member functions
196 // These are undocumented and may change or
197 // disappear in future releases.
198 /////////////////////////////////////////////
199
200 enum { _bz_staticLengthCount = 0,
201 _bz_dynamicLengthCount = 1,
202 _bz_staticLength = 0 };
203
204 _bz_bool _bz_hasFastAccess() const
205 { return isUnitStride(); }
206
207 P_numtype _bz_fastAccess(int i) const
208 {
209 return data_[i];
210 }
211
212 int _bz_suggestLength() const
213 { return length_; }
214
215private:
216 const P_numtype * _bz_restrict data_;
217 int stride_;
218 int length_;
219};
220
221BZ_NAMESPACE_END
222
223#endif // BZ_VECITER_H
Note: See TracBrowser for help on using the repository browser.