Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
58 lines
1.2 KiB
C++
58 lines
1.2 KiB
C++
#ifndef _CSINGLETON_H_
|
|
#define _CSINGLETON_H_
|
|
|
|
#include <cassert>
|
|
|
|
template<typename Derived>
|
|
class CSingleton
|
|
{
|
|
private:
|
|
|
|
static Derived* ms_pSingleton;
|
|
|
|
protected:
|
|
|
|
CSingleton();
|
|
~CSingleton();
|
|
|
|
public:
|
|
|
|
inline static Derived& GetInstance();
|
|
inline static Derived* GetInstancePtr();
|
|
};
|
|
|
|
|
|
template<typename Derived>
|
|
CSingleton<Derived>::CSingleton()
|
|
{
|
|
assert(!ms_pSingleton && "Singleton 클래스가 이미 생성되어 있습니다.");
|
|
size_t nOffset = (size_t)(Derived*) 1 - (size_t)(CSingleton<Derived>*)(Derived*) 1;
|
|
ms_pSingleton = (Derived*)((size_t)this + nOffset);
|
|
}
|
|
|
|
|
|
template<typename Derived>
|
|
CSingleton<Derived>::~CSingleton()
|
|
{
|
|
assert(ms_pSingleton && "Singleton 클래스가 생성되지 않았습니다");
|
|
ms_pSingleton = 0;
|
|
}
|
|
|
|
template<typename Derived>
|
|
inline Derived& CSingleton<Derived>::GetInstance()
|
|
{
|
|
assert(ms_pSingleton && "Singleton 클래스가 생성되지 않았습니다");
|
|
return (*ms_pSingleton);
|
|
}
|
|
|
|
template<typename Derived>
|
|
inline Derived* CSingleton<Derived>::GetInstancePtr()
|
|
{
|
|
assert(ms_pSingleton && "Singleton 클래스가 생성되지 않았습니다");
|
|
return (ms_pSingleton);
|
|
}
|
|
|
|
template<typename Derived>
|
|
Derived* CSingleton<Derived>::ms_pSingleton = 0;
|
|
|
|
#endif |