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<std::remove_cv_t<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<std::remove_cv_t<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 : BoundMethodBase(obj, object, type) {}
96 void invokePack(BoundMethodPackBase *pack)
override
98 auto *argsPack =
static_cast<PackType *
>(pack);
100 std::apply([&](Args &&...args) {
101 if constexpr (!std::is_void_v<R>)
102 argsPack->ret_ = invoke(std::forward<
decltype(args)>(args)...);
104 invoke(std::forward<
decltype(args)>(args)...);
105 }, std::move(argsPack->args_));
108 virtual R activate(Args... args,
bool deleteMethod =
false) = 0;
109 virtual R invoke(Args... args) = 0;
112template<
typename T,
typename R,
typename Func,
typename... Args>
113class BoundMethodFunctor :
public BoundMethodArgs<R, Args...>
116 using PackType =
typename BoundMethodArgs<R, Args...>::PackType;
118 BoundMethodFunctor(T *obj, Object *
object, Func func,
120 : BoundMethodArgs<R, Args...>(obj, object, type), func_(std::move(func))
124 R activate(Args... args,
bool deleteMethod =
false)
override
127 return func_(std::forward<Args>(args)...);
129 auto pack = std::make_shared<PackType>(std::forward<Args>(args)...);
130 [[maybe_unused]]
bool sync = BoundMethodBase::activatePack(pack, deleteMethod);
132 if constexpr (!std::is_void_v<R>)
133 return sync ? std::move(pack->ret_) : R();
136 R invoke(Args... args)
override
138 return func_(std::forward<Args>(args)...);
145template<
typename T,
typename R,
typename... Args>
146class BoundMethodMember :
public BoundMethodArgs<R, Args...>
149 using PackType =
typename BoundMethodArgs<R, Args...>::PackType;
151 BoundMethodMember(T *obj, Object *
object, R (T::*func)(Args...),
153 : BoundMethodArgs<R, Args...>(obj, object, type), func_(func)
157 bool match(R (T::*func)(Args...)) const { return func == func_; }
159 R activate(Args... args,
bool deleteMethod =
false)
override
161 if (!this->object_) {
162 T *obj =
static_cast<T *
>(this->obj_);
163 return (obj->*func_)(std::forward<Args>(args)...);
166 auto pack = std::make_shared<PackType>(std::forward<Args>(args)...);
167 [[maybe_unused]]
bool sync = BoundMethodBase::activatePack(pack, deleteMethod);
169 if constexpr (!std::is_void_v<R>)
170 return sync ? std::move(pack->ret_) : R();
173 R invoke(Args... args)
override
175 T *obj =
static_cast<T *
>(this->obj_);
176 return (obj->*func_)(std::forward<Args>(args)...);
180 R (T::*func_)(Args...);
183template<
typename R,
typename... Args>
184class BoundMethodStatic :
public BoundMethodArgs<R, Args...>
187 BoundMethodStatic(R (*func)(Args...))
193 bool match(R (*func)(Args...))
const {
return func == func_; }
195 R activate(Args... args, [[maybe_unused]]
bool deleteMethod =
false)
override
197 return (*func_)(std::forward<Args>(args)...);
200 R invoke(Args...)
override