Jpp  16.0.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
12 namespace {
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  */
38 int 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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
T get(const JHead &header)
Get object from header.
Auxiliary class to identify common base class in type list.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG