1 | // -*- C++ -*- |
---|
2 | /*************************************************************************** |
---|
3 | * blitz/vecwhere.h where(X,Y,Z) function for vectors |
---|
4 | * |
---|
5 | * $Id: vecwhere.h,v 1.5 2005/05/07 04:17:56 julianc Exp $ |
---|
6 | * |
---|
7 | * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org> |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * Suggestions: blitz-dev@oonumerics.org |
---|
20 | * Bugs: blitz-bugs@oonumerics.org |
---|
21 | * |
---|
22 | * For more information, please see the Blitz++ Home Page: |
---|
23 | * http://oonumerics.org/blitz/ |
---|
24 | * |
---|
25 | ****************************************************************************/ |
---|
26 | |
---|
27 | #ifndef BZ_VECWHERE_H |
---|
28 | #define BZ_VECWHERE_H |
---|
29 | |
---|
30 | #ifndef BZ_VECEXPR_H |
---|
31 | #error <blitz/vecwhere.h> must be included via <blitz/vector.h> |
---|
32 | #endif |
---|
33 | |
---|
34 | BZ_NAMESPACE(blitz) |
---|
35 | |
---|
36 | template<typename P_expr1, typename P_expr2, typename P_expr3> |
---|
37 | class _bz_VecWhere { |
---|
38 | |
---|
39 | public: |
---|
40 | typedef P_expr1 T_expr1; |
---|
41 | typedef P_expr2 T_expr2; |
---|
42 | typedef P_expr3 T_expr3; |
---|
43 | typedef _bz_typename T_expr2::T_numtype T_numtype2; |
---|
44 | typedef _bz_typename T_expr3::T_numtype T_numtype3; |
---|
45 | typedef BZ_PROMOTE(T_numtype2, T_numtype3) T_numtype; |
---|
46 | |
---|
47 | #ifdef BZ_PASS_EXPR_BY_VALUE |
---|
48 | _bz_VecWhere(T_expr1 a, T_expr2 b, T_expr3 c) |
---|
49 | : iter1_(a), iter2_(b), iter3_(c) |
---|
50 | { } |
---|
51 | #else |
---|
52 | _bz_VecWhere(const T_expr1& a, const T_expr2& b, const T_expr3& c) |
---|
53 | : iter1_(a), iter2_(b), iter3_(c) |
---|
54 | { } |
---|
55 | #endif |
---|
56 | |
---|
57 | #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR |
---|
58 | _bz_VecWhere(const _bz_VecWhere<T_expr1, T_expr2, T_expr3>& x) |
---|
59 | : iter1_(x.iter1_), iter2_(x.iter2_), iter3_(x.iter3_) |
---|
60 | { } |
---|
61 | #endif |
---|
62 | |
---|
63 | T_numtype operator[](int i) const |
---|
64 | { |
---|
65 | return iter1_[i] ? iter2_[i] : iter3_[i]; |
---|
66 | } |
---|
67 | |
---|
68 | static const int |
---|
69 | _bz_staticLengthCount = P_expr1::_bz_staticLengthCount |
---|
70 | + P_expr2::_bz_staticLengthCount |
---|
71 | + P_expr3::_bz_staticLengthCount, |
---|
72 | _bz_dynamicLengthCount = P_expr1::_bz_dynamicLengthCount |
---|
73 | + P_expr2::_bz_dynamicLengthCount |
---|
74 | + P_expr3::_bz_dynamicLengthCount, |
---|
75 | _bz_staticLength = |
---|
76 | _bz_meta_max<_bz_meta_max<P_expr1::_bz_staticLength, |
---|
77 | P_expr2::_bz_staticLength>::max, P_expr3::_bz_staticLength>::max; |
---|
78 | |
---|
79 | T_numtype _bz_fastAccess(int i) const |
---|
80 | { |
---|
81 | return iter1_._bz_fastAccess(i) |
---|
82 | ? iter2_._bz_fastAccess(i) |
---|
83 | : iter3_._bz_fastAccess(i); |
---|
84 | } |
---|
85 | |
---|
86 | bool _bz_hasFastAccess() const |
---|
87 | { |
---|
88 | return iter1_._bz_hasFastAccess() && |
---|
89 | iter2_._bz_hasFastAccess() && |
---|
90 | iter3_._bz_hasFastAccess(); |
---|
91 | } |
---|
92 | |
---|
93 | int length(int recommendedLength) const |
---|
94 | { |
---|
95 | return iter1_.length(recommendedLength); |
---|
96 | } |
---|
97 | |
---|
98 | int _bz_suggestLength() const |
---|
99 | { |
---|
100 | BZPRECONDITION( |
---|
101 | (iter1_._bz_suggestLength() == iter2_._bz_suggestLength()) |
---|
102 | && (iter2_._bz_suggestLength() == iter3_._bz_suggestLength())); |
---|
103 | |
---|
104 | return iter1_._bz_suggestLength(); |
---|
105 | } |
---|
106 | |
---|
107 | private: |
---|
108 | _bz_VecWhere() { } |
---|
109 | |
---|
110 | T_expr1 iter1_; |
---|
111 | T_expr2 iter2_; |
---|
112 | T_expr3 iter3_; |
---|
113 | }; |
---|
114 | |
---|
115 | BZ_NAMESPACE_END |
---|
116 | |
---|
117 | #include <blitz/vecwhere.cc> // Expression templates |
---|
118 | |
---|
119 | #endif // BZ_VECWHERE_H |
---|
120 | |
---|