X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/fb9d73b23b30461efaba93282e05ccf0cde2f395..e71a2a302d28430dc1bfee906f842f5f3d0fa3ce:/include/xbt/signal.hpp diff --git a/include/xbt/signal.hpp b/include/xbt/signal.hpp index 6824eee203..ef4ec9cf35 100644 --- a/include/xbt/signal.hpp +++ b/include/xbt/signal.hpp @@ -13,40 +13,38 @@ namespace simgrid { namespace xbt { - template class signal; - - /** A signal/slot mechanism - * - * The template parameter is the function signature of the signal. - * The return value currently ignored. - */ - template - class signal { - using callback_type = std::function; - std::map handlers_; - 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(); } - }; - +template class signal; + +/** @brief + * A signal/slot mechanism, where you can attach callbacks to a given signal, and then fire the signal. + * + * The template parameter is the function signature of the signal (the return value currently ignored). + */ +template class signal { + using callback_type = std::function; + std::map handlers_; + 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(); } +}; } }