Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JEnumeration.hh
Go to the documentation of this file.
1#ifndef __JLANG__JENUMERATION__
2#define __JLANG__JENUMERATION__
3
4#include <ostream>
5
6#include "JLang/JAssert.hh"
7#include "JLang/JType.hh"
8#include "JLang/JTypeID.hh"
9#include "JLang/JTypeList.hh"
10
11
12/**
13 * \author mdejong
14 */
15
16namespace JLANG {}
17namespace JPP { using namespace JLANG; }
18
19namespace JLANG {
20
21 /**
22 * Test presence of data type identifier in labelled type list.
23 */
24 template<class T, int ID>
25 struct JHasID
26 {
27 static const bool value = (JTypeID<T>::ID == ID);
28 };
29
30
31 /**
32 * Recursive test of presence data type identifier in labelled type list.
33 */
34 template<class JHead_t, class JTail_t, int ID>
35 struct JHasID<JTypeList<JHead_t, JTail_t>, ID>
36 {
37 static const bool value = (JHasID<JHead_t, ID>::value ||
39 };
40
41
42 /**
43 * Enumeration of single data type.
44 */
45 template<class T>
47 {
48 /**
49 * Get label of given data type.
50 *
51 * \param type data type
52 * \return label
53 */
54 static inline JLabel_t getLabel(const JType<T>& type)
55 {
59 }
60
61
62 /**
63 * Get label of given object.
64 *
65 * \param object object
66 * \return label
67 */
68 static inline JLabel_t getLabel(const T& object)
69 {
70 return getLabel(JType<T>());
71 }
72
73
74 /**
75 * Print enumeration.
76 *
77 * \param out output stream
78 * \return output stream
79 */
80 static std::ostream& print(std::ostream& out)
81 {
82 out << getLabel(JType<T>()) << std::endl;
83
84 return out;
85 }
86 };
87
88
89 /**
90 * Enumeration of multiple data types.
91 *
92 * The uniqueness of each data type and identifier in the type list is verified;
93 * failure causes a compiler error.
94 */
95 template<class JHead_t, class JTail_t>
96 struct JEnumeration< JTypeList<JHead_t, JTail_t> > :
97 public JEnumeration<JHead_t>,
98 public JEnumeration<JTail_t>,
99 public virtual JAssert<!JHasType<JTail_t, JHead_t> ::value &&
100 !JHasID <JTail_t, JTypeID<JHead_t>::ID>::value>
101 {
102 using JEnumeration<JHead_t>::getLabel;
103 using JEnumeration<JTail_t>::getLabel;
104
105
106 /**
107 * Print enumeration.
108 *
109 * \param out output stream
110 * \return output stream
111 */
112 static std::ostream& print(std::ostream& out)
113 {
116
117 return out;
118 }
119 };
120
121
122 /**
123 * Terminator class of recursive JEnumeration class.
124 */
125 template<class JHead_t>
126 struct JEnumeration< JTypeList<JHead_t, JNullType> > :
127 public JEnumeration<JHead_t>
128 {};
129}
130
131#endif
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Generation of compiler error.
Definition JAssert.hh:17
static std::ostream & print(std::ostream &out)
Print enumeration.
Enumeration of single data type.
static JLabel_t getLabel(const T &object)
Get label of given object.
static std::ostream & print(std::ostream &out)
Print enumeration.
static JLabel_t getLabel(const JType< T > &type)
Get label of given data type.
Test presence of data type identifier in labelled type list.
static const bool value
Auxiliary data structure to label data types within a type list.
Definition JTypeID.hh:22
Auxiliary class for no type definition.
Definition JNullType.hh:19
Type list.
Definition JTypeList.hh:23
Auxiliary class for a type holder.
Definition JType.hh:19
Template definition of policy class to label data types in a type list.
Definition JTypeID.hh:194