Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JEnumeration.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5
6#include "JLang/JTypeList.hh"
7#include "JLang/JTypeID.hh"
9#include "JROOT/JRootLabel.hh"
10
12
13#include "Jeep/JParser.hh"
14#include "Jeep/JMessage.hh"
15
16
17template<> struct JTypeID<int> : public JLabel<1> {};
18template<> struct JTypeID<long int> : public JLabel<1> {}; // will give compile error if also included in type list
19template<> struct JTypeID<std::string> : public JLabel<2> {};
20template<> struct JTypeID<double> : public JLabel<3> {};
21
22
23struct __A__; // user class without ID; requires specialisation of class JTypeID.
24
25template<> struct JTypeID<__A__> : public JLabel<4> {};
26
27
28struct __B__ { // user class with ID; does not require specialisation of class JTypeID.
29
30 static const int ID = 9;
31
32 static const char* getName() { return "__B__"; } // optional name
33 static int getVersion() { return 123; } // optional version
34};
35
36
37template<> // template specialisation for class with ROOT dictionary
39 public JROOT::JRootLabel<11, KM3NETDAQ::JDAQTimeslice>
40{};
41
42
43#define PRINT(OUT, ENUMERATION, CLASS) \
44 OUT << setw(10) << left << #CLASS << " --> " << ENUMERATION.getLabel(JLANG::JType<CLASS>()).getID() << endl;
45
46
47/**
48 * \file
49 *
50 * Example program to test JLANG::JEnumeration class.
51 * \author mdejong
52 */
53int main(int argc, char **argv)
54{
55 using namespace std;
56
57 int debug;
58
59 try {
60
61 JParser<> zap("Example program to test class enumeration.");
62
63 zap['d'] = make_field(debug) = 0;
64
65 zap(argc, argv);
66 }
67 catch(const exception &error) {
68 FATAL(error.what() << endl);
69 }
70
71
72 using namespace JPP;
73
74
75 typedef
76 JTypeList<int,
77 JTypeList<__A__,
78 JTypeList<__B__,
80 JTypeList<std::string,
81 JTypeList<double> > > > > > JTypelist_t;
82
83
84 const JEnumeration<JTypelist_t> enumeration;
85
86
87 enumeration.print(cout);
88
89 PRINT(cout, enumeration, int);
90 PRINT(cout, enumeration, __B__);
91}
int main(int argc, char **argv)
#define PRINT(OUT, ENUMERATION, CLASS)
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
Enumeration of single data type.
static std::ostream & print(std::ostream &out)
Print enumeration.
Type list.
Definition JTypeList.hh:23
Auxiliary data structure to label data types within a type list.
Definition JTypeID.hh:141
Replica of structure JLANG::JLabel for data types with ROOT I/O.
Definition JRootLabel.hh:20
Template definition of policy class to label data types in a type list.
Definition JTypeID.hh:194
static const char * getName()
static int getVersion()