Crazy Eddie's GUI System 0.8.7
FunctorCopySlot.h
1/************************************************************************
2 created: Tue Feb 28 2006
3 authors: Paul D Turner <paul@cegui.org.uk>
4 Martin Preisler <martin@preisler.me>
5*************************************************************************/
6/***************************************************************************
7 * Copyright (C) 2004 - 2014 Paul D Turner & The CEGUI Development Team
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining
10 * a copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 ***************************************************************************/
28#ifndef _CEGUIFunctorCopySlot_h_
29#define _CEGUIFunctorCopySlot_h_
30
31#include "CEGUI/SlotFunctorBase.h"
32
33// Start of CEGUI namespace section
34namespace CEGUI
35{
36
37namespace FunctorCopySlot_detail
38{
39 typedef char Yes;
40 typedef int No;
41
42 template<typename T>
44 {
45 template<typename U, bool (U::*)(const EventArgs&) const> struct SFINAE {};
46 template<typename U> static Yes Test(SFINAE<U, &U::operator()>*);
47 template<typename U> static No Test(...);
48 static const bool Value = sizeof(Test<T>(0)) == sizeof(Yes);
49 };
50
51 template<typename T>
53 {
54 template<typename U, bool (U::*)(const EventArgs&)> struct SFINAE {};
55 template<typename U> static Yes Test(SFINAE<U, &U::operator()>*);
56 template<typename U> static No Test(...);
57 static const bool Value = sizeof(Test<T>(0)) == sizeof(Yes);
58 };
59
60 template<typename T>
62 {
63 template<typename U, void (U::*)(const EventArgs&) const> struct SFINAE {};
64 template<typename U> static Yes Test(SFINAE<U, &U::operator()>*);
65 template<typename U> static No Test(...);
66 static const bool Value = sizeof(Test<T>(0)) == sizeof(Yes);
67 };
68
69 template<typename T>
71 {
72 template<typename U, void (U::*)(const EventArgs&)> struct SFINAE {};
73 template<typename U> static Yes Test(SFINAE<U, &U::operator()>*);
74 template<typename U> static No Test(...);
75 static const bool Value = sizeof(Test<T>(0)) == sizeof(Yes);
76 };
77
78 template<typename T>
80 {
81 template<typename U, bool (U::*)() const> struct SFINAE {};
82 template<typename U> static Yes Test(SFINAE<U, &U::operator()>*);
83 template<typename U> static No Test(...);
84 static const bool Value = sizeof(Test<T>(0)) == sizeof(Yes);
85 };
86
87 template<typename T>
89 {
90 template<typename U, bool (U::*)()> struct SFINAE {};
91 template<typename U> static Yes Test(SFINAE<U, &U::operator()>*);
92 template<typename U> static No Test(...);
93 static const bool Value = sizeof(Test<T>(0)) == sizeof(Yes);
94 };
95
96 template<typename T>
98 {
99 template<typename U, void (U::*)() const> struct SFINAE {};
100 template<typename U> static Yes Test(SFINAE<U, &U::operator()>*);
101 template<typename U> static No Test(...);
102 static const bool Value = sizeof(Test<T>(0)) == sizeof(Yes);
103 };
104
105 // The following 3 templates use the same idea as boost::disable_if
106 template <bool B, class T = void>
108 {
109 typedef T Type;
110 };
111
112 template <class T>
113 struct DisableIfC<true, T>
114 {};
115
116 template <class Cond, class T = void>
117 struct DisableIf : public DisableIfC<Cond::Value, T>
118 {};
119
120
121 // The following is just overload trickery to accommodate 8 allowed
122 // operator() signatures:
123 //
124 // 1) bool (const EventArgs&) const = BoolEventArgsConstOp
125 // 2) bool (const EventArgs&) = BoolEventArgsOp
126 // 3) void (const EventArgs&) const = VoidEventArgsConstOp
127 // 4) void (const EventArgs&) = VoidEventArgsOp
128 // 5) bool () const = BoolNoArgsConstOp
129 // 6) bool () = BoolNoArgsOp
130 // 7) void () const = VoidNoArgsConstOp
131 // 8) void () = VoidNoArgsOp
132 //
133 // The calls are priorised as outlined above, if call 1) is possible, no
134 // other variants are tried, ...
135
136 template<typename T>
137 inline bool call(const T& functor, bool(T::*member_fn)(const EventArgs&) const, const EventArgs& args,
138 void* = 0,
139 void* = 0,
140 void* = 0,
141 void* = 0,
142 void* = 0,
143 void* = 0,
144 void* = 0
145 )
146 {
147 return CEGUI_CALL_MEMBER_FN(functor, member_fn)(args);
148 }
149
150 template<typename T>
151 inline bool call(T& functor, bool(T::*member_fn)(const EventArgs&), const EventArgs& args,
152 typename DisableIf<HasBoolEventArgsConstOp<T> >::Type* = 0,
153 void* = 0,
154 void* = 0,
155 void* = 0,
156 void* = 0,
157 void* = 0,
158 void* = 0
159 )
160 {
161 return CEGUI_CALL_MEMBER_FN(functor, member_fn)(args);
162 }
163
164 template<typename T>
165 inline bool call(const T& functor, void(T::*member_fn)(const EventArgs&) const, const EventArgs& args,
166 typename DisableIf<HasBoolEventArgsConstOp<T> >::Type* = 0,
167 typename DisableIf<HasBoolEventArgsOp<T> >::Type* = 0,
168 void* = 0,
169 void* = 0,
170 void* = 0,
171 void* = 0,
172 void* = 0
173 )
174 {
175 CEGUI_CALL_MEMBER_FN(functor, member_fn)(args);
176 return true;
177 }
178
179 template<typename T>
180 inline bool call(T& functor, void(T::*member_fn)(const EventArgs&), const EventArgs& args,
181 typename DisableIf<HasBoolEventArgsConstOp<T> >::Type* = 0,
182 typename DisableIf<HasBoolEventArgsOp<T> >::Type* = 0,
183 typename DisableIf<HasVoidEventArgsConstOp<T> >::Type* = 0,
184 void* = 0,
185 void* = 0,
186 void* = 0,
187 void* = 0
188 )
189 {
190 CEGUI_CALL_MEMBER_FN(functor, member_fn)(args);
191 return true;
192 }
193
194 template<typename T>
195 inline bool call(const T& functor, bool(T::*member_fn)() const, const EventArgs& /*args*/,
196 typename DisableIf<HasBoolEventArgsConstOp<T> >::Type* = 0,
197 typename DisableIf<HasBoolEventArgsOp<T> >::Type* = 0,
198 typename DisableIf<HasVoidEventArgsConstOp<T> >::Type* = 0,
199 typename DisableIf<HasVoidEventArgsOp<T> >::Type* = 0,
200 void* = 0,
201 void* = 0,
202 void* = 0
203 )
204 {
205 return CEGUI_CALL_MEMBER_FN(functor, member_fn)();
206 }
207
208 template<typename T>
209 inline bool call(T& functor, bool(T::*member_fn)(), const EventArgs& /*args*/,
210 typename DisableIf<HasBoolEventArgsConstOp<T> >::Type* = 0,
211 typename DisableIf<HasBoolEventArgsOp<T> >::Type* = 0,
212 typename DisableIf<HasVoidEventArgsConstOp<T> >::Type* = 0,
213 typename DisableIf<HasVoidEventArgsOp<T> >::Type* = 0,
214 typename DisableIf<HasBoolNoArgsConstOp<T> >::Type* = 0,
215 void* = 0,
216 void* = 0
217 )
218 {
219 return CEGUI_CALL_MEMBER_FN(functor, member_fn)();
220 }
221
222 template<typename T>
223 inline bool call(const T& functor, void(T::*member_fn)() const, const EventArgs& /*args*/,
224 typename DisableIf<HasBoolEventArgsConstOp<T> >::Type* = 0,
225 typename DisableIf<HasBoolEventArgsOp<T> >::Type* = 0,
226 typename DisableIf<HasVoidEventArgsConstOp<T> >::Type* = 0,
227 typename DisableIf<HasVoidEventArgsOp<T> >::Type* = 0,
228 typename DisableIf<HasBoolNoArgsConstOp<T> >::Type* = 0,
229 typename DisableIf<HasBoolNoArgsOp<T> >::Type* = 0,
230 void* = 0
231 )
232 {
233 CEGUI_CALL_MEMBER_FN(functor, member_fn)();
234 return true;
235 }
236
237 template<typename T>
238 inline bool call(T& functor, void(T::*member_fn)(), const EventArgs& /*args*/,
239 typename DisableIf<HasBoolEventArgsConstOp<T> >::Type* = 0,
240 typename DisableIf<HasBoolEventArgsOp<T> >::Type* = 0,
241 typename DisableIf<HasVoidEventArgsConstOp<T> >::Type* = 0,
242 typename DisableIf<HasVoidEventArgsOp<T> >::Type* = 0,
243 typename DisableIf<HasBoolNoArgsConstOp<T> >::Type* = 0,
244 typename DisableIf<HasBoolNoArgsOp<T> >::Type* = 0,
245 typename DisableIf<HasVoidNoArgsConstOp<T> >::Type* = 0
246 )
247 {
248 CEGUI_CALL_MEMBER_FN(functor, member_fn)();
249 return true;
250 }
251}
252
258template<typename T>
260{
261public:
262 FunctorCopySlot(const T& functor):
263 d_functor(functor)
264 {}
265
266 virtual bool operator()(const EventArgs& args)
267 {
268 return FunctorCopySlot_detail::call<T>(d_functor, &T::operator(), args);
269 }
270
271private:
272 T d_functor;
273};
274
275}
276
277#endif // end of guard _CEGUIFunctorCopySlot_h_
Base class used as the argument to all subscribers Event object.
Definition: EventArgs.h:51
Slot template class that creates a functor that calls back via a copy of a functor object.
Definition: FunctorCopySlot.h:260
Defines abstract interface which will be used when constructing various functor objects that bind slo...
Definition: SlotFunctorBase.h:44
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
Definition: FunctorCopySlot.h:108
Definition: FunctorCopySlot.h:118
Definition: FunctorCopySlot.h:89