2023-10-13 08:40:59 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-10-26 22:13:07 +02:00
|
|
|
#include <memory>
|
2023-10-13 08:40:59 +02:00
|
|
|
|
2023-11-05 15:56:28 +01:00
|
|
|
namespace Common {
|
|
|
|
|
2023-10-13 08:40:59 +02:00
|
|
|
template <class T>
|
2023-11-05 15:56:28 +01:00
|
|
|
class Singleton {
|
2023-10-26 22:13:07 +02:00
|
|
|
public:
|
2023-11-05 15:56:28 +01:00
|
|
|
static T* Instance() {
|
2023-10-13 08:40:59 +02:00
|
|
|
if (!m_instance) {
|
2023-10-26 22:13:07 +02:00
|
|
|
m_instance = std::make_unique<T>();
|
2023-10-13 08:40:59 +02:00
|
|
|
}
|
2023-10-26 22:29:05 +02:00
|
|
|
return m_instance.get();
|
2023-10-13 08:40:59 +02:00
|
|
|
}
|
|
|
|
|
2023-10-26 22:13:07 +02:00
|
|
|
protected:
|
2023-11-05 15:56:28 +01:00
|
|
|
Singleton();
|
|
|
|
~Singleton();
|
2023-10-13 08:40:59 +02:00
|
|
|
|
2023-10-26 22:13:07 +02:00
|
|
|
private:
|
|
|
|
static inline std::unique_ptr<T> m_instance{};
|
|
|
|
};
|
2023-11-05 15:56:28 +01:00
|
|
|
|
|
|
|
} // namespace Common
|