source: XMLIO_V2/external/include/blitz/vecpickiter.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: 4.3 KB
Line 
1// -*- C++ -*-
2/***************************************************************************
3 * blitz/vecpickiter.h      Declaration of VectorPickIter<T_numtype> and
4 *                          VectorPickIterConst<T_numtype> classes
5 *
6 * $Id: vecpickiter.h,v 1.5 2005/05/07 04:17:56 julianc Exp $
7 *
8 * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * Suggestions:          blitz-dev@oonumerics.org
21 * Bugs:                 blitz-bugs@oonumerics.org
22 *
23 * For more information, please see the Blitz++ Home Page:
24 *    http://oonumerics.org/blitz/
25 *
26 ***************************************************************************/
27
28#ifndef BZ_VECPICKITER_H
29#define BZ_VECPICKITER_H
30
31#ifndef BZ_VECPICK_H
32 #include <blitz/vecpick.h>
33#endif
34
35BZ_NAMESPACE(blitz)
36
37template<typename P_numtype>
38class VectorPickIter {
39
40public:
41    typedef P_numtype  T_numtype;
42
43    explicit VectorPickIter(VectorPick<T_numtype>& x)
44        : data_(x.vector().data()), index_(x.indexSet().data())
45    {
46        dataStride_  = x.vector().stride();
47        indexStride_ = x.indexSet().stride();
48        length_ = x.indexSet().length();
49    }
50
51#ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
52    VectorPickIter(const VectorPickIter<T_numtype>& x)
53    {
54        data_ = x.data_;
55        index_ = x.index_;
56        dataStride_ = x.dataStride_;
57        indexStride_ = x.indexStride_;
58        length_ = x.length_;
59    }
60#endif
61
62    T_numtype operator[](int i) const
63    {
64        BZPRECONDITION(i < length_);
65        return data_[dataStride_ * index_[i * indexStride_]];
66    }
67
68    T_numtype& operator[](int i)
69    {
70        BZPRECONDITION(i < length_);
71        return data_[dataStride_ * index_[i * indexStride_]];
72    }
73
74    int length(int) const
75    { return length_; }
76
77    int _bz_suggestLength() const
78    { return length_; }
79
80    bool isUnitStride() const
81    { return (dataStride_  == 1) && (indexStride_ == 1); }
82
83    bool _bz_hasFastAccess() const
84    { return isUnitStride(); }
85
86    T_numtype _bz_fastAccess(int i) const
87    {   
88         return data_[index_[i]];
89    }
90
91    T_numtype&  _bz_fastAccess(int i)
92    {
93         return data_[index_[i]];
94    }
95
96    static const int
97        _bz_staticLengthCount = 0,
98        _bz_dynamicLengthCount = 1,
99        _bz_staticLength = 0;
100
101private:
102    T_numtype * restrict data_;
103    int dataStride_;
104    const int * restrict index_;
105    int indexStride_;
106    int length_;
107};
108
109template<typename P_numtype>
110class VectorPickIterConst {
111
112public:
113    typedef P_numtype  T_numtype;
114
115    explicit VectorPickIterConst(const VectorPick<T_numtype>& x)
116        : data_(x.vector().data()), index_(x.indexSet().data())
117    {
118        dataStride_  = x.vector().stride();
119        indexStride_ = x.indexSet().stride();
120        length_ = x.indexSet().length();
121    }
122
123#ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
124    VectorPickIterConst(const VectorPickIterConst<T_numtype>& x)
125    {
126        data_ = x.data_;
127        index_ = x.index_;
128        dataStride_ = x.dataStride_;
129        indexStride_ = x.indexStride_;
130        length_ = x.length_;
131    }
132#endif
133
134    T_numtype operator[](int i) const
135    {
136        BZPRECONDITION(i < length_);
137        return data_[dataStride_ * index_[i * indexStride_]];
138    }
139
140    int length(int) const
141    { return length_; }
142
143    int _bz_suggestLength() const
144    { return length_; }
145
146    bool isUnitStride() const
147    { return (dataStride_  == 1) && (indexStride_ == 1); }
148
149    bool _bz_hasFastAccess() const
150    { return isUnitStride(); }
151
152    T_numtype _bz_fastAccess(int i) const
153    {
154         return data_[index_[i]];
155    }
156
157    static const int 
158        _bz_staticLengthCount = 0,
159        _bz_dynamicLengthCount = 1,
160        _bz_staticLength = 0;
161
162private:
163    const T_numtype * restrict data_;
164    int dataStride_;
165    const int * restrict index_;
166    int indexStride_;
167    int length_;
168};
169
170BZ_NAMESPACE_END
171
172#endif // BZ_VECPICKITER_H
173
Note: See TracBrowser for help on using the repository browser.