Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JStreamObjectOutput.hh
Go to the documentation of this file.
1#ifndef __JLANG__JSTREAMOBJECTOUTPUT__
2#define __JLANG__JSTREAMOBJECTOUTPUT__
3
4#include <string>
5#include <ostream>
6
8#include "JLang/JTypeList.hh"
9#include "JLang/JNullType.hh"
10
11
12/**
13 * \author mdejong
14 */
15
16namespace JLANG {}
17namespace JPP { using namespace JLANG; }
18
19namespace JLANG {
20
21
22 /**
23 * Template implementation of stream output for single data type.
24 *
25 * This class implements the JLANG::JObjectOutput interface.
26 */
27 template<class T>
29 public virtual JObjectOutput<T>
30 {
31 public:
32 /**
33 * Constructor.
34 *
35 * \param out output stream
36 * \param sep token separator
37 */
38 JStreamObjectOutput(std::ostream& out,
39 const std::string& sep = "") :
40 __out(out),
41 __sep(sep)
42 {}
43
44
45 /**
46 * Object output.
47 *
48 * \param object object
49 * \return true if OK; else false
50 */
51 virtual bool put(const T& object) override
52 {
53 __out << object << __sep;
54
55 return (bool) __out;
56 }
57
58
59 /**
60 * Get token separator.
61 *
62 * \return separator
63 */
64 const std::string& getSeparator() const
65 {
66 return this->__sep;
67 }
68
69
70 /**
71 * Set token separator.
72 *
73 * \param sep separator
74 */
75 void setSeparator(const std::string& sep)
76 {
77 this->__sep = sep;
78 }
79
80 private:
81 std::ostream& __out;
82 std::string __sep;
83 };
84
85
86 /**
87 * Template specialisationimplementation of stream object output for multiple data types.
88 *
89 * This class recursively implements the JLANG::JObjectOutput interface
90 * for all data types by deriving from:
91 * - JStreamObjectOutput<JHead_t>; and
92 * - JStreamObjectOutput<JTail_t>.
93 */
94 template<class JHead_t, class JTail_t>
95 class JStreamObjectOutput< JTypeList<JHead_t, JTail_t> > :
96 public virtual JObjectOutput< JTypeList<JHead_t, JTail_t> >,
97 public JStreamObjectOutput<JHead_t>,
98 public JStreamObjectOutput<JTail_t>
99
100 {
101 public:
102
103 using JStreamObjectOutput<JHead_t>::put;
104 using JStreamObjectOutput<JTail_t>::put;
105
106
107 /**
108 * Constructor.
109 *
110 * \param out output stream
111 * \param sep token separator
112 */
113 JStreamObjectOutput(std::ostream& out,
114 const std::string& sep = "") :
115 JStreamObjectOutput<JHead_t>(out, sep),
116 JStreamObjectOutput<JTail_t>(out, sep)
117 {}
118
119
120 /**
121 * Set token separator.
122 *
123 * \param sep separator
124 */
130 };
131
132
133 /**
134 * Terminator class of recursive JStreamObjectOutput class.
135 */
136 template<class JHead_t>
138 public JStreamObjectOutput<JHead_t>
139 {
140 public:
141
142 using JStreamObjectOutput<JHead_t>::put;
143
144
145 /**
146 * Constructor.
147 *
148 * \param out output stream
149 * \param sep token separator
150 */
151 JStreamObjectOutput(std::ostream& out,
152 const std::string& sep = "") :
153 JStreamObjectOutput<JHead_t>(out, sep)
154 {}
155 };
156}
157
158#endif
Template interface of object output for single data type.
JStreamObjectOutput(std::ostream &out, const std::string &sep="")
Constructor.
JStreamObjectOutput(std::ostream &out, const std::string &sep="")
Constructor.
void setSeparator(const std::string &sep)
Set token separator.
Template implementation of stream output for single data type.
void setSeparator(const std::string &sep)
Set token separator.
virtual bool put(const T &object) override
Object output.
const std::string & getSeparator() const
Get token separator.
JStreamObjectOutput(std::ostream &out, const std::string &sep="")
Constructor.
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for no type definition.
Definition JNullType.hh:19
Type list.
Definition JTypeList.hh:23