blitz Version 0.10
|
00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * blitz/vecpick.h Declaration of the VectorPick<T_numtype> class 00004 * 00005 * $Id: vecpick.h,v 1.6 2011/03/25 22:41:16 julianc Exp $ 00006 * 00007 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org> 00008 * 00009 * This file is a part of Blitz. 00010 * 00011 * Blitz is free software: you can redistribute it and/or modify 00012 * it under the terms of the GNU Lesser General Public License 00013 * as published by the Free Software Foundation, either version 3 00014 * of the License, or (at your option) any later version. 00015 * 00016 * Blitz is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with Blitz. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 * Suggestions: blitz-devel@lists.sourceforge.net 00025 * Bugs: blitz-support@lists.sourceforge.net 00026 * 00027 * For more information, please see the Blitz++ Home Page: 00028 * https://sourceforge.net/projects/blitz/ 00029 * 00030 ***************************************************************************/ 00031 00032 #ifndef BZ_VECPICK_H 00033 #define BZ_VECPICK_H 00034 00035 #include <blitz/vector.h> 00036 00037 BZ_NAMESPACE(blitz) 00038 00039 // Forward declarations 00040 00041 template<typename P_numtype> class VectorPickIter; 00042 template<typename P_numtype> class VectorPickIterConst; 00043 00044 // Declaration of class VectorPick<P_numtype> 00045 00046 template<typename P_numtype> 00047 class VectorPick { 00048 00049 public: 00051 // Public Types 00053 00054 typedef P_numtype T_numtype; 00055 typedef Vector<T_numtype> T_vector; 00056 typedef Vector<int> T_indexVector; 00057 typedef VectorPick<T_numtype> T_pick; 00058 typedef VectorPickIter<T_numtype> T_iterator; 00059 typedef VectorPickIterConst<T_numtype> T_constIterator; 00060 00062 // Constructors // 00064 00065 VectorPick(T_vector& vector, T_indexVector& indexarg) 00066 : vector_(vector), index_(indexarg) 00067 { } 00068 00069 VectorPick(const T_pick& vecpick) 00070 : vector_(const_cast<T_vector&>(vecpick.vector_)), 00071 index_(const_cast<T_indexVector&>(vecpick.index_)) 00072 { } 00073 00074 VectorPick(T_pick& vecpick, Range r) 00075 : vector_(vecpick.vector_), index_(vecpick.index_[r]) 00076 { } 00077 00079 // Member functions 00081 00082 T_iterator beginFast() 00083 { return VectorPickIter<T_numtype>(*this); } 00084 00085 T_constIterator beginFast() const 00086 { return VectorPickIterConst<T_numtype>(*this); } 00087 00088 // T_vector copy() const; 00089 00090 // T_iterator end(); 00091 00092 // T_constIterator end() const; 00093 00094 T_indexVector& indexSet() 00095 { return index_; } 00096 00097 const T_indexVector& indexSet() const 00098 { return index_; } 00099 00100 int length() const 00101 { return index_.length(); } 00102 00103 void setVector(Vector<T_numtype>& x) 00104 { vector_.reference(x); } 00105 00106 void setIndex(Vector<int>& index) 00107 { index_.reference(index); } 00108 00109 T_vector& vector() 00110 { return vector_; } 00111 00112 const T_vector& vector() const 00113 { return vector_; } 00114 00116 // Library-internal member functions 00117 // These are undocumented and may change or 00118 // disappear in future releases. 00120 00121 int _bz_suggestLength() const 00122 { return index_.length(); } 00123 00124 bool _bz_hasFastAccess() const 00125 { return vector_._bz_hasFastAccess() && index_._bz_hasFastAccess(); } 00126 00127 T_numtype& _bz_fastAccess(int i) 00128 { return vector_._bz_fastAccess(index_._bz_fastAccess(i)); } 00129 00130 T_numtype _bz_fastAccess(int i) const 00131 { return vector_._bz_fastAccess(index_._bz_fastAccess(i)); } 00132 00133 _bz_VecExpr<T_constIterator> _bz_asVecExpr() const 00134 { return _bz_VecExpr<T_constIterator>(beginFast()); } 00135 00137 // Subscripting operators 00139 00140 T_numtype operator()(int i) const 00141 { 00142 BZPRECONDITION(index_.stride() == 1); 00143 BZPRECONDITION(vector_.stride() == 1); 00144 BZPRECONDITION(i < index_.length()); 00145 BZPRECONDITION(index_[i] < vector_.length()); 00146 return vector_(index_(i)); 00147 } 00148 00149 T_numtype& operator()(int i) 00150 { 00151 BZPRECONDITION(index_.stride() == 1); 00152 BZPRECONDITION(vector_.stride() == 1); 00153 BZPRECONDITION(i < index_.length()); 00154 BZPRECONDITION(index_[i] < vector_.length()); 00155 return vector_(index_(i)); 00156 } 00157 00158 T_numtype operator[](int i) const 00159 { 00160 BZPRECONDITION(index_.stride() == 1); 00161 BZPRECONDITION(vector_.stride() == 1); 00162 BZPRECONDITION(i < index_.length()); 00163 BZPRECONDITION(index_[i] < vector_.length()); 00164 return vector_[index_[i]]; 00165 } 00166 00167 T_numtype& operator[](int i) 00168 { 00169 BZPRECONDITION(index_.stride() == 1); 00170 BZPRECONDITION(vector_.stride() == 1); 00171 BZPRECONDITION(i < index_.length()); 00172 BZPRECONDITION(index_[i] < vector_.length()); 00173 return vector_[index_[i]]; 00174 } 00175 00176 T_pick operator()(Range r) 00177 { 00178 return T_pick(*this, index_[r]); 00179 } 00180 00181 T_pick operator[](Range r) 00182 { 00183 return T_pick(*this, index_[r]); 00184 } 00185 00187 // Assignment operators 00189 00190 // Scalar operand 00191 T_pick& operator=(T_numtype); 00192 T_pick& operator+=(T_numtype); 00193 T_pick& operator-=(T_numtype); 00194 T_pick& operator*=(T_numtype); 00195 T_pick& operator/=(T_numtype); 00196 T_pick& operator%=(T_numtype); 00197 T_pick& operator^=(T_numtype); 00198 T_pick& operator&=(T_numtype); 00199 T_pick& operator|=(T_numtype); 00200 T_pick& operator>>=(int); 00201 T_pick& operator<<=(int); 00202 00203 // Vector operand 00204 template<typename P_numtype2> T_pick& operator=(const Vector<P_numtype2> &); 00205 template<typename P_numtype2> T_pick& operator+=(const Vector<P_numtype2> &); 00206 template<typename P_numtype2> T_pick& operator-=(const Vector<P_numtype2> &); 00207 template<typename P_numtype2> T_pick& operator*=(const Vector<P_numtype2> &); 00208 template<typename P_numtype2> T_pick& operator/=(const Vector<P_numtype2> &); 00209 template<typename P_numtype2> T_pick& operator%=(const Vector<P_numtype2> &); 00210 template<typename P_numtype2> T_pick& operator^=(const Vector<P_numtype2> &); 00211 template<typename P_numtype2> T_pick& operator&=(const Vector<P_numtype2> &); 00212 template<typename P_numtype2> T_pick& operator|=(const Vector<P_numtype2> &); 00213 template<typename P_numtype2> T_pick& operator>>=(const Vector<P_numtype2> &); 00214 template<typename P_numtype2> T_pick& operator<<=(const Vector<P_numtype2> &); 00215 00216 // Vector expression operand 00217 template<typename P_expr> T_pick& operator=(_bz_VecExpr<P_expr>); 00218 template<typename P_expr> T_pick& operator+=(_bz_VecExpr<P_expr>); 00219 template<typename P_expr> T_pick& operator-=(_bz_VecExpr<P_expr>); 00220 template<typename P_expr> T_pick& operator*=(_bz_VecExpr<P_expr>); 00221 template<typename P_expr> T_pick& operator/=(_bz_VecExpr<P_expr>); 00222 template<typename P_expr> T_pick& operator%=(_bz_VecExpr<P_expr>); 00223 template<typename P_expr> T_pick& operator^=(_bz_VecExpr<P_expr>); 00224 template<typename P_expr> T_pick& operator&=(_bz_VecExpr<P_expr>); 00225 template<typename P_expr> T_pick& operator|=(_bz_VecExpr<P_expr>); 00226 template<typename P_expr> T_pick& operator>>=(_bz_VecExpr<P_expr>); 00227 template<typename P_expr> T_pick& operator<<=(_bz_VecExpr<P_expr>); 00228 00229 // Range operand 00230 T_pick& operator=(Range); 00231 T_pick& operator+=(Range); 00232 T_pick& operator-=(Range); 00233 T_pick& operator*=(Range); 00234 T_pick& operator/=(Range); 00235 T_pick& operator%=(Range); 00236 T_pick& operator^=(Range); 00237 T_pick& operator&=(Range); 00238 T_pick& operator|=(Range); 00239 T_pick& operator>>=(Range); 00240 T_pick& operator<<=(Range); 00241 00242 // Vector pick operand 00243 template<typename P_numtype2> 00244 T_pick& operator=(const VectorPick<P_numtype2> &); 00245 template<typename P_numtype2> 00246 T_pick& operator+=(const VectorPick<P_numtype2> &); 00247 template<typename P_numtype2> 00248 T_pick& operator-=(const VectorPick<P_numtype2> &); 00249 template<typename P_numtype2> 00250 T_pick& operator*=(const VectorPick<P_numtype2> &); 00251 template<typename P_numtype2> 00252 T_pick& operator/=(const VectorPick<P_numtype2> &); 00253 template<typename P_numtype2> 00254 T_pick& operator%=(const VectorPick<P_numtype2> &); 00255 template<typename P_numtype2> 00256 T_pick& operator^=(const VectorPick<P_numtype2> &); 00257 template<typename P_numtype2> 00258 T_pick& operator&=(const VectorPick<P_numtype2> &); 00259 template<typename P_numtype2> 00260 T_pick& operator|=(const VectorPick<P_numtype2> &); 00261 template<typename P_numtype2> 00262 T_pick& operator>>=(const VectorPick<P_numtype2> &); 00263 template<typename P_numtype2> 00264 T_pick& operator<<=(const VectorPick<P_numtype2> &); 00265 00266 // Random operand 00267 template<typename P_distribution> 00268 T_pick& operator=(Random<P_distribution>& random); 00269 template<typename P_distribution> 00270 T_pick& operator+=(Random<P_distribution>& random); 00271 template<typename P_distribution> 00272 T_pick& operator-=(Random<P_distribution>& random); 00273 template<typename P_distribution> 00274 T_pick& operator*=(Random<P_distribution>& random); 00275 template<typename P_distribution> 00276 T_pick& operator/=(Random<P_distribution>& random); 00277 template<typename P_distribution> 00278 T_pick& operator%=(Random<P_distribution>& random); 00279 template<typename P_distribution> 00280 T_pick& operator^=(Random<P_distribution>& random); 00281 template<typename P_distribution> 00282 T_pick& operator&=(Random<P_distribution>& random); 00283 template<typename P_distribution> 00284 T_pick& operator|=(Random<P_distribution>& random); 00285 00286 private: 00287 VectorPick() { } 00288 00289 template<typename P_expr, typename P_updater> 00290 inline void _bz_assign(P_expr, P_updater); 00291 00292 private: 00293 T_vector vector_; 00294 T_indexVector index_; 00295 }; 00296 00297 BZ_NAMESPACE_END 00298 00299 #include <blitz/vecpick.cc> 00300 #include <blitz/vecpickio.cc> 00301 #include <blitz/vecpickiter.h> 00302 00303 #endif // BZ_VECPICK_H