Jpp  15.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTemplateIO.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <sstream>
4 
5 #include "JLang/JEquals.hh"
6 #include "JLang/JMultiEquals.hh"
9 
10 #include "Jeep/JParser.hh"
11 #include "Jeep/JMessage.hh"
12 
13 
14 namespace {
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  */
140 int 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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
Template definition of auxiliary base class for composite data types which derive from one or more ba...
Template definition of auxiliary base class for data structures composed of multiple base classes wit...
Definition: JMultiEquals.hh:32
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
Template definition of auxiliary base class for composite data types which derive from one or more ba...
#define FATAL(A)
Definition: JMessage.hh:67
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition: JHead.hh:1618
then JCalibrateToT a
Definition: JTuneHV.sh:116
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
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
bool equals(const JFirst_t &first, const JSecond_t &second, const double precision=std::numeric_limits< double >::min())
Check equality.
Definition: JMathToolkit.hh:86
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