mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-06-28 10:55:11 -04:00
Implement a simple function register manager (SysReg)
This commit is contained in:
18
include/sysreg.h
Normal file
18
include/sysreg.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace VoidFrame {
|
||||
class SysReg {
|
||||
public:
|
||||
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);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::unique_ptr<std::function<void(void)>>>
|
||||
callbacks;
|
||||
};
|
||||
} // namespace VoidFrame
|
||||
18
src/sysreg.cpp
Normal file
18
src/sysreg.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "../include/sysreg.h"
|
||||
|
||||
using namespace VoidFrame;
|
||||
|
||||
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); }
|
||||
Reference in New Issue
Block a user