Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JTemplateIO.cc
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3#include <sstream>
4
5#include "JLang/JEquals.hh"
9
10#include "Jeep/JParser.hh"
11#include "Jeep/JMessage.hh"
12
13
14namespace {
15
16 using namespace JPP;
17
18
19 struct __A__ :
20 public JEquals<__A__>
21 {
22 __A__() :
23 value(0)
24 {}
25
26 __A__(int __value) :
27 value(__value)
28 {}
29
30 bool equals(const __A__& object) const
31 {
32 return this->value == object.value;
33 }
34
35 friend std::istream& operator>>(std::istream& in, __A__& object)
36 {
37 return in >> object.value;
38 }
39
40 friend std::ostream& operator<<(std::ostream& out, const __A__& object)
41 {
42 return out << object.value;
43 }
44
45 int value;
46 };
47
48 struct __B__ :
49 public JEquals<__B__>
50 {
51 __B__() :
52 value(0)
53 {}
54
55 __B__(int __value) :
56 value(__value)
57 {}
58
59 bool equals(const __B__& object) const
60 {
61 return this->value == object.value;
62 }
63
64 friend std::istream& operator>>(std::istream& in, __B__& object)
65 {
66 return in >> object.value;
67 }
68
69 friend std::ostream& operator<<(std::ostream& out, const __B__& object)
70 {
71 return out << object.value;
72 }
73
74 int value;
75 };
76
77
78 struct __C__ :
79 public JEquals<__C__>
80 {
81 __C__() :
82 value(0)
83 {}
84
85 __C__(int __value) :
86 value(__value)
87 {}
88
89 bool equals(const __C__& object) const
90 {
91 return this->value == object.value;
92 }
93
94 friend std::istream& operator>>(std::istream& in, __C__& object)
95 {
96 return in >> object.value;
97 }
98
99 friend std::ostream& operator<<(std::ostream& out, const __C__& object)
100 {
101 return out << object.value;
102 }
103
104 int value;
105 };
106
107 /**
108 * Composite data structure.
109 */
110 struct __D__ :
111 public __A__,
112 public __B__,
113 public __C__,
114 public JMultiEquals<__D__, JTYPELIST<__A__, __B__, __C__>::typelist>,
115 public JTemplateReader<std::istream, __D__, JTYPELIST<__A__, __B__, __C__>::typelist>,
116 public JTemplateWriter<std::ostream, __D__, JTYPELIST<__A__, __B__, __C__>::typelist>
117 {
118 __D__() :
119 __A__(),
120 __B__(),
121 __C__()
122 {}
123
124 __D__(const int a,
125 const int b,
126 const int c) :
127 __A__(a),
128 __B__(b),
129 __C__(c)
130 {}
131 };
132}
133
134/**
135 * \file
136 *
137 * Example program to test JLANG::JTemplateReader and JLANG::JTemplateWriter classes.
138 * \author mdejong
139 */
140int main(int argc, char **argv)
141{
142 using namespace std;
143
144 int debug;
145
146 try {
147
148 JParser<> zap("Example program to test template I/O.");
149
150 zap['d'] = make_field(debug) = 3;
151
152 zap(argc, argv);
153 }
154 catch(const exception &error) {
155 FATAL(error.what() << endl);
156 }
157
158 using namespace JPP;
159
160 const __D__ a(1,2,3);
161
162 {
163 stringstream io;
164
165 io << a;
166
167 __D__ b;
168
169 io >> b;
170
171 DEBUG("a = " << a << endl);
172 DEBUG("b = " << b << endl);
173
174 ASSERT(a == b);
175 }
176 {
178
179 stringstream io;
180
181 io << a;
182
183 for (int value, i = 0; io >> value; ++i) {
184
185 const int c = io.get();
186
187 ASSERT((i < 2 && c == (int) '|') ||
188 (i == 2 && c == EOF));
189 }
190 }
191
192 return 0;
193}
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition JHead.hh:1832
General purpose messaging.
#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
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
Utility class to parse command line options.
Definition JParser.hh:1698
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
const double a
bool equals(const JFirst_t &first, const JSecond_t &second, const double precision=std::numeric_limits< double >::min())
Check equality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Template definition of auxiliary base class for comparison of data structures.
Definition JEquals.hh:84
Template definition of auxiliary base class for data structures composed of multiple base classes wit...
Template definition of auxiliary base class for composite data types which derive from one or more ba...
Template definition of auxiliary base class for composite data types which derive from one or more ba...