signal: drop sink::before
This commit is contained in:
@@ -325,15 +325,6 @@ As shown above, listeners don't have to strictly follow the signature of the
|
||||
signal. As long as a listener can be invoked with the given arguments to yield a
|
||||
result that is convertible to the given return type, everything works just
|
||||
fine.<br/>
|
||||
It's also possible to connect a listener before other elements already contained
|
||||
by the signal. The `before` function returns a `sink` object that is correctly
|
||||
initialized for the purpose and can be used to connect one or more listeners in
|
||||
order and in the desired position:
|
||||
|
||||
```cpp
|
||||
sink.before<&foo>().connect<&listener::bar>(instance);
|
||||
```
|
||||
|
||||
In all cases, the `connect` member function returns by default a `connection`
|
||||
object to be used as an alternative to break a connection by means of its
|
||||
`release` member function.<br/>
|
||||
|
||||
@@ -372,23 +372,13 @@ class sink<sigh<Ret(Args...), Allocator>> {
|
||||
sink{*static_cast<signal_type *>(signal)}.disconnect<Candidate>();
|
||||
}
|
||||
|
||||
auto before(delegate_type call) {
|
||||
const auto &calls = signal->calls;
|
||||
const auto it = std::find(calls.cbegin(), calls.cend(), std::move(call));
|
||||
|
||||
sink other{*this};
|
||||
other.offset = calls.cend() - it;
|
||||
return other;
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a sink that is allowed to modify a given signal.
|
||||
* @param ref A valid reference to a signal object.
|
||||
*/
|
||||
sink(sigh<Ret(Args...), Allocator> &ref) noexcept
|
||||
: offset{},
|
||||
signal{&ref} {}
|
||||
: signal{&ref} {}
|
||||
|
||||
/**
|
||||
* @brief Returns false if at least a listener is connected to the sink.
|
||||
@@ -398,77 +388,6 @@ public:
|
||||
return signal->calls.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a sink that connects before a given free function or an
|
||||
* unbound member.
|
||||
* @tparam Function A valid free function pointer.
|
||||
* @return A properly initialized sink object.
|
||||
*/
|
||||
template<auto Function>
|
||||
[[nodiscard]] sink before() {
|
||||
delegate_type call{};
|
||||
call.template connect<Function>();
|
||||
return before(std::move(call));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a sink that connects before a free function with payload
|
||||
* or a bound member.
|
||||
* @tparam Candidate Member or free function to look for.
|
||||
* @tparam Type Type of class or type of payload.
|
||||
* @param value_or_instance A valid object that fits the purpose.
|
||||
* @return A properly initialized sink object.
|
||||
*/
|
||||
template<auto Candidate, typename Type>
|
||||
[[nodiscard]] sink before(Type &&value_or_instance) {
|
||||
delegate_type call{};
|
||||
call.template connect<Candidate>(value_or_instance);
|
||||
return before(std::move(call));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a sink that connects before a given instance or specific
|
||||
* payload.
|
||||
* @tparam Type Type of class or type of payload.
|
||||
* @param value_or_instance A valid object that fits the purpose.
|
||||
* @return A properly initialized sink object.
|
||||
*/
|
||||
template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<std::remove_pointer_t<Type>>, void>, sink>>
|
||||
[[nodiscard]] sink before(Type &value_or_instance) {
|
||||
return before(&value_or_instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a sink that connects before a given instance or specific
|
||||
* payload.
|
||||
* @param value_or_instance A valid pointer that fits the purpose.
|
||||
* @return A properly initialized sink object.
|
||||
*/
|
||||
[[nodiscard]] sink before(const void *value_or_instance) {
|
||||
sink other{*this};
|
||||
|
||||
if(value_or_instance) {
|
||||
const auto &calls = signal->calls;
|
||||
const auto it = std::find_if(calls.cbegin(), calls.cend(), [value_or_instance](const auto &delegate) {
|
||||
return delegate.data() == value_or_instance;
|
||||
});
|
||||
|
||||
other.offset = calls.cend() - it;
|
||||
}
|
||||
|
||||
return other;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a sink that connects before anything else.
|
||||
* @return A properly initialized sink object.
|
||||
*/
|
||||
[[nodiscard]] sink before() {
|
||||
sink other{*this};
|
||||
other.offset = signal->calls.size();
|
||||
return other;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Connects a free function (with or without payload), a bound or an
|
||||
* unbound member to a signal.
|
||||
@@ -483,7 +402,7 @@ public:
|
||||
|
||||
delegate_type call{};
|
||||
call.template connect<Candidate>(value_or_instance...);
|
||||
signal->calls.insert(signal->calls.end() - offset, std::move(call));
|
||||
signal->calls.push_back(std::move(call));
|
||||
|
||||
delegate<void(void *)> conn{};
|
||||
conn.template connect<&release<Candidate, Type...>>(value_or_instance...);
|
||||
@@ -524,7 +443,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
difference_type offset;
|
||||
signal_type *signal;
|
||||
};
|
||||
|
||||
|
||||
@@ -427,82 +427,6 @@ TEST_F(SigH, ConstNonConstNoExcept) {
|
||||
ASSERT_EQ(cfunctor.cnt, 2);
|
||||
}
|
||||
|
||||
TEST_F(SigH, BeforeFunction) {
|
||||
entt::sigh<void(int)> sigh;
|
||||
entt::sink sink{sigh};
|
||||
before_after functor;
|
||||
|
||||
sink.connect<&before_after::add>(functor);
|
||||
sink.connect<&before_after::static_add>();
|
||||
sink.before<&before_after::static_add>().connect<&before_after::mul>(functor);
|
||||
sigh.publish(2);
|
||||
|
||||
ASSERT_EQ(functor.value, 6);
|
||||
}
|
||||
|
||||
TEST_F(SigH, BeforeMemberFunction) {
|
||||
entt::sigh<void(int)> sigh;
|
||||
entt::sink sink{sigh};
|
||||
before_after functor;
|
||||
|
||||
sink.connect<&before_after::static_add>();
|
||||
sink.connect<&before_after::add>(functor);
|
||||
sink.before<&before_after::add>(functor).connect<&before_after::mul>(functor);
|
||||
sigh.publish(2);
|
||||
|
||||
ASSERT_EQ(functor.value, 6);
|
||||
}
|
||||
|
||||
TEST_F(SigH, BeforeFunctionWithPayload) {
|
||||
entt::sigh<void(int)> sigh;
|
||||
entt::sink sink{sigh};
|
||||
before_after functor;
|
||||
|
||||
sink.connect<&before_after::static_add>();
|
||||
sink.connect<&before_after::static_mul>(functor);
|
||||
sink.before<&before_after::static_mul>(functor).connect<&before_after::add>(functor);
|
||||
sigh.publish(2);
|
||||
|
||||
ASSERT_EQ(functor.value, 8);
|
||||
}
|
||||
|
||||
TEST_F(SigH, BeforeInstanceOrPayload) {
|
||||
entt::sigh<void(int)> sigh;
|
||||
entt::sink sink{sigh};
|
||||
before_after functor;
|
||||
|
||||
sink.connect<&before_after::static_mul>(functor);
|
||||
sink.connect<&before_after::add>(functor);
|
||||
sink.before(functor).connect<&before_after::static_add>();
|
||||
sigh.publish(2);
|
||||
|
||||
ASSERT_EQ(functor.value, 6);
|
||||
}
|
||||
|
||||
TEST_F(SigH, BeforeAnythingElse) {
|
||||
entt::sigh<void(int)> sigh;
|
||||
entt::sink sink{sigh};
|
||||
before_after functor;
|
||||
|
||||
sink.connect<&before_after::add>(functor);
|
||||
sink.before().connect<&before_after::mul>(functor);
|
||||
sigh.publish(2);
|
||||
|
||||
ASSERT_EQ(functor.value, 2);
|
||||
}
|
||||
|
||||
TEST_F(SigH, BeforeListenerNotPresent) {
|
||||
entt::sigh<void(int)> sigh;
|
||||
entt::sink sink{sigh};
|
||||
before_after functor;
|
||||
|
||||
sink.connect<&before_after::mul>(functor);
|
||||
sink.before<&before_after::add>(&functor).connect<&before_after::add>(functor);
|
||||
sigh.publish(2);
|
||||
|
||||
ASSERT_EQ(functor.value, 2);
|
||||
}
|
||||
|
||||
TEST_F(SigH, UnboundDataMember) {
|
||||
sigh_listener listener;
|
||||
entt::sigh<bool &(sigh_listener &)> sigh;
|
||||
|
||||
Reference in New Issue
Block a user