libfilezilla
wxinvoker.hpp
Go to the documentation of this file.
1 #ifndef LIBFILEZILLA_GLUE_WXINVOKER_HEADER
2 #define LIBFILEZILLA_GLUE_WXINVOKER_HEADER
3 
8 #include "../invoker.hpp"
9 
10 #include <wx/event.h>
11 
12 namespace fz {
13 
15 template<typename... Args>
16 std::function<void(Args...)> do_make_invoker(wxEvtHandler& handler, std::function<void(Args...)> && f)
17 {
18  return [&handler, cf = f](Args&&... args) mutable {
19  auto cb = [cf, targs = std::make_tuple(std::forward<Args>(args)...)] {
20  std::apply(cf, targs);
21  };
22  handler.CallAfter(cb);
23  };
24 }
25 
27 template<typename F>
28 auto make_invoker(wxEvtHandler& handler, F && f)
29 {
30  return do_make_invoker(handler, decltype(get_func_type(&F::operator()))(std::forward<F>(f)));
31 }
32 
34 inline invoker_factory get_invoker_factory(wxEvtHandler& handler)
35 {
36  return [&handler](std::function<void()> const& cb) mutable {
37  handler.CallAfter(cb);
38  };
39 }
40 
41 }
42 
43 #endif
The namespace used by libfilezilla.
Definition: apply.hpp:17
auto apply(Obj &&obj, F &&f, Tuple &&args) -> decltype(apply_(std::forward< Obj >(obj), std::forward< F >(f), std::forward< Tuple >(args), Seq()))
Apply tuple to pointer to member.
Definition: apply.hpp:48
invoker_factory get_invoker_factory(event_loop &loop)
Creates an invoker factory.
auto make_invoker(event_loop &loop, F &&f)
Wraps the passed function, so that it is always invoked in the context of the loop.
Definition: invoker.hpp:54