own implementation of singleton and logger
This commit is contained in:
1 parent
f6c5bcca39
commit
6aed7b0027
19 files changed
+745
-206
No files matched your search
@@ -0,0 +1,30 @@
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
|
||||
class SingletonManager {
|
||||
public:
|
||||
// Priority: Higher numbers are destroyed LAST (e.g., Logger = 100)
|
||||
static void registerShutdown(const int priority, const std::function<void()> &shutdownFunc) {
|
||||
m_registry.push_back({priority, shutdownFunc});
|
||||
// Sort so that high priority stays at the end (destroyed last)
|
||||
std::ranges::sort(m_registry, [](const auto& a, const auto& b) {
|
||||
return a.priority < b.priority;
|
||||
});
|
||||
}
|
||||
|
||||
static void shutdownAll() {
|
||||
// Destroy in reverse priority (highest priority first? No, usually reverse order of arrival)
|
||||
// Here we destroy from lowest priority to highest.
|
||||
for (auto& [priority, func] : m_registry) {
|
||||
std::cerr << priority << ": " << &func << std::endl;
|
||||
func();
|
||||
}
|
||||
m_registry.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
struct Entry { int priority; std::function<void()> func; };
|
||||
static inline std::vector<Entry> m_registry;
|
||||
};
|
||||
Reference in new issue
Block a user