[221] | 1 | /***************************************************************************
|
---|
| 2 | * blitz/vecwhere.h where(X,Y,Z) function for vectors
|
---|
| 3 | *
|
---|
| 4 | * $Id: vecwhere.h,v 1.1.1.1 1999-04-09 17:59:00 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.4 1998/03/14 00:04:47 tveldhui
|
---|
| 27 | * 0.2-alpha-05
|
---|
| 28 | *
|
---|
| 29 | * Revision 1.3 1997/07/16 14:51:20 tveldhui
|
---|
| 30 | * Update: Alpha release 0.2 (Arrays)
|
---|
| 31 | *
|
---|
| 32 | * Revision 1.2 1997/01/24 14:42:00 tveldhui
|
---|
| 33 | * Periodic RCS update
|
---|
| 34 | *
|
---|
| 35 | * Revision 1.1 1997/01/23 03:28:28 tveldhui
|
---|
| 36 | * Periodic RCS update
|
---|
| 37 | *
|
---|
| 38 | */
|
---|
| 39 |
|
---|
| 40 | #ifndef BZ_VECWHERE_H
|
---|
| 41 | #define BZ_VECWHERE_H
|
---|
| 42 |
|
---|
| 43 | #ifndef BZ_VECEXPR_H
|
---|
| 44 | #error <blitz/vecwhere.h> must be included via <blitz/vector.h>
|
---|
| 45 | #endif
|
---|
| 46 |
|
---|
| 47 | BZ_NAMESPACE(blitz)
|
---|
| 48 |
|
---|
| 49 | template<class P_expr1, class P_expr2, class P_expr3>
|
---|
| 50 | class _bz_VecWhere {
|
---|
| 51 |
|
---|
| 52 | public:
|
---|
| 53 | typedef P_expr1 T_expr1;
|
---|
| 54 | typedef P_expr2 T_expr2;
|
---|
| 55 | typedef P_expr3 T_expr3;
|
---|
| 56 | typedef _bz_typename T_expr2::T_numtype T_numtype2;
|
---|
| 57 | typedef _bz_typename T_expr3::T_numtype T_numtype3;
|
---|
| 58 | typedef BZ_PROMOTE(T_numtype2, T_numtype3) T_numtype;
|
---|
| 59 |
|
---|
| 60 | #ifdef BZ_PASS_EXPR_BY_VALUE
|
---|
| 61 | _bz_VecWhere(T_expr1 a, T_expr2 b, T_expr3 c)
|
---|
| 62 | : iter1_(a), iter2_(b), iter3_(c)
|
---|
| 63 | { }
|
---|
| 64 | #else
|
---|
| 65 | _bz_VecWhere(const T_expr1& a, const T_expr2& b, const T_expr3& c)
|
---|
| 66 | : iter1_(a), iter2_(b), iter3_(c)
|
---|
| 67 | { }
|
---|
| 68 | #endif
|
---|
| 69 |
|
---|
| 70 | #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
|
---|
| 71 | _bz_VecWhere(const _bz_VecWhere<T_expr1, T_expr2, T_expr3>& x)
|
---|
| 72 | : iter1_(x.iter1_), iter2_(x.iter2_), iter3_(x.iter3_)
|
---|
| 73 | { }
|
---|
| 74 | #endif
|
---|
| 75 |
|
---|
| 76 | T_numtype operator[](int i) const
|
---|
| 77 | {
|
---|
| 78 | return iter1_[i] ? iter2_[i] : iter3_[i];
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | enum {
|
---|
| 82 | _bz_staticLengthCount =
|
---|
| 83 | P_expr1::_bz_staticLengthCount + P_expr2::_bz_staticLengthCount
|
---|
| 84 | + P_expr3::_bz_staticLengthCount,
|
---|
| 85 |
|
---|
| 86 | _bz_dynamicLengthCount =
|
---|
| 87 | P_expr1::_bz_dynamicLengthCount + P_expr2::_bz_dynamicLengthCount
|
---|
| 88 | + P_expr3::_bz_dynamicLengthCount,
|
---|
| 89 |
|
---|
| 90 | _bz_staticLength =
|
---|
| 91 | _bz_meta_max<_bz_meta_max<P_expr1::_bz_staticLength,
|
---|
| 92 | P_expr2::_bz_staticLength>::max, P_expr3::_bz_staticLength>::max
|
---|
| 93 | };
|
---|
| 94 |
|
---|
| 95 | T_numtype _bz_fastAccess(int i) const
|
---|
| 96 | {
|
---|
| 97 | return iter1_._bz_fastAccess(i)
|
---|
| 98 | ? iter2_._bz_fastAccess(i)
|
---|
| 99 | : iter3_._bz_fastAccess(i);
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | _bz_bool _bz_hasFastAccess() const
|
---|
| 103 | {
|
---|
| 104 | return iter1_._bz_hasFastAccess() &&
|
---|
| 105 | iter2_._bz_hasFastAccess() &&
|
---|
| 106 | iter3_._bz_hasFastAccess();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | int length(int recommendedLength) const
|
---|
| 110 | {
|
---|
| 111 | return iter1_.length(recommendedLength);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | int _bz_suggestLength() const
|
---|
| 115 | {
|
---|
| 116 | BZPRECONDITION(
|
---|
| 117 | (iter1_._bz_suggestLength() == iter2_._bz_suggestLength())
|
---|
| 118 | && (iter2_._bz_suggestLength() == iter3_._bz_suggestLength()));
|
---|
| 119 |
|
---|
| 120 | return iter1_._bz_suggestLength();
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | private:
|
---|
| 124 | _bz_VecWhere() { }
|
---|
| 125 |
|
---|
| 126 | T_expr1 iter1_;
|
---|
| 127 | T_expr2 iter2_;
|
---|
| 128 | T_expr3 iter3_;
|
---|
| 129 | };
|
---|
| 130 |
|
---|
| 131 | BZ_NAMESPACE_END
|
---|
| 132 |
|
---|
| 133 | #include <blitz/vecwhere.cc> // Expression templates
|
---|
| 134 |
|
---|
| 135 | #endif // BZ_VECWHERE_H
|
---|
| 136 |
|
---|