Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
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 "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

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file JByteArrayIO.cc.

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 }
Utility class to parse command line options.
Definition: JParser.hh:1493
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
int debug
debug level
Definition: JSirene.cc:61
#define FATAL(A)
Definition: JMessage.hh:67
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62