Jpp
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__, int>
38
{
39
__B__(
const
int
__value) :
40
value(__value)
41
{}
42
43
bool
less(
const
__B__&
object
)
const
44
{
45
return
this->value <
object
.value;
46
}
47
48
bool
less(
const
int
value)
const
49
{
50
return
this->value < value;
51
}
52
53
bool
more(
const
int
value)
const
54
{
55
return
this->value > 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
* Print.
68
*
69
* \param OUT output stream
70
* \param OP operator
71
* \param A first object
72
* \param B second object
73
*/
74
#define PRINT(OUT,OP,A,B) \
75
OUT << "(" << A << ") " << #OP " (" << B << ") => " << (A OP B) << std::endl;
76
}
77
78
/**
79
* \file
80
*
81
* Example program to test JLANG::JComparable class.
82
* \author mdejong
83
*/
84
int
main
(
int
argc,
char
**argv)
85
{
86
using namespace
std;
87
using namespace
JPP;
88
89
int
debug
;
90
91
try
{
92
93
JParser<>
zap(
"Example program to test comparisons of objects."
);
94
95
zap[
'd'
] =
make_field
(
debug
) = 3;
96
97
zap(argc, argv);
98
}
99
catch
(
const
exception &error) {
100
FATAL
(error.what() << endl);
101
}
102
103
104
__A__ a1(0);
105
__A__ a2(1);
106
107
PRINT
(cout, ==, a1, a2);
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
114
__B__ b1(0);
115
__B__ b2(1);
116
117
PRINT
(cout, ==, b1, b1);
118
PRINT
(cout, !=, b1, b2);
119
PRINT
(cout, <, b1, b2);
120
PRINT
(cout, <=, b1, b2);
121
PRINT
(cout, >, b1, b2);
122
PRINT
(cout, >=, b1, b2);
123
124
PRINT
(cout, ==, b1, 1);
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
131
ASSERT
(a1 == a1);
132
ASSERT
(a1 != a2);
133
ASSERT
(a1 < a2);
134
ASSERT
(a1 <= a2);
135
ASSERT
(! (a1 > a2));
136
ASSERT
(! (a1 >= a2));
137
138
ASSERT
(b1 == b1);
139
ASSERT
(b1 != b2);
140
ASSERT
(b1 < b2);
141
ASSERT
(b1 <= b2);
142
ASSERT
(! (b1 > b2));
143
ASSERT
(! (b1 >= b2));
144
145
ASSERT
(b1 == 0);
146
ASSERT
(b1 != 1);
147
ASSERT
(b1 < 1);
148
ASSERT
(b1 <= 1);
149
ASSERT
(! (b1 > 1));
150
ASSERT
(! (b1 >= 1));
151
152
return
0;
153
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1410
ASSERT
#define ASSERT(A)
Assert macro.
Definition:
JMessage.hh:72
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1836
PRINT
#define PRINT(OUT, OP, A, B)
Print.
Definition:
JComparable.cc:74
debug
int debug
debug level
Definition:
JSirene.cc:59
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:65
JParser.hh
Utility class to parse command line options.
operator<<
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
Definition:
clb_common_header.hh:71
main
int main(int argc, char *argv[])
Definition:
Main.cpp:15
Generated by
1.8.5