| [221] | 1 | /*************************************************************************** | 
|---|
|  | 2 | * blitz/vecpickiter.h      Declaration of VectorPickIter<T_numtype> and | 
|---|
|  | 3 | *                          VectorPickIterConst<T_numtype> classes | 
|---|
|  | 4 | * | 
|---|
|  | 5 | * $Id: vecpickiter.h,v 1.1.1.1 1999-04-09 17:59:00 ansari Exp $ | 
|---|
|  | 6 | * | 
|---|
|  | 7 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca> | 
|---|
|  | 8 | * | 
|---|
|  | 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. | 
|---|
|  | 13 | * | 
|---|
|  | 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. | 
|---|
|  | 18 | * | 
|---|
|  | 19 | * Suggestions:          blitz-suggest@cybervision.com | 
|---|
|  | 20 | * Bugs:                 blitz-bugs@cybervision.com | 
|---|
|  | 21 | * | 
|---|
|  | 22 | * For more information, please see the Blitz++ Home Page: | 
|---|
|  | 23 | *    http://seurat.uwaterloo.ca/blitz/ | 
|---|
|  | 24 | * | 
|---|
|  | 25 | *************************************************************************** | 
|---|
|  | 26 | * $Log: not supported by cvs2svn $ | 
|---|
|  | 27 | * Revision 1.5  1998/03/14 00:04:47  tveldhui | 
|---|
|  | 28 | * 0.2-alpha-05 | 
|---|
|  | 29 | * | 
|---|
|  | 30 | * Revision 1.4  1997/07/16 14:51:20  tveldhui | 
|---|
|  | 31 | * Update: Alpha release 0.2 (Arrays) | 
|---|
|  | 32 | * | 
|---|
|  | 33 | * Revision 1.3  1997/01/24 14:42:00  tveldhui | 
|---|
|  | 34 | * Periodic RCS update | 
|---|
|  | 35 | * | 
|---|
|  | 36 | * Revision 1.2  1997/01/23 03:28:28  tveldhui | 
|---|
|  | 37 | * Periodic RCS update | 
|---|
|  | 38 | * | 
|---|
|  | 39 | * Revision 1.1  1997/01/13 22:19:58  tveldhui | 
|---|
|  | 40 | * Periodic RCS update | 
|---|
|  | 41 | * | 
|---|
|  | 42 | * | 
|---|
|  | 43 | */ | 
|---|
|  | 44 |  | 
|---|
|  | 45 | #ifndef BZ_VECPICKITER_H | 
|---|
|  | 46 | #define BZ_VECPICKITER_H | 
|---|
|  | 47 |  | 
|---|
|  | 48 | #ifndef BZ_VECPICK_H | 
|---|
|  | 49 | #include <blitz/vecpick.h> | 
|---|
|  | 50 | #endif | 
|---|
|  | 51 |  | 
|---|
|  | 52 | BZ_NAMESPACE(blitz) | 
|---|
|  | 53 |  | 
|---|
|  | 54 | template<class P_numtype> | 
|---|
|  | 55 | class VectorPickIter { | 
|---|
|  | 56 |  | 
|---|
|  | 57 | public: | 
|---|
|  | 58 | typedef P_numtype  T_numtype; | 
|---|
|  | 59 |  | 
|---|
|  | 60 | _bz_explicit VectorPickIter(VectorPick<T_numtype>& x) | 
|---|
|  | 61 | : data_(x.vector().data()), index_(x.indexSet().data()) | 
|---|
|  | 62 | { | 
|---|
|  | 63 | dataStride_  = x.vector().stride(); | 
|---|
|  | 64 | indexStride_ = x.indexSet().stride(); | 
|---|
|  | 65 | length_ = x.indexSet().length(); | 
|---|
|  | 66 | } | 
|---|
|  | 67 |  | 
|---|
|  | 68 | #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR | 
|---|
|  | 69 | VectorPickIter(const VectorPickIter<T_numtype>& x) | 
|---|
|  | 70 | { | 
|---|
|  | 71 | data_ = x.data_; | 
|---|
|  | 72 | index_ = x.index_; | 
|---|
|  | 73 | dataStride_ = x.dataStride_; | 
|---|
|  | 74 | indexStride_ = x.indexStride_; | 
|---|
|  | 75 | length_ = x.length_; | 
|---|
|  | 76 | } | 
|---|
|  | 77 | #endif | 
|---|
|  | 78 |  | 
|---|
|  | 79 | T_numtype operator[](int i) const | 
|---|
|  | 80 | { | 
|---|
|  | 81 | BZPRECONDITION(i < length_); | 
|---|
|  | 82 | return data_[dataStride_ * index_[i * indexStride_]]; | 
|---|
|  | 83 | } | 
|---|
|  | 84 |  | 
|---|
|  | 85 | T_numtype& operator[](int i) | 
|---|
|  | 86 | { | 
|---|
|  | 87 | BZPRECONDITION(i < length_); | 
|---|
|  | 88 | return data_[dataStride_ * index_[i * indexStride_]]; | 
|---|
|  | 89 | } | 
|---|
|  | 90 |  | 
|---|
|  | 91 | int length(int) const | 
|---|
|  | 92 | { return length_; } | 
|---|
|  | 93 |  | 
|---|
|  | 94 | int _bz_suggestLength() const | 
|---|
|  | 95 | { return length_; } | 
|---|
|  | 96 |  | 
|---|
|  | 97 | _bz_bool isUnitStride() const | 
|---|
|  | 98 | { return (dataStride_  == 1) && (indexStride_ == 1); } | 
|---|
|  | 99 |  | 
|---|
|  | 100 | _bz_bool _bz_hasFastAccess() const | 
|---|
|  | 101 | { return isUnitStride(); } | 
|---|
|  | 102 |  | 
|---|
|  | 103 | T_numtype _bz_fastAccess(int i) const | 
|---|
|  | 104 | { | 
|---|
|  | 105 | return data_[index_[i]]; | 
|---|
|  | 106 | } | 
|---|
|  | 107 |  | 
|---|
|  | 108 | T_numtype&  _bz_fastAccess(int i) | 
|---|
|  | 109 | { | 
|---|
|  | 110 | return data_[index_[i]]; | 
|---|
|  | 111 | } | 
|---|
|  | 112 |  | 
|---|
|  | 113 | enum { _bz_staticLengthCount = 0, | 
|---|
|  | 114 | _bz_dynamicLengthCount = 1, | 
|---|
|  | 115 | _bz_staticLength = 0 }; | 
|---|
|  | 116 |  | 
|---|
|  | 117 | private: | 
|---|
|  | 118 | T_numtype * _bz_restrict data_; | 
|---|
|  | 119 | int dataStride_; | 
|---|
|  | 120 | const int * _bz_restrict index_; | 
|---|
|  | 121 | int indexStride_; | 
|---|
|  | 122 | int length_; | 
|---|
|  | 123 | }; | 
|---|
|  | 124 |  | 
|---|
|  | 125 | template<class P_numtype> | 
|---|
|  | 126 | class VectorPickIterConst { | 
|---|
|  | 127 |  | 
|---|
|  | 128 | public: | 
|---|
|  | 129 | typedef P_numtype  T_numtype; | 
|---|
|  | 130 |  | 
|---|
|  | 131 | _bz_explicit VectorPickIterConst(const VectorPick<T_numtype>& x) | 
|---|
|  | 132 | : data_(x.vector().data()), index_(x.indexSet().data()) | 
|---|
|  | 133 | { | 
|---|
|  | 134 | dataStride_  = x.vector().stride(); | 
|---|
|  | 135 | indexStride_ = x.indexSet().stride(); | 
|---|
|  | 136 | length_ = x.indexSet().length(); | 
|---|
|  | 137 | } | 
|---|
|  | 138 |  | 
|---|
|  | 139 | #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR | 
|---|
|  | 140 | VectorPickIterConst(const VectorPickIterConst<T_numtype>& x) | 
|---|
|  | 141 | { | 
|---|
|  | 142 | data_ = x.data_; | 
|---|
|  | 143 | index_ = x.index_; | 
|---|
|  | 144 | dataStride_ = x.dataStride_; | 
|---|
|  | 145 | indexStride_ = x.indexStride_; | 
|---|
|  | 146 | length_ = x.length_; | 
|---|
|  | 147 | } | 
|---|
|  | 148 | #endif | 
|---|
|  | 149 |  | 
|---|
|  | 150 | T_numtype operator[](int i) const | 
|---|
|  | 151 | { | 
|---|
|  | 152 | BZPRECONDITION(i < length_); | 
|---|
|  | 153 | return data_[dataStride_ * index_[i * indexStride_]]; | 
|---|
|  | 154 | } | 
|---|
|  | 155 |  | 
|---|
|  | 156 | int length(int) const | 
|---|
|  | 157 | { return length_; } | 
|---|
|  | 158 |  | 
|---|
|  | 159 | int _bz_suggestLength() const | 
|---|
|  | 160 | { return length_; } | 
|---|
|  | 161 |  | 
|---|
|  | 162 | _bz_bool isUnitStride() const | 
|---|
|  | 163 | { return (dataStride_  == 1) && (indexStride_ == 1); } | 
|---|
|  | 164 |  | 
|---|
|  | 165 | _bz_bool _bz_hasFastAccess() const | 
|---|
|  | 166 | { return isUnitStride(); } | 
|---|
|  | 167 |  | 
|---|
|  | 168 | T_numtype _bz_fastAccess(int i) const | 
|---|
|  | 169 | { | 
|---|
|  | 170 | return data_[index_[i]]; | 
|---|
|  | 171 | } | 
|---|
|  | 172 |  | 
|---|
|  | 173 | enum { _bz_staticLengthCount = 0, | 
|---|
|  | 174 | _bz_dynamicLengthCount = 1, | 
|---|
|  | 175 | _bz_staticLength = 0 }; | 
|---|
|  | 176 |  | 
|---|
|  | 177 | private: | 
|---|
|  | 178 | const T_numtype * _bz_restrict data_; | 
|---|
|  | 179 | int dataStride_; | 
|---|
|  | 180 | const int * _bz_restrict index_; | 
|---|
|  | 181 | int indexStride_; | 
|---|
|  | 182 | int length_; | 
|---|
|  | 183 | }; | 
|---|
|  | 184 |  | 
|---|
|  | 185 | BZ_NAMESPACE_END | 
|---|
|  | 186 |  | 
|---|
|  | 187 | #endif // BZ_VECPICKITER_H | 
|---|
|  | 188 |  | 
|---|