source: XMLIO_V2/external/include/blitz/vecpick.h @ 73

Last change on this file since 73 was 73, checked in by ymipsl, 14 years ago
  • Property svn:eol-style set to native
File size: 10.1 KB
Line 
1/***************************************************************************
2 * blitz/vecpick.h      Declaration of the VectorPick<T_numtype> class
3 *
4 * $Id: vecpick.h,v 1.5 2005/10/06 23:28:55 julianc Exp $
5 *
6 * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
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-dev@oonumerics.org
19 * Bugs:                 blitz-bugs@oonumerics.org
20 *
21 * For more information, please see the Blitz++ Home Page:
22 *    http://oonumerics.org/blitz/
23 *
24 ***************************************************************************/
25
26#ifndef BZ_VECPICK_H
27#define BZ_VECPICK_H
28
29#include <blitz/vector.h>
30
31BZ_NAMESPACE(blitz)
32
33// Forward declarations
34
35template<typename P_numtype> class VectorPickIter;
36template<typename P_numtype> class VectorPickIterConst;
37
38// Declaration of class VectorPick<P_numtype>
39
40template<typename P_numtype>
41class VectorPick {
42
43public:
44    //////////////////////////////////////////////
45    // Public Types
46    //////////////////////////////////////////////
47
48    typedef P_numtype                      T_numtype;
49    typedef Vector<T_numtype>              T_vector;
50    typedef Vector<int>                    T_indexVector;
51    typedef VectorPick<T_numtype>          T_pick;
52    typedef VectorPickIter<T_numtype>      T_iterator;
53    typedef VectorPickIterConst<T_numtype> T_constIterator;
54
55    //////////////////////////////////////////////
56    // Constructors                             //
57    //////////////////////////////////////////////
58
59    VectorPick(T_vector& vector, T_indexVector& indexarg)
60        : vector_(vector), index_(indexarg)
61    { }
62
63    VectorPick(const T_pick& vecpick)
64        : vector_(const_cast<T_vector&>(vecpick.vector_)), 
65          index_(const_cast<T_indexVector&>(vecpick.index_))
66    { }
67
68    VectorPick(T_pick& vecpick, Range r)
69        : vector_(vecpick.vector_), index_(vecpick.index_[r])
70    { }
71 
72    //////////////////////////////////////////////
73    // Member functions
74    //////////////////////////////////////////////
75
76    T_iterator         beginFast()
77    { return VectorPickIter<T_numtype>(*this); }
78
79    T_constIterator    beginFast()      const
80    { return VectorPickIterConst<T_numtype>(*this); }
81
82    // T_vector           copy()       const;
83
84    // T_iterator         end();
85
86    // T_constIterator    end()        const;
87
88    T_indexVector&     indexSet()
89    { return index_; }
90 
91    const T_indexVector& indexSet()      const
92    { return index_; }
93
94    int           length()     const
95    { return index_.length(); }
96
97    void               setVector(Vector<T_numtype>& x)
98    { vector_.reference(x); }
99
100    void               setIndex(Vector<int>& index)
101    { index_.reference(index); }
102
103    T_vector&          vector()
104    { return vector_; }
105
106    const T_vector&    vector()     const
107    { return vector_; }
108
109    /////////////////////////////////////////////
110    // Library-internal member functions
111    // These are undocumented and may change or
112    // disappear in future releases.
113    /////////////////////////////////////////////
114
115    int        _bz_suggestLength() const
116    { return index_.length(); }
117
118    bool        _bz_hasFastAccess() const
119    { return vector_._bz_hasFastAccess() && index_._bz_hasFastAccess(); }
120
121    T_numtype&      _bz_fastAccess(int i)
122    { return vector_._bz_fastAccess(index_._bz_fastAccess(i)); }
123
124    T_numtype       _bz_fastAccess(int i) const
125    { return vector_._bz_fastAccess(index_._bz_fastAccess(i)); }
126
127    _bz_VecExpr<T_constIterator> _bz_asVecExpr() const
128    { return _bz_VecExpr<T_constIterator>(beginFast()); }
129
130    //////////////////////////////////////////////
131    // Subscripting operators
132    //////////////////////////////////////////////
133
134    T_numtype       operator()(int i) const
135    { 
136        BZPRECONDITION(index_.stride() == 1);
137        BZPRECONDITION(vector_.stride() == 1);
138        BZPRECONDITION(i < index_.length());
139        BZPRECONDITION(index_[i] < vector_.length());
140        return vector_(index_(i));
141    }
142
143    T_numtype&      operator()(int i)
144    {
145        BZPRECONDITION(index_.stride() == 1);
146        BZPRECONDITION(vector_.stride() == 1);
147        BZPRECONDITION(i < index_.length());
148        BZPRECONDITION(index_[i] < vector_.length());
149        return vector_(index_(i));
150    }
151
152    T_numtype       operator[](int i) const
153    {
154        BZPRECONDITION(index_.stride() == 1);
155        BZPRECONDITION(vector_.stride() == 1);
156        BZPRECONDITION(i < index_.length());
157        BZPRECONDITION(index_[i] < vector_.length());
158        return vector_[index_[i]];
159    }
160
161    T_numtype&      operator[](int i)
162    {
163        BZPRECONDITION(index_.stride() == 1);
164        BZPRECONDITION(vector_.stride() == 1);
165        BZPRECONDITION(i < index_.length());
166        BZPRECONDITION(index_[i] < vector_.length());
167        return vector_[index_[i]];
168    }
169
170    T_pick          operator()(Range r)
171    {
172        return T_pick(*this, index_[r]);
173    }
174
175    T_pick          operator[](Range r)
176    {
177        return T_pick(*this, index_[r]);
178    }
179
180    //////////////////////////////////////////////
181    // Assignment operators
182    //////////////////////////////////////////////
183
184    // Scalar operand
185    T_pick& operator=(T_numtype);
186    T_pick& operator+=(T_numtype);
187    T_pick& operator-=(T_numtype);
188    T_pick& operator*=(T_numtype);
189    T_pick& operator/=(T_numtype);
190    T_pick& operator%=(T_numtype);
191    T_pick& operator^=(T_numtype);
192    T_pick& operator&=(T_numtype);
193    T_pick& operator|=(T_numtype);
194    T_pick& operator>>=(int);
195    T_pick& operator<<=(int);
196
197    // Vector operand
198    template<typename P_numtype2> T_pick& operator=(const Vector<P_numtype2> &);
199    template<typename P_numtype2> T_pick& operator+=(const Vector<P_numtype2> &);
200    template<typename P_numtype2> T_pick& operator-=(const Vector<P_numtype2> &);
201    template<typename P_numtype2> T_pick& operator*=(const Vector<P_numtype2> &);
202    template<typename P_numtype2> T_pick& operator/=(const Vector<P_numtype2> &);
203    template<typename P_numtype2> T_pick& operator%=(const Vector<P_numtype2> &);
204    template<typename P_numtype2> T_pick& operator^=(const Vector<P_numtype2> &);
205    template<typename P_numtype2> T_pick& operator&=(const Vector<P_numtype2> &);
206    template<typename P_numtype2> T_pick& operator|=(const Vector<P_numtype2> &);
207    template<typename P_numtype2> T_pick& operator>>=(const Vector<P_numtype2> &);
208    template<typename P_numtype2> T_pick& operator<<=(const Vector<P_numtype2> &);
209
210    // Vector expression operand
211    template<typename P_expr> T_pick& operator=(_bz_VecExpr<P_expr>);
212    template<typename P_expr> T_pick& operator+=(_bz_VecExpr<P_expr>);
213    template<typename P_expr> T_pick& operator-=(_bz_VecExpr<P_expr>);
214    template<typename P_expr> T_pick& operator*=(_bz_VecExpr<P_expr>);
215    template<typename P_expr> T_pick& operator/=(_bz_VecExpr<P_expr>);
216    template<typename P_expr> T_pick& operator%=(_bz_VecExpr<P_expr>);
217    template<typename P_expr> T_pick& operator^=(_bz_VecExpr<P_expr>);
218    template<typename P_expr> T_pick& operator&=(_bz_VecExpr<P_expr>);
219    template<typename P_expr> T_pick& operator|=(_bz_VecExpr<P_expr>);
220    template<typename P_expr> T_pick& operator>>=(_bz_VecExpr<P_expr>);
221    template<typename P_expr> T_pick& operator<<=(_bz_VecExpr<P_expr>);
222
223    // Range operand
224    T_pick& operator=(Range);
225    T_pick& operator+=(Range);
226    T_pick& operator-=(Range);
227    T_pick& operator*=(Range);
228    T_pick& operator/=(Range);
229    T_pick& operator%=(Range);
230    T_pick& operator^=(Range);
231    T_pick& operator&=(Range);
232    T_pick& operator|=(Range);
233    T_pick& operator>>=(Range);
234    T_pick& operator<<=(Range);
235
236    // Vector pick operand
237    template<typename P_numtype2> 
238    T_pick& operator=(const VectorPick<P_numtype2> &);
239    template<typename P_numtype2> 
240    T_pick& operator+=(const VectorPick<P_numtype2> &);
241    template<typename P_numtype2> 
242    T_pick& operator-=(const VectorPick<P_numtype2> &);
243    template<typename P_numtype2> 
244    T_pick& operator*=(const VectorPick<P_numtype2> &);
245    template<typename P_numtype2> 
246    T_pick& operator/=(const VectorPick<P_numtype2> &);
247    template<typename P_numtype2> 
248    T_pick& operator%=(const VectorPick<P_numtype2> &);
249    template<typename P_numtype2> 
250    T_pick& operator^=(const VectorPick<P_numtype2> &);
251    template<typename P_numtype2> 
252    T_pick& operator&=(const VectorPick<P_numtype2> &);
253    template<typename P_numtype2> 
254    T_pick& operator|=(const VectorPick<P_numtype2> &);
255    template<typename P_numtype2> 
256    T_pick& operator>>=(const VectorPick<P_numtype2> &);
257    template<typename P_numtype2> 
258    T_pick& operator<<=(const VectorPick<P_numtype2> &);
259
260    // Random operand
261    template<typename P_distribution>
262    T_pick& operator=(Random<P_distribution>& random);
263    template<typename P_distribution>
264    T_pick& operator+=(Random<P_distribution>& random);
265    template<typename P_distribution>
266    T_pick& operator-=(Random<P_distribution>& random);
267    template<typename P_distribution>
268    T_pick& operator*=(Random<P_distribution>& random);
269    template<typename P_distribution>
270    T_pick& operator/=(Random<P_distribution>& random);
271    template<typename P_distribution>
272    T_pick& operator%=(Random<P_distribution>& random);
273    template<typename P_distribution>
274    T_pick& operator^=(Random<P_distribution>& random);
275    template<typename P_distribution>
276    T_pick& operator&=(Random<P_distribution>& random);
277    template<typename P_distribution>
278    T_pick& operator|=(Random<P_distribution>& random);
279
280private:
281    VectorPick() { }
282
283    template<typename P_expr, typename P_updater>
284    inline void _bz_assign(P_expr, P_updater);
285
286private:
287    T_vector vector_;
288    T_indexVector index_;
289};
290
291BZ_NAMESPACE_END
292
293#include <blitz/vecpick.cc>
294#include <blitz/vecpickio.cc>
295#include <blitz/vecpickiter.h>
296
297#endif // BZ_VECPICK_H
Note: See TracBrowser for help on using the repository browser.