Jpp  16.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
10 #include "JLang/JObjectStreamIO.hh"
11 #include "JLang/JStringStream.hh"
12 
13 #include "Jeep/JComment.hh"
14 #include "Jeep/JStreamToolkit.hh"
15 
16 
17 /**
18  * \file
19  *
20  * Container I/O.
21  * \author mdejong
22  */
23 namespace JEEP {}
24 namespace JPP { using namespace JEEP; }
25 
26 namespace 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
friend std::istream & operator>>(std::istream &in, JContainer &container)
Read container from input.
Definition: JContainer.hh:53
is
Definition: JDAQCHSM.chsm:167
std::istream & readObject(std::istream &in, T &object)
Stream input of object.
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition: JContainer.hh:39
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
Auxiliary class for comment.
Definition: JComment.hh:41
JComment comment
Definition: JContainer.hh:90
JContainer_t container_type
Definition: JContainer.hh:43
Auxiliary base class for storing and loading a single object to and from an ASCII file...
friend std::ostream & operator<<(std::ostream &out, const JContainer &container)
Write container to output.
Definition: JContainer.hh:78
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:42
File status.
std::ostream & writeObject(std::ostream &out, const T &object)
Stream output of object.