-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add conditional hook macros and ShipInit module
- Loading branch information
1 parent
b38794e
commit 3917e3b
Showing
5 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef SHIP_INIT_HPP | ||
#define SHIP_INIT_HPP | ||
|
||
#ifdef __cplusplus | ||
|
||
#include <vector> | ||
#include <set> | ||
|
||
struct ShipInit { | ||
static std::unordered_map<std::string, std::vector<std::function<void()>>>& GetAll() { | ||
static std::unordered_map<std::string, std::vector<std::function<void()>>> shipInitFuncs; | ||
return shipInitFuncs; | ||
} | ||
|
||
static void InitAll() { | ||
ShipInit::Init("*"); | ||
} | ||
|
||
static void Init(const std::string& path) { | ||
auto& shipInitFuncs = ShipInit::GetAll(); | ||
for (const auto& initFunc : shipInitFuncs[path]) { | ||
initFunc(); | ||
} | ||
} | ||
}; | ||
|
||
struct RegisterShipInitFunc { | ||
RegisterShipInitFunc(std::function<void()> initFunc, const std::set<std::string>& updatePaths = {}) { | ||
auto& shipInitFuncs = ShipInit::GetAll(); | ||
|
||
shipInitFuncs["*"].push_back(initFunc); | ||
|
||
for (const auto& path : updatePaths) { | ||
shipInitFuncs[path].push_back(initFunc); | ||
} | ||
} | ||
}; | ||
|
||
#endif // __cplusplus | ||
|
||
#endif // SHIP_INIT_HPP |