Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSTDObjectWriter.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <vector>
6 #include <set>
7 
9 
10 #include "Jeep/JParser.hh"
11 #include "Jeep/JMessage.hh"
12 
13 namespace {
14 
15  /**
16  * Check if two ranges are equal.
17  *
18  * \param __begin1 begin of first data set
19  * \param __end1 end of first data set
20  * \param __begin2 begin of second data set
21  * \param __end2 end of second data set
22  * \return true if two data sets are equals; else false
23  */
24  template<class U, class V>
25  inline bool equals(U __begin1, U __end1,
26  V __begin2, V __end2)
27  {
28  U p = __begin1;
29  V q = __begin2;
30 
31  for ( ; p != __end1 && q != __end2; ++p, ++q) {
32  if (*p != *q) {
33  return false;
34  }
35  }
36 
37  return (p == __end1 && q == __end2);
38  }
39 
40  template<class T>
41  void print(std::ostream& out, int debug, const char* title, T __begin, T __end)
42  {
43  using namespace std;
44  using namespace JPP;
45 
46  if (debug >= debug_t) {
47  out << title << endl;
48  copy(__begin, __end, ostream_iterator<typename T::value_type>(out, " "));
49  out << endl;
50  }
51  }
52 }
53 
54 
55 /**
56  * \file
57  *
58  * Example program to test JLANG::JSTDObjectWriter class.
59  * \author mdejong
60  */
61 int main(int argc, char **argv)
62 {
63  using namespace std;
64 
65  int debug;
66 
67  try {
68 
69  JParser<> zap("Example program to test object output using STD containers.");
70 
71  zap['d'] = make_field(debug) = 3;
72 
73  zap(argc, argv);
74  }
75  catch(const exception &error) {
76  FATAL(error.what() << endl);
77  }
78 
79 
80  using namespace JPP;
81 
83 
84  data.push_back(3.0);
85  data.push_back(2.0);
86  data.push_back(1.0);
87 
88  print(cout, debug, "data", data.begin(), data.end());
89 
90  {
91  typedef vector<double> buffer_type;
92 
93  buffer_type buffer;
94 
95  JSTDObjectWriter<double> out(buffer);
96 
97  for (vector<double>::const_iterator i = data.begin(); i != data.end(); ++i) {
98  out.put(*i);
99  }
100 
101  print(cout, debug, "JSTDObjectWriter<double>(vector<double>&);", buffer.begin(), buffer.end());
102 
103  ASSERT(equals(data.begin(), data.end(),
104  buffer.begin(), buffer.end()));
105  }
106  {
107  typedef set<double> buffer_type;
108 
109  buffer_type buffer;
110 
111  JSTDObjectWriter<double> out(buffer);
112 
113  for (vector<double>::const_iterator i = data.begin(); i != data.end(); ++i) {
114  out.put(*i);
115  }
116 
117  print(cout, debug, "JSTDObjectWriter<double>(set<double>&);", buffer.begin(), buffer.end());
118 
119  ASSERT(equals(data.rbegin(), data.rend(),
120  buffer.begin(), buffer.end()));
121  }
122 
123  return 0;
124 }
Utility class to parse command line options.
Definition: JParser.hh:1514
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
do set_variable OUTPUT_DIRECTORY $WORKDIR T
print
Definition: JConvertDusj.sh:44
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
bool equals(const JFirst_t &first, const JSecond_t &second, const double precision=std::numeric_limits< double >::min())
Check equality.
Definition: JMathToolkit.hh:86
int debug
debug level