TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ObjectRegistry< T, Key > Class Template Reference

#include <ObjectRegistry.h>

Public Types

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

Public Member Functions

const T * GetRegistryItem (Key key) const
 Returns a registry item. More...
 
bool InsertItem (T *obj, Key key, bool _override=false)
 Inserts a registry item. More...
 
void RemoveItem (Key key, bool delete_object=true)
 Removes a registry item. More...
 
bool HasItem (Key key) const
 Returns true if registry contains an item. More...
 
unsigned int GetRegisteredItems (std::vector< Key > &l) const
 Inefficiently return a vector of registered items. More...
 
RegistryMapType constGetRegisteredItems () const
 Return the map of registered items. More...
 
 ObjectRegistry ()
 
 ~ObjectRegistry ()
 

Static Public Member Functions

static ObjectRegistry< T, Key > * instance ()
 

Private Attributes

RegistryMapType i_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

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

Constructor & Destructor Documentation

template<class T, class Key = std::string>
ObjectRegistry< T, Key >::ObjectRegistry ( )
inline
99 { }
template<class T, class Key = std::string>
ObjectRegistry< T, Key >::~ObjectRegistry ( )
inline
101  {
102  for (typename RegistryMapType::iterator iter=i_registeredObjects.begin(); iter != i_registeredObjects.end(); ++iter)
103  delete iter->second;
104  i_registeredObjects.clear();
105  }
RegistryMapType i_registeredObjects
Definition: ObjectRegistry.h:107

Member Function Documentation

template<class T, class Key = std::string>
unsigned int ObjectRegistry< T, Key >::GetRegisteredItems ( std::vector< Key > &  l) const
inline

Inefficiently return a vector of registered items.

85  {
86  unsigned int sz = l.size();
87  l.resize(sz + i_registeredObjects.size());
88  for (typename RegistryMapType::const_iterator iter = i_registeredObjects.begin(); iter != i_registeredObjects.end(); ++iter)
89  l[sz++] = iter->first;
90  return i_registeredObjects.size();
91  }
RegistryMapType i_registeredObjects
Definition: ObjectRegistry.h:107
template<class T, class Key = std::string>
RegistryMapType const& ObjectRegistry< T, Key >::GetRegisteredItems ( ) const
inline

Return the map of registered items.

95  {
96  return i_registeredObjects;
97  }
RegistryMapType i_registeredObjects
Definition: ObjectRegistry.h:107
template<class T, class Key = std::string>
const T* ObjectRegistry< T, Key >::GetRegistryItem ( Key  key) const
inline

Returns a registry item.

44  {
45  typename RegistryMapType::const_iterator iter = i_registeredObjects.find(key);
46  return( iter == i_registeredObjects.end() ? NULL : iter->second );
47  }
arena_t NULL
Definition: jemalloc_internal.h:624
RegistryMapType i_registeredObjects
Definition: ObjectRegistry.h:107
template<class T, class Key = std::string>
bool ObjectRegistry< T, Key >::HasItem ( Key  key) const
inline

Returns true if registry contains an item.

79  {
80  return (i_registeredObjects.find(key) != i_registeredObjects.end());
81  }
RegistryMapType i_registeredObjects
Definition: ObjectRegistry.h:107
template<class T, class Key = std::string>
bool ObjectRegistry< T, Key >::InsertItem ( T *  obj,
Key  key,
bool  _override = false 
)
inline

Inserts a registry item.

51  {
52  typename RegistryMapType::iterator iter = i_registeredObjects.find(key);
53  if ( iter != i_registeredObjects.end() )
54  {
55  if ( !_override )
56  return false;
57  delete iter->second;
58  i_registeredObjects.erase(iter);
59  }
60 
61  i_registeredObjects[key] = obj;
62  return true;
63  }
RegistryMapType i_registeredObjects
Definition: ObjectRegistry.h:107
template<class T, class Key = std::string>
static ObjectRegistry<T, Key>* ObjectRegistry< T, Key >::instance ( )
inlinestatic
37  {
39  return &instance;
40  }
Definition: ObjectRegistry.h:31
static ObjectRegistry< T, Key > * instance()
Definition: ObjectRegistry.h:36

+ Here is the caller graph for this function:

template<class T, class Key = std::string>
void ObjectRegistry< T, Key >::RemoveItem ( Key  key,
bool  delete_object = true 
)
inline

Removes a registry item.

67  {
68  typename RegistryMapType::iterator iter = i_registeredObjects.find(key);
69  if ( iter != i_registeredObjects.end() )
70  {
71  if ( delete_object )
72  delete iter->second;
73  i_registeredObjects.erase(iter);
74  }
75  }
RegistryMapType i_registeredObjects
Definition: ObjectRegistry.h:107

Member Data Documentation

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

The documentation for this class was generated from the following file: