Jpp 19.3.0-rc.2
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 <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 24 of file JByteArrayIO.cc.

25{
26 using namespace std;
27 using namespace JPP;
28
29 int debug;
30
31 try {
32
33 JParser<> zap("Example program to test byte array I/O.");
34
35 zap['d'] = make_field(debug) = 3;
36
37 zap(argc, argv);
38 }
39 catch(const exception &error) {
40 FATAL(error.what() << endl);
41 }
42
43
44 int i1 = 999;
45 double x1 = 123.456;
46 string s1 = "hello world";
47 JObjectID o1 = 999;
48
50
51 for (double x = 0.0; x < 10.5; x += 1.0) {
52 v1.push_back(x);
53 }
54
55 list<string> l1;
56
57 l1.push_back("hello");
58 l1.push_back("world");
59
61
62 m1[1] = 1;
63 m1[2] = 4;
64 m1[3] = 9;
65
67
68 out << i1 << x1 << s1 << v1 << l1 << m1 << o1;
69
70 DEBUG("Buffer size " << out.size() << endl);
71
72 JByteArrayReader in(out.data(), out.size());
73
74 int i2 = 0;
75 double x2 = 0.0;
76 string s2 = "";
77 JObjectID o2 = -1;
78
80
81 list<string> l2;
82
84
85 in >> i2 >> x2 >> s2 >> v2 >> l2 >> m2 >> o2;
86
87 ASSERT(i1 == i2);
88 ASSERT(x1 == x2);
89 ASSERT(s1 == s2);
90 ASSERT(v1 == v2);
91 ASSERT(l1 == l2);
92 ASSERT(m1 == m2);
93 ASSERT(o1 == o2);
94
95 return 0;
96}
#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:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Byte array binary input.
Byte array binary output.
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).