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