1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef TRINITY_FACTORY_HOLDER |
---|
22 | #define TRINITY_FACTORY_HOLDER |
---|
23 | |
---|
24 | #include "Platform/Define.h" |
---|
25 | #include "Utilities/TypeList.h" |
---|
26 | #include "ObjectRegistry.h" |
---|
27 | #include "Policies/SingletonImp.h" |
---|
28 | |
---|
29 | /** FactoryHolder holds a factory object of a specific type |
---|
30 | */ |
---|
31 | template<class T, class Key = std::string> |
---|
32 | class TRINITY_DLL_DECL FactoryHolder |
---|
33 | { |
---|
34 | public: |
---|
35 | typedef ObjectRegistry<FactoryHolder<T, Key >, Key > FactoryHolderRegistry; |
---|
36 | typedef Trinity::Singleton<FactoryHolderRegistry > FactoryHolderRepository; |
---|
37 | |
---|
38 | FactoryHolder(Key k) : i_key(k) {} |
---|
39 | virtual ~FactoryHolder() {} |
---|
40 | inline Key key() const { return i_key; } |
---|
41 | |
---|
42 | void RegisterSelf(void) { FactoryHolderRepository::Instance().InsertItem(this, i_key); } |
---|
43 | void DeregisterSelf(void) { FactoryHolderRepository::Instance().RemoveItem(this, false); } |
---|
44 | |
---|
45 | /// Abstract Factory create method |
---|
46 | virtual T* Create(void *data = NULL) const = 0; |
---|
47 | private: |
---|
48 | Key i_key; |
---|
49 | }; |
---|
50 | |
---|
51 | /** Permissible is a classic way of letting the object decide |
---|
52 | * whether how good they handle things. This is not retricted |
---|
53 | * to factory selectors. |
---|
54 | */ |
---|
55 | template<class T> |
---|
56 | class Permissible |
---|
57 | { |
---|
58 | public: |
---|
59 | virtual ~Permissible() {} |
---|
60 | virtual int Permit(const T *) const = 0; |
---|
61 | }; |
---|
62 | #endif |
---|