From 38eeb3659da20273773c38828060508803c3b80d Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 13 Dec 2024 17:20:43 +0100 Subject: [PATCH] More useful signal_ class --- src/nrncvode/cvodeobj.h | 2 ++ src/utils/signal.hpp | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/nrncvode/cvodeobj.h b/src/nrncvode/cvodeobj.h index 1ad36e4cb4..eb8b52a665 100644 --- a/src/nrncvode/cvodeobj.h +++ b/src/nrncvode/cvodeobj.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "nrnmpi.h" #include "nrnneosm.h" //#include "shared/nvector_serial.h" diff --git a/src/utils/signal.hpp b/src/utils/signal.hpp index 49362c8de4..7a51c0ecec 100644 --- a/src/utils/signal.hpp +++ b/src/utils/signal.hpp @@ -1,21 +1,31 @@ #pragma -#include +#include -template +template class signal_ { public: template - void connect(F f) { - functors.push_back(f); + unsigned connect(F f) { + ++counter; + functors[counter] = f; + return counter; } - void send(T wc) { - for (auto& f: functors) { - std::invoke(f, wc); + void disconnect(unsigned i) { + auto it = functors.find(i); + if (it != functors.end()) { + functors.erase(it); + } + } + + void send(Args... args) { + for (const auto& [i, f]: functors) { + std::invoke(f, args...); } } private: - std::list> functors; + unsigned counter = 0; + std::map> functors; };