mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-17 02:50:29 +00:00
feat(Core/Misc): remove and replace ACE_Singleton (#2418)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user