27 concept delegate_pipe_c = std::default_initializable<T> &&
requires(T t) {
28 { t | t } -> std::convertible_to<T>;
31 using delegate_token_type = time_ordered_priority_key;
65 template<
class signature_t>
82 template<
class derived_t,
class return_t,
class... args_t>
92 using function_type = std::function<return_t(args_t...)>;
95 using single_value_type = std::pair<time_ordered_priority_key, function_type>;
96 using container_type = std::flat_map<time_ordered_priority_key, function_type>;
97 using variant_type = std::variant<single_value_type, container_type>;
98 using data_type = std::optional<variant_type>;
110 template<
class... creation_args_t>
124 template<callable_c<return_t, args_t...> callable_t>
139 template<
class object_t>
142 return_t (object_t::*pMethod)(args_t...),
143 priority ePriority = priority::normal) noexcept;
153 template<callable_c<return_t, args_t...> callable_t>
156 priority ePriority = priority::normal) noexcept;
167 template<
class object_t>
170 return_t (object_t::*pMethod)(args_t...),
171 priority ePriority = priority::normal) noexcept;
183 template<
class object_t, callable_c<return_t, args_t...> callable_t>
185 std::weak_ptr<object_t> pWeakObject,
187 priority ePriority = priority::normal) noexcept;
198 template<
class object_t>
200 std::weak_ptr<object_t> pWeakObject,
201 return_t (object_t::*pMethod)(args_t...),
202 priority ePriority = priority::normal) noexcept;
214 void clear() noexcept;
225 size_t size()
const noexcept;
238 bool empty()
const noexcept;
249 template<
class invoke_single_t,
class invoke_multiple_t>
250 return_t
execute_internal(
const invoke_single_t& invokeSingle,
const invoke_multiple_t& invokeMultiple) noexcept;
283 template<
class object_t, callable_c<return_t, object_t*, args_t...> callable_t>
287 data_type m_optFunctions;
288 std::flat_map<time_ordered_priority_key, std::weak_ptr<const void>> m_WeakSubscriptions;
291 std::shared_ptr<base_delegate*> m_pDelegateAliveMarker;
297 template<
class return_t,
class... args_t>
298 requires(
sizeof...(args_t) > 0 && (!std::is_void_v<args_t> && ...))
299 class
delegate<return_t(args_t...)> final
300 : public details::base_delegate<
delegate<return_t(args_t...)>, return_t, args_t...>
310 return_t execute(args_t... args) noexcept;
314 template<
class return_t>
329 #include <qx/patterns/delegate.inl>
return_t execute() noexcept
Execute all the callables the delegate has.
Single or multicast delegate.
Class for RAII: functor passed in constructor will be called in destructor.
void clear_dead() noexcept
Remove weak subscriptions whose tracked objects have expired, without invoking callbacks.
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.
void clear() noexcept
Clear all the callables in this 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.
bool empty() const noexcept
Check if this delegate is empty.
size_t size() const noexcept
Get the number of functions bound to this delegate.
static derived_t create_singlecast(creation_args_t... args) noexcept
Create a singlecast delegate.
bool remove(delegate_token_type token) noexcept
Remove a callable using its token.
delegate_token_type add_token(callable_t callable, priority ePriority=priority::normal) noexcept
Add a callable using a token with manual unsubscribing.
return_t execute_internal(const invoke_single_t &invokeSingle, const invoke_multiple_t &invokeMultiple) noexcept
Execute all callables.
bool is_singlecast() const noexcept
Check whether exactly one callable is bound to this delegate.
A class that can be used as a key in ordered containers so that items are ordered in descending order...
requires(same_variadic_args_v< args_t... >) const expr auto coalesce(args_t &&... args)
Coalesce function, C# a ?? b analogue.
priority
User may use the predefined values or the custom ones, for ex. "normal - 1", this type is supposed to...