Jpp
15.0.0-rc.2
the software that should make you happy
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JLang
JComparable.cc
Go to the documentation of this file.
1
2
#include <iostream>
3
#include <iomanip>
4
5
#include "
JLang/JComparable.hh
"
6
7
#include "
Jeep/JParser.hh
"
8
#include "
Jeep/JMessage.hh
"
9
10
11
namespace
{
12
13
using namespace
JPP;
14
15
struct
__A__ :
16
public
JComparable
<__A__>
17
{
18
__A__(
int
__value) :
19
value(__value)
20
{}
21
22
bool
less(
const
__A__&
object
)
const
23
{
24
return
this->value <
object
.value;
25
}
26
27
friend
std::ostream&
operator<<
(std::ostream& out,
const
__A__&
object
)
28
{
29
return
out <<
object
.value;
30
}
31
32
int
value;
33
};
34
35
36
struct
__B__ :
37
public
JComparable
<__B__>,
38
public
JComparable
<__B__, int>
39
{
40
__B__(
const
int
__value) :
41
value(__value)
42
{}
43
44
bool
less(
const
__B__&
object
)
const
45
{
46
return
this->value <
object
.value;
47
}
48
49
bool
less(
const
int
value)
const
50
{
51
return
this->value < value;
52
}
53
54
bool
more(
const
int
value)
const
55
{
56
return
this->value > value;
57
}
58
59
friend
std::ostream&
operator<<
(std::ostream& out,
const
__B__&
object
)
60
{
61
return
out <<
object
.value;
62
}
63
64
int
value;
65
};
66
67
/**
68
* Print.
69
*
70
* \param OUT output stream
71
* \param OP operator
72
* \param A first object
73
* \param B second object
74
*/
75
#define PRINT(OUT,OP,A,B) \
76
OUT << "(" << A << ") " << #OP " (" << B << ") => " << (A OP B) << std::endl;
77
}
78
79
/**
80
* \file
81
*
82
* Example program to test JLANG::JComparable class.
83
* \author mdejong
84
*/
85
int
main
(
int
argc,
char
**argv)
86
{
87
using namespace
std;
88
using namespace
JPP;
89
90
int
debug
;
91
92
try
{
93
94
JParser<>
zap(
"Example program to test comparisons of objects."
);
95
96
zap[
'd'
] =
make_field
(
debug
) = 3;
97
98
zap(argc, argv);
99
}
100
catch
(
const
exception &error) {
101
FATAL
(error.what() << endl);
102
}
103
104
105
__A__ a1(0);
106
__A__ a2(1);
107
108
PRINT
(cout, ==, a1, a2);
109
PRINT
(cout, !=, a1, a2);
110
PRINT
(cout, <, a1, a2);
111
PRINT
(cout, <=, a1, a2);
112
PRINT
(cout, >, a1, a2);
113
PRINT
(cout, >=, a1, a2);
114
115
__B__ b1(0);
116
__B__ b2(1);
117
118
PRINT
(cout, ==, b1, b1);
119
PRINT
(cout, !=, b1, b2);
120
PRINT
(cout, <, b1, b2);
121
PRINT
(cout, <=, b1, b2);
122
PRINT
(cout, >, b1, b2);
123
PRINT
(cout, >=, b1, b2);
124
125
PRINT
(cout, ==, b1, 1);
126
PRINT
(cout, !=, b1, 1);
127
PRINT
(cout, <, b1, 1);
128
PRINT
(cout, <=, b1, 1);
129
PRINT
(cout, >, b1, 1);
130
PRINT
(cout, >=, b1, 1);
131
132
ASSERT
(a1 == a1);
133
ASSERT
(a1 != a2);
134
ASSERT
(a1 < a2);
135
ASSERT
(a1 <= a2);
136
ASSERT
(! (a1 > a2));
137
ASSERT
(! (a1 >= a2));
138
139
ASSERT
(b1 == b1);
140
ASSERT
(b1 != b2);
141
ASSERT
(b1 < b2);
142
ASSERT
(b1 <= b2);
143
ASSERT
(! (b1 > b2));
144
ASSERT
(! (b1 >= b2));
145
146
ASSERT
(b1 == 0);
147
ASSERT
(b1 != 1);
148
ASSERT
(b1 < 1);
149
ASSERT
(b1 <= 1);
150
ASSERT
(! (b1 > 1));
151
ASSERT
(! (b1 >= 1));
152
153
return
0;
154
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1500
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition:
JMessage.hh:90
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1961
PRINT
#define PRINT(OUT, OP, A, B)
Print.
Definition:
JComparable.cc:75
debug
int debug
debug level
Definition:
JSirene.cc:63
JComparable.hh
JLANG::JComparable
Template definition of auxiliary base class for comparison of data structures.
Definition:
JComparable.hh:24
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JParser.hh
Utility class to parse command line options.
operator<<
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
Definition:
clb_common_header.hh:72
Generated by
1.8.5