Jpp  18.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
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

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 
75  typedef vector<__A__> buffer_type;
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());
100  }
101 
102 
103  sort(buffer.begin(), buffer.end(), make_comparator(&__A__::get, JComparison::gt()));
104 
105  print(cout, debug,
106  "sort(.., make_comparator(&__A__::get, JComparison::gt()))",
107  buffer.begin(), buffer.end());
108 
109  for (buffer_type::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
110  ASSERT(p->get() > q->get());
111  }
112 
113 
114  sort(buffer.begin(), buffer.end(), make_comparator(&__A__::a));
115 
116  print(cout, debug,
117  "sort(.., make_comparator(&__A__::a))",
118  buffer.begin(), buffer.end());
119 
120  for (buffer_type::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
121  ASSERT(p->a < q->a);
122  }
123 
124  sort(buffer.begin(), buffer.end(), make_comparator(&__A__::a, JComparison::gt()));
125 
126  print(cout, debug,
127  "sort(.., make_comparator(&__A__::a), JComparison::gt())",
128  buffer.begin(), buffer.end());
129 
130  for (buffer_type::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
131  ASSERT(p->a > q->a);
132  }
133 
134  return 0;
135 }
Utility class to parse command line options.
Definition: JParser.hh:1514
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
T get(const JHead &header)
Get object from header.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
then JCalibrateToT a
Definition: JTuneHV.sh:116
print
Definition: JConvertDusj.sh:44
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level