00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * blitz/vecpickiter.h Declaration of VectorPickIter<T_numtype> and 00004 * VectorPickIterConst<T_numtype> classes 00005 * 00006 * $Id: vecpickiter.h,v 1.5 2005/05/07 04:17:56 julianc Exp $ 00007 * 00008 * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org> 00009 * 00010 * This program is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU General Public License 00012 * as published by the Free Software Foundation; either version 2 00013 * of the License, or (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * Suggestions: blitz-dev@oonumerics.org 00021 * Bugs: blitz-bugs@oonumerics.org 00022 * 00023 * For more information, please see the Blitz++ Home Page: 00024 * http://oonumerics.org/blitz/ 00025 * 00026 ***************************************************************************/ 00027 00028 #ifndef BZ_VECPICKITER_H 00029 #define BZ_VECPICKITER_H 00030 00031 #ifndef BZ_VECPICK_H 00032 #include <blitz/vecpick.h> 00033 #endif 00034 00035 BZ_NAMESPACE(blitz) 00036 00037 template<typename P_numtype> 00038 class VectorPickIter { 00039 00040 public: 00041 typedef P_numtype T_numtype; 00042 00043 explicit VectorPickIter(VectorPick<T_numtype>& x) 00044 : data_(x.vector().data()), index_(x.indexSet().data()) 00045 { 00046 dataStride_ = x.vector().stride(); 00047 indexStride_ = x.indexSet().stride(); 00048 length_ = x.indexSet().length(); 00049 } 00050 00051 #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR 00052 VectorPickIter(const VectorPickIter<T_numtype>& x) 00053 { 00054 data_ = x.data_; 00055 index_ = x.index_; 00056 dataStride_ = x.dataStride_; 00057 indexStride_ = x.indexStride_; 00058 length_ = x.length_; 00059 } 00060 #endif 00061 00062 T_numtype operator[](int i) const 00063 { 00064 BZPRECONDITION(i < length_); 00065 return data_[dataStride_ * index_[i * indexStride_]]; 00066 } 00067 00068 T_numtype& operator[](int i) 00069 { 00070 BZPRECONDITION(i < length_); 00071 return data_[dataStride_ * index_[i * indexStride_]]; 00072 } 00073 00074 int length(int) const 00075 { return length_; } 00076 00077 int _bz_suggestLength() const 00078 { return length_; } 00079 00080 bool isUnitStride() const 00081 { return (dataStride_ == 1) && (indexStride_ == 1); } 00082 00083 bool _bz_hasFastAccess() const 00084 { return isUnitStride(); } 00085 00086 T_numtype _bz_fastAccess(int i) const 00087 { 00088 return data_[index_[i]]; 00089 } 00090 00091 T_numtype& _bz_fastAccess(int i) 00092 { 00093 return data_[index_[i]]; 00094 } 00095 00096 static const int 00097 _bz_staticLengthCount = 0, 00098 _bz_dynamicLengthCount = 1, 00099 _bz_staticLength = 0; 00100 00101 private: 00102 T_numtype * restrict data_; 00103 int dataStride_; 00104 const int * restrict index_; 00105 int indexStride_; 00106 int length_; 00107 }; 00108 00109 template<typename P_numtype> 00110 class VectorPickIterConst { 00111 00112 public: 00113 typedef P_numtype T_numtype; 00114 00115 explicit VectorPickIterConst(const VectorPick<T_numtype>& x) 00116 : data_(x.vector().data()), index_(x.indexSet().data()) 00117 { 00118 dataStride_ = x.vector().stride(); 00119 indexStride_ = x.indexSet().stride(); 00120 length_ = x.indexSet().length(); 00121 } 00122 00123 #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR 00124 VectorPickIterConst(const VectorPickIterConst<T_numtype>& x) 00125 { 00126 data_ = x.data_; 00127 index_ = x.index_; 00128 dataStride_ = x.dataStride_; 00129 indexStride_ = x.indexStride_; 00130 length_ = x.length_; 00131 } 00132 #endif 00133 00134 T_numtype operator[](int i) const 00135 { 00136 BZPRECONDITION(i < length_); 00137 return data_[dataStride_ * index_[i * indexStride_]]; 00138 } 00139 00140 int length(int) const 00141 { return length_; } 00142 00143 int _bz_suggestLength() const 00144 { return length_; } 00145 00146 bool isUnitStride() const 00147 { return (dataStride_ == 1) && (indexStride_ == 1); } 00148 00149 bool _bz_hasFastAccess() const 00150 { return isUnitStride(); } 00151 00152 T_numtype _bz_fastAccess(int i) const 00153 { 00154 return data_[index_[i]]; 00155 } 00156 00157 static const int 00158 _bz_staticLengthCount = 0, 00159 _bz_dynamicLengthCount = 1, 00160 _bz_staticLength = 0; 00161 00162 private: 00163 const T_numtype * restrict data_; 00164 int dataStride_; 00165 const int * restrict index_; 00166 int indexStride_; 00167 int length_; 00168 }; 00169 00170 BZ_NAMESPACE_END 00171 00172 #endif // BZ_VECPICKITER_H 00173