blitz/vecpick.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  * blitz/vecpick.h      Declaration of the VectorPick<T_numtype> class
00003  *
00004  * $Id: vecpick.h,v 1.5 2005/10/06 23:28:55 julianc Exp $
00005  *
00006  * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * Suggestions:          blitz-dev@oonumerics.org
00019  * Bugs:                 blitz-bugs@oonumerics.org
00020  *
00021  * For more information, please see the Blitz++ Home Page:
00022  *    http://oonumerics.org/blitz/
00023  *
00024  ***************************************************************************/
00025 
00026 #ifndef BZ_VECPICK_H
00027 #define BZ_VECPICK_H
00028 
00029 #include <blitz/vector.h>
00030 
00031 BZ_NAMESPACE(blitz)
00032 
00033 // Forward declarations
00034 
00035 template<typename P_numtype> class VectorPickIter;
00036 template<typename P_numtype> class VectorPickIterConst;
00037 
00038 // Declaration of class VectorPick<P_numtype>
00039 
00040 template<typename P_numtype>
00041 class VectorPick {
00042 
00043 public:
00045     // Public Types
00047 
00048     typedef P_numtype                      T_numtype;
00049     typedef Vector<T_numtype>              T_vector;
00050     typedef Vector<int>                    T_indexVector;
00051     typedef VectorPick<T_numtype>          T_pick;
00052     typedef VectorPickIter<T_numtype>      T_iterator;
00053     typedef VectorPickIterConst<T_numtype> T_constIterator;
00054 
00056     // Constructors                             //
00058 
00059     VectorPick(T_vector& vector, T_indexVector& indexarg)
00060         : vector_(vector), index_(indexarg)
00061     { }
00062 
00063     VectorPick(const T_pick& vecpick)
00064         : vector_(const_cast<T_vector&>(vecpick.vector_)), 
00065           index_(const_cast<T_indexVector&>(vecpick.index_))
00066     { }
00067 
00068     VectorPick(T_pick& vecpick, Range r)
00069         : vector_(vecpick.vector_), index_(vecpick.index_[r])
00070     { }
00071  
00073     // Member functions
00075 
00076     T_iterator         beginFast()
00077     { return VectorPickIter<T_numtype>(*this); }
00078 
00079     T_constIterator    beginFast()      const
00080     { return VectorPickIterConst<T_numtype>(*this); }
00081 
00082     // T_vector           copy()       const;
00083 
00084     // T_iterator         end();
00085 
00086     // T_constIterator    end()        const;
00087 
00088     T_indexVector&     indexSet()
00089     { return index_; }
00090  
00091     const T_indexVector& indexSet()      const
00092     { return index_; }
00093 
00094     int           length()     const
00095     { return index_.length(); }
00096 
00097     void               setVector(Vector<T_numtype>& x)
00098     { vector_.reference(x); }
00099 
00100     void               setIndex(Vector<int>& index)
00101     { index_.reference(index); }
00102 
00103     T_vector&          vector()
00104     { return vector_; }
00105 
00106     const T_vector&    vector()     const
00107     { return vector_; }
00108 
00110     // Library-internal member functions
00111     // These are undocumented and may change or
00112     // disappear in future releases.
00114 
00115     int        _bz_suggestLength() const
00116     { return index_.length(); }
00117 
00118     bool        _bz_hasFastAccess() const
00119     { return vector_._bz_hasFastAccess() && index_._bz_hasFastAccess(); }
00120 
00121     T_numtype&      _bz_fastAccess(int i)
00122     { return vector_._bz_fastAccess(index_._bz_fastAccess(i)); }
00123 
00124     T_numtype       _bz_fastAccess(int i) const
00125     { return vector_._bz_fastAccess(index_._bz_fastAccess(i)); }
00126 
00127     _bz_VecExpr<T_constIterator> _bz_asVecExpr() const
00128     { return _bz_VecExpr<T_constIterator>(beginFast()); }
00129 
00131     // Subscripting operators
00133 
00134     T_numtype       operator()(int i) const
00135     { 
00136         BZPRECONDITION(index_.stride() == 1);
00137         BZPRECONDITION(vector_.stride() == 1);
00138         BZPRECONDITION(i < index_.length());
00139         BZPRECONDITION(index_[i] < vector_.length());
00140         return vector_(index_(i));
00141     }
00142 
00143     T_numtype&      operator()(int i)
00144     {
00145         BZPRECONDITION(index_.stride() == 1);
00146         BZPRECONDITION(vector_.stride() == 1);
00147         BZPRECONDITION(i < index_.length());
00148         BZPRECONDITION(index_[i] < vector_.length());
00149         return vector_(index_(i));
00150     }
00151 
00152     T_numtype       operator[](int i) const
00153     {
00154         BZPRECONDITION(index_.stride() == 1);
00155         BZPRECONDITION(vector_.stride() == 1);
00156         BZPRECONDITION(i < index_.length());
00157         BZPRECONDITION(index_[i] < vector_.length());
00158         return vector_[index_[i]];
00159     }
00160 
00161     T_numtype&      operator[](int i)
00162     {
00163         BZPRECONDITION(index_.stride() == 1);
00164         BZPRECONDITION(vector_.stride() == 1);
00165         BZPRECONDITION(i < index_.length());
00166         BZPRECONDITION(index_[i] < vector_.length());
00167         return vector_[index_[i]];
00168     }
00169 
00170     T_pick          operator()(Range r)
00171     {
00172         return T_pick(*this, index_[r]);
00173     }
00174 
00175     T_pick          operator[](Range r)
00176     {
00177         return T_pick(*this, index_[r]);
00178     }
00179 
00181     // Assignment operators
00183 
00184     // Scalar operand
00185     T_pick& operator=(T_numtype);
00186     T_pick& operator+=(T_numtype);
00187     T_pick& operator-=(T_numtype);
00188     T_pick& operator*=(T_numtype);
00189     T_pick& operator/=(T_numtype);
00190     T_pick& operator%=(T_numtype);
00191     T_pick& operator^=(T_numtype);
00192     T_pick& operator&=(T_numtype);
00193     T_pick& operator|=(T_numtype);
00194     T_pick& operator>>=(int);
00195     T_pick& operator<<=(int);
00196 
00197     // Vector operand
00198     template<typename P_numtype2> T_pick& operator=(const Vector<P_numtype2> &);
00199     template<typename P_numtype2> T_pick& operator+=(const Vector<P_numtype2> &);
00200     template<typename P_numtype2> T_pick& operator-=(const Vector<P_numtype2> &);
00201     template<typename P_numtype2> T_pick& operator*=(const Vector<P_numtype2> &);
00202     template<typename P_numtype2> T_pick& operator/=(const Vector<P_numtype2> &);
00203     template<typename P_numtype2> T_pick& operator%=(const Vector<P_numtype2> &);
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 
00210     // Vector expression operand
00211     template<typename P_expr> T_pick& operator=(_bz_VecExpr<P_expr>);
00212     template<typename P_expr> T_pick& operator+=(_bz_VecExpr<P_expr>);
00213     template<typename P_expr> T_pick& operator-=(_bz_VecExpr<P_expr>);
00214     template<typename P_expr> T_pick& operator*=(_bz_VecExpr<P_expr>);
00215     template<typename P_expr> T_pick& operator/=(_bz_VecExpr<P_expr>);
00216     template<typename P_expr> T_pick& operator%=(_bz_VecExpr<P_expr>);
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 
00223     // Range operand
00224     T_pick& operator=(Range);
00225     T_pick& operator+=(Range);
00226     T_pick& operator-=(Range);
00227     T_pick& operator*=(Range);
00228     T_pick& operator/=(Range);
00229     T_pick& operator%=(Range);
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 
00236     // Vector pick operand
00237     template<typename P_numtype2> 
00238     T_pick& operator=(const VectorPick<P_numtype2> &);
00239     template<typename P_numtype2> 
00240     T_pick& operator+=(const VectorPick<P_numtype2> &);
00241     template<typename P_numtype2> 
00242     T_pick& operator-=(const VectorPick<P_numtype2> &);
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 
00260     // Random operand
00261     template<typename P_distribution>
00262     T_pick& operator=(Random<P_distribution>& random);
00263     template<typename P_distribution>
00264     T_pick& operator+=(Random<P_distribution>& random);
00265     template<typename P_distribution>
00266     T_pick& operator-=(Random<P_distribution>& random);
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 
00280 private:
00281     VectorPick() { }
00282 
00283     template<typename P_expr, typename P_updater>
00284     inline void _bz_assign(P_expr, P_updater);
00285 
00286 private:
00287     T_vector vector_;
00288     T_indexVector index_;
00289 };
00290 
00291 BZ_NAMESPACE_END
00292 
00293 #include <blitz/vecpick.cc>
00294 #include <blitz/vecpickio.cc>
00295 #include <blitz/vecpickiter.h>
00296 
00297 #endif // BZ_VECPICK_H

Generated on Mon Dec 3 09:21:55 2007 for blitz by  doxygen 1.5.1