X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/611d822b02f836d7abe031cced6adc4281ef4356..cff982bd049d26d7acbd0e23324e0de051b06d0d:/include/xbt/signal.hpp diff --git a/include/xbt/signal.hpp b/include/xbt/signal.hpp index 1cd6e06f41..36bd87f2dc 100644 --- a/include/xbt/signal.hpp +++ b/include/xbt/signal.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2014-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2014-2020. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -7,8 +7,8 @@ #define SIMGRID_XBT_SIGNAL_HPP #include +#include #include -#include namespace simgrid { namespace xbt { @@ -23,22 +23,24 @@ namespace xbt { */ template class signal { - private: - typedef std::function callback_type; - std::vector handlers_; + using callback_type = std::function; + std::map handlers_; + unsigned int callback_sequence_id = 0; + public: - template - void connect(U slot) + template unsigned int connect(U slot) { - handlers_.push_back(std::move(slot)); + handlers_.insert({callback_sequence_id, std::move(slot)}); + return callback_sequence_id++; } R operator()(P... args) const { for (auto const& handler : handlers_) - handler(args...); + handler.second(args...); } - void disconnectSlots() { handlers_.clear(); } - int getSlotsAmount() { return handlers_.size(); } + void disconnect(unsigned int id) { handlers_.erase(id); } + void disconnect_slots() { handlers_.clear(); } + int get_slot_count() { return handlers_.size(); } }; }