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