update singleton
This commit is contained in:
parent
a794894452
commit
f786ab67ef
|
|
@ -68,11 +68,11 @@ public:
|
|||
|
||||
void DestroyModule() override;
|
||||
|
||||
~AudioModule();
|
||||
|
||||
private:
|
||||
AudioModule();
|
||||
|
||||
~AudioModule();
|
||||
|
||||
private:
|
||||
IXAudio2* x_audio2_;
|
||||
IXAudio2MasteringVoice* mastering_voice_;
|
||||
|
|
|
|||
|
|
@ -102,11 +102,11 @@ public:
|
|||
|
||||
void HandleEvent(Event* evt) override;
|
||||
|
||||
virtual ~Director();
|
||||
|
||||
private:
|
||||
Director();
|
||||
|
||||
virtual ~Director();
|
||||
|
||||
private:
|
||||
bool render_border_enabled_;
|
||||
Stack<StagePtr> stages_;
|
||||
|
|
|
|||
|
|
@ -19,12 +19,13 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
template <typename _Ty>
|
||||
struct Singleton
|
||||
class Singleton
|
||||
{
|
||||
protected:
|
||||
Singleton() = default;
|
||||
|
|
@ -32,29 +33,47 @@ protected:
|
|||
Singleton& operator=(const Singleton&) = delete;
|
||||
|
||||
private:
|
||||
struct ObjectCreator
|
||||
struct InstanceCreator
|
||||
{
|
||||
ObjectCreator()
|
||||
InstanceCreator()
|
||||
{
|
||||
(void)Singleton<_Ty>::GetInstance();
|
||||
(void)Singleton<_Ty>::GetInstancePtr();
|
||||
}
|
||||
|
||||
inline void Dummy() const {}
|
||||
};
|
||||
static ObjectCreator creator_;
|
||||
static InstanceCreator creator_;
|
||||
|
||||
public:
|
||||
using object_type = _Ty;
|
||||
|
||||
static std::unique_ptr<object_type> instance_ptr_;
|
||||
|
||||
static inline object_type& GetInstance()
|
||||
{
|
||||
static object_type instance;
|
||||
return *GetInstancePtr();
|
||||
}
|
||||
|
||||
static inline object_type* GetInstancePtr()
|
||||
{
|
||||
creator_.Dummy();
|
||||
return instance;
|
||||
if (!instance_ptr_)
|
||||
{
|
||||
instance_ptr_.reset(new object_type);
|
||||
}
|
||||
return instance_ptr_.get();
|
||||
}
|
||||
|
||||
static inline void DestroyInstance()
|
||||
{
|
||||
instance_ptr_.reset();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename _Ty>
|
||||
typename Singleton<_Ty>::ObjectCreator Singleton<_Ty>::creator_;
|
||||
typename Singleton<_Ty>::InstanceCreator Singleton<_Ty>::creator_;
|
||||
|
||||
template <typename _Ty>
|
||||
typename std::unique_ptr<_Ty> Singleton<_Ty>::instance_ptr_;
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -102,11 +102,11 @@ public:
|
|||
*/
|
||||
bool ExtractResourceToFile(const Resource& res, const String& dest_file_name) const;
|
||||
|
||||
~FileSystem();
|
||||
|
||||
private:
|
||||
FileSystem();
|
||||
|
||||
~FileSystem();
|
||||
|
||||
private:
|
||||
Vector<String> search_paths_;
|
||||
UnorderedMap<String, String> file_lookup_dict_;
|
||||
|
|
|
|||
|
|
@ -112,11 +112,11 @@ public:
|
|||
|
||||
void HandleEvent(Event* evt) override;
|
||||
|
||||
~Input();
|
||||
|
||||
private:
|
||||
Input();
|
||||
|
||||
~Input();
|
||||
|
||||
void UpdateKey(KeyCode key, bool down);
|
||||
|
||||
void UpdateButton(MouseButton btn, bool down);
|
||||
|
|
|
|||
|
|
@ -74,11 +74,11 @@ public:
|
|||
/// @brief 헌왕뻠닸
|
||||
void Clear();
|
||||
|
||||
virtual ~TextureCache();
|
||||
|
||||
private:
|
||||
TextureCache();
|
||||
|
||||
virtual ~TextureCache();
|
||||
|
||||
private:
|
||||
using TextureMap = UnorderedMap<size_t, TexturePtr>;
|
||||
TextureMap texture_cache_;
|
||||
|
|
|
|||
|
|
@ -126,11 +126,11 @@ public:
|
|||
/// @note 此操作会重定向输出流到标准输出流
|
||||
void ShowConsole(bool show);
|
||||
|
||||
~Logger();
|
||||
|
||||
private:
|
||||
Logger();
|
||||
|
||||
~Logger();
|
||||
|
||||
void Prepare(Level level, StringStream& sstream);
|
||||
|
||||
void Output(Level level, StringStream& sstream);
|
||||
|
|
|
|||
|
|
@ -88,11 +88,11 @@ public:
|
|||
/// @brief 清空所有资源
|
||||
void Clear();
|
||||
|
||||
virtual ~ResourceCache();
|
||||
|
||||
private:
|
||||
ResourceCache();
|
||||
|
||||
virtual ~ResourceCache();
|
||||
|
||||
private:
|
||||
UnorderedMap<String, ObjectBasePtr> object_cache_;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue