Acheron
Loading...
Searching...
No Matches
singleton.hpp
1#pragma once
2
3#include <cassert>
4
5namespace acheron::ecs {
11 template<typename T>
13 public:
19 static void Set(const T& value) {
20 instance() = value;
21 initialized() = true;
22 }
23
30 static T& Get() {
31 assert(initialized() && "Singleton not set");
32 return instance();
33 }
34
40 static bool IsSet() {
41 return initialized();
42 }
43
44 private:
48 static T& instance() {
49 static T obj;
50 return obj;
51 }
52
56 static bool& initialized() {
57 static bool flag = false;
58 return flag;
59 }
60 };
61}
Interal storage wrapper for singletons.
Definition singleton.hpp:12
static bool IsSet()
Check if the singleton is set.
Definition singleton.hpp:40
static void Set(const T &value)
Initializes singleton and sets the instance value.
Definition singleton.hpp:19
static T & Get()
Get the instance of a singleton.
Definition singleton.hpp:30