Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JBool.cc
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3
4#include "JLang/JBool.hh"
6
7#include "Jeep/JParser.hh"
8#include "Jeep/JMessage.hh"
9
10
11namespace {
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 */
82int 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}
#define C_OPERAND(OP, A, B)
Operand macro.
Definition JBool.cc:62
int main(int argc, char **argv)
Definition JBool.cc:82
#define C_SWITCH(VALUE, A, B)
Switch macro.
Definition JBool.cc:73
General purpose messaging.
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse command line options.
Definition JParser.hh:1698
std::ostream & operator<<(std::ostream &out, const JAHRSCalibration &calibration)
Write AHRS calibration to output stream.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Type definition of logical AND.
Definition JBool.hh:307
Auxiliary template class for type bool.
Definition JBool.hh:21
static JBool<!value > c_not()
Make logical NOT.
Definition JBool.hh:57
Type definition of logical OR.
Definition JBool.hh:322
Type definition of logical XOR.
Definition JBool.hh:337