Jpp  18.2.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
7 #include "JLang/JObjectOutput.hh"
8 #include "JLang/JTypeList.hh"
9 #include "JLang/JNullType.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JLANG {}
17 namespace JPP { using namespace JLANG; }
18 
19 namespace 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;
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 
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  */
125  void setSeparator(const std::string& sep)
126  {
129  }
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 
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
void setSeparator(const std::string &sep)
Set token separator.
JStreamObjectOutput(std::ostream &out, const std::string &sep="")
Constructor.
void setSeparator(const std::string &sep)
Set token separator.
Type list.
Definition: JTypeList.hh:22
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Auxiliary class for no type definition.
Definition: JNullType.hh:19
then awk string
JStreamObjectOutput(std::ostream &out, const std::string &sep="")
Constructor.
Template implementation of stream output for single data type.
Template interface of object output for single data type.
const std::string & getSeparator() const
Get token separator.
JStreamObjectOutput(std::ostream &out, const std::string &sep="")
Constructor.
virtual bool put(const T &object) override
Object output.