shadPS4/src/common/singleton.h

29 lines
496 B
C
Raw Normal View History

2024-02-23 21:32:32 +00:00
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2023-10-13 06:40:59 +00:00
#pragma once
2023-10-26 20:13:07 +00:00
#include <memory>
2023-10-13 06:40:59 +00:00
namespace Common {
2023-10-13 06:40:59 +00:00
template <class T>
class Singleton {
2023-10-26 20:13:07 +00:00
public:
static T* Instance() {
2023-10-13 06:40:59 +00:00
if (!m_instance) {
2023-10-26 20:13:07 +00:00
m_instance = std::make_unique<T>();
2023-10-13 06:40:59 +00:00
}
return m_instance.get();
2023-10-13 06:40:59 +00:00
}
2023-10-26 20:13:07 +00:00
protected:
Singleton();
~Singleton();
2023-10-13 06:40:59 +00:00
2023-10-26 20:13:07 +00:00
private:
static inline std::unique_ptr<T> m_instance{};
};
} // namespace Common