Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JComparator.cc File Reference

Auxiliary program to test JLANG::JComparator class and helper methods. More...

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <iterator>
#include "JLang/JComparator.hh"
#include "JLang/JComparison.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to test JLANG::JComparator class and helper methods.

Author
mdejong

Definition in file JComparator.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 56 of file JComparator.cc.

57{
58 using namespace std;
59 using namespace JPP;
60
61 int debug;
62
63 try {
64
65 JParser<> zap("Auxiliary program to test object comparison methods.");
66
67 zap['d'] = make_field(debug) = 3;
68
69 zap(argc, argv);
70 }
71 catch(const exception &error) {
72 FATAL(error.what() << endl);
73 }
74
76
77 buffer_type buffer;
78
79 buffer.push_back(__A__(3.0));
80 buffer.push_back(__A__(4.0));
81 buffer.push_back(__A__(2.0));
82 buffer.push_back(__A__(1.0));
83 buffer.push_back(__A__(5.0));
84
85 ASSERT(buffer.size() >= 2);
86
87 print(cout, debug,
88 "data",
89 buffer.begin(), buffer.end());
90
91
92 sort(buffer.begin(), buffer.end(), make_comparator(&__A__::get));
93
94 print(cout, debug,
95 "sort(.., make_comparator(&__A__::get))",
96 buffer.begin(), buffer.end());
97
98 for (buffer_type::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
99 ASSERT(p->get() < q->get(), "test sort");
100 }
101
102
103 {
104 for (const auto& i : buffer) {
105
106 buffer_type::const_iterator p = lower_bound(buffer.begin(), buffer.end(), i.get(), make_comparator(&__A__::get));
107
108 ASSERT(p != buffer.end() && i.get() == p->get(), "test lower_bound");
109 }
110 }
111
112 sort(buffer.begin(), buffer.end(), make_comparator(&__A__::get, JComparison::gt()));
113
114 print(cout, debug,
115 "sort(.., make_comparator(&__A__::get, JComparison::gt()))",
116 buffer.begin(), buffer.end());
117
118 for (buffer_type::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
119 ASSERT(p->get() > q->get());
120 }
121
122
123 sort(buffer.begin(), buffer.end(), make_comparator(&__A__::a));
124
125 print(cout, debug,
126 "sort(.., make_comparator(&__A__::a))",
127 buffer.begin(), buffer.end());
128
129 for (buffer_type::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
130 ASSERT(p->a < q->a);
131 }
132
133 sort(buffer.begin(), buffer.end(), make_comparator(&__A__::a, JComparison::gt()));
134
135 print(cout, debug,
136 "sort(.., make_comparator(&__A__::a), JComparison::gt())",
137 buffer.begin(), buffer.end());
138
139 for (buffer_type::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
140 ASSERT(p->a > q->a);
141 }
142
143 return 0;
144}
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#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
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).