1 #ifndef ENTT_SIGNAL_DELEGATE_HPP 2 #define ENTT_SIGNAL_DELEGATE_HPP 6 #include "../config/config.h" 35 template<
typename Ret,
typename... Args>
37 using proto_fn_type = Ret(
void *, Args...);
38 using stub_type = std::pair<void *, proto_fn_type *>;
40 template<Ret(*Function)(Args...)>
41 static Ret proto(
void *, Args... args) {
42 return (Function)(args...);
45 template<
typename Class, Ret(Class:: *Member)(Args...)>
46 static Ret proto(
void *instance, Args... args) {
47 return (static_cast<Class *>(instance)->*Member)(args...);
60 bool empty() const ENTT_NOEXCEPT {
69 template<Ret(*Function)(Args...)>
71 stub = std::make_pair(
nullptr, &proto<Function>);
85 template<
typename Class, Ret(Class:: *Member)(Args...)>
86 void connect(Class *instance) ENTT_NOEXCEPT {
87 stub = std::make_pair(instance, &proto<Class, Member>);
96 stub.second =
nullptr;
105 return stub.second(stub.first, args...);
117 return stub.first == other.stub.first && stub.second == other.stub.second;
136 template<
typename Ret,
typename... Args>
138 return !(lhs == rhs);
145 #endif // ENTT_SIGNAL_DELEGATE_HPP constexpr bool operator!=(const HashedString &lhs, const HashedString &rhs) ENTT_NOEXCEPT
Compares two hashed strings.
void connect() ENTT_NOEXCEPT
Binds a free function to a delegate.
Ret operator()(Args... args) const
Triggers a delegate.
Basic delegate implementation.
Delegate() ENTT_NOEXCEPT
Default constructor.
bool operator==(const Delegate< Ret(Args...)> &other) const ENTT_NOEXCEPT
Checks if the contents of the two delegates are different.
bool empty() const ENTT_NOEXCEPT
Checks whether a delegate actually stores a listener.
void reset() ENTT_NOEXCEPT
Resets a delegate.
void connect(Class *instance) ENTT_NOEXCEPT
Connects a member function for a given instance to a delegate.