Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JBaseClass.cc
Go to the documentation of this file.
1
2#include <iostream>
3#include <iomanip>
4
5#include "JLang/JBaseClass.hh"
6#include "JLang/JTypeList.hh"
7
8#include "Jeep/JParser.hh"
9#include "Jeep/JMessage.hh"
10
11
12namespace {
13
14 struct __A__ {
15 static char get() { return 'A'; }
16 };
17
18 struct __B__ : public __A__ {
19 static char get() { return 'B'; }
20 };
21
22 struct __C__ : public __A__ {
23 static char get() { return 'C'; }
24 };
25
26 struct __D__ : public __A__ {
27 static char get() { return 'D'; }
28 };
29}
30
31
32/**
33 * \file
34 *
35 * Example program to test JLANG::JBaseClass class.
36 * \author mdejong
37 */
38int main(int argc, char **argv)
39{
40 using namespace std;
41
42 int debug;
43
44 try {
45
46 JParser<> zap("Example program to test selection of base class.");
47
48 zap['d'] = make_field(debug) = 3;
49
50 zap(argc, argv);
51 }
52 catch(const exception &error) {
53 FATAL(error.what() << endl);
54 }
55
56 using namespace JPP;
57
58 typedef JTYPELIST<__A__,
59 __B__,
60 __C__,
61 __D__>::typelist typelistABCD;
62
63 typedef JTYPELIST<__B__,
64 __A__,
65 __C__,
66 __D__>::typelist typelistBACD;
67
68 typedef JTYPELIST<__B__,
69 __C__,
70 __A__,
71 __D__>::typelist typelistBCAD;
72
73 typedef JTYPELIST<__B__,
74 __C__,
75 __D__,
76 __A__>::typelist typelistBCDA;
77
78 DEBUG("A,B,C,D <- A? " << (JBaseType_t<__A__, typelistABCD>::is_base) << endl);
79 DEBUG("A,B,C,D <- B? " << (JBaseType_t<__B__, typelistABCD>::is_base) << endl);
80
81 DEBUG("A,B,C,D -> " << JBaseClass<typelistABCD>::data_type::get() << endl);
82 DEBUG("B,A,C,D -> " << JBaseClass<typelistBACD>::data_type::get() << endl);
83 DEBUG("B,C,A,D -> " << JBaseClass<typelistBCAD>::data_type::get() << endl);
84 DEBUG("B,C,D,A -> " << JBaseClass<typelistBCDA>::data_type::get() << endl);
85 DEBUG("B -> " << JBaseClass< JTypeList<__B__> >::data_type::get() << endl);
86
91 ASSERT(JBaseClass< JTypeList<__B__> >::data_type::get() == __B__::get());
92 /*
93 typedef JTYPELIST<__B__,
94 __C__,
95 __D__>::typelist typelist;
96
97 typedef JBaseClass<typelist>::data_type data_type; // will give compiler error (as should be)
98 */
99
100 return 0;
101}
int main(int argc, char **argv)
Definition JBaseClass.cc:38
Auxiliary class to identify common base class in type list.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#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).
Template definition of class to look for base class in type list.
Template class to test for polymorphism.
Definition JBaseClass.hh:22
Auxiliary class for recursive type list generation.
Definition JTypeList.hh:351
Type list.
Definition JTypeList.hh:23