X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/515245055b58d2eb5eeae7af82fb6070cea6bcc8..fb9d73b23b30461efaba93282e05ccf0cde2f395:/include/xbt/signal.hpp diff --git a/include/xbt/signal.hpp b/include/xbt/signal.hpp index 1f53eaae91..6824eee203 100644 --- a/include/xbt/signal.hpp +++ b/include/xbt/signal.hpp @@ -16,11 +16,10 @@ namespace xbt { template class signal; /** A signal/slot mechanism - * - * S is expected to be the function signature of the signal. - * I'm not sure we need a return value (it is currently ignored). - * If we don't we might use `signal` instead. - */ + * + * The template parameter is the function signature of the signal. + * The return value currently ignored. + */ template class signal { using callback_type = std::function; @@ -28,18 +27,23 @@ namespace xbt { unsigned int callback_sequence_id = 0; public: + /** Add a new callback to this signal */ template unsigned int connect(U slot) { handlers_.insert({callback_sequence_id, std::move(slot)}); return callback_sequence_id++; } + /** Fire that signal, invoking all callbacks */ R operator()(P... args) const { for (auto const& handler : handlers_) handler.second(args...); } + /** Remove a callback */ void disconnect(unsigned int id) { handlers_.erase(id); } + /** Remove all callbacks */ void disconnect_slots() { handlers_.clear(); } + /** Get the amount of callbacks */ int get_slot_count() { return handlers_.size(); } };