X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/fd769219531a772284d75320187a0ef9f8118afd..22639e2bf15d31eabcd2224b9e850a108ae3ca57:/include/xbt/signal.hpp diff --git a/include/xbt/signal.hpp b/include/xbt/signal.hpp index 714ae0d17d..a5e654494a 100644 --- a/include/xbt/signal.hpp +++ b/include/xbt/signal.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2014-2015. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2014-2019. 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. */ @@ -6,52 +6,43 @@ #ifndef SIMGRID_XBT_SIGNAL_HPP #define SIMGRID_XBT_SIGNAL_HPP -#if SIMGRID_HAVE_LIBSIG -#include -#else -#include -#endif +#include +#include +#include namespace simgrid { namespace xbt { -#if SIMGRID_HAVE_LIBSIG + template class signal; - // Wraps sigc++ signals with the interface of boost::signals2: - 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. + */ template class signal { - private: - sigc::signal sig_; + typedef std::function callback_type; + std::map handlers_; + unsigned int callback_sequence_id = 0; + public: - template XBT_ALWAYS_INLINE - void connect(U&& slot) - { - sig_.connect(std::forward(slot)); - } - template XBT_ALWAYS_INLINE - void connect(Res(*slot)(Args...)) - { - sig_.connect(sigc::ptr_fun(slot)); - } - template XBT_ALWAYS_INLINE - R operator()(Args&&... args) const + template unsigned int connect(U slot) { - return sig_.emit(std::forward(args)...); + handlers_.insert({callback_sequence_id, std::move(slot)}); + return callback_sequence_id++; } - void disconnect_all_slots() + R operator()(P... args) const { - sig_.clear(); + for (auto const& handler : handlers_) + handler.second(args...); } + void disconnect(unsigned int id) { handlers_.erase(id); } + void disconnect_slots() { handlers_.clear(); } + int get_slot_count() { return handlers_.size(); } }; -#else - - template - using signal = ::boost::signals2::signal; - -#endif - } }