summaryrefslogtreecommitdiffstats
path: root/src/input/detail/systemTraits.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/input/detail/systemTraits.h')
-rw-r--r--src/input/detail/systemTraits.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/input/detail/systemTraits.h b/src/input/detail/systemTraits.h
new file mode 100644
index 0000000..7f5582f
--- /dev/null
+++ b/src/input/detail/systemTraits.h
@@ -0,0 +1,94 @@
+/*
+ # 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/systemTraits.h:
+ # - Define system traits and provide a way to match against them
+ # --------------------------------------------------------------------------
+ */
+
+#ifndef SYSTEMTRAITS_H_
+#define SYSTEMTRAITS_H_
+
+#include "typeList.h"
+
+#define DEFINE_SYSTEM_TRAIT(name) struct name;
+#define BEGIN_SYSTEM_TRAITS typedef TypeList<
+#define END_SYSTEM_TRAITS > SystemTraits;
+
+namespace input_policy
+{
+
+// Trait names are externally visible.
+DEFINE_SYSTEM_TRAIT(UnixLike)
+DEFINE_SYSTEM_TRAIT(LinuxSystem)
+DEFINE_SYSTEM_TRAIT(X11GUI)
+DEFINE_SYSTEM_TRAIT(ConsoleKitSupported)
+
+namespace detail
+{
+BEGIN_SYSTEM_TRAITS
+#ifdef __linux
+UnixLike,
+LinuxSystem,
+X11GUI,
+ConsoleKitSupported
+#endif
+END_SYSTEM_TRAITS
+}
+
+/////////////////////////////////////////////////////////////////////////
+// Boolean logic as applied to system traits
+/////////////////////////////////////////////////////////////////////////
+template<IMPLICIT_TYPE_LIST_PARAMS(T)>
+struct AllOf;
+
+template<IMPLICIT_TYPE_LIST_PARAMS(T)>
+struct AnyOf;
+
+namespace detail
+{
+/////////////////////////////////////////////////////////////////////////
+// Does the list of system traits match what we have given?
+/////////////////////////////////////////////////////////////////////////
+template<typename Needles, typename Haystack>
+struct Matches
+{
+ // if Needles is neither AnyOf<...> nor AllOf<...>
+ // then we need to know if the Haystack contains it:
+ static const bool value = Contains<Needles, Haystack>::value;
+};
+
+template<typename Haystack>
+struct MatchesPredicate
+{
+ template<typename Needle>
+ struct apply
+ {
+ static const bool value = Matches<Needle, Haystack>::value;
+ };
+};
+
+template<IMPLICIT_TYPE_LIST_PARAMS_NODEFAULT(T), typename Haystack>
+struct Matches<AnyOf<IMPLICIT_TYPE_LIST_ARGS(T)>, Haystack>
+{
+ static const bool value = ForAnyInTypeList<MatchesPredicate<Haystack>, IMPLICIT_TYPE_LIST(T)>::value;
+};
+
+template<IMPLICIT_TYPE_LIST_PARAMS_NODEFAULT(T), typename Haystack>
+struct Matches<AllOf<IMPLICIT_TYPE_LIST_ARGS(T)>, Haystack>
+{
+ static const bool value = ForAllInTypeList<MatchesPredicate<Haystack>, IMPLICIT_TYPE_LIST(T)>::value;
+};
+}
+
+}
+
+#endif /* SYSTEMTRAITS_H_ */