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. More...
 
bool InsertItem (T *obj, Key const &key, bool force=false)
 Inserts a registry item. More...
 
bool HasItem (Key const &key) const
 Returns true if registry contains an item. More...
 
RegistryMapType const & GetRegisteredItems () const
 Return the map of registered items. More...
 

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
81{ }

◆ ~ObjectRegistry()

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

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.

73 {
74 return _registeredObjects;
75 }
RegistryMapType _registeredObjects
Definition: ObjectRegistry.h:78

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.

35 {
36 auto itr = _registeredObjects.find(key);
37 if (itr == _registeredObjects.end())
38 return nullptr;
39 return itr->second.get();
40 }

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.

67 {
68 return (_registeredObjects.count(key) > 0);
69 }

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.

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

References ObjectRegistry< T, Key >::_registeredObjects.

◆ instance()

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

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

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

Member Data Documentation

◆ _registeredObjects