Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JContainer.hh
Go to the documentation of this file.
1#ifndef __JEEP__JCONTAINER__
2#define __JEEP__JCONTAINER__
3
4#include <istream>
5#include <ostream>
6#include <fstream>
7#include <iomanip>
8
11
12#include "Jeep/JComment.hh"
14
15
16/**
17 * \file
18 *
19 * Container I/O.
20 * \author mdejong
21 */
22namespace JEEP {}
23namespace JPP { using namespace JEEP; }
24
25namespace JEEP {
26
28
29
30 /**
31 * Auxiliary wrapper for I/O of container with optional comment (see JComment).
32 *
33 * When used in conjunction with the command line parser JPARSER::JParser, \n
34 * the value at the corresponding option can contain data or be the name of a file.\n
35 * The I/O of the actual container is handled via the auxiliary methods that are part of JStreamToolkit.hh.
36 */
37 template<class JContainer_t, class container_type = JContainer_t>
38 struct JContainer :
39 public JContainer_t,
40 public JObjectStreamIO< JContainer<JContainer_t> >
41 {
42 //typedef JContainer_t container_type;
43
44
45 /**
46 * Read container from input.
47 *
48 * \param in input stream
49 * \param container container
50 * \return input stream
51 */
52 friend inline std::istream& operator>>(std::istream& in, JContainer& container)
53 {
54 using namespace JPP;
55
56 JStringStream is(in);
57
58 is >> container.comment;
59
60 readObject(is, static_cast<container_type&>(container));
61
62 return in;
63 }
64
65
66 /**
67 * Write container to output.
68 *
69 * \param out output stream
70 * \param container container
71 * \return output stream
72 */
73 friend inline std::ostream& operator<<(std::ostream& out, const JContainer& container)
74 {
75 using namespace std;
76 using namespace JPP;
77
78 out << container.comment;
79
80 writeObject(out, "", static_cast<const container_type&>(container), '\n');
81
82 return out;
83 }
84
86 };
87}
88
89#endif
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
General puprpose classes and methods.
std::ostream & writeObject(std::ostream &out, const T &object)
Stream output of object.
std::istream & readObject(std::istream &in, T &object)
Stream input of object.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for comment.
Definition JComment.hh:43
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition JContainer.hh:41
friend std::istream & operator>>(std::istream &in, JContainer &container)
Read container from input.
Definition JContainer.hh:52
friend std::ostream & operator<<(std::ostream &out, const JContainer &container)
Write container to output.
Definition JContainer.hh:73
Auxiliary base class for storing and loading a single object to and from an ASCII file,...