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