Jpp  17.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JComparisonAvailable.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JLang/JComparable.hh"
6 #include "JLang/JEquals.hh"
7 #include "JLang/JMultiEquals.hh"
9 
10 #include "Jeep/JParser.hh"
11 #include "Jeep/JMessage.hh"
12 
13 
14 namespace {
15 
16  using namespace JPP;
17 
18 
19  struct __A__ {};
20  struct __B__ {};
21  struct __C__ : public __B__ {};
22 
23  struct __D__ :
24  public JComparable<__D__>
25  {
26  bool less(const __D__& object) const { return true; }
27  };
28 
29  inline bool operator!=(const __A__& first, const __A__& second) { return false; }
30  inline bool operator< (const __B__& first, const __B__& second) { return false; }
31  inline bool operator> (const __B__& first, const __B__& second) { return false; }
32 
33  struct __E__ :
34  public __A__,
35  public __D__,
36  // adddition of this base class solves the ambiguity problem.
37  public JMultiEquals<__E__, JTYPELIST<__A__, __D__>::typelist>
38  {};
39 }
40 
41 /**
42  * Print availabilty of comparison operators.
43  *
44  * \param OUT output stream
45  * \param CLASS class name
46  */
47 #define PRINT(OUT, CLASS) \
48  OUT << std::setw(6) << std::left << #CLASS << ' ' ; \
49  OUT << ' ' << JComparisonAvailable<CLASS>::has_eq << ' '; \
50  OUT << ' ' << JComparisonAvailable<CLASS>::has_ne << ' '; \
51  OUT << ' ' << JComparisonAvailable<CLASS>::has_lt << ' '; \
52  OUT << ' ' << JComparisonAvailable<CLASS>::has_gt << ' '; \
53  OUT << ' ' << JComparisonAvailable<CLASS>::has_le << ' '; \
54  OUT << ' ' << JComparisonAvailable<CLASS>::has_ge << std::endl;
55 
56 
57 /**
58  * \file
59  *
60  * Example program to test JLANG::JComparisonAvailable and JLANG::JComparable classes.
61  * \author mdejong
62  */
63 int main(int argc, char **argv)
64 {
65  using namespace std;
66  using namespace JPP;
67 
68  int debug;
69 
70  try {
71 
72  JParser<> zap("Example program to test availability of object comparisons.");
73 
74  zap['d'] = make_field(debug) = 3;
75 
76  zap(argc, argv);
77  }
78  catch(const exception &error) {
79  FATAL(error.what() << endl);
80  }
81 
82  if (debug >= debug_t) {
83 
84  cout << setw(6) << left << "class" << ' ' << "eq ne lt gt le ge" << endl;
85 
86  PRINT(cout, __A__);
87  PRINT(cout, __B__);
88  PRINT(cout, __C__);
89  PRINT(cout, __D__);
90  PRINT(cout, __E__);
91  }
92 
93  ASSERT(JComparisonAvailable<__A__>::has_eq == false);
94  ASSERT(JComparisonAvailable<__A__>::has_ne == true);
95  ASSERT(JComparisonAvailable<__A__>::has_lt == false);
96  ASSERT(JComparisonAvailable<__A__>::has_le == false);
97  ASSERT(JComparisonAvailable<__A__>::has_gt == false);
98  ASSERT(JComparisonAvailable<__A__>::has_ge == false);
99 
100  ASSERT(JComparisonAvailable<__C__>::has_eq == false);
101  ASSERT(JComparisonAvailable<__C__>::has_ne == false);
102  ASSERT(JComparisonAvailable<__C__>::has_lt == true);
103  ASSERT(JComparisonAvailable<__C__>::has_le == false);
104  ASSERT(JComparisonAvailable<__C__>::has_gt == true);
105  ASSERT(JComparisonAvailable<__C__>::has_ge == false);
106 
107  ASSERT(JComparisonAvailable<__D__>::has_eq == true);
108  ASSERT(JComparisonAvailable<__D__>::has_ne == true);
109  ASSERT(JComparisonAvailable<__D__>::has_lt == true);
110  ASSERT(JComparisonAvailable<__D__>::has_le == true);
111  ASSERT(JComparisonAvailable<__D__>::has_gt == true);
112  ASSERT(JComparisonAvailable<__D__>::has_ge == true);
113 
114  ASSERT(JComparisonAvailable<__E__>::has_eq == true);
115  ASSERT(JComparisonAvailable<__E__>::has_ne == true);
116  ASSERT(JComparisonAvailable<__E__>::has_lt == true);
117  ASSERT(JComparisonAvailable<__E__>::has_le == true);
118  ASSERT(JComparisonAvailable<__E__>::has_gt == true);
119  ASSERT(JComparisonAvailable<__E__>::has_ge == true);
120 
121  return 0;
122 }
Utility class to parse command line options.
Definition: JParser.hh:1517
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition: JHead.hh:1741
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Template definition of auxiliary base class for data structures composed of multiple base classes wit...
Definition: JMultiEquals.hh:32
JNullType operator>(JAnyType, JAnyType)
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
#define PRINT(OUT, CLASS)
Print availabilty of comparison operators.
Utility class to parse command line options.
JNullType operator!=(JAnyType, JAnyType)
int debug
debug level