X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/efd5719fdcd06a99d1fd644b81c7e9d578c08fc5..3297da9f47ce18371941b2b48a2f4018b4793ced:/include/xbt/signal.hpp diff --git a/include/xbt/signal.hpp b/include/xbt/signal.hpp index 2068546289..4c1d46d22d 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-2018. 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,47 +6,45 @@ #ifndef SIMGRID_XBT_SIGNAL_HPP #define SIMGRID_XBT_SIGNAL_HPP -#ifdef SIMGRID_HAVE_LIBSIG -#include +#include +#include +#include namespace simgrid { namespace xbt { - // Wraps sigc++ signals with the interface of boost::signals2: - template class signal; + + 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...)) + template + 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 + R operator()(P... args) const { - return sig_.emit(std::forward(args)...); + for (auto const& handler : handlers_) + handler(args...); } + void disconnect_slots() { handlers_.clear(); } + int get_slot_count() { return handlers_.size(); } + // deprecated + XBT_ATTRIB_DEPRECATED_v323("Please use xbt::disconnect_slots)") void disconnectSlots() { disconnect_slots(); } + XBT_ATTRIB_DEPRECATED_v323("Please use xbt::get_slot_count)") int getSlotsAmount() { return get_slot_count(); } }; -} -} -#else - -#include -namespace simgrid { -namespace xbt { - template - using signal = ::boost::signals2::signal; } } #endif - -#endif