Jpp  15.0.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JStreamToolkit.hh
Go to the documentation of this file.
1 #ifndef __JEEP__JSTREAMTOOLKIT__
2 #define __JEEP__JSTREAMTOOLKIT__
3 
4 #include <istream>
5 #include <ostream>
6 #include <iterator>
7 
8 #include "JLang/JSTDTypes.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JEEP {}
16 namespace JPP { using namespace JEEP; }
17 
18 namespace JEEP {
19 
20  /**
21  * Stream input of object.
22  *
23  * \param in input stream
24  * \param object object
25  * \return input stream
26  */
27  template<class T>
28  inline std::istream& readObject(std::istream& in, T& object)
29  {
30  return in >> object;
31  }
32 
33 
34  /**
35  * Stream output of object.
36  *
37  * \param out output stream
38  * \param object object
39  * \return output stream
40  */
41  template<class T>
42  inline std::ostream& writeObject(std::ostream& out, const T& object)
43  {
44  return out << object;
45  }
46 
47 
48  /**
49  * Stream output of object.
50  *
51  * \param out output stream
52  * \param prefix prefix
53  * \param object object
54  * \param postfix postfix
55  * \return output stream
56  */
57  template<class T>
58  inline std::ostream& writeObject(std::ostream& out,
59  const char* prefix,
60  const T& object,
61  const char postfix)
62  {
63  return out << prefix << object << postfix;
64  }
65 
66 
67  /**
68  * Template specialisation of method readObject() for std::pair.
69  *
70  * \param in input stream
71  * \param object object
72  * \return input stream
73  */
74  template<class JFirst_t, class JSecond_t>
75  inline std::istream& readObject(std::istream& in, std::pair<JFirst_t, JSecond_t>& object)
76  {
77  readObject(in, object.first);
78  readObject(in, object.second);
79 
80  return in;
81  }
82 
83 
84  /**
85  * Template specialisation of method writeObject() for std::pair.
86  *
87  * \param out output stream
88  * \param object object
89  * \return output stream
90  */
91  template<class JFirst_t, class JSecond_t>
92  inline std::ostream& writeObject(std::ostream& out, const std::pair<JFirst_t, JSecond_t>& object)
93  {
94  writeObject(out, object.first);
95  writeObject(out, ' ');
96  writeObject(out, object.second);
97 
98  return out;
99  }
100 
101 
102  /**
103  * Template specialisation of method writeObject() for std::pair.
104  *
105  * \param out output stream
106  * \param prefix prefix
107  * \param object object
108  * \param postfix postfix
109  * \return output stream
110  */
111  template<class JFirst_t, class JSecond_t>
112  inline std::ostream& writeObject(std::ostream& out,
113  const char* prefix,
114  const std::pair<JFirst_t, JSecond_t>& object,
115  const char postfix)
116  {
117  writeObject(out, prefix);
118  writeObject(out, object.first);
119  writeObject(out, ' ');
120  writeObject(out, object.second);
121  writeObject(out, postfix);
122 
123  return out;
124  }
125 
126 
127  /**
128  * Template specialisation of method readObject() for std::vector.
129  *
130  * \param in input stream
131  * \param object object
132  * \return input stream
133  */
134  template<class JElement_t, class JAllocator_t>
135  inline std::istream& readObject(std::istream& in, std::vector<JElement_t, JAllocator_t>& object)
136  {
137  for (JElement_t element; readObject(in, element); ) {
138  object.push_back(element);
139  }
140 
141  return in;
142  }
143 
144 
145  /**
146  * Template specialisation of method writeObject() for std::vector.
147  *
148  * \param out output stream
149  * \param object object
150  * \return output stream
151  */
152  template<class JElement_t, class JAllocator_t>
153  inline std::ostream& writeObject(std::ostream& out, const std::vector<JElement_t, JAllocator_t>& object)
154  {
155  for (typename std::vector<JElement_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
156  writeObject(out, ' ');
157  writeObject(out, *i);
158  }
159 
160  return out;
161  }
162 
163 
164  /**
165  * Template specialisation of method writeObject() for std::vector.
166  *
167  * \param out output stream
168  * \param prefix prefix
169  * \param object object
170  * \param postfix postfix
171  * \return output stream
172  */
173  template<class JElement_t, class JAllocator_t>
174  inline std::ostream& writeObject(std::ostream& out,
175  const char* prefix,
177  const char postfix)
178  {
179  for (typename std::vector<JElement_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
180  writeObject(out, prefix, *i, postfix);
181  }
182 
183  return out;
184  }
185 
186 
187  /**
188  * Template specialisation of method readObject() for std::list.
189  *
190  * \param in input stream
191  * \param object object
192  * \return input stream
193  */
194  template<class JElement_t, class JAllocator_t>
195  inline std::istream& readObject(std::istream& in, std::list<JElement_t, JAllocator_t>& object)
196  {
197  for (JElement_t element; readObject(in, element); ) {
198  object.push_back(element);
199  }
200 
201  return in;
202  }
203 
204 
205  /**
206  * Template specialisation of method writeObject() for std::list.
207  *
208  * \param out output stream
209  * \param object object
210  * \return output stream
211  */
212  template<class JElement_t, class JAllocator_t>
213  inline std::ostream& writeObject(std::ostream& out, const std::list<JElement_t, JAllocator_t>& object)
214  {
215  for (typename std::list<JElement_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
216  writeObject(out, ' ');
217  writeObject(out, *i);
218  }
219 
220  return out;
221  }
222 
223 
224  /**
225  * Template specialisation of method writeObject() for std::list.
226  *
227  * \param out output stream
228  * \param prefix prefix
229  * \param object object
230  * \param postfix postfix
231  * \return output stream
232  */
233  template<class JElement_t, class JAllocator_t>
234  inline std::ostream& writeObject(std::ostream& out,
235  const char* prefix,
237  const char postfix)
238  {
239  for (typename std::list<JElement_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
240  writeObject(out, prefix, *i, postfix);
241  }
242 
243  return out;
244  }
245 
246 
247  /**
248  * Template specialisation of method readObject() for std::set.
249  *
250  * \param in input stream
251  * \param object object
252  * \return input stream
253  */
254  template<class JElement_t, class JComparator_t, class JAllocator_t>
255  inline std::istream& readObject(std::istream& in, std::set<JElement_t, JComparator_t, JAllocator_t>& object)
256  {
257  for (JElement_t element; readObject(in, element); ) {
258 
260 
261  if (!result.second) {
262  object.erase (result.first);
263  object.insert(element);
264  }
265  }
266 
267  return in;
268  }
269 
270 
271  /**
272  * Template specialisation of method writeObject() for std::set.
273  *
274  * \param out output stream
275  * \param object object
276  * \return output stream
277  */
278  template<class JElement_t, class JComparator_t, class JAllocator_t>
279  inline std::ostream& writeObject(std::ostream& out, const std::set<JElement_t, JComparator_t, JAllocator_t>& object)
280  {
281  for (typename std::set<JElement_t, JComparator_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
282  writeObject(out, ' ');
283  writeObject(out, *i);
284  }
285 
286  return out;
287  }
288 
289 
290  /**
291  * Template specialisation of method writeObject() for std::set.
292  *
293  * \param out output stream
294  * \param prefix prefix
295  * \param object object
296  * \param postfix postfix
297  * \return output stream
298  */
299  template<class JElement_t, class JComparator_t, class JAllocator_t>
300  inline std::ostream& writeObject(std::ostream& out,
301  const char* prefix,
303  const char postfix)
304  {
305  for (typename std::set<JElement_t, JComparator_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
306  writeObject(out, prefix, *i, postfix);
307  }
308 
309  return out;
310  }
311 
312 
313  /**
314  * Template specialisation of method readObject() for std::multiset.
315  *
316  * \param in input stream
317  * \param object object
318  * \return input stream
319  */
320  template<class JElement_t, class JComparator_t, class JAllocator_t>
321  inline std::istream& readObject(std::istream& in, std::multiset<JElement_t, JComparator_t, JAllocator_t>& object)
322  {
323  for (JElement_t element; readObject(in, element); ) {
324  object.insert(element);
325  }
326 
327  return in;
328  }
329 
330 
331  /**
332  * Template specialisation of method writeObject() for std::multiset.
333  *
334  * \param out output stream
335  * \param object object
336  * \return output stream
337  */
338  template<class JElement_t, class JComparator_t, class JAllocator_t>
339  inline std::ostream& writeObject(std::ostream& out, const std::multiset<JElement_t, JComparator_t, JAllocator_t>& object)
340  {
341  for (typename std::multiset<JElement_t, JComparator_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
342  writeObject(out, ' ');
343  writeObject(out, *i);
344  }
345 
346  return out;
347  }
348 
349 
350  /**
351  * Template specialisation of method writeObject() for std::multiset.
352  *
353  * \param out output stream
354  * \param prefix prefix
355  * \param object object
356  * \param postfix postfix
357  * \return output stream
358  */
359  template<class JElement_t, class JComparator_t, class JAllocator_t>
360  inline std::ostream& writeObject(std::ostream& out,
361  const char* prefix,
363  const char postfix)
364  {
365  for (typename std::multiset<JElement_t, JComparator_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
366  writeObject(out, prefix, *i, postfix);
367  }
368 
369  return out;
370  }
371 
372 
373  /**
374  * Template specialisation of method readObject() for std::map.
375  *
376  * \param in input stream
377  * \param object object
378  * \return input stream
379  */
380  template<class JKey_t, class JValue_t, class JComparator_t, class JAllocator_t>
381  inline std::istream& readObject(std::istream& in, std::map<JKey_t, JValue_t, JComparator_t, JAllocator_t>& object)
382  {
383  for (std::pair<JKey_t, JValue_t> element; readObject(in, element); ) {
384 
386 
387  if (!result.second) {
388  result.first->second = element.second;
389  }
390  }
391 
392  return in;
393  }
394 
395 
396  /**
397  * Template specialisation of method writeObject() for std::map.
398  *
399  * \param out output stream
400  * \param object object
401  * \return output stream
402  */
403  template<class JKey_t, class JValue_t, class JComparator_t, class JAllocator_t>
404  inline std::ostream& writeObject(std::ostream& out, const std::map<JKey_t, JValue_t, JComparator_t, JAllocator_t>& object)
405  {
406  for (typename std::map<JKey_t, JValue_t, JComparator_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
407  writeObject(out, ' ');
408  writeObject(out, *i);
409  }
410 
411  return out;
412  }
413 
414 
415  /**
416  * Template specialisation of method writeObject() for std::map.
417  *
418  * \param out output stream
419  * \param prefix prefix
420  * \param object object
421  * \param postfix postfix
422  * \return output stream
423  */
424  template<class JKey_t, class JValue_t, class JComparator_t, class JAllocator_t>
425  inline std::ostream& writeObject(std::ostream& out,
426  const char* prefix,
428  const char postfix)
429  {
430  for (typename std::map<JKey_t, JValue_t, JComparator_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
431  writeObject(out, prefix, *i, postfix);
432  }
433 
434  return out;
435  }
436 
437 
438  /**
439  * Template specialisation of method readObject() for std::multimap.
440  *
441  * \param in input stream
442  * \param object object
443  * \return input stream
444  */
445  template<class JKey_t, class JValue_t, class JComparator_t, class JAllocator_t>
447  {
448  for (std::pair<JKey_t, JValue_t> element; readObject(in, element); ) {
449  object.insert(element);
450  }
451 
452  return in;
453  }
454 
455 
456  /**
457  * Template specialisation of method writeObject() for std::multimap.
458  *
459  * \param out output stream
460  * \param object object
461  * \return output stream
462  */
463  template<class JKey_t, class JValue_t, class JComparator_t, class JAllocator_t>
464  inline std::ostream& writeObject(std::ostream& out, const std::multimap<JKey_t, JValue_t, JComparator_t, JAllocator_t>& object)
465  {
466  for (typename std::multimap<JKey_t, JValue_t, JComparator_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
467  writeObject(out, ' ');
468  writeObject(out, *i);
469  }
470 
471  return out;
472  }
473 
474 
475  /**
476  * Template specialisation of method writeObject() for std::multimap.
477  *
478  * \param out output stream
479  * \param prefix prefix
480  * \param object object
481  * \param postfix postfix
482  * \return output stream
483  */
484  template<class JKey_t, class JValue_t, class JComparator_t, class JAllocator_t>
485  inline std::ostream& writeObject(std::ostream& out,
486  const char* prefix,
488  const char postfix)
489  {
490  for (typename std::multimap<JKey_t, JValue_t, JComparator_t, JAllocator_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
491  writeObject(out, prefix, *i, postfix);
492  }
493 
494  return out;
495  }
496 
497 
498  /**
499  * Write array of objects.
500  *
501  * \param out output stream
502  * \param left left bracket
503  * \param right right bracket
504  * \param sep separator
505  * \param __begin begin of data
506  * \param __end end of data
507  * \return output stream
508  */
509  template<class T>
510  inline std::ostream& writeArray(std::ostream& out,
511  const char* left,
512  const char* right,
513  const char* sep,
514  T __begin,
515  T __end)
516  {
517  if (std::distance(__begin, __end) != 0) {
518 
519  out << left;
520 
521  T i = __begin;
522 
523  writeObject(out, *i);
524 
525  while (++i != __end) {
526 
527  out << sep;
528 
529  JEEP::writeObject(out, *i);
530  }
531 
532  out << right;
533  }
534 
535  return out;
536  }
537 }
538 #endif
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
std::istream & readObject(std::istream &in, T &object)
Stream input of object.
return result
Definition: JPolint.hh:727
do set_variable OUTPUT_DIRECTORY $WORKDIR T
std::ostream & writeArray(std::ostream &out, const char *left, const char *right, const char *sep, T __begin, T __end)
Write array of objects.
Forward declarations of STD containers.
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::ostream & writeObject(std::ostream &out, const T &object)
Stream output of object.