Jpp
examples
JIO
JByteArrayIO.cc
Go to the documentation of this file.
1
2
#include <string>
3
#include <iostream>
4
#include <iomanip>
5
#include <vector>
6
#include <map>
7
#include <list>
8
9
#include "
JIO/JByteArrayIO.hh
"
10
#include "
JIO/JSTDIO.hh
"
11
12
#include "
Jeep/JStreamToolkit.hh
"
13
#include "
Jeep/JParser.hh
"
14
#include "
Jeep/JMessage.hh
"
15
16
17
/**
18
* \file
19
*
20
* Example program to test JIO::JByteArrayReader and JIO::JByteArrayWriter.
21
* \author mdejong
22
*/
23
int
main
(
int
argc,
char
**argv)
24
{
25
using namespace
std
;
26
using namespace
JPP
;
27
28
int
debug
;
29
30
try
{
31
32
JParser<>
zap(
"Example program to test byte array I/O."
);
33
34
zap[
'd'
] =
make_field
(
debug
) = 3;
35
36
zap(argc, argv);
37
}
38
catch
(
const
exception &error) {
39
FATAL
(error.what() << endl);
40
}
41
42
43
int
i1 = 999;
44
double
x1 = 123.456;
45
string
s1 =
"hello world"
;
46
47
vector<double>
v1;
48
49
for
(
double
x = 0.0; x < 10.5; x += 1.0) {
50
v1.push_back(x);
51
}
52
53
list<string>
l1;
54
55
l1.push_back(
"hello"
);
56
l1.push_back(
"world"
);
57
58
map<int, int>
m1;
59
60
m1[1] = 1;
61
m1[2] = 4;
62
m1[3] = 9;
63
64
JByteArrayWriter out;
65
66
out << i1 << x1 << s1 << v1 << l1 << m1;
67
68
DEBUG
(
"Buffer size "
<< out.size() << endl);
69
70
JByteArrayReader in(out.data(), out.size());
71
72
int
i2 = 0;
73
double
x2 = 0.0;
74
string
s2 =
""
;
75
76
vector<double>
v2;
77
78
list<string>
l2;
79
80
map<int, int>
m2;
81
82
in >> i2 >> x2 >> s2 >> v2 >> l2 >> m2;
83
84
ASSERT
(i1 == i2);
85
ASSERT
(x1 == x2);
86
ASSERT
(s1 == s2);
87
ASSERT
(v1 == v2);
88
ASSERT
(l1 == l2);
89
ASSERT
(m1 == m2);
90
91
return
0;
92
}
93
JMessage.hh
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition:
JMessage.hh:90
std::vector< double >
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition:
JAAnetToolkit.hh:37
debug
int debug
debug level
Definition:
JSirene.cc:59
JSTDIO.hh
JStreamToolkit.hh
std::map
Definition:
JSTDTypes.hh:16
JParser.hh
JByteArrayIO.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1954
DEBUG
#define DEBUG(A)
Message macros.
Definition:
JMessage.hh:62
std
Definition:
jaanetDictionary.h:36
main
int main(int argc, char **argv)
Definition:
JByteArrayIO.cc:23
std::list
Definition:
JSTDTypes.hh:24
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
Generated by
1.8.16