Jpp  18.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTypeID.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JTYPEID__
2 #define __JLANG__JTYPEID__
3 
4 #include <ostream>
5 
6 #include "JLang/JNullType.hh"
7 #include "JLang/JTest.hh"
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JLANG {}
15 namespace JPP { using namespace JLANG; }
16 
17 namespace JLANG {
18 
19  /**
20  * Auxiliary data structure to label data types within a type list.
21  */
22  struct JLabel_t {
23  /**
24  * Constructor.
25  *
26  * \param ID identifier
27  * \param name name
28  * \param version version
29  */
30  JLabel_t(const int ID,
31  const char* name,
32  const int version) :
33  __ID (ID),
34  __name (name),
35  __version(version)
36  {}
37 
38 
39  /**
40  * Get data type identifier.
41  *
42  * \return identifier
43  */
44  inline int getID() const
45  {
46  return __ID;
47  }
48 
49 
50  /**
51  * Get name of data type.
52  *
53  * \return name
54  */
55  inline const char* getName() const
56  {
57  return __name;
58  }
59 
60 
61  /**
62  * Get version of data type.
63  *
64  * \return version
65  */
66  inline int getVersion() const
67  {
68  return __version;
69  }
70 
71 
72  /**
73  * Write label to output.
74  *
75  * \param out output stream
76  * \param object label
77  * \return output stream
78  */
79  friend inline std::ostream& operator<<(std::ostream& out, const JLabel_t& object)
80  {
81  return out << object.getID() << '/'
82  << object.getName() << ':'
83  << object.getVersion();
84  }
85 
86  protected:
87  int __ID;
88  const char* __name;
89  int __version;
90  };
91 
92 
93  /**
94  * Get default name of data type.
95  *
96  * \return name
97  */
98  inline const char* getDefaultName()
99  {
100  return "?";
101  }
102 
103 
104  /**
105  * Get default version of data type.
106  *
107  * \return version
108  */
109  inline int getDefaultVersion()
110  {
111  return -1;
112  }
113 
114 
115  /**
116  * Test availability of static member methods for labelling data types in a type list.
117  */
118  template <class T>
119  class JTypeID_t :
120  public JTest
121  {
122  template<class U> static JTrue test1(JTypecheck<const char* (*)(), &U::getName>*);
123  template<class U> static JFalse test1(...);
124 
125  template<class U> static JTrue test2(JTypecheck<int (*)(), &U::getVersion>*);
126  template<class U> static JFalse test2(...);
127 
128  public:
129  static const bool has_name = sizeof(test1<T>(NULL)) == sizeof(JTrue);
130  static const bool has_version = sizeof(test2<T>(NULL)) == sizeof(JTrue);
131  };
132 }
133 
134 
135 /**
136  * Auxiliary data structure to label data types within a type list.
137  */
138 template<int __ID,
139  const char* (*__getName) () = JLANG::getDefaultName,
140  int (*__getVersion)() = JLANG::getDefaultVersion>
141 struct JLabel {
142 
143  /**
144  * Data type identifier.
145  */
146  static const int ID = __ID;
147 
148 
149  /**
150  * Get name of data type.
151  *
152  * \return name
153  */
154  static inline const char* getName()
155  {
156  return (*__getName)();
157  }
158 
159 
160  /**
161  * Get version of data type.
162  *
163  * \return version
164  */
165  static inline int getVersion()
166  {
167  return (*__getVersion)();
168  }
169 };
170 
171 
172 /**
173  * Template definition of policy class to label data types in a type list.
174  *
175  * A default implementation of this class is provided for data types which already have a unique identifier.
176  * This identifier should be implemented as follows:
177  * <pre>
178  * static const int ID = <value>;
179  * </pre>
180  *
181  * The optional name and/or a version is then maintained, provided their implementations
182  * follow the corresponding declarations in JLANG::JTypeID_t, i.e:
183  * <pre>
184  * static const char* getName();
185  * static int getVersion();
186  * </pre>
187  *
188  * A specialisation of this class should otherwise be provided, e.g.\ by deriving it from class JLabel.
189  * The specialisation should provide the static data member <tt>ID</tt> and the static member methods listed above.
190  */
191 template<class T,
194 struct JTypeID {};
195 
196 
197 /**
198  * Template specialisation of class without name and version.
199  */
200 template<class T>
201 struct JTypeID<T, false, false> :
202  public JLabel<T::ID>
203 {};
204 
205 
206 /**
207  * Template specialisation of class with name and without version.
208  */
209 template<class T>
210 struct JTypeID<T, true, false> :
211  public JLabel<T::ID, &T::getName>
212 {};
213 
214 
215 /**
216  * Template specialisation of class without name and with version.
217  */
218 template<class T>
219 struct JTypeID<T, false, true> :
220  public JLabel<T::ID, &JLANG::getDefaultName, &T::getVersion>
221 {};
222 
223 
224 /**
225  * Template specialisation of class with name and version.
226  */
227 template<class T>
228 struct JTypeID<T, true, true> :
229  public JLabel<T::ID, &T::getName, &T::getVersion>
230 {};
231 
232 
233 /**
234  * Template specialisation of class JTypeID for class JLANG::JNullType.
235  */
236 template<>
237 struct JTypeID<JLANG::JNullType> :
238  public JLabel<0>
239 {};
240 
241 #endif
static int getVersion()
Get version of data type.
Definition: JTypeID.hh:165
static JTrue test1(JTypecheck< const char *(*)(),&U::getName > *)
Test availability of static member methods for labelling data types in a type list.
Definition: JTypeID.hh:119
version
Definition: JEditTuneHV.sh:5
int getVersion(const std::string &version)
Get numerical value of AHRS calibration version.
Template definition of policy class to label data types in a type list.
Definition: JTypeID.hh:194
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
static const bool has_version
Definition: JTypeID.hh:130
static JTrue test2(JTypecheck< int(*)(),&U::getVersion > *)
const char * __name
Definition: JTypeID.hh:88
Auxiliary data structure to label data types within a type list.
Definition: JTypeID.hh:141
JLabel_t(const int ID, const char *name, const int version)
Constructor.
Definition: JTypeID.hh:30
Auxiliary base class for compile time evaluation of test.
Definition: JTest.hh:21
friend std::ostream & operator<<(std::ostream &out, const JLabel_t &object)
Write label to output.
Definition: JTypeID.hh:79
definition of true
Definition: JTest.hh:24
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Auxiliary class for no type definition.
Definition: JNullType.hh:19
static const char * getName()
Get name of data type.
Definition: JTypeID.hh:154
const char * getDefaultName()
Get default name of data type.
Definition: JTypeID.hh:98
Auxiliary data structure to label data types within a type list.
Definition: JTypeID.hh:22
int getDefaultVersion()
Get default version of data type.
Definition: JTypeID.hh:109
definition of false
Definition: JTest.hh:25
int getVersion() const
Get version of data type.
Definition: JTypeID.hh:66
const char * getName()
Get ROOT name of given data type.
Definition: JRootToolkit.hh:57
const char * getName() const
Get name of data type.
Definition: JTypeID.hh:55
int getID() const
Get data type identifier.
Definition: JTypeID.hh:44
Auxiliary class for type checking.
Definition: JTest.hh:36
static const bool has_name
Definition: JTypeID.hh:129