X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ae4d609abce3048d0dc0f636074a8a0a6964c113..56a800c7de10c3e3a1a854434e6bfdeb01696dba:/include/xbt/signal.hpp diff --git a/include/xbt/signal.hpp b/include/xbt/signal.hpp index 26bd2df57f..08fbff611a 100644 --- a/include/xbt/signal.hpp +++ b/include/xbt/signal.hpp @@ -6,53 +6,43 @@ #ifndef SIMGRID_XBT_SIGNAL_HPP #define SIMGRID_XBT_SIGNAL_HPP -#include "simgrid_config.h" -#if SIMGRID_HAVE_LIBSIG -#include -#else -#include -#endif +#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::vector handlers_; public: template XBT_ALWAYS_INLINE - void connect(U&& slot) - { - sig_.connect(std::forward(slot)); - } - template XBT_ALWAYS_INLINE - void connect(Res(*slot)(Args...)) + void connect(U slot) { - sig_.connect(sigc::ptr_fun(slot)); + handlers_.push_back(std::move(slot)); } - template XBT_ALWAYS_INLINE - R operator()(Args&&... args) const + XBT_ALWAYS_INLINE + R operator()(P... args) const { - return sig_.emit(std::forward(args)...); + for (auto& handler : handlers_) + handler(args...); } void disconnect_all_slots() { - sig_.clear(); + handlers_.clear(); } }; -#else - - template - using signal = ::boost::signals2::signal; - -#endif - } }