25 concept delegate_pipe_c = std::is_default_constructible_v<T> && !std::is_arithmetic_v<T> && requires(T t) {
26 { t | t } -> std::convertible_to<T>;
30 concept delegate_return_c = std::is_void_v<T> || delegate_pipe_c<T>;
32 using delegate_token_type = time_ordered_priority_key;
52 template<
class derived_t, delegate_return_c return_t,
class... args_t>
62 using function_type = std::function<return_t(args_t...)>;
65 using container_type = std::map<time_ordered_priority_key, function_type>;
77 template<
class... creation_args_t>
90 template<callable_c<return_t, args_t...> callable_t>
101 template<callable_c<return_t, args_t...> callable_t>
104 priority ePriority = priority::normal) noexcept;
115 template<
class object_t>
118 return_t (object_t::*pMethod)(args_t...),
119 priority ePriority = priority::normal) noexcept;
131 template<
class object_t, callable_c<return_t, args_t...> callable_t>
133 std::weak_ptr<object_t> pWeakObject,
135 priority ePriority = priority::normal) noexcept;
146 template<
class object_t>
148 std::weak_ptr<object_t> pWeakObject,
149 return_t (object_t::*pMethod)(args_t...),
150 priority ePriority = priority::normal) noexcept;
162 void clear() noexcept;
173 template<
class invoke_single_t,
class invoke_multiple_t>
174 return_t
execute_internal(
const invoke_single_t& invokeSingle,
const invoke_multiple_t& invokeMultiple)
194 template<
class object_t, callable_c<return_t, object_t*, args_t...> callable_t>
199 container_type m_Functions;
202 std::shared_ptr<bool> m_pDelegateAliveMarker = std::make_shared<bool>(
true);
205 template<delegate_return_c return_t = void,
class... args_t>
209 template<delegate_return_c return_t,
class... args_t>
210 requires(
sizeof...(args_t) > 0 && (!std::is_void_v<args_t> && ...))
221 return_t
execute(args_t... args)
const noexcept;
225 template<delegate_return_c return_t>
235 return_t
execute()
const noexcept;
Single or multicast delegate. Use the qx::delegate<> class in your code.
bool remove(delegate_token_type token) noexcept
Remove a callable using its token.
return_t execute_internal(const invoke_single_t &invokeSingle, const invoke_multiple_t &invokeMultiple) const noexcept
Execute all callables.
static derived_t create_singlecast(creation_args_t... args) noexcept
Create a singlecast delegate.
destruction_callback add_destruction_callback(callable_t callable, priority ePriority=priority::normal) noexcept
Add a callable that will be removed from the delegate when its destruction callback is destroyed.
void clear() noexcept
Clear all the callables in this delegate.
delegate_token_type add_weak(std::weak_ptr< object_t > pWeakObject, callable_t callable, priority ePriority=priority::normal) noexcept
Add a callable that will be executed only if the appropriate weak object is valid.
delegate_token_type add_free(callable_t callable, priority ePriority=priority::normal) noexcept
Add a callable without any protection.
Class for RAII: functor passed in constructor will be called in destructor.
return_t execute(args_t... args) const noexcept
Execute all the callables the delegate has.
priority
User may use the predefined values or the custom ones, for ex. "normal - 1", this type is supposed to...
A structure that can be used as a key in ordered containers so that items are ordered in descending o...