34 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) 35 #error "Only <final/final.h> can be included directly." 41 #include "final/ftypes.h" 42 #include "final/util/fstring.h" 59 template <
typename FuncPtr>
61 : cb_signal(std::move(s))
64 , cb_function(std::move(c))
76 void* cb_function_ptr{};
90 using enable_if_ObjectPointer_t =
91 std::enable_if_t< ! std::is_member_function_pointer<T>::value
92 && ! std::is_function<std::remove_pointer_t<T>>::value
93 && ! std::is_function<T>::value
94 && std::is_pointer<T>::value
95 && std::is_object<T>::value
96 && ! std::is_class<T>::value
99 using enable_if_ClassObject_t =
100 std::enable_if_t< ! std::is_member_function_pointer<T>::value
101 && ! std::is_function<std::remove_pointer_t<T>>::value
102 && ! std::is_function<T>::value
103 && ! std::is_pointer<T>::value
104 && std::is_object<T>::value
105 && std::is_class<T>::value
107 template <
typename T>
108 using enable_if_MemberFunctionPointer_t =
109 std::enable_if_t< std::is_member_function_pointer<T>::value
110 && ! std::is_function<std::remove_pointer_t<T>>::value
111 && ! std::is_function<T>::value
112 && ! std::is_pointer<T>::value
113 && std::is_object<T>::value
114 && ! std::is_class<T>::value
116 template <
typename T>
117 using enable_if_FunctionPointer_t =
118 std::enable_if_t< ! std::is_member_function_pointer<T>::value
119 && std::is_function<std::remove_pointer_t<T>>::value
120 && ! std::is_function<T>::value
121 && std::is_pointer<T>::value
122 && std::is_object<T>::value
123 && ! std::is_class<T>::value
125 template <
typename T>
126 using enable_if_FunctionReference_t =
127 std::enable_if_t< ! std::is_member_function_pointer<T>::value
128 && std::is_function<std::remove_pointer_t<T>>::value
129 && std::is_function<T>::value
130 && ! std::is_pointer<T>::value
131 && ! std::is_object<T>::value
132 && ! std::is_class<T>::value
148 auto getClassName()
const ->
FString;
149 auto getCallbackCount()
const -> std::size_t;
152 template <
typename Object
154 , enable_if_ObjectPointer_t<Object> = nullptr
155 , enable_if_MemberFunctionPointer_t<Function> = nullptr
157 void addCallback (
FString&& cb_signal
158 , Object&& cb_instance
159 , Function&& cb_member
160 , Args&&... args) noexcept;
161 template <
typename Object
163 , enable_if_ObjectPointer_t<Object> = nullptr
164 , enable_if_ClassObject_t<Function> = nullptr
166 void addCallback (
FString&& cb_signal
167 , Object&& cb_instance
168 , Function&& cb_function
169 , Args&&... args) noexcept;
170 template <
typename Function
171 , enable_if_ClassObject_t<Function> = nullptr
173 void addCallback (
FString&& cb_signal
174 , Function&& cb_function
175 , Args&&... args) noexcept;
176 template <
typename Function
177 , enable_if_ClassObject_t<Function> = nullptr
179 void addCallback (
FString&& cb_signal
180 , Function& cb_function
181 , Args&&... args) noexcept;
182 template <
typename Function
183 , enable_if_FunctionReference_t<Function> = nullptr
185 void addCallback (
FString&& cb_signal
186 , Function& cb_function
187 , Args&&... args) noexcept;
188 template <
typename Function
189 , enable_if_FunctionPointer_t<Function> = nullptr
191 void addCallback (
FString&& cb_signal
192 , Function&& cb_function
193 , Args&&... args) noexcept;
194 template <
typename Object
195 , enable_if_ObjectPointer_t<Object> =
nullptr>
196 void delCallback (Object&& cb_instance) noexcept;
197 void delCallback (
const FString& cb_signal);
198 template <
typename Object
199 , enable_if_ObjectPointer_t<Object> =
nullptr>
200 void delCallback (
const FString& cb_signal
201 , Object&& cb_instance ) noexcept;
202 template <
typename FunctionPtr
203 , enable_if_FunctionPointer_t<FunctionPtr> =
nullptr>
204 void delCallback (FunctionPtr&& cb_func_ptr) noexcept;
205 template <
typename Function
206 , enable_if_FunctionReference_t<Function> =
nullptr>
207 void delCallback (
const Function& cb_function);
209 void emitCallback (
const FString& emit_signal)
const;
213 using FCallbackObjects = std::vector<FCallbackData>;
216 FCallbackObjects callback_objects{};
221 inline auto FCallback::getClassName()
const ->
FString 222 {
return "FCallback"; }
225 inline auto FCallback::getCallbackCount()
const -> std::size_t
226 {
return callback_objects.size(); }
229 template <
typename Object
231 , FCallback::enable_if_ObjectPointer_t<Object>
232 , FCallback::enable_if_MemberFunctionPointer_t<Function>
234 inline void FCallback::addCallback (
FString&& cb_signal
235 , Object&& cb_instance
236 , Function&& cb_member
237 , Args&&... args) noexcept
241 Object instance = cb_instance;
242 auto fn = std::bind ( std::forward<Function>(cb_member)
243 , std::forward<Object>(cb_instance)
244 , std::forward<Args>(args)... );
245 callback_objects.emplace_back (std::move(cb_signal), instance,
nullptr, fn);
249 template <
typename Object
251 , FCallback::enable_if_ObjectPointer_t<Object>
252 , FCallback::enable_if_ClassObject_t<Function>
254 inline void FCallback::addCallback (
FString&& cb_signal
255 , Object&& cb_instance
256 , Function&& cb_function
257 , Args&&... args) noexcept
261 auto fn = std::bind (std::forward<Function>(cb_function), std::forward<Args>(args)...);
262 callback_objects.emplace_back (std::move(cb_signal), cb_instance,
nullptr, fn);
266 template <
typename Function
267 , FCallback::enable_if_ClassObject_t<Function>
269 inline void FCallback::addCallback (
FString&& cb_signal
270 , Function&& cb_function
271 , Args&&... args) noexcept
275 auto fn = std::bind ( std::forward<Function>(cb_function)
276 , std::forward<Args>(args)... );
277 callback_objects.emplace_back (std::move(cb_signal),
nullptr,
nullptr, fn);
281 template <
typename Function
282 , FCallback::enable_if_ClassObject_t<Function>
284 inline void FCallback::addCallback (
FString&& cb_signal
285 , Function& cb_function
286 , Args&&... args) noexcept
290 auto fn = std::bind (cb_function, std::forward<Args>(args)...);
291 callback_objects.emplace_back (std::move(cb_signal),
nullptr,
nullptr, fn);
295 template <
typename Function
296 , FCallback::enable_if_FunctionReference_t<Function>
298 inline void FCallback::addCallback (
FString&& cb_signal
299 , Function& cb_function
300 , Args&&... args) noexcept
304 auto ptr =
reinterpret_cast<void*
>(&cb_function);
305 auto fn = std::bind (cb_function, std::forward<Args>(args)...);
306 callback_objects.emplace_back (std::move(cb_signal),
nullptr, ptr, fn);
310 template <
typename Function
311 , FCallback::enable_if_FunctionPointer_t<Function>
313 inline void FCallback::addCallback (
FString&& cb_signal
314 , Function&& cb_function
315 , Args&&... args) noexcept
319 auto ptr =
reinterpret_cast<void*
>(cb_function);
320 auto fn = std::bind ( std::forward<Function>(cb_function)
321 , std::forward<Args>(args)... );
322 callback_objects.emplace_back(std::move(cb_signal),
nullptr, ptr, fn);
326 template <
typename Object
327 , FCallback::enable_if_ObjectPointer_t<Object>>
328 inline void FCallback::delCallback (Object&& cb_instance) noexcept
332 if ( callback_objects.empty() )
335 auto iter = callback_objects.cbegin();
337 while ( iter != callback_objects.cend() )
339 if ( iter->cb_instance == cb_instance )
340 iter = callback_objects.erase(iter);
347 template <
typename Object
348 , FCallback::enable_if_ObjectPointer_t<Object>>
349 inline void FCallback::delCallback (
const FString& cb_signal
350 , Object&& cb_instance ) noexcept
355 if ( callback_objects.empty() )
358 auto iter = callback_objects.cbegin();
360 while ( iter != callback_objects.cend() )
362 if ( iter->cb_signal == cb_signal
363 && iter->cb_instance == cb_instance )
364 iter = callback_objects.erase(iter);
371 template <
typename FunctionPtr
372 , FCallback::enable_if_FunctionPointer_t<FunctionPtr>>
373 inline void FCallback::delCallback (FunctionPtr&& cb_func_ptr) noexcept
378 if ( callback_objects.empty() )
381 auto ptr =
reinterpret_cast<void*
>(cb_func_ptr);
382 auto iter = callback_objects.cbegin();
384 while ( iter != callback_objects.cend() )
386 if ( iter->cb_function_ptr == ptr )
387 iter = callback_objects.erase(iter);
394 template <
typename Function
395 , FCallback::enable_if_FunctionReference_t<Function>>
396 inline void FCallback::delCallback (
const Function& cb_function)
401 if ( callback_objects.empty() )
404 auto ptr =
reinterpret_cast<void*
>(&cb_function);
405 auto iter = callback_objects.cbegin();
407 while ( iter != callback_objects.cend() )
409 if ( iter->cb_function_ptr == ptr )
410 iter = callback_objects.erase(iter);
418 #endif // FCALLBACK_H Definition: fcallback.h:54
Definition: fcallback.h:85
Definition: class_template.cpp:25