summaryrefslogtreecommitdiffstats
path: root/src/input/detail/policyChain.h
blob: efaf371e911fef15eac8f33e46c60afc90f6151b (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
/*
 # 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/policyChain.h:
 #  - Tie together the different bits of policy information a handler may
 #    give us
 # --------------------------------------------------------------------------
 */

#ifndef POLICYCHAIN_H_
#define POLICYCHAIN_H_

#include "typeList.h"

namespace input_policy
{
namespace detail
{

template<typename BaseCase, typename PolicyList>
struct PolicyChain : public PolicyList::head::template apply_<PolicyChain<BaseCase, typename PolicyList::tail> >
{
};

template<typename BaseCase>
struct PolicyChain<BaseCase, EmptyList> : public BaseCase
{
};

}
}

/////////////////////////////////////////////////////////////////////////
// Macros that enable specification of policies:
//  A policy is declared like this:
//  template< PARAM1, PARAM2, ... >
//  BEGIN_POLICY_CLASS(MyPolicy) {
//    static const int field1 = 2;
//    ...
//  } END_POLICY_CLASS(MyPolicy);
/////////////////////////////////////////////////////////////////////////
#define BEGIN_POLICY_CLASS(policyName) \
	struct policyName { \
	  template<typename NextPolicy> \
	  struct apply_ : public NextPolicy
#define END_POLICY_CLASS \
	; };

/////////////////////////////////////////////////////////////////////////
// A macro that enables us to use a template parameter list
// in a class using a policy, like this:
//
//	template<POLICY_PARAMS>
//	struct MyPolicyBasedClass
//	{
//    typedef USE_POLICY(baseCase) policy_type;
//	};
//
// now, the following type is valid:
//  MyPolicyBasedClass<Policy1, Policy2>
/////////////////////////////////////////////////////////////////////////
#define POLICY_PARAMS IMPLICIT_TYPE_LIST_PARAMS(Policy)
#define POLICY_PARAMS_LIST IMPLICIT_TYPE_LIST(Policy)
#define USE_POLICY(baseCase) ::input_policy::detail::PolicyChain<baseCase, POLICY_PARAMS_LIST>

#endif /* POLICYCHAIN_H_ */