mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-07-01 20:55:11 -04:00
Compare commits
2 Commits
70df396822
...
2f753f0c47
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f753f0c47 | ||
|
|
e1fce167e2 |
19
include/sysreg.h
Normal file
19
include/sysreg.h
Normal 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
26
src/sysreg.cpp
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user