input.add_callback

This commit is contained in:
MihailRis
2024-05-05 06:49:17 +03:00
parent 92f6fd2226
commit ba885e4e08
7 changed files with 66 additions and 6 deletions
+32
View File
@@ -0,0 +1,32 @@
#ifndef UTIL_RUNNABLES_LIST_HPP_
#define UTIL_RUNNABLES_LIST_HPP_
#include "../typedefs.h"
#include "../delegates.h"
#include <memory>
#include <unordered_map>
namespace util {
class RunnablesList {
int nextid = 1;
std::unordered_map<int, runnable> runnables;
public:
observer_handler add(runnable callback) {
int id = nextid++;
runnables[id] = callback;
return observer_handler(new int(id), [this](int* id) {
runnables.erase(*id);
delete id;
});
}
void notify() {
for (auto& entry : runnables) {
entry.second();
}
}
};
}
#endif // UTIL_RUNNABLES_LIST_HPP_