feat(Core/Misc): remove and replace ACE_Singleton (#2418)

This commit is contained in:
Kargatum
2019-12-21 00:29:29 +07:00
committed by GitHub
parent 16b45bf334
commit 4a8f1de538
88 changed files with 486 additions and 250 deletions

View File

@@ -25,7 +25,6 @@
#include "WorldModel.h"
#include <G3D/Vector3.h>
#include <ace/Null_Mutex.h>
#include <ace/Singleton.h>
#include "DisableMgr.h"
#include "DBCStores.h"
#include "Log.h"

View File

@@ -8,6 +8,12 @@
#include "Errors.h"
#include "Log.h"
ConfigMgr* ConfigMgr::instance()
{
static ConfigMgr instance;
return &instance;
}
// Defined here as it must not be exposed to end-users.
bool ConfigMgr::GetValueHelper(const char* name, ACE_TString &result)
{

View File

@@ -10,7 +10,6 @@
#include <string>
#include <list>
#include <vector>
#include <ace/Singleton.h>
#include <ace/Configuration_Import_Export.h>
#include <ace/Thread_Mutex.h>
#include <AutoPtr.h>
@@ -19,13 +18,12 @@ typedef acore::AutoPtr<ACE_Configuration_Heap, ACE_Null_Mutex> Config;
class ConfigMgr
{
friend class ACE_Singleton<ConfigMgr, ACE_Null_Mutex>;
friend class ConfigLoader;
ConfigMgr() { }
~ConfigMgr() { }
public:
static ConfigMgr* instance();
/// Method used only for loading main configuration files (authserver.conf and worldserver.conf)
bool LoadInitial(char const* file);
@@ -62,10 +60,12 @@ private:
Config _config;
LockType _configLock;
ConfigMgr(ConfigMgr const&);
ConfigMgr& operator=(ConfigMgr const&);
ConfigMgr() = default;
ConfigMgr(ConfigMgr const&) = delete;
ConfigMgr& operator=(ConfigMgr const&) = delete;
~ConfigMgr() = default;
};
#define sConfigMgr ACE_Singleton<ConfigMgr, ACE_Null_Mutex>::instance()
#define sConfigMgr ConfigMgr::instance()
#endif

View File

@@ -11,30 +11,30 @@
#include "Dynamic/TypeList.h"
#include "ObjectRegistry.h"
/** FactoryHolder holds a factory object of a specific type
/*
* FactoryHolder holds a factory object of a specific type
*/
template<class T, class Key = std::string>
class FactoryHolder
{
public:
typedef ObjectRegistry<FactoryHolder<T, Key >, Key > FactoryHolderRegistry;
friend class ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex>;
typedef ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex> FactoryHolderRepository;
public:
typedef ObjectRegistry<FactoryHolder<T, Key >, Key > FactoryHolderRegistry;
FactoryHolder(Key k) : i_key(k) { }
virtual ~FactoryHolder() { }
inline Key key() const { return i_key; }
FactoryHolder(Key k) : i_key(k) { }
virtual ~FactoryHolder() { }
inline Key key() const { return i_key; }
void RegisterSelf(void) { FactoryHolderRepository::instance()->InsertItem(this, i_key); }
void DeregisterSelf(void) { FactoryHolderRepository::instance()->RemoveItem(this, false); }
void RegisterSelf(void) { FactoryHolderRegistry::instance()->InsertItem(this, i_key); }
void DeregisterSelf(void) { FactoryHolderRegistry::instance()->RemoveItem(this, false); }
/// Abstract Factory create method
virtual T* Create(void *data = NULL) const = 0;
private:
Key i_key;
/// Abstract Factory create method
virtual T* Create(void* data = NULL) const = 0;
private:
Key i_key;
};
/** Permissible is a classic way of letting the object decide
/*
* Permissible is a classic way of letting the object decide
* whether how good they handle things. This is not retricted
* to factory selectors.
*/
@@ -45,5 +45,5 @@ class Permissible
virtual ~Permissible() { }
virtual int Permit(const T *) const = 0;
};
#endif
#endif

View File

@@ -8,7 +8,6 @@
#define ACORE_OBJECTREGISTRY_H
#include "Define.h"
#include <ace/Singleton.h>
#include <string>
#include <vector>
#include <map>
@@ -29,6 +28,12 @@ class ObjectRegistry
return( iter == i_registeredObjects.end() ? NULL : iter->second );
}
static ObjectRegistry<T, Key>* instance()
{
static ObjectRegistry<T, Key>* instance = new ObjectRegistry<T, Key>();
return instance;
}
/// Inserts a registry item
bool InsertItem(T *obj, Key key, bool override = false)
{

View File

@@ -65,6 +65,12 @@ Log::~Log()
miscLogFile = NULL;
}
Log* Log::instance()
{
static Log instance;
return &instance;
}
void Log::SetLogLevel(char *Level)
{
int32 NewLevel = atoi((char*)Level);

View File

@@ -9,7 +9,6 @@
#include "Common.h"
#include <ace/Task.h>
#include <ace/Singleton.h>
class WorldPacket;
@@ -96,13 +95,17 @@ const int Colors = int(WHITE)+1;
class Log
{
friend class ACE_Singleton<Log, ACE_Thread_Mutex>;
private:
Log();
~Log();
Log(Log const&) = delete;
Log(Log&&) = delete;
Log& operator=(Log const&) = delete;
Log& operator=(Log&&) = delete;
public:
static Log* instance();
void Initialize();
void ReloadConfig();
@@ -194,7 +197,7 @@ class Log
DebugLogFilters m_DebugLogMask;
};
#define sLog ACE_Singleton<Log, ACE_Thread_Mutex>::instance()
#define sLog Log::instance()
#endif

View File

@@ -1,13 +1,12 @@
#include <ace/Singleton.h>
#include <ace/Thread_Mutex.h>
#include <ace/Log_Msg.h>
#include "Threading.h"
#include "DelayExecutor.h"
DelayExecutor* DelayExecutor::instance()
{
return ACE_Singleton<DelayExecutor, ACE_Thread_Mutex>::instance();
static DelayExecutor instance;
return &instance;
}
DelayExecutor::DelayExecutor()