libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
slot.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <algorithm>
14#include <cstddef>
15#include <functional>
16#include <utility>
17#include <tuple>
18#include <promeki/function.h>
19#include <promeki/namespace.h>
20
21PROMEKI_NAMESPACE_BEGIN
22
23class Variant;
24class VariantList;
25
42template <typename... Args> class Slot {
43 public:
45 using Function = promeki::Function<void(Args...)>;
46
54 Slot(const Function &func, void *owner = nullptr, const char *prototype = nullptr, int id = -1)
55 : _owner(owner), _prototype(prototype), _id(id), _function(func) {}
56
58 void *owner() const { return _owner; }
59
61 const char *prototype() const { return _prototype; }
62
64 int id() const { return _id; }
65
67 void setID(int val) { _id = val; }
68
73 template <typename T> struct removeConstAndRef {
74 using type = std::remove_const_t<std::remove_reference_t<T>>;
75 };
76
78 template <typename T> using RemoveConstAndRef = typename removeConstAndRef<T>::type;
79
94 static VariantList pack(Args... args);
95
100 void exec(Args... args) {
101 _function(args...);
102 return;
103 }
104
117 void exec(const VariantList &variantList);
118
119 private:
120 void *_owner = nullptr;
121 const char *_prototype = nullptr;
122 int _id = -1;
123 Function _function;
124
125 template <std::size_t... Idx>
126 void execFromVariantList(std::index_sequence<Idx...>, const VariantList &variantList);
127
128 template <std::size_t Idx> decltype(auto) unpackVariant(const Variant &variant);
129};
130
131PROMEKI_NAMESPACE_END
132
133#endif // PROMEKI_ENABLE_CORE