Compare commits

..

2 Commits

Author SHA1 Message Date
Maple Redleaf
2f753f0c47 Add SysReg::NewCallback for future use 2025-11-12 11:31:22 -06:00
Maple Redleaf
e1fce167e2 Implement a simple function register manager (SysReg) 2025-11-12 11:22:01 -06:00
2 changed files with 45 additions and 0 deletions

19
include/sysreg.h Normal file
View File

@@ -0,0 +1,19 @@
#include <functional>
#include <memory>
#include <string>
#include <vector>
namespace VoidFrame {
class SysReg {
public:
const std::function<void(void)> *
RegisterCallback(const std::string &&name,
std::function<void(void)> &callback);
const std::function<void(void)> *GetCallback(std::string &&name);
void DeleteCallback(std::string &&name);
const std::function<void(void)> *NewCallback(const std::string &&name);
private:
std::unordered_map<std::string, std::unique_ptr<std::function<void(void)>>>
callbacks;
};
} // namespace VoidFrame

26
src/sysreg.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "../include/sysreg.h"
using namespace VoidFrame;
const std::function<void(void)> *
SysReg::RegisterCallback(const std::string &&name,
std::function<void(void)> &callback) {
callbacks[name] =
std::make_unique<std::function<void(void)>>(std::move(callback));
return callbacks[name].get();
}
const std::function<void(void)> *SysReg::GetCallback(std::string &&name) {
return callbacks[name].get();
}
void SysReg::DeleteCallback(std::string &&name) { callbacks.erase(name); }
const std::function<void(void)> *SysReg::NewCallback(const std::string &&name) {
if (callbacks.count(name) == 0) {
callbacks[name] = std::make_unique<std::function<void(void)>>([]() {});
}
return callbacks[name].get();
}