summaryrefslogtreecommitdiffstats
path: root/src/input/detail/gen/gen_typeList.cpp
blob: 21056f9dbceea3978737ca15f2444c618903e075 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
 #
 # This program is free software distributed under the GPL version 2.
 # See http://openslx.org/COPYING
 #
 # If you have any feedback please consult http://openslx.org/feedback and
 # send your suggestions, praise, or complaints to feedback@openslx.org
 #
 # General information about OpenSLX can be found at http://openslx.org/
 # --------------------------------------------------------------------------
 # detail/gen/gen_policyChain.cpp:
 #  - generate the input_policy::detail::TypeList class
 # --------------------------------------------------------------------------
 */

#include <iostream>

using namespace std;

#define NUM_MAX_ENTRIES 16

int main(int, char**)
{
	int i;

	cout << "template<";
	for(i = 0; i < NUM_MAX_ENTRIES; i++)
	{
		if(i)
			cout << ", ";
		cout << "typename T" << i << " = void";
	}
	cout << ">\nstruct TypeList {\n";
	cout << "typedef T0 head;\n";
	cout << "typedef TypeList<";
	for(i = 1; i < NUM_MAX_ENTRIES; i++)
	{
		if(i > 1)
			cout << ", ";
		cout << "T" << i;
	}
	cout << ", void > tail;\n";
	cout << "};\n";

	// Contains:
	cout << "template<typename Needle, typename Haystack>\n"
			"struct Contains { static const int index = -1; static const bool value = false; };\n";

	//   specializations:
	cout << "#ifndef DOXYGEN_RUNNING\n";
	for(i = 0; i < NUM_MAX_ENTRIES; i++)
	{
		int j;

		cout << "template<typename Needle";
		for(j = 0; j < NUM_MAX_ENTRIES; j++)
		{
			if(j == i)
				continue;
			cout << ", typename T" << j;
		}
		cout << ">\nstruct Contains<Needle, TypeList<";
		for(j = 0; j < NUM_MAX_ENTRIES; j++)
		{
			if(j)
				cout << ", ";
			if(j == i)
				cout << "Needle";
			else
				cout << "T" << j;
		}
		cout << "> >\n{ static const int index = " << i << "; static const bool value = true; };\n";
	}
	cout << "#endif\n";

	// Empty List:
	cout << "typedef TypeList<";
	for(i = 0; i < NUM_MAX_ENTRIES; i++)
	{
		if(i)
			cout << ", ";
		cout << "void";
	}
	cout << " > EmptyList;\n";

	// Macros:
	cout << "#define IMPLICIT_TYPE_LIST_PARAMS(prefix) ";
	for(i = 0; i < NUM_MAX_ENTRIES; i++)
	{
		if(i)
			cout << ", ";
		cout << "typename prefix##" << i << " = void";
	}
	cout << "\n";

	cout << "#define IMPLICIT_TYPE_LIST_PARAMS_NODEFAULT(prefix) ";
	for(i = 0; i < NUM_MAX_ENTRIES; i++)
	{
		if(i)
			cout << ", ";
		cout << "typename prefix##" << i;
	}
	cout << "\n";

	cout << "#define IMPLICIT_TYPE_LIST_ARGS(prefix) ";
	for(i = 0; i < NUM_MAX_ENTRIES; i++)
	{
		if(i)
			cout << ", ";
		cout << "prefix##" << i;
	}
	cout << "\n";

	cout << "#define IMPLICIT_TYPE_LIST(prefix) ::input_policy::detail::TypeList<IMPLICIT_TYPE_LIST_ARGS(prefix) >\n";

	return 0;
}