Jpp  15.0.1-rc.1-highqe
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 #include "JLang/JObjectID.hh"
12 
13 #include "Jeep/JStreamToolkit.hh"
14 #include "Jeep/JParser.hh"
15 #include "Jeep/JMessage.hh"
16 
17 
18 /**
19  * \file
20  *
21  * Example program to test JIO::JByteArrayReader and JIO::JByteArrayWriter.
22  * \author mdejong
23  */
24 int main(int argc, char **argv)
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 
49  vector<double> v1;
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 
60  map<int, int> m1;
61 
62  m1[1] = 1;
63  m1[2] = 4;
64  m1[3] = 9;
65 
66  JByteArrayWriter out;
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 
79  vector<double> v2;
80 
81  list<string> l2;
82 
83  map<int, int> m2;
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 }
97 
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
STD extensions for binary I/O.