A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
added circle placement for ns3 wifi nodes
[simgrid.git]
/
include
/
xbt
/
signal.hpp
diff --git
a/include/xbt/signal.hpp
b/include/xbt/signal.hpp
index c81b95bcbb31b4dc9f033f11bc3fabe8469e4094..4289edd0f68c568ef55cb4d68bf97170c06379fc 100644
(file)
--- a/
include/xbt/signal.hpp
+++ b/
include/xbt/signal.hpp
@@
-1,4
+1,4
@@
-/* Copyright (c) 2014-20
19
. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2014-20
20
. 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. */
/* 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 <functional>
#define SIMGRID_XBT_SIGNAL_HPP
#include <functional>
+#include <map>
#include <utility>
#include <utility>
-#include <vector>
namespace simgrid {
namespace xbt {
namespace simgrid {
namespace xbt {
@@
-23,25
+23,24
@@
namespace xbt {
*/
template<class R, class... P>
class signal<R(P...)> {
*/
template<class R, class... P>
class signal<R(P...)> {
- private:
typedef std::function<R(P...)> callback_type;
typedef std::function<R(P...)> callback_type;
- std::vector<callback_type> handlers_;
+ std::map<unsigned int, callback_type> handlers_;
+ unsigned int callback_sequence_id = 0;
+
public:
public:
- template<class U>
- void connect(U slot)
+ template <class U> 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_)
}
R operator()(P... args) const
{
for (auto const& handler : handlers_)
- handler(args...);
+ handler
.second
(args...);
}
}
+ void disconnect(unsigned int id) { handlers_.erase(id); }
void disconnect_slots() { handlers_.clear(); }
int get_slot_count() { return handlers_.size(); }
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(); }
};
}
};
}