Jpp
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JLang
JPipe.cc
Go to the documentation of this file.
1
2
#include <string>
3
#include <iostream>
4
#include <iomanip>
5
#include <vector>
6
7
#include "
JLang/JSTDObjectReader.hh
"
8
#include "
JLang/JSTDObjectWriter.hh
"
9
#include "
JLang/JStreamObjectOutput.hh
"
10
#include "
JLang/JObjectSelector.hh
"
11
#include "
JLang/JPipe.hh
"
12
13
#include "
Jeep/JParser.hh
"
14
#include "
Jeep/JMessage.hh
"
15
16
17
namespace
{
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
*/
66
int
main
(
int
argc,
char
**argv)
67
{
68
using namespace
std;
69
70
int
mod;
71
int
debug
;
72
73
try
{
74
75
JParser<>
zap(
"Example program to test object iteration using pipe."
);
76
77
zap[
'M'
] =
make_field
(mod) = 2;
78
zap[
'd'
] =
make_field
(
debug
) = 3;
79
80
zap(argc, argv);
81
}
82
catch
(
const
exception &error) {
83
FATAL
(error.what() << endl);
84
}
85
86
87
using namespace
JPP;
88
89
typedef
vector<int>
buffer_type;
90
91
buffer_type buffer;
92
93
for
(
int
i = 0; i != 20; ++i) {
94
buffer.push_back(i);
95
}
96
97
JSTDObjectReader<int>
in
(buffer);
98
99
if
(
debug
>=
debug_t
) {
100
101
JStreamObjectOutput<int>
out(cout,
"\n"
);
102
103
in | JModulo(mod) | out;
104
}
105
106
buffer_type data;
107
108
JSTDObjectWriter<int>
out(data);
109
110
in.
rewind
();
111
112
in | JModulo(mod) | out;
113
114
ASSERT
(!data.empty());
115
116
for
(buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) {
117
ASSERT
((*i)%mod == 0);
118
}
119
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1493
JEEP::debug_t
debug
Definition:
JMessage.hh:29
in
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition:
JSirene.sh:45
JSTDObjectReader.hh
std::vector< int >
JLANG::JSTDObjectWriter
Implementation of object output from STD container.
Definition:
JSTDObjectWriter.hh:24
JLANG::JObjectSelector
Interface for selection of objects.
Definition:
JObjectIterator.hh:33
JLANG::JObjectSelector::argument_type
JClass< T >::argument_type argument_type
Type definition of argument of interface method.
Definition:
JObjectSelector.hh:27
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition:
JMessage.hh:90
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1954
JSTDObjectWriter.hh
JPipe.hh
Implementation of pipe operation for object iterators.
JLANG::JRewindable::rewind
virtual void rewind()=0
Rewind.
debug
int debug
debug level
Definition:
JSirene.cc:61
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JLANG::JSTDObjectReader
Implementation of object iteration from STD container.
Definition:
JSTDObjectReader.hh:24
JParser.hh
Utility class to parse command line options.
JLANG::JStreamObjectOutput
Template implementation of stream output for single data type.
Definition:
JStreamObjectOutput.hh:28
JObjectSelector.hh
JStreamObjectOutput.hh
main
int main(int argc, char *argv[])
Definition:
Main.cpp:15
Generated by
1.8.5