Jpp  16.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRootStreamObjectOutput.hh
Go to the documentation of this file.
1 #ifndef __JROOT__JSTREAMOBJECTOUTPUT__
2 #define __JROOT__JSTREAMOBJECTOUTPUT__
3 
4 #include <string>
5 
6 #include "JLang/JObjectOutput.hh"
7 #include "JLang/JTypeList.hh"
8 #include "JLang/JNullType.hh"
9 
10 #include "JROOT/JRootStreamer.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JROOT {}
18 namespace JPP { using namespace JROOT; }
19 
20 namespace JROOT {
21 
23  using JLANG::JTypeList;
24  using JLANG::JNullType;
25 
26 
27  /**
28  * Template implementation of stream output for single data type based on ROOT dictionary.
29  *
30  * This class implements the JLANG::JObjectOutput interface.
31  */
32  template<class T>
34  public virtual JObjectOutput<T>
35  {
36  public:
37  /**
38  * Constructor.
39  *
40  * \param out output stream
41  * \param sep token separator
42  */
44  const std::string& sep = "") :
45  __out(out),
46  __sep(sep)
47  {}
48 
49 
50  /**
51  * Object output.
52  *
53  * \param object object
54  * \return true if OK; else false
55  */
56  virtual bool put(const T& object) override
57  {
58  __out.putObject(object) << __sep;
59 
60  return (bool) __out;
61  }
62 
63 
64  /**
65  * Get token separator.
66  *
67  * \return separator
68  */
69  const std::string& getSeparator() const
70  {
71  return this->__sep;
72  }
73 
74 
75  /**
76  * Set token separator.
77  *
78  * \param sep separator
79  */
80  void setSeparator(const std::string& sep)
81  {
82  this->__sep = sep;
83  }
84 
85  private:
87  std::string __sep;
88  };
89 
90 
91  /**
92  * Template specialisationimplementation of stream object output for multiple data types.
93  *
94  * This class recursively implements the JLANG::JObjectOutput interface
95  * for all data types by deriving from:
96  * - JRootStreamObjectOutput<JHead_t>; and
97  * - JRootStreamObjectOutput<JTail_t>.
98  */
99  template<class JHead_t, class JTail_t>
100  class JRootStreamObjectOutput< JTypeList<JHead_t, JTail_t> > :
101  public virtual JObjectOutput< JTypeList<JHead_t, JTail_t> >,
102  public JRootStreamObjectOutput<JHead_t>,
103  public JRootStreamObjectOutput<JTail_t>
104 
105  {
106  public:
107 
110 
111 
112  /**
113  * Constructor.
114  *
115  * \param out output stream
116  * \param sep token separator
117  */
119  const std::string& sep = "") :
120  JRootStreamObjectOutput<JHead_t>(out, sep),
121  JRootStreamObjectOutput<JTail_t>(out, sep)
122  {}
123 
124 
125  /**
126  * Set token separator.
127  *
128  * \param sep separator
129  */
130  void setSeparator(const std::string& sep)
131  {
134  }
135  };
136 
137 
138  /**
139  * Terminator class of recursive JRootStreamObjectOutput class.
140  */
141  template<class JHead_t>
143  public JRootStreamObjectOutput<JHead_t>
144  {
145  public:
146 
148 
149 
150  /**
151  * Constructor.
152  *
153  * \param out output stream
154  * \param sep token separator
155  */
157  const std::string& sep = "") :
158  JRootStreamObjectOutput<JHead_t>(out, sep)
159  {}
160  };
161 }
162 
163 #endif
const std::string & getSeparator() const
Get token separator.
Implementation for ASCII output of objects with ROOT dictionary.
JRootStreamObjectOutput(JRootWriter &out, const std::string &sep="")
Constructor.
JRootStreamObjectOutput(JRootWriter &out, const std::string &sep="")
Constructor.
Template implementation of stream output for single data type based on ROOT dictionary.
virtual bool put(const T &object) override
Object output.
JRootStreamObjectOutput(JRootWriter &out, const std::string &sep="")
Constructor.
JRootWriter & putObject(const T &object)
Write object.
Type list.
Definition: JTypeList.hh:22
ASCII I/O of objects with ROOT dictionary.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Auxiliary class for no type definition.
Definition: JNullType.hh:19
void setSeparator(const std::string &sep)
Set token separator.
Template interface of object output for single data type.
void setSeparator(const std::string &sep)
Set token separator.