1#ifndef ENTT_SIGNAL_SIGH_HPP
2#define ENTT_SIGNAL_SIGH_HPP
22template<
typename Type>
34template<
typename Type,
typename Allocator>
53template<
typename Ret,
typename...
Args,
typename Allocator>
57 using alloc_traits = std::allocator_traits<Allocator>;
59 using container_type = std::vector<delegate_type, typename alloc_traits::template rebind_alloc<delegate_type>>;
71 :
sigh{allocator_type{}} {}
85 : calls{
other.calls} {}
100 : calls{std::move(
other.calls)} {}
147 return calls.get_allocator();
163 return calls.empty();
174 for(
auto pos = calls.size();
pos; --
pos) {
193 template<
typename Func>
195 for(
auto pos = calls.size();
pos; --
pos) {
196 if constexpr(std::is_void_v<Ret> || !std::is_invocable_v<Func, Ret>) {
199 if constexpr(std::is_invocable_r_v<bool, Func>) {
207 if constexpr(std::is_invocable_r_v<bool, Func, Ret>) {
208 if(func(calls[
pos - 1u](
args...))) {
212 func(calls[
pos - 1u](
args...));
219 container_type calls;
234 : disconnect{fn}, signal{
ref} {}
246 return static_cast<bool>(disconnect);
290 : conn{std::exchange(
other.conn, {})} {}
309 conn = std::exchange(
other.conn, {});
328 return static_cast<bool>(conn);
359template<
typename Ret,
typename...
Args,
typename Allocator>
363 using difference_type =
typename signal_type::container_type::difference_type;
365 template<auto Cand
idate,
typename Type>
370 template<auto Cand
idate>
371 static void release(
void *signal) {
375 template<
typename Func>
376 void disconnect_if(Func callback) {
377 for(
auto pos = signal->calls.size();
pos; --
pos) {
378 if(
auto &
elem = signal->calls[
pos - 1u]; callback(
elem)) {
379 elem = std::move(signal->calls.back());
380 signal->calls.pop_back();
398 return signal->calls.empty();
409 template<
auto Candidate,
typename... Type>
413 delegate_type
call{};
415 signal->calls.push_back(std::move(
call));
419 return {conn, signal};
429 template<
auto Candidate,
typename... Type>
431 delegate_type
call{};
448 signal->calls.clear();
465template<
typename Ret,
typename...
Args,
typename Allocator>
connection()
Default constructor.
void release()
Breaks the connection.
Utility class to use to send around functions and members.
Basic delegate implementation.
Unmanaged signal handler.
void publish(Args... args) const
Triggers a signal.
Allocator allocator_type
Allocator type.
sigh() noexcept(noexcept(allocator_type{}))
Default constructor.
sigh(const sigh &other)
Copy constructor.
~sigh()=default
Default destructor.
sigh & operator=(sigh &&other) noexcept
Move assignment operator.
void swap(sigh &other) noexcept
Exchanges the contents with those of a given signal handler.
size_type size() const noexcept
Number of listeners connected to the signal.
sigh(sigh &&other, const allocator_type &allocator)
Allocator-extended move constructor.
sigh(sigh &&other) noexcept
Move constructor.
constexpr allocator_type get_allocator() const noexcept
Returns the associated allocator.
sigh(const allocator_type &allocator) noexcept
Constructs a signal handler with a given allocator.
bool empty() const noexcept
Returns false if at least a listener is connected to the signal.
std::size_t size_type
Unsigned integer type.
sigh & operator=(const sigh &other)
Copy assignment operator.
sigh(const sigh &other, const allocator_type &allocator)
Allocator-extended copy constructor.
void collect(Func func, Args... args) const
Collects return values from the listeners.
Unmanaged signal handler.
void disconnect(const void *value_or_instance)
Disconnects free functions with payload or bound members from a signal.
sink(sigh< Ret(Args...), Allocator > &ref) noexcept
Constructs a sink that is allowed to modify a given signal.
bool empty() const noexcept
Returns false if at least a listener is connected to the sink.
void disconnect()
Disconnects all the listeners from a signal.
connection connect(Type &&...value_or_instance)
Connects a free function (with or without payload), a bound or an unbound member to a signal.
void disconnect(Type &&...value_or_instance)
Disconnects a free function (with or without payload), a bound or an unbound member from a signal.
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
constexpr void swap(compressed_pair< First, Second > &lhs, compressed_pair< First, Second > &rhs)
Swaps two compressed pair objects.
@ ref
Aliasing mode, the object points to a non-const element.
sink(sigh< Ret(Args...), Allocator > &) -> sink< sigh< Ret(Args...), Allocator > >
Deduction guide.
scoped_connection()=default
Default constructor.
void release()
Breaks the connection.
scoped_connection(scoped_connection &&other) noexcept
Move constructor.
~scoped_connection()
Automatically breaks the link on destruction.
scoped_connection & operator=(const scoped_connection &)=delete
Default copy assignment operator, deleted on purpose.
scoped_connection(const connection &other)
Constructs a scoped connection from a basic connection.
scoped_connection(const scoped_connection &)=delete
Default copy constructor, deleted on purpose.
scoped_connection & operator=(connection other)
Acquires a connection.
scoped_connection & operator=(scoped_connection &&other) noexcept
Move assignment operator.