Jpp  test_elongated_shower_pde
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPredicate.cc File Reference

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

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <iterator>
#include "JLang/JPredicate.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::JPredicate class and helper methods.

Author
mdejong

Definition in file JPredicate.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 56 of file JPredicate.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 selection 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  vector<__A__> buffer;
76 
77  buffer.push_back(__A__(3));
78  buffer.push_back(__A__(4));
79  buffer.push_back(__A__(2));
80  buffer.push_back(__A__(1));
81  buffer.push_back(__A__(5));
82 
83 
84  print(cout, debug, "data:", buffer.begin(), buffer.end());
85 
86  int x = 3;
87 
88  {
89  vector<__A__>::const_iterator p = find_if(buffer.begin(), buffer.end(), make_predicate(&__A__::a, x));
90 
91  DEBUG("has " << x << "? " << (p != buffer.end() ? "yes" : "no") << endl);
92 
93  ASSERT(p != buffer.end() && p->a == x);
94  }
95 
96  {
97  vector<__A__>::const_iterator p = find_if(buffer.begin(), buffer.end(), make_predicate(&__A__::get, x));
98 
99  DEBUG("has " << x << "? " << (p != buffer.end() ? "yes" : "no") << endl);
100 
101  ASSERT(p != buffer.end() && p->get() == x);
102  }
103 
104  {
105  vector<__A__>::iterator p = partition(buffer.begin(), buffer.end(), make_predicate(&__A__::a, x, JComparison::lt()));
106 
107  print(cout, debug, "selection:", buffer.begin(), p);
108 
109  for (vector<__A__>::iterator i = buffer.begin(); i != p; ++i) {
110  ASSERT(i->a < x);
111  }
112  }
113 
114  return 0;
115 }
Utility class to parse command line options.
Definition: JParser.hh:1500
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
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:1961
int debug
debug level
Definition: JSirene.cc:68
print
Definition: JConvertDusj.sh:44
#define FATAL(A)
Definition: JMessage.hh:67
then JCalibrateToT a
Definition: JTuneHV.sh:116
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG