knowL: Knowledge Libraries
Loading...
Searching...
No Matches
AsynchronousFunction.h
1#pragma once
2
3#include <functional>
4#include <type_traits>
5
6#include <QObject>
7
8class QThread;
9
10namespace knowCore
11{
12 namespace details
13 {
14 class AsynchronousFunctionCall : public QObject
15 {
16 Q_OBJECT
17 public slots:
18 void call(void* arg)
19 {
20 m_function(arg);
21 }
22 void setFunction(const std::function<void(void*)>& _function) { m_function = _function; }
23 private:
24 std::function<void(void*)> m_function;
25 };
26 }
30 template<typename... _Args_>
32 {
33 typedef std::tuple<std::decay_t<_Args_>...> ArgsTuple;
34 public:
35 AsynchronousFunction(const std::function<void(_Args_...)>& _function, QThread* _thread) : m_call(new details::AsynchronousFunctionCall)
36 {
37 m_call->moveToThread(_thread);
38 m_call->setFunction([_function](void* _args)
39 {
40 ArgsTuple* args = reinterpret_cast<ArgsTuple*>(_args);
41 std::apply(_function, *args);
42 delete args;
43 });
44 }
46 {
47 delete m_call;
48 }
52 void operator()(_Args_... _args)
53 {
54 ArgsTuple* t = new ArgsTuple(/*std::make_tuple<details::remove_cvref<_Args_...>>(*/_args...)/*)*/;
55 QMetaObject::invokeMethod(m_call, "call", Qt::QueuedConnection, Q_ARG(void*, t));
56 }
57 private:
59 };
60}
Definition AsynchronousFunction.h:32
void operator()(_Args_... _args)
Definition AsynchronousFunction.h:52
Definition AsynchronousFunction.h:15