Jpp  master_rocky
the software that should make you happy
Functions
JFind_if.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/JFind_if.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 JFind_if.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 68 of file JFind_if.cc.

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 }
#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:69
#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
const double a
Definition: JQuadrature.cc:42
std::ostream & print(std::ostream &out, const JTestSummary &summary, const char delimiter=' ', const bool useColors=true)
Print test summary.
JFind_if< JResult_t T::*, JPredicate_t > make_find_if(JResult_t T::*member, const JPredicate_t &predicate)
Helper method to create find_if for data member.
Definition: JFind_if.hh:119
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14