26class BoundMethodPackBase
29 virtual ~BoundMethodPackBase() =
default;
32template<
typename R,
typename... Args>
33class BoundMethodPack :
public BoundMethodPackBase
36 template<
typename... Ts>
37 BoundMethodPack(Ts &&...args)
38 : args_(std::forward<Ts>(args)...)
42 std::tuple<typename std::remove_reference_t<Args>...> args_;
46template<
typename... Args>
47class BoundMethodPack<void, Args...> :
public BoundMethodPackBase
50 template<
typename... Ts>
51 BoundMethodPack(Ts &&...args)
52 : args_(std::forward<Ts>(args)...)
56 std::tuple<typename std::remove_reference_t<Args>...> args_;
63 : obj_(obj), object_(object), connectionType_(type)
66 virtual ~BoundMethodBase() =
default;
68 template<typename T, std::enable_if_t<!std::is_same<Object, T>::value> * =
nullptr>
69 bool match(T *obj) {
return obj == obj_; }
70 bool match(Object *
object) {
return object == object_; }
72 Object *object()
const {
return object_; }
74 virtual void invokePack(BoundMethodPackBase *pack) = 0;
77 bool activatePack(std::shared_ptr<BoundMethodPackBase> pack,
87template<
typename R,
typename... Args>
88class BoundMethodArgs :
public BoundMethodBase
91 using PackType = BoundMethodPack<R, Args...>;
94 template<std::size_t... I>
95 void invokePack(BoundMethodPackBase *pack, std::index_sequence<I...>)
97 [[maybe_unused]]
auto *args =
static_cast<PackType *
>(pack);
99 if constexpr (!std::is_void_v<R>)
100 args->ret_ = invoke(std::get<I>(args->args_)...);
102 invoke(std::get<I>(args->args_)...);
107 : BoundMethodBase(obj, object, type) {}
109 void invokePack(BoundMethodPackBase *pack)
override
111 invokePack(pack, std::make_index_sequence<
sizeof...(Args)>{});
114 virtual R activate(Args... args,
bool deleteMethod =
false) = 0;
115 virtual R invoke(Args... args) = 0;
118template<
typename T,
typename R,
typename Func,
typename... Args>
119class BoundMethodFunctor :
public BoundMethodArgs<R, Args...>
122 using PackType =
typename BoundMethodArgs<R, Args...>::PackType;
124 BoundMethodFunctor(T *obj, Object *
object, Func func,
126 : BoundMethodArgs<R, Args...>(obj, object, type), func_(std::move(func))
130 R activate(Args... args,
bool deleteMethod =
false)
override
133 return func_(std::forward<Args>(args)...);
135 auto pack = std::make_shared<PackType>(std::forward<Args>(args)...);
136 [[maybe_unused]]
bool sync = BoundMethodBase::activatePack(pack, deleteMethod);
138 if constexpr (!std::is_void_v<R>)
139 return sync ? std::move(pack->ret_) : R();
142 R invoke(Args... args)
override
144 return func_(std::forward<Args>(args)...);
151template<
typename T,
typename R,
typename... Args>
152class BoundMethodMember :
public BoundMethodArgs<R, Args...>
155 using PackType =
typename BoundMethodArgs<R, Args...>::PackType;
157 BoundMethodMember(T *obj, Object *
object, R (T::*func)(Args...),
159 : BoundMethodArgs<R, Args...>(obj, object, type), func_(func)
163 bool match(R (T::*func)(Args...))
const {
return func == func_; }
165 R activate(Args... args,
bool deleteMethod =
false)
override
167 if (!this->object_) {
168 T *obj =
static_cast<T *
>(this->obj_);
169 return (obj->*func_)(std::forward<Args>(args)...);
172 auto pack = std::make_shared<PackType>(std::forward<Args>(args)...);
173 [[maybe_unused]]
bool sync = BoundMethodBase::activatePack(pack, deleteMethod);
175 if constexpr (!std::is_void_v<R>)
176 return sync ? std::move(pack->ret_) : R();
179 R invoke(Args... args)
override
181 T *obj =
static_cast<T *
>(this->obj_);
182 return (obj->*func_)(std::forward<Args>(args)...);
186 R (T::*func_)(Args...);
189template<
typename R,
typename... Args>
190class BoundMethodStatic :
public BoundMethodArgs<R, Args...>
193 BoundMethodStatic(R (*func)(Args...))
199 bool match(R (*func)(Args...))
const {
return func == func_; }
201 R activate(Args... args, [[maybe_unused]]
bool deleteMethod =
false)
override
203 return (*func_)(std::forward<Args>(args)...);
206 R invoke(Args...)
override