1 /* Copyright (c) 2014-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_XBT_SIGNAL_HPP
7 #define SIMGRID_XBT_SIGNAL_HPP
16 template<class S> class signal;
18 /** A signal/slot mechanism
20 * S is expected to be the function signature of the signal.
21 * I'm not sure we need a return value (it is currently ignored).
22 * If we don't we might use `signal<P1, P2, ...>` instead.
24 template<class R, class... P>
25 class signal<R(P...)> {
27 typedef std::function<R(P...)> callback_type;
28 std::vector<callback_type> handlers_;
33 handlers_.push_back(std::move(slot));
35 R operator()(P... args) const
37 for (auto const& handler : handlers_)
40 void disconnect_slots() { handlers_.clear(); }
41 int get_slot_count() { return handlers_.size(); }
43 XBT_ATTRIB_DEPRECATED_v323("Please use xbt::disconnect_slots)") void disconnectSlots() { disconnect_slots(); }
44 XBT_ATTRIB_DEPRECATED_v323("Please use xbt::get_slot_count)") int getSlotsAmount() { return get_slot_count(); }