Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
metaprogramming_util.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3 * Author: Andreas Vogel
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__COMMON__METAPROGRAMMING_UTIL__
34#define __H__COMMON__METAPROGRAMMING_UTIL__
35
36namespace ug {
37
40
41template <int N>
42struct Int2Type {
43 enum{ value = N};
44 typedef int value_type;
45};
46
47template <class T>
49
50template <class T>
51struct Pointer2Value<T*>{
52 typedef T type;
53};
54
56// TypeList
58
59// empty type
60struct EmptyType {};
61
62// TypeList
63template
64<
65 typename T1=EmptyType,
66 typename T2=EmptyType,
67 typename T3=EmptyType,
68 typename T4=EmptyType,
69 typename T5=EmptyType,
70 typename T6=EmptyType,
71 typename T7=EmptyType,
72 typename T8=EmptyType,
73 typename T9=EmptyType,
74 typename T10=EmptyType,
75 typename T11=EmptyType,
76 typename T12=EmptyType
77> struct TypeList;
78
79// implementation of TypeList
80template
81<
82 typename T1,
83 typename T2,
84 typename T3,
85 typename T4,
86 typename T5,
87 typename T6,
88 typename T7,
89 typename T8,
90 typename T9,
91 typename T10,
92 typename T11,
93 typename T12
94>
96{
97 typedef T1 head;
99 enum{length = tail::length+1};
100};
101
102// empty typelist specialization
103template<>
110
112// TypeValueList
114
115// TypeList
116template <typename TTypeList> struct TypeValueList
117{
118 typedef typename TTypeList::head head;
119 typedef typename TTypeList::tail tail;
120
123
124 explicit TypeValueList() {
125 std::cerr << "incomplete TVL\n";
126 }
127
129 TypeValueList<tail> typValList) :
130 hd(_hd), tl(typValList) {}
131
132};
133
134template <>
135struct TypeValueList< TypeList<> > {};
136
137
139// Factorial
141
145template <size_t n>
147{
148 enum{value = n*Factorial<n-1>::value};
149};
150
151template <>
152struct Factorial<1>
153{
154 enum {value = 1};
155};
156
158// Pow
160
163template <int n, size_t d>
164struct Pow
165{
166 enum{value = n*Pow<n, d-1>::value};
167};
168
169template <int n>
170struct Pow<n, 0>
171{
172 enum {value = 1};
173};
174
176// BinomialCoefficient
178
186template <size_t n, int k>
192
193// end rekursion
194template <size_t n>
196{
197 enum { value = 1};
198};
199// end rekursion
200template <size_t n>
202{
203 enum { value = 0};
204};
205// end rekursion
206template <size_t n>
208{
209 enum { value = 0};
210};
211// end rekursion
212template <size_t n>
214{
215 enum { value = 0};
216};
217// end rekursion
218template <size_t n>
220{
221 enum { value = 0};
222};
223
225// UniqueTypeID (sreiter)
229 public:
231 static UniqueTypeIDProvider utid;
232 return utid;
233 }
234
235 size_t new_id() {return ++m_id;}
236
237 private:
239 size_t m_id;
240};
241
243template <class TType>
245{
246 static size_t typeID = UniqueTypeIDProvider::inst().new_id();
247 return typeID;
248}
249
250// end group ugbase_common_util
252
253}
254
255#endif /* __H__COMMON__METAPROGRAMMING_UTIL__ */
a singleton class that returns a new id for each type
Definition metaprogramming_util.h:228
UniqueTypeIDProvider()
Definition metaprogramming_util.h:238
static UniqueTypeIDProvider & inst()
Definition metaprogramming_util.h:230
size_t new_id()
Definition metaprogramming_util.h:235
size_t m_id
Definition metaprogramming_util.h:239
size_t GetUniqueTypeID()
This method associated a unique unsigned integer value with each type.
Definition metaprogramming_util.h:244
the ug namespace
Definition metaprogramming_util.h:188
@ value
Definition metaprogramming_util.h:189
Definition metaprogramming_util.h:60
Definition metaprogramming_util.h:147
@ value
Definition metaprogramming_util.h:148
Definition metaprogramming_util.h:42
@ value
Definition metaprogramming_util.h:43
int value_type
Definition metaprogramming_util.h:44
T type
Definition metaprogramming_util.h:52
Definition metaprogramming_util.h:48
Definition metaprogramming_util.h:165
@ value
Definition metaprogramming_util.h:166
Definition metaprogramming_util.h:96
TypeList< T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 > tail
Definition metaprogramming_util.h:98
T1 head
Definition metaprogramming_util.h:97
@ length
Definition metaprogramming_util.h:99
Definition metaprogramming_util.h:117
TypeValueList< tail > tl
Definition metaprogramming_util.h:122
TTypeList::head head
Definition metaprogramming_util.h:118
TypeValueList(head _hd, TypeValueList< tail > typValList)
Definition metaprogramming_util.h:128
TTypeList::tail tail
Definition metaprogramming_util.h:119
head hd
Definition metaprogramming_util.h:121
TypeValueList()
Definition metaprogramming_util.h:124