shadPS4/src/common/singleton.h

26 lines
383 B
C
Raw Normal View History

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
namespace Common {
2023-10-13 08:40:59 +02:00
template <class T>
class Singleton {
2023-10-26 22:13:07 +02:00
public:
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
}
return m_instance.get();
2023-10-13 08:40:59 +02:00
}
2023-10-26 22:13:07 +02:00
protected:
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{};
};
} // namespace Common