-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_wcet.h
72 lines (60 loc) · 1.91 KB
/
test_wcet.h
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
#ifndef TEST_WCET_HEADER
#define TEST_WCET_HEADER
#include <cstdlib>
#include <iostream>
#include <memory> /* std::unique_ptr*/
#include <string>
#include <tuple> /* std::tuple*/
#include <vector>
class Invoker {
public:
template <typename Callable, typename... Args>
void loadFunc(Callable&& f, Args&&... args) {
_S_make_state(std::tuple<Callable, Args...>{std::forward<Callable>(f),
std::forward<Args>(args)...});
ready_ = 1;
}
void runFunc() {
if (ready_) invoker_->run();
}
private:
bool ready_;
struct __Invoker_Base {
virtual void run() = 0;
};
template <typename _Tuple>
struct _Invoker : public __Invoker_Base {
_Tuple _M_t;
_Invoker(_Tuple&& tp) : _M_t{tp} {}
template <size_t _Index>
static std::__tuple_element_t<_Index, _Tuple>&& _S_declval();
template <size_t... _Ind>
auto _M_invoke(std::_Index_tuple<_Ind...>) noexcept(
noexcept(std::__invoke(_S_declval<_Ind>()...)))
-> decltype(std::__invoke(_S_declval<_Ind>()...)) {
return std::__invoke(std::get<_Ind>(std::move(_M_t))...);
}
using _Indices = typename std::_Build_index_tuple<
std::tuple_size<_Tuple>::value>::__type;
virtual void run() override { _M_invoke(_Indices()); }
};
template <typename _Callable>
void _S_make_state(_Callable&& __f) {
invoker_ = std::unique_ptr<_Invoker<_Callable>>(
new _Invoker<_Callable>(std::forward<_Callable>(__f)));
}
std::unique_ptr<__Invoker_Base> invoker_;
};
class TaskLoader {
public:
template <typename Callable, typename... Args>
bool addTask(const std::string &name, Callable &&f, Args &&...args) {
auto it = mTaskArr.emplace(mTaskArr.end(), name, Invoker{});
it->second.loadFunc(std::forward<Callable>(f), std::forward<Args>(args)...);
return true;
}
bool RunTest();
private:
std::vector<std::pair<std::string, Invoker>> mTaskArr;
};
#endif