30 template <
class TOwningType,
class TEventArgs>
34 typedef std::function<void(TOwningType&, const TEventArgs&)>
EventFunction;
40 template <
typename TSubscribingType>
42 void (TSubscribingType::*member_func)(TOwningType&,
const TEventArgs&))
44 callbacks_.push_back(std::bind(member_func, caller, std::placeholders::_1, std::placeholders::_2));
47 template <
typename TSubscribingType>
49 void (TSubscribingType::*member_func)(TOwningType&,
const TEventArgs&))
51 std::function<void(TOwningType&, const TEventArgs&)> callback =
52 std::bind(member_func, caller, std::placeholders::_1, std::placeholders::_2);
53 for (
auto iter = callbacks_.begin(); iter != callbacks_.end(); iter++)
55 if (callback.target_type() == iter->target_type() &&
56 iter->template target<std::function<void(TOwningType&, const TEventArgs&)>>() ==
57 callback.template target<std::function<
void(TOwningType&,
const TEventArgs&)>>())
59 callbacks_.erase(iter);
60 callbacks_.shrink_to_fit();
67 std::vector<std::function<void(TOwningType&, const TEventArgs&)>>
callbacks_;
69 void invoke(TOwningType& sender, TEventArgs a)
71 const std::vector<EventFunction> callbacks(callbacks_);
72 for (
auto it = callbacks.begin(); it != callbacks.end(); ++it)
void invoke(TOwningType &sender, TEventArgs a)
void bind_member_func(TSubscribingType *caller, void(TSubscribingType::*member_func)(TOwningType &, const TEventArgs &))
void unbind_member_func(TSubscribingType *caller, void(TSubscribingType::*member_func)(TOwningType &, const TEventArgs &))
std::function< void(TOwningType &, const TEventArgs &)> EventFunction
std::vector< std::function< void(TOwningType &, const TEventArgs &)> > callbacks_
static const EventArgs EMPTY