knowL: Knowledge Libraries
Loading...
Searching...
No Matches
knowl
src
knowCore
AsynchronousFunction.h
1
#pragma once
2
3
#include <functional>
4
#include <type_traits>
5
6
#include <QObject>
7
8
class
QThread;
9
10
namespace
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_>
31
class
AsynchronousFunction
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
}
45
~AsynchronousFunction
()
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
:
58
details::AsynchronousFunctionCall
* m_call;
59
};
60
}
knowCore::AsynchronousFunction
Definition
AsynchronousFunction.h:32
knowCore::AsynchronousFunction::operator()
void operator()(_Args_... _args)
Definition
AsynchronousFunction.h:52
knowCore::details::AsynchronousFunctionCall
Definition
AsynchronousFunction.h:15
Generated by
1.12.0