Jpp test-rotations-new
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
9#include "JSystem/JStat.hh"
12
13#include "Jeep/JComment.hh"
15
16
17/**
18 * \file
19 *
20 * Container I/O.
21 * \author mdejong
22 */
23namespace JEEP {}
24namespace JPP { using namespace JEEP; }
25
26namespace JEEP {
27
29
30
31 /**
32 * Auxiliary wrapper for I/O of container with optional comment (see JComment).
33 *
34 * When used in conjunction with the command line parser JPARSER::JParser, \n
35 * the value at the corresponding option can contain data or be the name of a file.\n
36 * The I/O of the actual container is handled via the auxiliary methods that are part of JStreamToolkit.hh.
37 */
38 template<class JContainer_t>
39 struct JContainer :
40 public JContainer_t,
41 public JObjectStreamIO< JContainer<JContainer_t> >
42 {
43 typedef JContainer_t container_type;
44
45
46 /**
47 * Read container from input.
48 *
49 * \param in input stream
50 * \param container container
51 * \return input stream
52 */
53 friend inline std::istream& operator>>(std::istream& in, JContainer& container)
54 {
55 using namespace JPP;
56
57 JStringStream is(in);
58
59 if (getFileStatus(is.str().c_str())) {
60 is.load();
61 }
62
63 is >> container.comment;
64
65 readObject(is, static_cast<container_type&>(container));
66
67 return in;
68 }
69
70
71 /**
72 * Write container to output.
73 *
74 * \param out output stream
75 * \param container container
76 * \return output stream
77 */
78 friend inline std::ostream& operator<<(std::ostream& out, const JContainer& container)
79 {
80 using namespace std;
81 using namespace JPP;
82
83 out << container.comment;
84
85 writeObject(out, "", static_cast<const container_type&>(container), '\n');
86
87 return out;
88 }
89
91 };
92}
93
94#endif
File status.
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
void load()
Load data from file with name corresponding to current contents.
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:42
friend std::istream & operator>>(std::istream &in, JContainer &container)
Read container from input.
Definition JContainer.hh:53
friend std::ostream & operator<<(std::ostream &out, const JContainer &container)
Write container to output.
Definition JContainer.hh:78
JContainer_t container_type
Definition JContainer.hh:43
Auxiliary base class for storing and loading a single object to and from an ASCII file,...