-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_info.hpp
91 lines (67 loc) · 1.69 KB
/
task_info.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// === (C) 2020-2024 === parallel_f (tasks, queues, lists in parallel threads)
// Written by Denis Oliver Kropp <[email protected]>
#pragma once
#include <any>
#include <memory>
#include "log.hpp"
#include "task_base.hpp"
namespace parallel_f {
// parallel_f :: task_info == implementation
class task_info : public task_base, public std::enable_shared_from_this<task_info>
{
public:
class Value
{
friend class task_info;
private:
std::shared_ptr<task_info> task;
public:
Value(std::shared_ptr<task_info> task) : task(task) {}
template <typename _T>
_T get() {
return std::any_cast<_T>(task->value);
}
};
protected:
std::any value;
protected:
task_info() {}
template <typename Callable, typename... Args>
task_info(Callable callable, Args... args)
{
if (sizeof...(args)) {
LOG_DEBUG("task_info::task_info(): [[%s]], showing %zu arguments...\n", typeid(Callable).name(), sizeof...(args));
if (getDebugLevel() > 0)
(DumpArg<Args>(args), ...);
}
else
LOG_DEBUG("task_info::task_info(): [[%s]], no arguments...\n", typeid(Callable).name());
}
public:
Value result() { return Value(this->shared_from_this()); }
private:
template <typename ArgType>
void DumpArg(ArgType arg)
{
LOG_DEBUG("task_info::task_info(): Type: %s\n", typeid(ArgType).name());
}
};
template <>
inline std::any task_info::Value::get() {
return task->value;
}
template <>
inline void task_info::DumpArg(Value arg)
{
switch (parallel_f::getDebugLevel()) {
case 2:
arg.task->finish();
/* fall through */
case 1:
LOG_DEBUG("task_info::task_info(): Type: Value( %s )\n", arg.get<std::any>().type().name());
break;
case 0:
break;
}
}
}