Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JTemplateWriter.hh
Go to the documentation of this file.
1#ifndef __JLANG__JTEMPLATEWRITER__
2#define __JLANG__JTEMPLATEWRITER__
3
4#include <ostream>
5
6#include "JLang/JNullType.hh"
7#include "JLang/JTypeList.hh"
8#include "JLang/JType.hh"
9
10
11/**
12 * \author mdejong
13 */
14
15namespace JLANG {}
16namespace JPP { using namespace JLANG; }
17
18namespace JLANG {
19
20 /**
21 * Template definition of auxiliary base class for composite data types which derive
22 * from one or more base classes for which the redirect operator <tt><<</tt> is defined.
23 * The various specialisations of this class implement the redirect operator <tt><<</tt>
24 * for the derived class.
25 */
26 template<class JWriter_t,
27 class JClass_t = JNullType,
28 class JTypelist_t = JNullType>
30
31
32 /**
33 * Specialisation of class JTemplateWriter for general purpose write methods.
34 */
35 template<class JWriter_t>
37 {
38 protected:
39 /**
40 * Write method for single data types.
41 *
42 * \param out writer
43 * \param object object
44 * \param type type
45 * \return writer
46 */
47 template<class JClass_t>
48 static inline JWriter_t& write(JWriter_t& out,
49 const JClass_t& object,
50 const JType <JNullType>& type)
51 {
52 return out << object;
53 }
54
55
56 /**
57 * Write method for composite data types.
58 *
59 * \param out writer
60 * \param object object
61 * \param type type
62 * \return writer
63 */
64 template<class JClass_t, class JHead_t, class JTail_t>
65 static inline JWriter_t& write(JWriter_t& out,
66 const JClass_t& object,
68 {
69 out << static_cast<const JHead_t&>(object);
70
71 if (WHITE_SPACE) {
72 out << WHITE_SPACE;
73 }
74
75 return write(out, object, JType<JTail_t>());
76 }
77
78
79 /**
80 * Write method for composite data types.
81 *
82 * \param out writer
83 * \param object object
84 * \param type type
85 * \return writer
86 */
87 template<class JClass_t, class JHead_t>
88 static inline JWriter_t& write(JWriter_t& out,
89 const JClass_t& object,
91 {
92 return out << static_cast<const JHead_t&>(object);
93 }
94
95 public:
96 static const char* WHITE_SPACE; //!< White space between consecutive items in a type list.
97 };
98
99
100 /**
101 * Default white space is empty.
102 */
103 template<class JWriter_t>
104 const char* JTemplateWriter<JWriter_t>::WHITE_SPACE = NULL;
105
106
107 /**
108 * Specialisation of white space for std::ostream.
109 */
110 template<>
112
113
114 /**
115 * Specialisation of class JTemplateWriter for composite data type.
116 *
117 * This class uses in-class friend operators (see Barton-Nackman trick).
118 */
119 template<class JWriter_t, class JClass_t, class JHead_t, class JTail_t>
120 struct JTemplateWriter<JWriter_t, JClass_t, JTypeList<JHead_t, JTail_t> > :
121 public JTemplateWriter<JWriter_t>
122 {
123 /**
124 * Write operator.
125 *
126 * \param out writer
127 * \param object object
128 * \return true if first object is less than second object; else false
129 */
130 friend JWriter_t& operator<<(JWriter_t& out, const JClass_t& object)
131 {
132 return JTemplateWriter::write(out, object, JType< JTypeList<JHead_t, JTail_t> >());
133 }
134 };
135}
136
137#endif
bool write(const Vec &v, std::ostream &os)
Write a Vec(tor) to a stream.
Definition io_ascii.hh:155
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
friend JWriter_t & operator<<(JWriter_t &out, const JClass_t &object)
Write operator.
static JWriter_t & write(JWriter_t &out, const JClass_t &object, const JType< JTypeList< JHead_t, JTail_t > > &type)
Write method for composite data types.
static const char * WHITE_SPACE
White space between consecutive items in a type list.
static JWriter_t & write(JWriter_t &out, const JClass_t &object, const JType< JNullType > &type)
Write method for single data types.
static JWriter_t & write(JWriter_t &out, const JClass_t &object, const JType< JTypeList< JHead_t, JNullType > > &type)
Write method for composite data types.
Template definition of auxiliary base class for composite data types which derive from one or more ba...
const char * WHITE_SPACE
Specialisation of white space for std::ostream.
Type list.
Definition JTypeList.hh:23
Auxiliary class for a type holder.
Definition JType.hh:19