Jpp  17.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
static JLabel_t getLabel(const T &object)
Get label of given object.
Definition: JEnumeration.hh:68
Template definition of policy class to label data types in a type list.
Definition: JTypeID.hh:194
Enumeration of single data type.
Definition: JEnumeration.hh:46
Auxiliary class for a type holder.
Definition: JType.hh:19
Generation of compiler error.
Definition: JAssert.hh:17
static JLabel_t getLabel(const JType< T > &type)
Get label of given data type.
Definition: JEnumeration.hh:54
Type list.
Definition: JTypeList.hh:22
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Auxiliary class for no type definition.
Definition: JNullType.hh:19
then echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR &dev null set_variable DETECTOR $JPP_DATA km3net_reference detx set_variable NUMBER_OF_STRINGS set_variable ID if do_usage *then usage $script[detector file[variant[identifier]]] fi case set_variable ID
Definition: JDetector.sh:24
Auxiliary data structure to label data types within a type list.
Definition: JTypeID.hh:22
static std::ostream & print(std::ostream &out)
Print enumeration.
Test presence of data type identifier in labelled type list.
Definition: JEnumeration.hh:25
static std::ostream & print(std::ostream &out)
Print enumeration.
Definition: JEnumeration.hh:80
static const bool value
Definition: JEnumeration.hh:27