Jpp
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 
16 namespace JLANG {}
17 namespace JPP { using namespace JLANG; }
18 
19 namespace 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>
46  struct JEnumeration
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  {
56  return JLabel_t(JTypeID<T>::ID,
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  {
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
JLANG::JType
Auxiliary class for a type holder.
Definition: JType.hh:19
JTypeID
Template definition of policy class to label data types in a type list.
Definition: JTypeID.hh:194
JLANG::JNullType
Auxiliary class for no type definition.
Definition: JNullType.hh:19
JLANG::JEnumeration< JTypeList< JHead_t, JTail_t > >::print
static std::ostream & print(std::ostream &out)
Print enumeration.
Definition: JEnumeration.hh:112
JLANG::JEnumeration::getLabel
static JLabel_t getLabel(const T &object)
Get label of given object.
Definition: JEnumeration.hh:68
JTypeID.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLANG::JHasID::value
static const bool value
Definition: JEnumeration.hh:27
JLANG::JEnumeration::print
static std::ostream & print(std::ostream &out)
Print enumeration.
Definition: JEnumeration.hh:80
JLANG::JEnumeration::getLabel
static JLabel_t getLabel(const JType< T > &type)
Get label of given data type.
Definition: JEnumeration.hh:54
JLANG::JTypeList
Type list.
Definition: JTypeList.hh:22
ID
Definition: raw_data_converter.cpp:43
JTypeList.hh
JLANG::JLabel_t
Auxiliary data structure to label data types within a type list.
Definition: JTypeID.hh:22
JLANG
Auxiliary classes and methods for language specific functionality.
Definition: JAbstractClass.hh:10
JLANG::JHasID
Test presence of data type identifier in labelled type list.
Definition: JEnumeration.hh:25
JType.hh
JLANG::JEnumeration
Enumeration of single data type.
Definition: JEnumeration.hh:46
JAssert.hh
JLANG::JAssert
Generation of compiler error.
Definition: JAssert.hh:17