MyGUI: MyGUI_EventPair.h Source File

MyGUI 3.4.3

MyGUI_EventPair.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_EVENT_PAIR_H_
8#define MYGUI_EVENT_PAIR_H_
9
10#include "MyGUI_Prerequest.h"
11
12namespace MyGUI
13{
14#ifndef MYGUI_DONT_USE_OBSOLETE
15 template<typename EventObsolete, typename Event>
16 class CompositeEvent
17 {
18 using IObsoleteDelegate = typename EventObsolete::IDelegate;
19
20 public:
21 using IDelegate = typename Event::IDelegate;
22
23 template<class T>
24 CompositeEvent& operator=(T* _delegate)
25 {
26 m_eventObsolete.clear();
27 m_event = _delegate;
28 return *this;
29 }
30
31 template<class T>
32 CompositeEvent& operator=(const T& _delegate)
33 {
34 m_eventObsolete.clear();
35 m_event = _delegate;
36 return *this;
37 }
38
39 MYGUI_OBSOLETE("use : signature : Event::IDelegate * _delegate")
40 CompositeEvent& operator=(IObsoleteDelegate* _delegate)
41 {
42 m_eventObsolete = _delegate;
43 m_event.clear();
44 return *this;
45 }
46
47 template<class T>
48 void operator+=(T*) = delete;
49 template<class T>
50 void operator-=(T*) = delete;
51
52 MYGUI_OBSOLETE("use : signature : Event::IDelegate * _delegate")
53 void operator+=(IObsoleteDelegate* _delegate)
54 {
55 m_eventObsolete += _delegate;
56 m_event.clear();
57 }
58
59 void operator+=(IDelegate* _delegate)
60 {
61 m_eventObsolete.clear();
62 m_event += _delegate;
63 }
64
65 MYGUI_OBSOLETE("use : signature : Event::IDelegate * _delegate")
66 void operator-=(IObsoleteDelegate* _delegate)
67 {
68 m_eventObsolete -= _delegate;
69 m_event.clear();
70 }
71
72 void operator-=(IDelegate* _delegate)
73 {
74 m_eventObsolete.clear();
75 m_event -= _delegate;
76 }
77
78 void clear()
79 {
80 m_eventObsolete.clear();
81 m_event.clear();
82 }
83
84 bool empty() const
85 {
86 return m_eventObsolete.empty() && m_event.empty();
87 }
88
89 EventObsolete m_eventObsolete;
90 Event m_event;
91 };
92#endif
93
94 template<typename EventObsolete, typename Event>
95#ifdef MYGUI_DONT_USE_OBSOLETE
96 using EventPair = Event;
97#else
98 class EventPair : public CompositeEvent<EventObsolete, Event>
99 {
100 public:
101 using CompositeEvent<EventObsolete, Event>::operator=;
102 using CompositeEvent<EventObsolete, Event>::m_eventObsolete;
103 using CompositeEvent<EventObsolete, Event>::m_event;
104
105 template<typename TP1>
106 void operator()(TP1 p1) const
107 {
108 m_eventObsolete(p1);
109 m_event(p1);
110 }
111
112 template<typename TP1, typename TP2>
113 void operator()(TP1 p1, TP2 p2) const
114 {
115 m_eventObsolete(p1, p2);
116 m_event(p1, p2);
117 }
118
119 template<typename TP1, typename TP2, typename TP3>
120 void operator()(TP1 p1, TP2 p2, TP3 p3) const
121 {
122 m_eventObsolete(p1, p2, p3);
123 m_event(p1, p2, p3);
124 }
125
126 template<typename TP1, typename TP2, typename TP3, typename TP4>
127 void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4) const
128 {
129 m_eventObsolete(p1, p2, p3, p4);
130 m_event(p1, p2, p3, p4);
131 }
132
133 template<typename TP1, typename TP2, typename TP3, typename TP4, typename TP5>
134 void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5) const
135 {
136 m_eventObsolete(p1, p2, p3, p4, p5);
137 m_event(p1, p2, p3, p4, p5);
138 }
139
140 template<typename TP1, typename TP2, typename TP3, typename TP4, typename TP5, typename TP6>
141 void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6) const
142 {
143 m_eventObsolete(p1, p2, p3, p4, p5, p6);
144 m_event(p1, p2, p3, p4, p5, p6);
145 }
146
147 template<typename TP1, typename TP2, typename TP3, typename TP4, typename TP5, typename TP6, typename TP7>
148 void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7) const
149 {
150 m_eventObsolete(p1, p2, p3, p4, p5, p6, p7);
151 m_event(p1, p2, p3, p4, p5, p6, p7);
152 }
153
154 template<
155 typename TP1,
156 typename TP2,
157 typename TP3,
158 typename TP4,
159 typename TP5,
160 typename TP6,
161 typename TP7,
162 typename TP8>
163 void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7, TP8 p8) const
164 {
165 m_eventObsolete(p1, p2, p3, p4, p5, p6, p7, p8);
166 m_event(p1, p2, p3, p4, p5, p6, p7, p8);
167 }
168 };
169#endif
170
171 template<typename EventObsolete, typename Event>
172#ifdef MYGUI_DONT_USE_OBSOLETE
173 using EventPairAddParameter = Event;
174#else
175 class EventPairAddParameter : public CompositeEvent<EventObsolete, Event>
176 {
177 public:
178 using CompositeEvent<EventObsolete, Event>::operator=;
179 using CompositeEvent<EventObsolete, Event>::m_eventObsolete;
180 using CompositeEvent<EventObsolete, Event>::m_event;
181
182 // 1 to 2
183 template<typename TP1, typename TP2>
184 void operator()(TP1 p1, TP2 p2)
185 {
186 m_eventObsolete(p1);
187 m_event(p1, p2);
188 }
189
190 // 2 to 3
191 template<typename TP1, typename TP2, typename TP3, typename TP4>
192 void operator()(TP1 p1, TP2 p2, TP3 p3)
193 {
194 m_eventObsolete(p1, p2);
195 m_event(p1, p2, p3);
196 }
197
198 // 3 to 4
199 template<typename TP1, typename TP2, typename TP3, typename TP4>
200 void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4)
201 {
202 m_eventObsolete(p1, p2, p3);
203 m_event(p1, p2, p3, p4);
204 }
205 };
206#endif
207
208 template<typename EventObsolete, typename Event>
209#ifdef MYGUI_DONT_USE_OBSOLETE
210 using EventPairConvertStringView = Event;
211#else
212 class EventPairConvertStringView : public CompositeEvent<EventObsolete, Event>
213 {
214 template<class T>
215 T&& convertStringView(T&& value) const noexcept
216 {
217 return std::forward<T>(value);
218 }
219
220 template<class T>
221 std::basic_string<T> convertStringView(std::basic_string_view<T> value) const noexcept
222 {
223 return std::string{value};
224 }
225
226 public:
227 using CompositeEvent<EventObsolete, Event>::operator=;
228 using CompositeEvent<EventObsolete, Event>::m_eventObsolete;
229 using CompositeEvent<EventObsolete, Event>::m_event;
230
231 template<typename... Args>
232 void operator()(Args&&... args) const
233 {
234 if (!m_eventObsolete.empty())
235 m_eventObsolete(convertStringView(args)...);
236 m_event(args...);
237 }
238 };
239#endif
240
241} // namespace MyGUI
242
243#endif // MYGUI_EVENT_PAIR_H_
MYGUI_OBSOLETE
#define MYGUI_OBSOLETE(text)
Definition MyGUI_Diagnostic.h:68
MyGUI_Prerequest.h
MyGUI::CompositeEvent
Definition MyGUI_EventPair.h:17
MyGUI::CompositeEvent::operator+=
void operator+=(IDelegate *_delegate)
Definition MyGUI_EventPair.h:59
MyGUI::CompositeEvent::operator+=
void operator+=(T *)=delete
MyGUI::CompositeEvent::operator-=
void operator-=(T *)=delete
MyGUI::CompositeEvent::operator=
CompositeEvent & operator=(const T &_delegate)
Definition MyGUI_EventPair.h:32
MyGUI::CompositeEvent::m_eventObsolete
EventObsolete m_eventObsolete
Definition MyGUI_EventPair.h:89
MyGUI::CompositeEvent::operator-=
void operator-=(IDelegate *_delegate)
Definition MyGUI_EventPair.h:72
MyGUI::CompositeEvent::empty
bool empty() const
Definition MyGUI_EventPair.h:84
MyGUI::CompositeEvent::IDelegate
typename Event::IDelegate IDelegate
Definition MyGUI_EventPair.h:21
MyGUI::CompositeEvent::operator=
CompositeEvent & operator=(T *_delegate)
Definition MyGUI_EventPair.h:24
MyGUI::CompositeEvent::clear
void clear()
Definition MyGUI_EventPair.h:78
MyGUI::CompositeEvent::m_event
Event m_event
Definition MyGUI_EventPair.h:90
MyGUI::EventPairAddParameter
Definition MyGUI_EventPair.h:176
MyGUI::EventPairAddParameter::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4)
Definition MyGUI_EventPair.h:200
MyGUI::EventPairAddParameter::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3)
Definition MyGUI_EventPair.h:192
MyGUI::EventPairAddParameter::operator()
void operator()(TP1 p1, TP2 p2)
Definition MyGUI_EventPair.h:184
MyGUI::EventPairConvertStringView
Definition MyGUI_EventPair.h:213
MyGUI::EventPairConvertStringView::operator()
void operator()(Args &&... args) const
Definition MyGUI_EventPair.h:232
MyGUI::EventPair
Definition MyGUI_EventPair.h:99
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7, TP8 p8) const
Definition MyGUI_EventPair.h:163
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3) const
Definition MyGUI_EventPair.h:120
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4) const
Definition MyGUI_EventPair.h:127
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6) const
Definition MyGUI_EventPair.h:141
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2) const
Definition MyGUI_EventPair.h:113
MyGUI::EventPair::operator()
void operator()(TP1 p1) const
Definition MyGUI_EventPair.h:106
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5) const
Definition MyGUI_EventPair.h:134
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7) const
Definition MyGUI_EventPair.h:148
MyGUI
Definition MyGUI_ActionController.h:15