diff options
| author | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
|---|---|---|
| committer | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
| commit | e585187b248f48b3c6e9247b49fa07c6565d65e5 (patch) | |
| tree | 637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /src/framework/Dynamic | |
| parent | 26b5e033ffde3d161382fc9addbfa99738379641 (diff) | |
*Backed out changeset 3be01fb200a5
--HG--
branch : trunk
Diffstat (limited to 'src/framework/Dynamic')
| -rw-r--r-- | src/framework/Dynamic/FactoryHolder.h | 7 | ||||
| -rw-r--r-- | src/framework/Dynamic/ObjectRegistry.h | 13 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/framework/Dynamic/FactoryHolder.h b/src/framework/Dynamic/FactoryHolder.h index ab3671fc2c3..858b8c1e1d3 100644 --- a/src/framework/Dynamic/FactoryHolder.h +++ b/src/framework/Dynamic/FactoryHolder.h @@ -17,12 +17,15 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + #ifndef TRINITY_FACTORY_HOLDER #define TRINITY_FACTORY_HOLDER + #include "Platform/Define.h" #include "Utilities/TypeList.h" #include "ObjectRegistry.h" #include "Policies/SingletonImp.h" + /** FactoryHolder holds a factory object of a specific type */ template<class T, class Key = std::string> @@ -31,16 +34,20 @@ class TRINITY_DLL_DECL FactoryHolder public: typedef ObjectRegistry<FactoryHolder<T, Key >, Key > FactoryHolderRegistry; typedef Trinity::Singleton<FactoryHolderRegistry > FactoryHolderRepository; + 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); } + /// 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 * whether how good they handle things. This is not retricted * to factory selectors. diff --git a/src/framework/Dynamic/ObjectRegistry.h b/src/framework/Dynamic/ObjectRegistry.h index d266c280eb5..8c2659e8f53 100644 --- a/src/framework/Dynamic/ObjectRegistry.h +++ b/src/framework/Dynamic/ObjectRegistry.h @@ -17,14 +17,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + #ifndef TRINITY_OBJECTREGISTRY_H #define TRINITY_OBJECTREGISTRY_H + #include "Platform/Define.h" #include "Utilities/UnorderedMap.h" #include "Policies/Singleton.h" + #include <string> #include <vector> #include <map> + /** ObjectRegistry holds all registry item of the same type */ template<class T, class Key = std::string> @@ -32,12 +36,14 @@ class TRINITY_DLL_DECL ObjectRegistry { public: typedef std::map<Key, T *> RegistryMapType; + /// Returns a registry item const T* GetRegistryItem(Key key) const { typename RegistryMapType::const_iterator iter = i_registeredObjects.find(key); return( iter == i_registeredObjects.end() ? NULL : iter->second ); } + /// Inserts a registry item bool InsertItem(T *obj, Key key, bool override = false) { @@ -49,9 +55,11 @@ class TRINITY_DLL_DECL ObjectRegistry delete iter->second; i_registeredObjects.erase(iter); } + i_registeredObjects[key] = obj; return true; } + /// Removes a registry item void RemoveItem(Key key, bool delete_object = true) { @@ -63,11 +71,13 @@ class TRINITY_DLL_DECL ObjectRegistry i_registeredObjects.erase(iter); } } + /// Returns true if registry contains an item bool HasItem(Key key) const { return (i_registeredObjects.find(key) != i_registeredObjects.end()); } + /// Inefficiently return a vector of registered items unsigned int GetRegisteredItems(std::vector<Key> &l) const { @@ -77,14 +87,17 @@ class TRINITY_DLL_DECL ObjectRegistry l[sz++] = iter->first; return i_registeredObjects.size(); } + /// Return the map of registered items RegistryMapType const &GetRegisteredItems() const { return i_registeredObjects; } + private: RegistryMapType i_registeredObjects; friend class Trinity::OperatorNew<ObjectRegistry<T, Key> >; + // protected for friend use since it should be a singleton ObjectRegistry() {} ~ObjectRegistry() |
