Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JPipe.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <vector>
6
11#include "JLang/JPipe.hh"
12
13#include "Jeep/JParser.hh"
14#include "Jeep/JMessage.hh"
15
16
17namespace {
18
19 using namespace JPP;
20
21 /**
22 * Modulo selector.
23 */
24 struct JModulo :
25 public JObjectSelector<int>
26 {
27 typedef JObjectSelector<int>::argument_type argument_type;
28
29 /**
30 * Constructor.
31 *
32 * \param mod modulo
33 */
34 JModulo(int mod)
35 {
36 this->mod = mod;
37 }
38
39
40 /**
41 * Accept object.
42 *
43 * \param object object
44 * \return true if accepted; else false
45 */
46 virtual bool accept(argument_type object) const
47 {
48 if (mod == 0)
49 return true;
50 else if (mod > 0)
51 return ((int) object) % mod == 0;
52 else
53 return false;
54 }
55
56 int mod;
57 };
58}
59
60/**
61 * \file
62 *
63 * Example program to test JLANG::JPipe class.
64 * \author mdejong
65 */
66int main(int argc, char **argv)
67{
68 using namespace std;
69 using namespace JPP;
70
71 int mod;
72 int debug;
73
74 try {
75
76 JParser<> zap("Example program to test object iteration using pipe.");
77
78 zap['M'] = make_field(mod) = 2;
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
89
90 buffer_type buffer;
91
92 for (int i = 0; i != 20; ++i) {
93 buffer.push_back(i);
94 }
95
96 JSTDObjectReader<int> in(buffer);
97
98 if (debug >= debug_t) {
99
100 JStreamObjectOutput<int> out(cout, "\n");
101
102 in | JModulo(mod) | out;
103 }
104
105 buffer_type data;
106
107 JSTDObjectWriter<int> out(data);
108
109 in.rewind();
110
111 in | JModulo(mod) | out;
112
113 ASSERT(!data.empty());
114
115 for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
116 ASSERT((*i)%mod == 0);
117 }
118
119 return 0;
120}
General purpose messaging.
#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
int main(int argc, char **argv)
Definition JPipe.cc:66
Implementation of pipe operation for object iterators.
Interface for selection of objects.
JClass< T >::argument_type argument_type
Type definition of argument of interface method.
Implementation of object output from STD container.
Template implementation of stream output for single data type.
Utility class to parse command line options.
Definition JParser.hh:1698
@ debug_t
debug
Definition JMessage.hh:29
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< JHitW0 > buffer_type
hits
Definition JPerth.cc:70
Implementation of object iteration from STD container.