TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FactoryHolder.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITY_FACTORY_HOLDER
20 #define TRINITY_FACTORY_HOLDER
21 
22 #include "Define.h"
23 #include "Dynamic/TypeList.h"
24 #include "ObjectRegistry.h"
25 
28 template<class T, class Key = std::string>
30 {
31  public:
33 
34  FactoryHolder(Key k) : i_key(k) { }
35  virtual ~FactoryHolder() { }
36  inline Key key() const { return i_key; }
37 
38  void RegisterSelf(void) { FactoryHolderRegistry::instance()->InsertItem(this, i_key); }
39  void DeregisterSelf(void) { FactoryHolderRegistry::instance()->RemoveItem(this, false); }
40 
42  virtual T* Create(void *data = NULL) const = 0;
43  private:
44  Key i_key;
45 };
46 
51 template<class T>
53 {
54  public:
55  virtual ~Permissible() { }
56  virtual int Permit(const T *) const = 0;
57 };
58 #endif
59 
FactoryHolder(Key k)
Definition: FactoryHolder.h:34
virtual T * Create(void *data=NULL) const =0
Abstract Factory create method.
Definition: ObjectRegistry.h:31
Key i_key
Definition: FactoryHolder.h:44
Definition: FactoryHolder.h:29
arena_t NULL
Definition: jemalloc_internal.h:624
virtual ~Permissible()
Definition: FactoryHolder.h:55
static ObjectRegistry< T, Key > * instance()
Definition: ObjectRegistry.h:36
ObjectRegistry< FactoryHolder< T, Key >, Key > FactoryHolderRegistry
Definition: FactoryHolder.h:32
virtual int Permit(const T *) const =0
void RegisterSelf(void)
Definition: FactoryHolder.h:38
Definition: FactoryHolder.h:52
void DeregisterSelf(void)
Definition: FactoryHolder.h:39
Key key() const
Definition: FactoryHolder.h:36
virtual ~FactoryHolder()
Definition: FactoryHolder.h:35