| 1 | /*************************************************************************** | 
|---|
| 2 | * blitz/vecpick.h      Declaration of the VectorPick<T_numtype> class | 
|---|
| 3 | * | 
|---|
| 4 | * $Id: vecpick.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.5  1998/03/14 00:04:47  tveldhui | 
|---|
| 27 | * 0.2-alpha-05 | 
|---|
| 28 | * | 
|---|
| 29 | * Revision 1.4  1997/07/16 14:51:20  tveldhui | 
|---|
| 30 | * Update: Alpha release 0.2 (Arrays) | 
|---|
| 31 | * | 
|---|
| 32 | * Revision 1.3  1997/01/24 14:42:00  tveldhui | 
|---|
| 33 | * Periodic RCS update | 
|---|
| 34 | * | 
|---|
| 35 | * Revision 1.2  1997/01/23 03:28:28  tveldhui | 
|---|
| 36 | * Periodic RCS update | 
|---|
| 37 | * | 
|---|
| 38 | * Revision 1.1  1997/01/13 22:19:58  tveldhui | 
|---|
| 39 | * Periodic RCS update | 
|---|
| 40 | * | 
|---|
| 41 | * | 
|---|
| 42 | */ | 
|---|
| 43 |  | 
|---|
| 44 | #ifndef BZ_VECPICK_H | 
|---|
| 45 | #define BZ_VECPICK_H | 
|---|
| 46 |  | 
|---|
| 47 | #ifndef BZ_VECTOR_H | 
|---|
| 48 | #include <blitz/vector.h> | 
|---|
| 49 | #endif | 
|---|
| 50 |  | 
|---|
| 51 | BZ_NAMESPACE(blitz) | 
|---|
| 52 |  | 
|---|
| 53 | // Forward declarations | 
|---|
| 54 |  | 
|---|
| 55 | template<class P_numtype> class VectorPickIter; | 
|---|
| 56 | template<class P_numtype> class VectorPickIterConst; | 
|---|
| 57 |  | 
|---|
| 58 | // Declaration of class VectorPick<P_numtype> | 
|---|
| 59 |  | 
|---|
| 60 | template<class P_numtype> | 
|---|
| 61 | class VectorPick { | 
|---|
| 62 |  | 
|---|
| 63 | public: | 
|---|
| 64 | ////////////////////////////////////////////// | 
|---|
| 65 | // Public Types | 
|---|
| 66 | ////////////////////////////////////////////// | 
|---|
| 67 |  | 
|---|
| 68 | typedef P_numtype                      T_numtype; | 
|---|
| 69 | typedef Vector<T_numtype>              T_vector; | 
|---|
| 70 | typedef Vector<int>                    T_indexVector; | 
|---|
| 71 | typedef VectorPick<T_numtype>          T_pick; | 
|---|
| 72 | typedef VectorPickIter<T_numtype>      T_iterator; | 
|---|
| 73 | typedef VectorPickIterConst<T_numtype> T_constIterator; | 
|---|
| 74 |  | 
|---|
| 75 | ////////////////////////////////////////////// | 
|---|
| 76 | // Constructors                             // | 
|---|
| 77 | ////////////////////////////////////////////// | 
|---|
| 78 |  | 
|---|
| 79 | VectorPick(T_vector& vector, T_indexVector& indexarg) | 
|---|
| 80 | : vector_(vector), index_(indexarg) | 
|---|
| 81 | { } | 
|---|
| 82 |  | 
|---|
| 83 | VectorPick(const T_pick& vecpick) | 
|---|
| 84 | : vector_(const_cast<T_vector&>(vecpick.vector_)), | 
|---|
| 85 | index_(const_cast<T_indexVector&>(vecpick.index_)) | 
|---|
| 86 | { } | 
|---|
| 87 |  | 
|---|
| 88 | VectorPick(T_pick& vecpick, Range r) | 
|---|
| 89 | : vector_(vecpick.vector_), index_(vecpick.index_[r]) | 
|---|
| 90 | { } | 
|---|
| 91 |  | 
|---|
| 92 | ////////////////////////////////////////////// | 
|---|
| 93 | // Member functions | 
|---|
| 94 | ////////////////////////////////////////////// | 
|---|
| 95 |  | 
|---|
| 96 | T_iterator         begin() | 
|---|
| 97 | { return VectorPickIter<T_numtype>(*this); } | 
|---|
| 98 |  | 
|---|
| 99 | T_constIterator    begin()      const | 
|---|
| 100 | { return VectorPickIterConst<T_numtype>(*this); } | 
|---|
| 101 |  | 
|---|
| 102 | // T_vector           copy()       const; | 
|---|
| 103 |  | 
|---|
| 104 | // T_iterator         end(); | 
|---|
| 105 |  | 
|---|
| 106 | // T_constIterator    end()        const; | 
|---|
| 107 |  | 
|---|
| 108 | T_indexVector&     indexSet() | 
|---|
| 109 | { return index_; } | 
|---|
| 110 |  | 
|---|
| 111 | const T_indexVector& indexSet()      const | 
|---|
| 112 | { return index_; } | 
|---|
| 113 |  | 
|---|
| 114 | int           length()     const | 
|---|
| 115 | { return index_.length(); } | 
|---|
| 116 |  | 
|---|
| 117 | void               setVector(Vector<T_numtype>& x) | 
|---|
| 118 | { vector_.reference(x); } | 
|---|
| 119 |  | 
|---|
| 120 | void               setIndex(Vector<int>& index) | 
|---|
| 121 | { index_.reference(index); } | 
|---|
| 122 |  | 
|---|
| 123 | T_vector&          vector() | 
|---|
| 124 | { return vector_; } | 
|---|
| 125 |  | 
|---|
| 126 | const T_vector&    vector()     const | 
|---|
| 127 | { return vector_; } | 
|---|
| 128 |  | 
|---|
| 129 | ///////////////////////////////////////////// | 
|---|
| 130 | // Library-internal member functions | 
|---|
| 131 | // These are undocumented and may change or | 
|---|
| 132 | // disappear in future releases. | 
|---|
| 133 | ///////////////////////////////////////////// | 
|---|
| 134 |  | 
|---|
| 135 | int        _bz_suggestLength() const | 
|---|
| 136 | { return index_.length(); } | 
|---|
| 137 |  | 
|---|
| 138 | _bz_bool        _bz_hasFastAccess() const | 
|---|
| 139 | { return vector_._bz_hasFastAccess() && index_._bz_hasFastAccess(); } | 
|---|
| 140 |  | 
|---|
| 141 | T_numtype&      _bz_fastAccess(int i) | 
|---|
| 142 | { return vector_._bz_fastAccess(index_._bz_fastAccess(i)); } | 
|---|
| 143 |  | 
|---|
| 144 | T_numtype       _bz_fastAccess(int i) const | 
|---|
| 145 | { return vector_._bz_fastAccess(index_._bz_fastAccess(i)); } | 
|---|
| 146 |  | 
|---|
| 147 | _bz_VecExpr<T_constIterator> _bz_asVecExpr() const | 
|---|
| 148 | { return _bz_VecExpr<T_constIterator>(begin()); } | 
|---|
| 149 |  | 
|---|
| 150 | ////////////////////////////////////////////// | 
|---|
| 151 | // Subscripting operators | 
|---|
| 152 | ////////////////////////////////////////////// | 
|---|
| 153 |  | 
|---|
| 154 | T_numtype       operator()(int i) const | 
|---|
| 155 | { | 
|---|
| 156 | BZPRECONDITION(index_.stride() == 1); | 
|---|
| 157 | BZPRECONDITION(vector_.stride() == 1); | 
|---|
| 158 | BZPRECONDITION(i < index_.length()); | 
|---|
| 159 | BZPRECONDITION(index_[i] < vector_.length()); | 
|---|
| 160 | return vector_(index_(i)); | 
|---|
| 161 | } | 
|---|
| 162 |  | 
|---|
| 163 | T_numtype&      operator()(int i) | 
|---|
| 164 | { | 
|---|
| 165 | BZPRECONDITION(index_.stride() == 1); | 
|---|
| 166 | BZPRECONDITION(vector_.stride() == 1); | 
|---|
| 167 | BZPRECONDITION(i < index_.length()); | 
|---|
| 168 | BZPRECONDITION(index_[i] < vector_.length()); | 
|---|
| 169 | return vector_(index_(i)); | 
|---|
| 170 | } | 
|---|
| 171 |  | 
|---|
| 172 | T_numtype       operator[](int i) const | 
|---|
| 173 | { | 
|---|
| 174 | BZPRECONDITION(index_.stride() == 1); | 
|---|
| 175 | BZPRECONDITION(vector_.stride() == 1); | 
|---|
| 176 | BZPRECONDITION(i < index_.length()); | 
|---|
| 177 | BZPRECONDITION(index_[i] < vector_.length()); | 
|---|
| 178 | return vector_[index_[i]]; | 
|---|
| 179 | } | 
|---|
| 180 |  | 
|---|
| 181 | T_numtype&      operator[](int i) | 
|---|
| 182 | { | 
|---|
| 183 | BZPRECONDITION(index_.stride() == 1); | 
|---|
| 184 | BZPRECONDITION(vector_.stride() == 1); | 
|---|
| 185 | BZPRECONDITION(i < index_.length()); | 
|---|
| 186 | BZPRECONDITION(index_[i] < vector_.length()); | 
|---|
| 187 | return vector_[index_[i]]; | 
|---|
| 188 | } | 
|---|
| 189 |  | 
|---|
| 190 | T_pick          operator()(Range r) | 
|---|
| 191 | { | 
|---|
| 192 | return T_pick(*this, index_[r]); | 
|---|
| 193 | } | 
|---|
| 194 |  | 
|---|
| 195 | T_pick          operator[](Range r) | 
|---|
| 196 | { | 
|---|
| 197 | return T_pick(*this, index_[r]); | 
|---|
| 198 | } | 
|---|
| 199 |  | 
|---|
| 200 | ////////////////////////////////////////////// | 
|---|
| 201 | // Assignment operators | 
|---|
| 202 | ////////////////////////////////////////////// | 
|---|
| 203 |  | 
|---|
| 204 | // Scalar operand | 
|---|
| 205 | T_pick& operator=(T_numtype); | 
|---|
| 206 | T_pick& operator+=(T_numtype); | 
|---|
| 207 | T_pick& operator-=(T_numtype); | 
|---|
| 208 | T_pick& operator*=(T_numtype); | 
|---|
| 209 | T_pick& operator/=(T_numtype); | 
|---|
| 210 | T_pick& operator%=(T_numtype); | 
|---|
| 211 | T_pick& operator^=(T_numtype); | 
|---|
| 212 | T_pick& operator&=(T_numtype); | 
|---|
| 213 | T_pick& operator|=(T_numtype); | 
|---|
| 214 | T_pick& operator>>=(int); | 
|---|
| 215 | T_pick& operator<<=(int); | 
|---|
| 216 |  | 
|---|
| 217 | // Vector operand | 
|---|
| 218 | template<class P_numtype2> T_pick& operator=(const Vector<P_numtype2> &); | 
|---|
| 219 | template<class P_numtype2> T_pick& operator+=(const Vector<P_numtype2> &); | 
|---|
| 220 | template<class P_numtype2> T_pick& operator-=(const Vector<P_numtype2> &); | 
|---|
| 221 | template<class P_numtype2> T_pick& operator*=(const Vector<P_numtype2> &); | 
|---|
| 222 | template<class P_numtype2> T_pick& operator/=(const Vector<P_numtype2> &); | 
|---|
| 223 | template<class P_numtype2> T_pick& operator%=(const Vector<P_numtype2> &); | 
|---|
| 224 | template<class P_numtype2> T_pick& operator^=(const Vector<P_numtype2> &); | 
|---|
| 225 | template<class P_numtype2> T_pick& operator&=(const Vector<P_numtype2> &); | 
|---|
| 226 | template<class P_numtype2> T_pick& operator|=(const Vector<P_numtype2> &); | 
|---|
| 227 | template<class P_numtype2> T_pick& operator>>=(const Vector<P_numtype2> &); | 
|---|
| 228 | template<class P_numtype2> T_pick& operator<<=(const Vector<P_numtype2> &); | 
|---|
| 229 |  | 
|---|
| 230 | // Vector expression operand | 
|---|
| 231 | template<class P_expr> T_pick& operator=(_bz_VecExpr<P_expr>); | 
|---|
| 232 | template<class P_expr> T_pick& operator+=(_bz_VecExpr<P_expr>); | 
|---|
| 233 | template<class P_expr> T_pick& operator-=(_bz_VecExpr<P_expr>); | 
|---|
| 234 | template<class P_expr> T_pick& operator*=(_bz_VecExpr<P_expr>); | 
|---|
| 235 | template<class P_expr> T_pick& operator/=(_bz_VecExpr<P_expr>); | 
|---|
| 236 | template<class P_expr> T_pick& operator%=(_bz_VecExpr<P_expr>); | 
|---|
| 237 | template<class P_expr> T_pick& operator^=(_bz_VecExpr<P_expr>); | 
|---|
| 238 | template<class P_expr> T_pick& operator&=(_bz_VecExpr<P_expr>); | 
|---|
| 239 | template<class P_expr> T_pick& operator|=(_bz_VecExpr<P_expr>); | 
|---|
| 240 | template<class P_expr> T_pick& operator>>=(_bz_VecExpr<P_expr>); | 
|---|
| 241 | template<class P_expr> T_pick& operator<<=(_bz_VecExpr<P_expr>); | 
|---|
| 242 |  | 
|---|
| 243 | // Range operand | 
|---|
| 244 | T_pick& operator=(Range); | 
|---|
| 245 | T_pick& operator+=(Range); | 
|---|
| 246 | T_pick& operator-=(Range); | 
|---|
| 247 | T_pick& operator*=(Range); | 
|---|
| 248 | T_pick& operator/=(Range); | 
|---|
| 249 | T_pick& operator%=(Range); | 
|---|
| 250 | T_pick& operator^=(Range); | 
|---|
| 251 | T_pick& operator&=(Range); | 
|---|
| 252 | T_pick& operator|=(Range); | 
|---|
| 253 | T_pick& operator>>=(Range); | 
|---|
| 254 | T_pick& operator<<=(Range); | 
|---|
| 255 |  | 
|---|
| 256 | // Vector pick operand | 
|---|
| 257 | template<class P_numtype2> | 
|---|
| 258 | T_pick& operator=(const VectorPick<P_numtype2> &); | 
|---|
| 259 | template<class P_numtype2> | 
|---|
| 260 | T_pick& operator+=(const VectorPick<P_numtype2> &); | 
|---|
| 261 | template<class P_numtype2> | 
|---|
| 262 | T_pick& operator-=(const VectorPick<P_numtype2> &); | 
|---|
| 263 | template<class P_numtype2> | 
|---|
| 264 | T_pick& operator*=(const VectorPick<P_numtype2> &); | 
|---|
| 265 | template<class P_numtype2> | 
|---|
| 266 | T_pick& operator/=(const VectorPick<P_numtype2> &); | 
|---|
| 267 | template<class P_numtype2> | 
|---|
| 268 | T_pick& operator%=(const VectorPick<P_numtype2> &); | 
|---|
| 269 | template<class P_numtype2> | 
|---|
| 270 | T_pick& operator^=(const VectorPick<P_numtype2> &); | 
|---|
| 271 | template<class P_numtype2> | 
|---|
| 272 | T_pick& operator&=(const VectorPick<P_numtype2> &); | 
|---|
| 273 | template<class P_numtype2> | 
|---|
| 274 | T_pick& operator|=(const VectorPick<P_numtype2> &); | 
|---|
| 275 | template<class P_numtype2> | 
|---|
| 276 | T_pick& operator>>=(const VectorPick<P_numtype2> &); | 
|---|
| 277 | template<class P_numtype2> | 
|---|
| 278 | T_pick& operator<<=(const VectorPick<P_numtype2> &); | 
|---|
| 279 |  | 
|---|
| 280 | // Random operand | 
|---|
| 281 | template<class P_distribution> | 
|---|
| 282 | T_pick& operator=(Random<P_distribution>& random); | 
|---|
| 283 | template<class P_distribution> | 
|---|
| 284 | T_pick& operator+=(Random<P_distribution>& random); | 
|---|
| 285 | template<class P_distribution> | 
|---|
| 286 | T_pick& operator-=(Random<P_distribution>& random); | 
|---|
| 287 | template<class P_distribution> | 
|---|
| 288 | T_pick& operator*=(Random<P_distribution>& random); | 
|---|
| 289 | template<class P_distribution> | 
|---|
| 290 | T_pick& operator/=(Random<P_distribution>& random); | 
|---|
| 291 | template<class P_distribution> | 
|---|
| 292 | T_pick& operator%=(Random<P_distribution>& random); | 
|---|
| 293 | template<class P_distribution> | 
|---|
| 294 | T_pick& operator^=(Random<P_distribution>& random); | 
|---|
| 295 | template<class P_distribution> | 
|---|
| 296 | T_pick& operator&=(Random<P_distribution>& random); | 
|---|
| 297 | template<class P_distribution> | 
|---|
| 298 | T_pick& operator|=(Random<P_distribution>& random); | 
|---|
| 299 |  | 
|---|
| 300 | private: | 
|---|
| 301 | VectorPick() { } | 
|---|
| 302 |  | 
|---|
| 303 | template<class P_expr, class P_updater> | 
|---|
| 304 | inline void _bz_assign(P_expr, P_updater); | 
|---|
| 305 |  | 
|---|
| 306 | private: | 
|---|
| 307 | T_vector vector_; | 
|---|
| 308 | T_indexVector index_; | 
|---|
| 309 | }; | 
|---|
| 310 |  | 
|---|
| 311 | BZ_NAMESPACE_END | 
|---|
| 312 |  | 
|---|
| 313 | #include <blitz/vecpick.cc> | 
|---|
| 314 | #include <blitz/vecpickio.cc> | 
|---|
| 315 | #include <blitz/vecpickiter.h> | 
|---|
| 316 |  | 
|---|
| 317 | #endif // BZ_VECPICK_H | 
|---|