-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicolas Cornu
committed
Dec 13, 2024
1 parent
6df9a3b
commit 38eeb36
Showing
2 changed files
with
20 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#pragma once | ||
|
||
#include <list> | ||
|
||
#include "nrnmpi.h" | ||
#include "nrnneosm.h" | ||
//#include "shared/nvector_serial.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,31 @@ | ||
#pragma | ||
|
||
#include <list> | ||
#include <map> | ||
|
||
template <typename T> | ||
template <typename... Args> | ||
class signal_ { | ||
public: | ||
template <typename F> | ||
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<std::function<void(T)>> functors; | ||
unsigned counter = 0; | ||
std::map<int, std::function<void(Args...)>> functors; | ||
}; |