Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMultiEquals.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JLang/JEquals.hh"
6 #include "JLang/JMultiEquals.hh"
7 
8 #include "Jeep/JParser.hh"
9 #include "Jeep/JMessage.hh"
10 
11 
12 namespace {
13 
14  using namespace JPP;
15 
16 
17  struct __A__ :
18  public JEquals<__A__>
19  {
20  __A__() :
21  value(0)
22  {}
23 
24  __A__(int __value) :
25  value(__value)
26  {}
27 
28  bool equals(const __A__& object) const
29  {
30  return this->value == object.value;
31  }
32 
33  friend std::ostream& operator<<(std::ostream& out, const __A__& object)
34  {
35  return out << object.value;
36  }
37 
38  int value;
39  };
40 
41 
42  struct __B__ :
43  public JEquals<__B__>
44  {
45  __B__() :
46  value(0)
47  {}
48 
49  __B__(int __value) :
50  value(__value)
51  {}
52 
53  bool equals(const __B__& object) const
54  {
55  return this->value == object.value;
56  }
57 
58  friend std::ostream& operator<<(std::ostream& out, const __B__& object)
59  {
60  return out << object.value;
61  }
62 
63  int value;
64  };
65 
66 
67  struct __C__ :
68  public __A__,
69  public __B__,
70  public JMultiEquals<__C__, __A__>
71  {
72  __C__(const int a,
73  const int b) :
74  __A__(a),
75  __B__(b)
76  {}
77 
78  friend std::ostream& operator<<(std::ostream& out, const __C__& object)
79  {
80  return out << static_cast<const __A__&>(object) << ' '
81  << static_cast<const __B__&>(object);
82  }
83  };
84 
85 
86  struct __D__ :
87  public __A__,
88  public __B__,
89  public JMultiEquals<__D__, JTYPELIST<__A__, __B__>::typelist>
90  {
91  __D__(const int a,
92  const int b) :
93  __A__(a),
94  __B__(b)
95  {}
96 
97  friend std::ostream& operator<<(std::ostream& out, const __D__& object)
98  {
99  return out << static_cast<const __A__&>(object) << ' '
100  << static_cast<const __B__&>(object);
101  }
102  };
103 
104 
105  /**
106  * Print.
107  *
108  * \param OUT output stream
109  * \param OP operator
110  * \param A first object
111  * \param B second object
112  */
113 #define PRINT(OUT,OP,A,B) \
114  OUT << "(" << A << ") " << #OP " (" << B << ") => " << (A OP B) << std::endl;
115 }
116 
117 /**
118  * \file
119  *
120  * Example program to test JLANG::JMultiEquals class.
121  * \author mdejong
122  */
123 int main(int argc, char **argv)
124 {
125  using namespace std;
126  using namespace JPP;
127 
128  int debug;
129 
130  try {
131 
132  JParser<> zap("Example program to test object comparisons.");
133 
134  zap['d'] = make_field(debug) = 3;
135 
136  zap(argc, argv);
137  }
138  catch(const exception &error) {
139  FATAL(error.what() << endl);
140  }
141 
142  __C__ c1(1,1);
143  __C__ c2(1,1);
144  __C__ c3(0,1);
145  __C__ c4(1,0);
146 
147  PRINT(cout, ==, c1, c2);
148  PRINT(cout, !=, c1, c2);
149  PRINT(cout, ==, c1, c3);
150  PRINT(cout, !=, c1, c3);
151  PRINT(cout, ==, c1, c4);
152  PRINT(cout, !=, c1, c4);
153 
154  ASSERT(c1 == c2);
155  ASSERT(c1 != c3);
156  ASSERT(c1 == c4);
157 
158  __D__ d1(1,1);
159  __D__ d2(1,1);
160  __D__ d3(0,1);
161  __D__ d4(1,0);
162 
163  PRINT(cout, ==, d1, d2);
164  PRINT(cout, !=, d1, d2);
165  PRINT(cout, ==, d1, d3);
166  PRINT(cout, !=, d1, d3);
167  PRINT(cout, ==, d1, d4);
168  PRINT(cout, !=, d1, d4);
169 
170  ASSERT(d1 == d2);
171  ASSERT(d1 != d3);
172  ASSERT(d1 != d4);
173 
174  return 0;
175 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
Template definition of auxiliary base class for data structures composed of multiple base classes wit...
Definition: JMultiEquals.hh:32
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
TCanvas * c1
Global variables to handle mouse events.
then JCalibrateToT a
Definition: JTuneHV.sh:116
Utility class to parse command line options.
then echo Launching message logger in new window xterm geometry e JGetMessage H $HOST T $TAG d3
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
bool equals(const JFirst_t &first, const JSecond_t &second, const double precision=std::numeric_limits< double >::min())
Check equality.
Definition: JMathToolkit.hh:86
#define PRINT(OUT, OP, A, B)
Print.