[4] | 1 | /************************************************************** ggt-head beg |
---|
| 2 | * |
---|
| 3 | * GGT: Generic Graphics Toolkit |
---|
| 4 | * |
---|
| 5 | * Original Authors: |
---|
| 6 | * Allen Bierbaum |
---|
| 7 | * |
---|
| 8 | * ----------------------------------------------------------------- |
---|
| 9 | * File: VecOpsMeta.h,v |
---|
| 10 | * Date modified: 2005/05/16 14:19:44 |
---|
| 11 | * Version: 1.3 |
---|
| 12 | * ----------------------------------------------------------------- |
---|
| 13 | * |
---|
| 14 | *********************************************************** ggt-head end */ |
---|
| 15 | /*************************************************************** ggt-cpr beg |
---|
| 16 | * |
---|
| 17 | * GGT: The Generic Graphics Toolkit |
---|
| 18 | * Copyright (C) 2001,2002 Allen Bierbaum |
---|
| 19 | * |
---|
| 20 | * This library is free software; you can redistribute it and/or |
---|
| 21 | * modify it under the terms of the GNU Lesser General Public |
---|
| 22 | * License as published by the Free Software Foundation; either |
---|
| 23 | * version 2.1 of the License, or (at your option) any later version. |
---|
| 24 | * |
---|
| 25 | * This library is distributed in the hope that it will be useful, |
---|
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 28 | * Lesser General Public License for more details. |
---|
| 29 | * |
---|
| 30 | * You should have received a copy of the GNU Lesser General Public |
---|
| 31 | * License along with this library; if not, write to the Free Software |
---|
| 32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 33 | * |
---|
| 34 | ************************************************************ ggt-cpr end */ |
---|
| 35 | #ifndef _GMTL_VEC_OPS_META_H |
---|
| 36 | #define _GMTL_VEC_OPS_META_H |
---|
| 37 | |
---|
| 38 | #include <gmtl/Util/Meta.h> |
---|
| 39 | |
---|
| 40 | /** Meta programming classes for vec operations |
---|
| 41 | */ |
---|
| 42 | namespace gmtl |
---|
| 43 | { |
---|
| 44 | namespace meta |
---|
| 45 | { |
---|
| 46 | /** @ingroup VecOpsMeta */ |
---|
| 47 | //@{ |
---|
| 48 | |
---|
| 49 | /** meta class to unroll dot products. */ |
---|
| 50 | template<int ELT, typename T1, typename T2> |
---|
| 51 | struct DotVecUnrolled |
---|
| 52 | { |
---|
| 53 | static typename T1::DataType func(const T1& v1, const T2& v2) |
---|
| 54 | { return (v1[ELT]*v2[ELT]) + DotVecUnrolled<ELT-1,T1,T2>::func(v1,v2); } |
---|
| 55 | }; |
---|
| 56 | |
---|
| 57 | /** base cas for dot product unrolling. */ |
---|
| 58 | template<typename T1, typename T2> |
---|
| 59 | struct DotVecUnrolled<0,T1,T2> |
---|
| 60 | { |
---|
| 61 | static typename T1::DataType func(const T1& v1, const T2& v2) |
---|
| 62 | { return (v1[0]*v2[0]); } |
---|
| 63 | }; |
---|
| 64 | |
---|
| 65 | /** meta class to unroll length squared operation. */ |
---|
| 66 | template<int ELT, typename T> |
---|
| 67 | struct LenSqrVecUnrolled |
---|
| 68 | { |
---|
| 69 | static typename T::DataType func(const T& v) |
---|
| 70 | { return (v[ELT]*v[ELT]) + LenSqrVecUnrolled<ELT-1,T>::func(v); } |
---|
| 71 | }; |
---|
| 72 | |
---|
| 73 | /** base cas for dot product unrolling. */ |
---|
| 74 | template<typename T> |
---|
| 75 | struct LenSqrVecUnrolled<0,T> |
---|
| 76 | { |
---|
| 77 | static typename T::DataType func(const T& v) |
---|
| 78 | { return (v[0]*v[0]); } |
---|
| 79 | }; |
---|
| 80 | |
---|
| 81 | /** meta class to test vector equality. */ |
---|
| 82 | template<int ELT, typename VT> |
---|
| 83 | struct EqualVecUnrolled |
---|
| 84 | { |
---|
| 85 | static bool func(const VT& v1, const VT& v2) |
---|
| 86 | { return (v1[ELT]==v2[ELT]) && EqualVecUnrolled<ELT-1,VT>::func(v1,v2); } |
---|
| 87 | }; |
---|
| 88 | |
---|
| 89 | /** base cas for dot product unrolling. */ |
---|
| 90 | template<typename VT> |
---|
| 91 | struct EqualVecUnrolled<0,VT> |
---|
| 92 | { |
---|
| 93 | static bool func(const VT& v1, const VT& v2) |
---|
| 94 | { return (v1[0]==v2[0]); } |
---|
| 95 | }; |
---|
| 96 | //@} |
---|
| 97 | |
---|
| 98 | } // namespace meta |
---|
| 99 | } // end namespace |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | #endif |
---|