source: projectionDesigner/trunk/projdesigner/include/gmtl/VecOpsMeta.h @ 54

Last change on this file since 54 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 2.9 KB
Line 
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 */
42namespace gmtl
43{
44namespace meta
45{
46/** @ingroup VecOpsMeta */
47//@{
48
49/** meta class to unroll dot products. */
50template<int ELT, typename T1, typename T2>
51struct 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. */
58template<typename T1, typename T2>
59struct 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. */
66template<int ELT, typename T>
67struct 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. */
74template<typename T>
75struct 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. */
82template<int ELT, typename VT>
83struct 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. */
90template<typename VT>
91struct 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
Note: See TracBrowser for help on using the repository browser.