mirror of
https://gitlab.com/voidframe/voidframe-cpp.git
synced 2026-06-28 10:55:11 -04:00
Add SysReg::NewCallback for future use
This commit is contained in:
@@ -5,11 +5,12 @@
|
||||
namespace VoidFrame {
|
||||
class SysReg {
|
||||
public:
|
||||
std::function<void(void)> *
|
||||
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)>>>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
using namespace VoidFrame;
|
||||
|
||||
std::function<void(void)> *
|
||||
const std::function<void(void)> *
|
||||
SysReg::RegisterCallback(const std::string &&name,
|
||||
std::function<void(void)> &callback) {
|
||||
callbacks[name] =
|
||||
@@ -16,3 +16,11 @@ const std::function<void(void)> *SysReg::GetCallback(std::string &&name) {
|
||||
}
|
||||
|
||||
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