Jpp 21.0.1
the software that should make you happy
Loading...
Searching...
No Matches
JByteArrayIO.cc File Reference

Example program to test JIO::JByteArrayReader and JIO::JByteArrayWriter. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <array>
#include <vector>
#include <map>
#include <list>
#include "JIO/JByteArrayIO.hh"
#include "JIO/JSTDIO.hh"
#include "JLang/JObjectID.hh"
#include "Jeep/JStreamToolkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test JIO::JByteArrayReader and JIO::JByteArrayWriter.

Author
mdejong

Definition in file JByteArrayIO.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 25 of file JByteArrayIO.cc.

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}
#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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2107
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).