Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JValve.hh
Go to the documentation of this file.
1#ifndef __JLANG__JVALVE__
2#define __JLANG__JVALVE__
3
4#include "JLang/JDefault.hh"
5#include "JLang/JTypeList.hh"
6#include "JLang/JType.hh"
7
8/**
9 * \author mdejong
10 */
11
12namespace JLANG {}
13namespace JPP { using namespace JLANG; }
14
15namespace JLANG {
16
17 /**
18 * Auxiliary class for selection of data type.
19 */
20 template<class T>
21 class JValve :
22 public JDefault< JValve<T> >
23 {
24 public:
25 /**
26 * Default constructor.
27 *
28 * By default, the valve is open.
29 */
31 status(true)
32 {}
33
34
35 /**
36 * Constructor.
37 *
38 * \param controller controller of valve
39 */
40 template<class JController_t>
41 JValve(const JController_t& controller)
42 {
43 (*this)(controller);
44 }
45
46
47 /**
48 * Check if valve is open.
49 *
50 * \return true if open; else false
51 */
52 bool is_open() const
53 {
54 return status;
55 }
56
57
58 /**
59 * Open valve.
60 */
61 void open()
62 {
63 status = true;
64 }
65
66
67 /**
68 * Close valve.
69 */
70 void close()
71 {
72 status = false;
73 }
74
75
76 /**
77 * Set valve.
78 *
79 * The template argument <tt>JController_t</tt> refers to a data structure
80 * which should provide for the function object operator:
81 * <pre>
82 * bool operator()(JType<T>& type) const; // get status of valve
83 * </pre>
84 *
85 * \param controller controller of valve
86 */
87 template<class JController_t>
88 JValve& operator()(const JController_t& controller)
89 {
90 if (controller(JType<T>()))
91 this->open();
92 else
93 this->close();
94
95 return *this;
96 }
97
98 protected:
99 bool status;
100 };
101
102
103 /**
104 * Auxiliary class for selection of multiple data types.
105 *
106 * This class recursively defines the JLANG::JValve interface
107 * for all data types by deriving from:
108 * - JValve<JHead_t>; and
109 * - JValve<JTail_t>.
110 */
111 template<class JHead_t, class JTail_t>
112 class JValve< JTypeList<JHead_t, JTail_t> > :
113 public JDefault< JValve< JTypeList<JHead_t, JTail_t> > >,
114 public JValve<JHead_t>,
115 public JValve<JTail_t>
116 {
117 public:
119
120 /**
121 * Default constructor.
122 */
124 {}
125
126
127 /**
128 * Constructor.
129 *
130 * \param controller controller of valve
131 */
132 template<class JController_t>
133 JValve(const JController_t& controller)
134 {
135 (*this)(controller);
136 }
137
138
139 /**
140 * Set valve.
141 *
142 * The template argument <tt>JController_t</tt> refers to a data structure
143 * which should provide for the function object operator:
144 * <pre>
145 * bool operator()(JType<T>& type) const; // get status of valve
146 * </pre>
147 *
148 * \param controller controller of valve
149 */
150 template<class JController_t>
151 JValve& operator()(const JController_t& controller)
152 {
153 static_cast<JValve<JHead_t>&>(*this)(controller);
154 static_cast<JValve<JTail_t>&>(*this)(controller);
155
156 return *this;
157 }
158 };
159
160
161 /**
162 * Terminator class of recursive JValve class.
163 */
164 template<class JHead_t>
165 class JValve< JTypeList<JHead_t, JNullType> > :
166 public JValve<JHead_t>
167 {
168 public:
169 /**
170 * Default constructor.
171 */
173 {}
174
175
176 /**
177 * Constructor.
178 *
179 * \param controller controller of valve
180 */
181 template<class JController_t>
182 JValve(const JController_t& controller)
183 {
184 (*this)(controller);
185 }
186 };
187}
188
189#endif
JValve(const JController_t &controller)
Constructor.
Definition JValve.hh:182
JValve & operator()(const JController_t &controller)
Set valve.
Definition JValve.hh:151
JValve(const JController_t &controller)
Constructor.
Definition JValve.hh:133
Auxiliary class for selection of data type.
Definition JValve.hh:23
bool status
Definition JValve.hh:99
JValve()
Default constructor.
Definition JValve.hh:30
void open()
Open valve.
Definition JValve.hh:61
JValve & operator()(const JController_t &controller)
Set valve.
Definition JValve.hh:88
bool is_open() const
Check if valve is open.
Definition JValve.hh:52
JValve(const JController_t &controller)
Constructor.
Definition JValve.hh:41
void close()
Close valve.
Definition JValve.hh:70
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Simple default class.
Definition JDefault.hh:18
static const T & getDefault()
Definition JDefault.hh:24
Auxiliary class for no type definition.
Definition JNullType.hh:19
Type list.
Definition JTypeList.hh:23
Auxiliary class for a type holder.
Definition JType.hh:19