source: projectionDesigner/trunk/projdesigner/include/gmtl/Util/Meta.h @ 380

Last change on this file since 380 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 3.5 KB
Line 
1/************************************************************** ggt-head beg
2 *
3 * GGT: Generic Graphics Toolkit
4 *
5 * Original Authors:
6 *   Allen Bierbaum
7 *
8 * -----------------------------------------------------------------
9 * File:          Meta.h,v
10 * Date modified: 2004/10/30 18:24:34
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_METAPROGRAMMING_H
36#define _GMTL_METAPROGRAMMING_H
37
38#include <gmtl/Defines.h>
39
40/*** STRINGIZE and JOIN macros */
41/* Taken from boost (see boost.org) */
42
43//
44// Helper macro GMTL_STRINGIZE:
45// Converts the parameter X to a string after macro replacement
46// on X has been performed.
47//
48#define GMTL_STRINGIZE(X) GMTL_DO_STRINGIZE(X)
49#define GMTL_DO_STRINGIZE(X) #X
50
51//
52// Helper macro GMTL_JOIN:
53// The following piece of macro magic joins the two
54// arguments together, even when one of the arguments is
55// itself a macro (see 16.3.1 in C++ standard).  The key
56// is that macro expansion of macro arguments does not
57// occur in BOOST_DO_JOIN2 but does in BOOST_DO_JOIN.
58//
59#define GMTL_JOIN( X, Y ) GMTL_DO_JOIN( X, Y )
60#define GMTL_DO_JOIN( X, Y ) GMTL_DO_JOIN2(X,Y)
61#define GMTL_DO_JOIN2( X, Y ) X##Y
62
63
64/** Meta programming classes */
65namespace gmtl
66{
67   /** @ingroup Meta */
68   //@{
69
70   /** A lightweight identifier you can pass to overloaded functions
71    *  to typefy them.
72    *
73    *  Type2Type lets you transport the type information about T to functions
74    */
75   template <typename T>
76   struct Type2Type
77   {
78      typedef T OriginalType;
79   };
80
81   //@}
82
83   /** @ingroup HelperMeta */
84   //@{
85   template <class T> inline void ignore_unused_variable_warning(const T&) { }
86
87   //@}
88
89} // end namespace
90
91#ifndef GMTL_NO_METAPROG
92namespace gmtl
93{
94namespace meta
95{
96
97// ------ LOOP UnRolling ------------ //
98template<int ELT, typename T>
99struct AssignVecUnrolled
100{
101   static void func(T& lVec, const T& rVec)
102   {
103      AssignVecUnrolled<ELT-1,T>::func(lVec, rVec);
104      lVec[ELT] = rVec[ELT];
105   }
106};
107
108template<typename T>
109struct AssignVecUnrolled<0,T>
110{
111   static void func(T& lVec, const T& rVec)
112   { lVec[0] = rVec[0]; }
113};
114
115// Template programs for array assignment unrolled
116template<int ELT, typename T>
117struct AssignArrayUnrolled
118{
119   static void func(T* lVec, const T* rVec)
120   {
121      AssignArrayUnrolled<ELT-1,T>::func(lVec, rVec);
122      lVec[ELT] = rVec[ELT];
123   }
124};
125
126template<typename T>
127struct AssignArrayUnrolled<0,T>
128{
129   static void func(T* lVec, const T* rVec)
130   { lVec[0] = rVec[0]; }
131};
132
133}  // namespace meta
134}  // namespace gmtl
135#endif /* ! GMTL_NO_METAPROG */
136
137#endif
Note: See TracBrowser for help on using the repository browser.