Jpp 21.0.1
the software that should make you happy
Loading...
Searching...
No Matches
JByteArrayIO.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <array>
6#include <vector>
7#include <map>
8#include <list>
9
10#include "JIO/JByteArrayIO.hh"
11#include "JIO/JSTDIO.hh"
12#include "JLang/JObjectID.hh"
13
15#include "Jeep/JParser.hh"
16#include "Jeep/JMessage.hh"
17
18
19/**
20 * \file
21 *
22 * Example program to test JIO::JByteArrayReader and JIO::JByteArrayWriter.
23 * \author mdejong
24 */
25int main(int argc, char **argv)
26{
27 using namespace std;
28 using namespace JPP;
29
30 int debug;
31
32 try {
33
34 JParser<> zap("Example program to test byte array I/O.");
35
36 zap['d'] = make_field(debug) = 3;
37
38 zap(argc, argv);
39 }
40 catch(const exception &error) {
41 FATAL(error.what() << endl);
42 }
43
44
45 int i1 = 999;
46 double x1 = 123.456;
47 string s1 = "hello world";
48 JObjectID<void> o1 = 999;
49
51 array<double, 5> a1 = { 1.0, 2.0, 3.0, 4.0, 5.0 };
52
53 for (double x = 0.0; x < 10.5; x += 1.0) {
54 v1.push_back(x);
55 }
56
57 list<string> l1;
58
59 l1.push_back("hello");
60 l1.push_back("world");
61
63
64 m1[1] = 1;
65 m1[2] = 4;
66 m1[3] = 9;
67
69
70 out << i1 << x1 << s1 << v1 << a1 << l1 << m1 << o1;
71
72 DEBUG("Buffer size " << out.size() << endl);
73
74 JByteArrayReader in(out.data(), out.size());
75
76 int i2 = 0;
77 double x2 = 0.0;
78 string s2 = "";
79 JObjectID<void> o2 = -1;
80
82
84
85 list<string> l2;
86
88
89 in >> i2 >> x2 >> s2 >> v2 >> a2 >> l2 >> m2 >> o2;
90
91 ASSERT(i1 == i2);
92 ASSERT(x1 == x2);
93 ASSERT(s1 == s2);
94 ASSERT(v1 == v2);
95 ASSERT(a1 == a2);
96 ASSERT(l1 == l2);
97 ASSERT(m1 == m2);
98 ASSERT(o1 == o2);
99
100 return 0;
101}
102
General purpose messaging.
#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:74
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2107
STD extensions for binary I/O.
Byte array binary input.
Byte array binary output.
Utility class to parse command line options.
Definition JParser.hh:1664
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).