Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JFind_if.cc
Go to the documentation of this file.
1
2#include <iostream>
3#include <iomanip>
4#include <vector>
5#include <algorithm>
6#include <iterator>
7
8#include "JLang/JFind_if.hh"
9
10#include "Jeep/JParser.hh"
11#include "Jeep/JMessage.hh"
12
13
14namespace {
15
16 class __A__ {
17 public:
18 __A__(const int a)
19 {
20 this->a = a;
21 }
22
23 int get() const
24 {
25 return a;
26 }
27
28 friend inline std::ostream& operator<<(std::ostream& out, const __A__& object) { return out << object.a; }
29
30 int a;
31 };
32
33 class JPredicate_t {
34 public:
35 JPredicate_t(const int value) :
36 value(value)
37 {}
38
39 bool operator()(const int value) const
40 {
41 return this->value == value;
42 }
43
44 int value;
45 };
46
47 template<class T>
48 void print(std::ostream& out, int debug, const char* title, T __begin, T __end)
49 {
50 using namespace std;
51 using namespace JPP;
52
53 if (debug >= debug_t) {
54 out << title << endl;
55 copy(__begin, __end, ostream_iterator<typename T::value_type>(out, " "));
56 out << endl;
57 }
58 }
59}
60
61
62/**
63 * \file
64 *
65 * Auxiliary program to test JLANG::JPredicate class and helper methods.
66 * \author mdejong
67 */
68int main(int argc, char **argv)
69{
70 using namespace std;
71 using namespace JPP;
72
73 int debug;
74
75 try {
76
77 JParser<> zap("Auxiliary program to test object selection methods.");
78
79 zap['d'] = make_field(debug) = 3;
80
81 zap(argc, argv);
82 }
83 catch(const exception &error) {
84 FATAL(error.what() << endl);
85 }
86
87 vector<__A__> buffer;
88
89 buffer.push_back(__A__(3));
90 buffer.push_back(__A__(4));
91 buffer.push_back(__A__(2));
92 buffer.push_back(__A__(1));
93 buffer.push_back(__A__(5));
94
95
96 print(cout, debug, "data:", buffer.begin(), buffer.end());
97
98 JPredicate_t predicate(3);
99
100 {
101 vector<__A__>::const_iterator p = find_if(buffer.begin(), buffer.end(), make_find_if(&__A__::a, predicate));
102
103 DEBUG("has " << predicate.value << "? " << (p != buffer.end() ? "yes" : "no") << endl);
104
105 ASSERT(p != buffer.end() && p->a == predicate.value);
106 }
107
108 {
109 vector<__A__>::const_iterator p = find_if(buffer.begin(), buffer.end(), make_find_if(&__A__::get, predicate));
110
111 DEBUG("has " << predicate.value << "? " << (p != buffer.end() ? "yes" : "no") << endl);
112
113 ASSERT(p != buffer.end() && p->get() == predicate.value);
114 }
115
116 return 0;
117}
int main(int argc, char **argv)
Definition JFind_if.cc:68
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#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
void print(const TH1 &h1, std::ostream &out)
Print histogram parameters.
Utility class to parse command line options.
Definition JParser.hh:1698
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
const double a
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).