Jpp
18.5.2
the software that should make you happy
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JLang
JVectorize.cc
Go to the documentation of this file.
1
2
#include <iostream>
3
#include <iomanip>
4
#include <vector>
5
6
#include "
JLang/JVectorize.hh
"
7
8
#include "
Jeep/JParser.hh
"
9
#include "
Jeep/JMessage.hh
"
10
11
12
namespace
{
13
14
struct
__A__
15
{
16
__A__() :
17
i
(0)
18
{}
19
20
__A__(
const
int
__i) :
21
i
(__i)
22
{}
23
24
int
get
()
const
{
return
i
; }
25
26
friend
inline
std::ostream&
operator<<
(std::ostream& out,
const
__A__&
object
)
27
{
28
return
out <<
object
.i;
29
}
30
31
int
i
;
32
};
33
34
35
/**
36
* Print data.
37
*
38
* \param out output stream
39
* \param N number of elements
40
* \param p pointer to data
41
*/
42
template
<
class
T>
43
inline
void
print
(std::ostream& out,
int
N
,
T
* p)
44
{
45
using namespace
std;
46
47
for
(
int
i
= 0;
i
!=
N
; ++
i
) {
48
out <<
' '
<< setw(2) << p[
i
];
49
}
50
51
cout << endl;
52
}
53
}
54
55
56
/**
57
* \file
58
*
59
* Example program to test JLANG::make_array method.
60
* \author mdejong
61
*/
62
int
main
(
int
argc,
char
**argv)
63
{
64
using namespace
std;
65
66
int
debug
;
67
68
try
{
69
70
JParser<>
zap(
"Example program to test converions of array of objects to array of data members."
);
71
72
zap[
'd'
] =
make_field
(
debug
) = 3;
73
74
zap(argc, argv);
75
}
76
catch
(
const
exception &error) {
77
FATAL
(error.what() << endl);
78
}
79
80
81
using namespace
JPP;
82
83
vector<__A__>
buffer;
84
85
int
numberOfElements = 5;
86
87
for
(
int
i
= 0;
i
!= numberOfElements; ++
i
) {
88
buffer.push_back(__A__(
i
));
89
}
90
91
if
(
debug
>=
debug_t
) {
92
print
(cout, numberOfElements, buffer.data());
93
print
(cout, numberOfElements,
make_array
(buffer.begin(), buffer.end(), &
__A__::get
).
data
());
94
print
(cout, numberOfElements,
make_array
(buffer.begin(), buffer.end(), &
__A__::i
) .
data
());
95
}
96
97
{
98
const
int
* p =
make_array
(buffer.begin(), buffer.end(), &
__A__::get
).
data
();
99
100
for
(
int
i
= 0;
i
!= numberOfElements; ++
i
, ++p) {
101
ASSERT
(buffer[
i
].
get
() == *p);
102
}
103
}
104
105
{
106
const
int
* p =
make_array
(buffer.begin(), buffer.end(), &
__A__::i
).
data
();
107
108
for
(
int
i
= 0;
i
!= numberOfElements; ++
i
, ++p) {
109
ASSERT
(buffer[
i
].
i
== *p);
110
}
111
}
112
113
return
0;
114
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1514
JEEP::debug_t
debug
Definition:
JMessage.hh:29
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
JAANET::get
T get(const JHead &header)
Get object from header.
Definition:
JHeadToolkit.hh:261
std::vector
Definition:
JSTDTypes.hh:12
i
then rm i
Definition:
JEvtReweightMupageParameterScan.sh:309
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:1989
JLANG::make_array
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition:
JVectorize.hh:54
T
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Definition:
JCalibrateHeight.sh:61
JVectorize.hh
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
print
print
Definition:
JConvertDusj.sh:44
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
N
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition:
JMuonPostfit.sh:40
JParser.hh
Utility class to parse command line options.
operator<<
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
Definition:
clb_common_header.hh:72
applications.data
tuple data
Definition:
applications.py:8
debug
int debug
debug level
Definition:
archive-put-wiki-detectors.sh:92
Generated by
1.8.5