Jpp
17.3.0-rc.1
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
JBool.cc
Go to the documentation of this file.
1
#include <iostream>
2
#include <iomanip>
3
4
#include "
JLang/JBool.hh
"
5
#include "
JLang/JConversion.hh
"
6
7
#include "
Jeep/JParser.hh
"
8
#include "
Jeep/JMessage.hh
"
9
10
11
namespace
{
12
13
using namespace
JPP;
14
15
16
/**
17
* Write bool to output.
18
*
19
* \param out output stream
20
* \param object bool
21
* \return output stream
22
*/
23
template
<
bool
value>
24
std::ostream& operator<<(std::ostream& out, const JBool<value>& object)
25
{
26
return
out <<
object
.value;
27
}
28
29
30
/**
31
* Test overload resolution.
32
*
33
* \param option true
34
* \return true
35
*/
36
inline
bool
invert(
const
JBool<true>
& option)
37
{
38
return
false
;
39
}
40
41
42
/**
43
* Test overload resolution.
44
*
45
* \param option false
46
* \return false
47
*/
48
inline
bool
invert(
const
JBool<false>
& option)
49
{
50
return
true
;
51
}
52
}
53
54
/**
55
* Operand macro.
56
*
57
* \param OP logical operator
58
* \param A first value
59
* \param B second value
60
* \return result
61
*/
62
#define C_OPERAND(OP, A, B) OP< JBool<A>, JBool<B> >::value
63
64
/**
65
* Switch macro.\n
66
* The result equals first option if value true; else second option.
67
*
68
* \param VALUE value
69
* \param A first option
70
* \param B second option
71
* \return result
72
*/
73
#define C_SWITCH(VALUE, A, B) VALUE.c_switch<A,B>()
74
75
76
/**
77
* \file
78
*
79
* Example program to test JLANG::JBool class. .
80
* \author mdejong
81
*/
82
int
main
(
int
argc,
char
**argv)
83
{
84
using namespace
std;
85
86
int
debug
;
87
88
try
{
89
90
JParser<>
zap(
"Example program to test boolean algebra at compile time."
);
91
92
zap[
'd'
] =
make_field
(
debug
) = 3;
93
94
zap(argc, argv);
95
}
96
catch
(
const
exception &error) {
97
FATAL
(error.what() << endl);
98
}
99
100
using namespace
JPP;
101
102
const
bool
X
=
true
;
103
const
bool
Y
=
false
;
104
105
ASSERT
(
JBool<X>::value
==
true
);
106
ASSERT
(
JBool<Y>::value
==
false
);
107
108
ASSERT
(
C_OPERAND
(
AND
,
X
,
X
) ==
true
);
109
ASSERT
(
C_OPERAND
(
AND
,
X
,
Y
) ==
false
);
110
ASSERT
(
C_OPERAND
(
OR
,
X
,
X
) ==
true
);
111
ASSERT
(
C_OPERAND
(
OR
,
Y
,
Y
) ==
false
);
112
ASSERT
(
C_OPERAND
(
OR
,
X
,
Y
) ==
true
);
113
ASSERT
(
C_OPERAND
(
XOR
,
X
,
X
) ==
false
);
114
ASSERT
(
C_OPERAND
(
XOR
,
X
,
Y
) ==
true
);
115
116
ASSERT
(invert(
JBool<true>
()) ==
false
);
117
ASSERT
(invert(
JBool<false>
()) ==
true
);
118
119
JBool<true>
option;
120
121
ASSERT
(
C_SWITCH
(option,
X
,
Y
));
122
ASSERT
(!
C_SWITCH
(option,
Y
,
X
));
123
124
ASSERT
(!
C_SWITCH
(option.c_not(),
X
,
Y
));
125
ASSERT
(
C_SWITCH
(option.c_not(),
Y
,
X
));
126
127
return
0;
128
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1517
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
Y
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
Definition:
detector-XY:fit1d.sh:33
JLANG::XOR
Type definition of logical XOR.
Definition:
JBool.hh:337
JConversion.hh
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition:
JMessage.hh:90
JLANG::JBool
Auxiliary template class for type bool.
Definition:
JBool.hh:20
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1993
JBool.hh
C_SWITCH
#define C_SWITCH(VALUE, A, B)
Switch macro.
Definition:
JBool.cc:73
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JParser.hh
Utility class to parse command line options.
JLANG::AND
Type definition of logical AND.
Definition:
JBool.hh:307
X
no fit printf nominal n $STRING awk v X
Definition:
detector-XY:fit.sh:102
C_OPERAND
#define C_OPERAND(OP, A, B)
Operand macro.
Definition:
JBool.cc:62
JLANG::OR
Type definition of logical OR.
Definition:
JBool.hh:322
debug
int debug
debug level
Definition:
archive-put-wiki-detectors.sh:92
Generated by
1.8.5