| [221] | 1 | /*************************************************************************** | 
|---|
|  | 2 | * blitz/veciter.h      Iterator classes for Vector<P_numtype> | 
|---|
|  | 3 | * | 
|---|
|  | 4 | * $Id: veciter.h,v 1.1.1.1 1999-04-09 17:59:00 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.6  1998/03/14 00:04:47  tveldhui | 
|---|
|  | 27 | * 0.2-alpha-05 | 
|---|
|  | 28 | * | 
|---|
|  | 29 | * Revision 1.5  1997/07/16 14:51:20  tveldhui | 
|---|
|  | 30 | * Update: Alpha release 0.2 (Arrays) | 
|---|
|  | 31 | * | 
|---|
|  | 32 | * Revision 1.4  1997/01/24 14:42:00  tveldhui | 
|---|
|  | 33 | * Periodic RCS update | 
|---|
|  | 34 | * | 
|---|
|  | 35 | * Revision 1.3  1997/01/23 03:28:28  tveldhui | 
|---|
|  | 36 | * Periodic RCS update | 
|---|
|  | 37 | * | 
|---|
|  | 38 | * Revision 1.2  1997/01/13 22:19:58  tveldhui | 
|---|
|  | 39 | * Periodic RCS update | 
|---|
|  | 40 | * | 
|---|
|  | 41 | * | 
|---|
|  | 42 | */ | 
|---|
|  | 43 |  | 
|---|
|  | 44 |  | 
|---|
|  | 45 | #ifndef BZ_VECITER_H | 
|---|
|  | 46 | #define BZ_VECITER_H | 
|---|
|  | 47 |  | 
|---|
|  | 48 | #ifndef BZ_VECTOR_H | 
|---|
|  | 49 | #error <blitz/veciter.h> should be included via <blitz/vector.h> | 
|---|
|  | 50 | #endif | 
|---|
|  | 51 |  | 
|---|
|  | 52 | BZ_NAMESPACE(blitz) | 
|---|
|  | 53 |  | 
|---|
|  | 54 | // Declaration of class VectorIter | 
|---|
|  | 55 | template<class P_numtype> | 
|---|
|  | 56 | class VectorIter { | 
|---|
|  | 57 | public: | 
|---|
|  | 58 | typedef P_numtype T_numtype; | 
|---|
|  | 59 |  | 
|---|
|  | 60 | _bz_explicit VectorIter(Vector<P_numtype>& x) | 
|---|
|  | 61 | : data_(x.data()) | 
|---|
|  | 62 | { | 
|---|
|  | 63 | stride_ = x.stride(); | 
|---|
|  | 64 | length_ = x.length(); | 
|---|
|  | 65 | } | 
|---|
|  | 66 |  | 
|---|
|  | 67 | VectorIter(P_numtype* _bz_restrict data, int stride, int length) | 
|---|
|  | 68 | : data_(data), stride_(stride), length_(length) | 
|---|
|  | 69 | { } | 
|---|
|  | 70 |  | 
|---|
|  | 71 | #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR | 
|---|
|  | 72 | VectorIter(const VectorIter<P_numtype>& x) | 
|---|
|  | 73 | { | 
|---|
|  | 74 | data_ = x.data_; | 
|---|
|  | 75 | stride_ = x.stride_; | 
|---|
|  | 76 | length_ = x.length_; | 
|---|
|  | 77 | } | 
|---|
|  | 78 | #endif | 
|---|
|  | 79 |  | 
|---|
|  | 80 | P_numtype operator[](int i) const | 
|---|
|  | 81 | { | 
|---|
|  | 82 | BZPRECONDITION(i < length_); | 
|---|
|  | 83 | return data_[i*stride_]; | 
|---|
|  | 84 | } | 
|---|
|  | 85 |  | 
|---|
|  | 86 | P_numtype& _bz_restrict operator[](int i) | 
|---|
|  | 87 | { | 
|---|
|  | 88 | BZPRECONDITION(i < length_); | 
|---|
|  | 89 | return data_[i*stride_]; | 
|---|
|  | 90 | } | 
|---|
|  | 91 |  | 
|---|
|  | 92 | P_numtype operator()(int i) const | 
|---|
|  | 93 | { | 
|---|
|  | 94 | BZPRECONDITION(i < length_); | 
|---|
|  | 95 | return data_[i*stride_]; | 
|---|
|  | 96 | } | 
|---|
|  | 97 |  | 
|---|
|  | 98 | P_numtype& _bz_restrict operator()(int i) | 
|---|
|  | 99 | { | 
|---|
|  | 100 | BZPRECONDITION(i < length_); | 
|---|
|  | 101 | return data_[i*stride_]; | 
|---|
|  | 102 | } | 
|---|
|  | 103 |  | 
|---|
|  | 104 | P_numtype operator*() const | 
|---|
|  | 105 | { return *data_; } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | P_numtype& operator*() | 
|---|
|  | 108 | { return *data_; } | 
|---|
|  | 109 |  | 
|---|
|  | 110 | VectorIter<P_numtype> operator+(int i) | 
|---|
|  | 111 | { | 
|---|
|  | 112 | // NEEDS_WORK -- precondition checking? | 
|---|
|  | 113 | return VectorIter<P_numtype>(data_+i*stride_, stride_, length_-i); | 
|---|
|  | 114 | } | 
|---|
|  | 115 |  | 
|---|
|  | 116 | int length(int) const | 
|---|
|  | 117 | { return length_; } | 
|---|
|  | 118 |  | 
|---|
|  | 119 | _bz_bool isUnitStride() const | 
|---|
|  | 120 | { return (stride_ == 1); } | 
|---|
|  | 121 |  | 
|---|
|  | 122 | ///////////////////////////////////////////// | 
|---|
|  | 123 | // Library-internal member functions | 
|---|
|  | 124 | // These are undocumented and may change or | 
|---|
|  | 125 | // disappear in future releases. | 
|---|
|  | 126 | ///////////////////////////////////////////// | 
|---|
|  | 127 |  | 
|---|
|  | 128 | enum { _bz_staticLengthCount = 0, | 
|---|
|  | 129 | _bz_dynamicLengthCount = 1, | 
|---|
|  | 130 | _bz_staticLength = 0 }; | 
|---|
|  | 131 |  | 
|---|
|  | 132 | _bz_bool _bz_hasFastAccess() const | 
|---|
|  | 133 | { return isUnitStride(); } | 
|---|
|  | 134 |  | 
|---|
|  | 135 | P_numtype _bz_fastAccess(int i) const | 
|---|
|  | 136 | { return data_[i]; } | 
|---|
|  | 137 |  | 
|---|
|  | 138 | P_numtype& _bz_restrict _bz_fastAccess(int i) | 
|---|
|  | 139 | { return data_[i]; } | 
|---|
|  | 140 |  | 
|---|
|  | 141 | int _bz_suggestLength() const | 
|---|
|  | 142 | { return length_; } | 
|---|
|  | 143 |  | 
|---|
|  | 144 | private: | 
|---|
|  | 145 | VectorIter() { } | 
|---|
|  | 146 | P_numtype * _bz_restrict data_; | 
|---|
|  | 147 | int stride_; | 
|---|
|  | 148 | int length_; | 
|---|
|  | 149 | }; | 
|---|
|  | 150 |  | 
|---|
|  | 151 |  | 
|---|
|  | 152 | template<class P_numtype> | 
|---|
|  | 153 | class VectorIterConst { | 
|---|
|  | 154 | public: | 
|---|
|  | 155 | typedef P_numtype T_numtype; | 
|---|
|  | 156 |  | 
|---|
|  | 157 | _bz_explicit VectorIterConst(const Vector<P_numtype>& x) | 
|---|
|  | 158 | : data_(x.data()) | 
|---|
|  | 159 | { | 
|---|
|  | 160 | stride_ = x.stride(); | 
|---|
|  | 161 | length_ = x.length(); | 
|---|
|  | 162 | } | 
|---|
|  | 163 |  | 
|---|
|  | 164 | #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR | 
|---|
|  | 165 | VectorIterConst(const VectorIterConst<P_numtype>& x) | 
|---|
|  | 166 | { | 
|---|
|  | 167 | data_ = x.data_; | 
|---|
|  | 168 | stride_ = x.stride_; | 
|---|
|  | 169 | length_ = x.length_; | 
|---|
|  | 170 | } | 
|---|
|  | 171 | #endif | 
|---|
|  | 172 |  | 
|---|
|  | 173 | P_numtype operator[](int i) const | 
|---|
|  | 174 | { | 
|---|
|  | 175 | BZPRECONDITION(i < length_); | 
|---|
|  | 176 | return data_[i*stride_]; | 
|---|
|  | 177 | } | 
|---|
|  | 178 |  | 
|---|
|  | 179 | P_numtype operator()(int i) const | 
|---|
|  | 180 | { | 
|---|
|  | 181 | BZPRECONDITION(i < length_); | 
|---|
|  | 182 | return data_[i*stride_]; | 
|---|
|  | 183 | } | 
|---|
|  | 184 |  | 
|---|
|  | 185 | int length(int) const | 
|---|
|  | 186 | { return length_; } | 
|---|
|  | 187 |  | 
|---|
|  | 188 | _bz_bool isUnitStride() const | 
|---|
|  | 189 | { return (stride_ == 1); } | 
|---|
|  | 190 |  | 
|---|
|  | 191 | ///////////////////////////////////////////// | 
|---|
|  | 192 | // Library-internal member functions | 
|---|
|  | 193 | // These are undocumented and may change or | 
|---|
|  | 194 | // disappear in future releases. | 
|---|
|  | 195 | ///////////////////////////////////////////// | 
|---|
|  | 196 |  | 
|---|
|  | 197 | enum { _bz_staticLengthCount = 0, | 
|---|
|  | 198 | _bz_dynamicLengthCount = 1, | 
|---|
|  | 199 | _bz_staticLength = 0 }; | 
|---|
|  | 200 |  | 
|---|
|  | 201 | _bz_bool  _bz_hasFastAccess() const | 
|---|
|  | 202 | { return isUnitStride(); } | 
|---|
|  | 203 |  | 
|---|
|  | 204 | P_numtype _bz_fastAccess(int i) const | 
|---|
|  | 205 | { | 
|---|
|  | 206 | return data_[i]; | 
|---|
|  | 207 | } | 
|---|
|  | 208 |  | 
|---|
|  | 209 | int _bz_suggestLength() const | 
|---|
|  | 210 | { return length_; } | 
|---|
|  | 211 |  | 
|---|
|  | 212 | private: | 
|---|
|  | 213 | const P_numtype * _bz_restrict data_; | 
|---|
|  | 214 | int stride_; | 
|---|
|  | 215 | int length_; | 
|---|
|  | 216 | }; | 
|---|
|  | 217 |  | 
|---|
|  | 218 | BZ_NAMESPACE_END | 
|---|
|  | 219 |  | 
|---|
|  | 220 | #endif // BZ_VECITER_H | 
|---|