Restructure repository to include all source folders
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>
This commit is contained in:
124
Server/RylServerProject/BaseLibrary/Pattern/Singleton.h
Normal file
124
Server/RylServerProject/BaseLibrary/Pattern/Singleton.h
Normal file
@@ -0,0 +1,124 @@
|
||||
#ifndef _CSINGLETON_H_
|
||||
#define _CSINGLETON_H_
|
||||
|
||||
#include <cassert>
|
||||
|
||||
template<typename Derived>
|
||||
class CSingleton
|
||||
{
|
||||
private:
|
||||
|
||||
static Derived* ms_pSingleton;
|
||||
|
||||
protected:
|
||||
|
||||
CSingleton();
|
||||
~CSingleton();
|
||||
|
||||
public:
|
||||
|
||||
static Derived& GetInstance();
|
||||
static Derived* GetInstancePtr();
|
||||
};
|
||||
|
||||
|
||||
template<typename Derived>
|
||||
CSingleton<Derived>::CSingleton()
|
||||
{
|
||||
assert(!ms_pSingleton && "Singleton Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̹<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ǿ<EFBFBD> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.");
|
||||
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 Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʾҽ<CABE><D2BD>ϴ<EFBFBD>");
|
||||
ms_pSingleton = 0;
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
inline Derived& CSingleton<Derived>::GetInstance()
|
||||
{
|
||||
assert(ms_pSingleton && "Singleton Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʾҽ<CABE><D2BD>ϴ<EFBFBD>");
|
||||
return (*ms_pSingleton);
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
inline Derived* CSingleton<Derived>::GetInstancePtr()
|
||||
{
|
||||
assert(ms_pSingleton && "Singleton Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʾҽ<CABE><D2BD>ϴ<EFBFBD>");
|
||||
return (ms_pSingleton);
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
Derived* CSingleton<Derived>::ms_pSingleton = 0;
|
||||
|
||||
|
||||
|
||||
// Scotte Meyer's Implementation
|
||||
template<typename Derived>
|
||||
class CStaticSingleton
|
||||
{
|
||||
public:
|
||||
|
||||
inline static Derived& GetInstance()
|
||||
{
|
||||
static Derived Instance;
|
||||
return Instance;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Derived>
|
||||
class CLeakStaticSingleton
|
||||
{
|
||||
public:
|
||||
|
||||
inline static Derived& GetInstance()
|
||||
{
|
||||
static Derived* lpInstance = new Derived;
|
||||
return *lpInstance;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// C++ FAQ's Implementation
|
||||
template<typename T>
|
||||
class CNiftyCounterSingleton
|
||||
{
|
||||
public:
|
||||
|
||||
CNiftyCounterSingleton() { ++nifty_count_; }
|
||||
~CNiftyCounterSingleton() { if ( 0 == --nifty_count_ && pInstance_ ) { delete pInstance_; } }
|
||||
|
||||
static T& GetInstance()
|
||||
{
|
||||
if (NULL == pInstance_) { pInstance_ = new T; }
|
||||
return *pInstance_;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static int nifty_count_;
|
||||
static T* pInstance_;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
int CNiftyCounterSingleton<T>::nifty_count_ = 0;
|
||||
|
||||
template<typename T>
|
||||
T* CNiftyCounterSingleton<T>::pInstance_ = 0;
|
||||
|
||||
/*
|
||||
Ŭ<><C5AC><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>.
|
||||
Ŭ<><C5AC><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, <20>Ҹ<EFBFBD><D2B8>ڴ<EFBFBD> private<74>̰<EFBFBD>, CNiftyCounterSingleton<6F><6E> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>.
|
||||
|
||||
namespace
|
||||
{
|
||||
CNiftyCounterSingleton<T> TNiftyCounter;
|
||||
}
|
||||
*/
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user