[221] | 1 | /***************************************************************************
|
---|
| 2 | * blitz/tinyveciter.h Declaration of TinyVectorIter<T,N,stride>
|
---|
| 3 | *
|
---|
| 4 | * $Id: tinyveciter.h,v 1.1.1.1 1999-04-09 17:59:01 ansari Exp $
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
|
---|
| 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-suggest@cybervision.com
|
---|
| 19 | * Bugs: blitz-bugs@cybervision.com
|
---|
| 20 | *
|
---|
| 21 | * For more information, please see the Blitz++ Home Page:
|
---|
| 22 | * http://seurat.uwaterloo.ca/blitz/
|
---|
| 23 | *
|
---|
| 24 | ***************************************************************************
|
---|
| 25 | * $Log: not supported by cvs2svn $
|
---|
| 26 | * Revision 1.2 1998/03/14 00:04:47 tveldhui
|
---|
| 27 | * 0.2-alpha-05
|
---|
| 28 | *
|
---|
| 29 | * Revision 1.1 1997/07/16 14:51:20 tveldhui
|
---|
| 30 | * Update: Alpha release 0.2 (Arrays)
|
---|
| 31 | *
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | #ifndef BZ_TINYVECITER_H
|
---|
| 36 | #define BZ_TINYVECITER_H
|
---|
| 37 |
|
---|
| 38 | #ifndef BZ_TINYVEC_H
|
---|
| 39 | #include <blitz/tinyvec.h>
|
---|
| 40 | #endif
|
---|
| 41 |
|
---|
| 42 | #ifndef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
|
---|
| 43 | #error "Debug in tinyveciter.h (this line shouldn't be here)"
|
---|
| 44 | #endif
|
---|
| 45 |
|
---|
| 46 | BZ_NAMESPACE(blitz)
|
---|
| 47 |
|
---|
| 48 | // N_stride has default 1, in forward declaration in <blitz/tinyvec.h>
|
---|
| 49 | template<class P_numtype, int N_length, int N_stride>
|
---|
| 50 | class TinyVectorIter {
|
---|
| 51 | public:
|
---|
| 52 | typedef P_numtype T_numtype;
|
---|
| 53 |
|
---|
| 54 | _bz_explicit TinyVectorIter(TinyVector<T_numtype, N_length>& x)
|
---|
| 55 | : data_(x.data())
|
---|
| 56 | { }
|
---|
| 57 |
|
---|
| 58 | #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
|
---|
| 59 | TinyVectorIter(const TinyVectorIter<T_numtype, N_length, N_stride>& iter)
|
---|
| 60 | : data_(iter.data_)
|
---|
| 61 | {
|
---|
| 62 | }
|
---|
| 63 | #endif
|
---|
| 64 |
|
---|
| 65 | T_numtype operator[](unsigned i) const
|
---|
| 66 | {
|
---|
| 67 | BZPRECONDITION(i < N_length);
|
---|
| 68 | return data_[i * N_stride];
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | T_numtype& _bz_restrict operator[](unsigned i)
|
---|
| 72 | {
|
---|
| 73 | BZPRECONDITION(i < N_length);
|
---|
| 74 | return data_[i * N_stride];
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | T_numtype operator()(unsigned i) const
|
---|
| 78 | {
|
---|
| 79 | BZPRECONDITION(i < N_length);
|
---|
| 80 | return data_[i * N_stride];
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | T_numtype& _bz_restrict operator()(unsigned i)
|
---|
| 84 | {
|
---|
| 85 | BZPRECONDITION(i < N_length);
|
---|
| 86 | return data_[i * N_stride];
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | unsigned length(unsigned) const
|
---|
| 90 | { return N_length; }
|
---|
| 91 |
|
---|
| 92 | enum { _bz_staticLengthCount = 1,
|
---|
| 93 | _bz_dynamicLengthCount = 0,
|
---|
| 94 | _bz_staticLength = 0 };
|
---|
| 95 |
|
---|
| 96 | _bz_bool _bz_hasFastAccess() const
|
---|
| 97 | { return _bz_true; }
|
---|
| 98 |
|
---|
| 99 | T_numtype _bz_fastAccess(unsigned i) const
|
---|
| 100 | { return data_[i * N_stride]; }
|
---|
| 101 |
|
---|
| 102 | T_numtype& _bz_fastAccess(unsigned i)
|
---|
| 103 | { return data_[i * N_stride]; }
|
---|
| 104 |
|
---|
| 105 | unsigned _bz_suggestLength() const
|
---|
| 106 | { return N_length; }
|
---|
| 107 |
|
---|
| 108 | private:
|
---|
| 109 | T_numtype * _bz_restrict data_;
|
---|
| 110 | };
|
---|
| 111 |
|
---|
| 112 | // N_stride has default 1, in forward declaration in <blitz/tinyvec.h>
|
---|
| 113 | template<class P_numtype, int N_length, int N_stride>
|
---|
| 114 | class TinyVectorIterConst {
|
---|
| 115 | public:
|
---|
| 116 | typedef P_numtype T_numtype;
|
---|
| 117 |
|
---|
| 118 | _bz_explicit TinyVectorIterConst(const TinyVector<T_numtype, N_length>& x)
|
---|
| 119 | : data_(x.data())
|
---|
| 120 | { }
|
---|
| 121 |
|
---|
| 122 | #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
|
---|
| 123 | TinyVectorIterConst(const TinyVectorIterConst<T_numtype, N_length,
|
---|
| 124 | N_stride>& iter)
|
---|
| 125 | : data_(iter.data_)
|
---|
| 126 | {
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | void operator=(const TinyVectorIterConst<T_numtype, N_length, N_stride>&
|
---|
| 130 | iter)
|
---|
| 131 | {
|
---|
| 132 | data_ = iter.data_;
|
---|
| 133 | }
|
---|
| 134 | #endif
|
---|
| 135 |
|
---|
| 136 | T_numtype operator[](unsigned i) const
|
---|
| 137 | {
|
---|
| 138 | BZPRECONDITION(i < N_length);
|
---|
| 139 | return data_[i * N_stride];
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | T_numtype operator()(unsigned i) const
|
---|
| 143 | {
|
---|
| 144 | BZPRECONDITION(i < N_length);
|
---|
| 145 | return data_[i * N_stride];
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | unsigned length(unsigned) const
|
---|
| 149 | { return N_length; }
|
---|
| 150 |
|
---|
| 151 | enum { _bz_staticLengthCount = 1,
|
---|
| 152 | _bz_dynamicLengthCount = 0,
|
---|
| 153 | _bz_staticLength = 0 };
|
---|
| 154 |
|
---|
| 155 | _bz_bool _bz_hasFastAccess() const
|
---|
| 156 | { return _bz_true; }
|
---|
| 157 |
|
---|
| 158 | T_numtype _bz_fastAccess(unsigned i) const
|
---|
| 159 | { return data_[i * N_stride]; }
|
---|
| 160 |
|
---|
| 161 | unsigned _bz_suggestLength() const
|
---|
| 162 | { return N_length; }
|
---|
| 163 |
|
---|
| 164 | private:
|
---|
| 165 | const T_numtype * _bz_restrict data_;
|
---|
| 166 | };
|
---|
| 167 |
|
---|
| 168 | BZ_NAMESPACE_END
|
---|
| 169 |
|
---|
| 170 | #endif // BZ_TINYVECITER_H
|
---|