AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ObjectRegistry< T, Key > Class Template Referencefinal

#include "ObjectRegistry.h"

Public Types

typedef std::map< Key, std::unique_ptr< T > > RegistryMapType
 

Public Member Functions

T const * GetRegistryItem (Key const &key) const
 Returns a registry item.
 
bool InsertItem (T *obj, Key const &key, bool force=false)
 Inserts a registry item.
 
bool HasItem (Key const &key) const
 Returns true if registry contains an item.
 
RegistryMapType const & GetRegisteredItems () const
 Return the map of registered items.
 

Static Public Member Functions

static ObjectRegistry< T, Key > * instance ()
 

Private Member Functions

 ObjectRegistry ()
 
 ~ObjectRegistry ()
 

Private Attributes

RegistryMapType _registeredObjects
 

Detailed Description

template<class T, class Key = std::string>
class ObjectRegistry< T, Key >

ObjectRegistry holds all registry item of the same type

Member Typedef Documentation

◆ RegistryMapType

template<class T , class Key = std::string>
typedef std::map<Key, std::unique_ptr<T> > ObjectRegistry< T, Key >::RegistryMapType

Constructor & Destructor Documentation

◆ ObjectRegistry()

template<class T , class Key = std::string>
ObjectRegistry< T, Key >::ObjectRegistry ( )
inlineprivate
84{ }

◆ ~ObjectRegistry()

template<class T , class Key = std::string>
ObjectRegistry< T, Key >::~ObjectRegistry ( )
inlineprivate
85{ }

Member Function Documentation

◆ GetRegisteredItems()

template<class T , class Key = std::string>
RegistryMapType const & ObjectRegistry< T, Key >::GetRegisteredItems ( ) const
inline

Return the map of registered items.

76 {
77 return _registeredObjects;
78 }
RegistryMapType _registeredObjects
Definition: ObjectRegistry.h:81

References ObjectRegistry< T, Key >::_registeredObjects.

◆ GetRegistryItem()

template<class T , class Key = std::string>
T const * ObjectRegistry< T, Key >::GetRegistryItem ( Key const &  key) const
inline

Returns a registry item.

38 {
39 auto itr = _registeredObjects.find(key);
40 if (itr == _registeredObjects.end())
41 return nullptr;
42 return itr->second.get();
43 }

References ObjectRegistry< T, Key >::_registeredObjects.

Referenced by FactorySelector::SelectFactory().

◆ HasItem()

template<class T , class Key = std::string>
bool ObjectRegistry< T, Key >::HasItem ( Key const &  key) const
inline

Returns true if registry contains an item.

70 {
71 return (_registeredObjects.count(key) > 0);
72 }

References ObjectRegistry< T, Key >::_registeredObjects.

◆ InsertItem()

template<class T , class Key = std::string>
bool ObjectRegistry< T, Key >::InsertItem ( T *  obj,
Key const &  key,
bool  force = false 
)
inline

Inserts a registry item.

53 {
54 auto itr = _registeredObjects.find(key);
55 if (itr != _registeredObjects.end())
56 {
57 if (!force)
58 {
59 return false;
60 }
61 _registeredObjects.erase(itr);
62 }
63
64 _registeredObjects.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(obj));
65 return true;
66 }

References ObjectRegistry< T, Key >::_registeredObjects.

◆ instance()

template<class T , class Key = std::string>
static ObjectRegistry< T, Key > * ObjectRegistry< T, Key >::instance ( )
inlinestatic
46 {
48 return instance;
49 }
Definition: ObjectRegistry.h:32
static ObjectRegistry< T, Key > * instance()
Definition: ObjectRegistry.h:45

References ObjectRegistry< T, Key >::instance().

Referenced by ObjectRegistry< T, Key >::instance(), and FactoryHolder< T, O, Key >::RegisterSelf().

Member Data Documentation

◆ _registeredObjects