TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TypeContainer.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_TYPECONTAINER_H
20 #define TRINITY_TYPECONTAINER_H
21 
22 /*
23  * Here, you'll find a series of containers that allow you to hold multiple
24  * types of object at the same time.
25  */
26 
27 #include <map>
28 #include <unordered_map>
29 #include <vector>
30 #include "Define.h"
31 #include "Dynamic/TypeList.h"
32 #include "GridRefManager.h"
33 
34 /*
35  * @class ContainerMapList is a mulit-type container for map elements
36  * By itself its meaningless but collaborate along with TypeContainers,
37  * it become the most powerfully container in the whole system.
38  */
39 template<class OBJECT>
41 {
42  //std::map<OBJECT_HANDLE, OBJECT *> _element;
44 };
45 
46 template<>
47 struct ContainerMapList<TypeNull> /* nothing is in type null */
48 {
49 };
50 
51 template<class H, class T>
53 {
56 };
57 
58 template<class OBJECT, class KEY_TYPE>
60 {
61  std::unordered_map<KEY_TYPE, OBJECT*> _element;
62 };
63 
64 template<class KEY_TYPE>
65 struct ContainerUnorderedMap<TypeNull, KEY_TYPE>
66 {
67 };
68 
69 template<class H, class T, class KEY_TYPE>
70 struct ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE>
71 {
74 };
75 
76 #include "TypeContainerFunctions.h"
77 
78 /*
79  * @class TypeMapContainer contains a fixed number of types and is
80  * determined at compile time. This is probably the most complicated
81  * class and do its simplest thing, that is, holds objects
82  * of different types.
83  */
84 
85 template<class OBJECT_TYPES>
87 {
88  public:
89  template<class SPECIFIC_TYPE> size_t Count() const { return Trinity::Count(i_elements, (SPECIFIC_TYPE*)NULL); }
90 
92  template<class SPECIFIC_TYPE>
93  bool insert(SPECIFIC_TYPE *obj)
94  {
95  SPECIFIC_TYPE* t = Trinity::Insert(i_elements, obj);
96  return (t != NULL);
97  }
98 
100  //template<class SPECIFIC_TYPE>
101  //bool remove(SPECIFIC_TYPE* obj)
102  //{
103  // SPECIFIC_TYPE* t = Trinity::Remove(i_elements, obj);
104  // return (t != NULL);
105  //}
106 
109 
110  private:
112 };
113 
114 template<class OBJECT_TYPES, class KEY_TYPE>
116 {
117 public:
118  template<class SPECIFIC_TYPE>
119  bool Insert(KEY_TYPE const& handle, SPECIFIC_TYPE* obj)
120  {
121  return Trinity::Insert(_elements, handle, obj);
122  }
123 
124  template<class SPECIFIC_TYPE>
125  bool Remove(KEY_TYPE const& handle)
126  {
127  return Trinity::Remove(_elements, handle, (SPECIFIC_TYPE*)NULL);
128  }
129 
130  template<class SPECIFIC_TYPE>
131  SPECIFIC_TYPE* Find(KEY_TYPE const& handle)
132  {
133  return Trinity::Find(_elements, handle, (SPECIFIC_TYPE*)NULL);
134  }
135 
138 
139 private:
141 };
142 
143 #endif
bool Remove(ContainerUnorderedMap< SPECIFIC_TYPE, KEY_TYPE > &elements, KEY_TYPE const &handle, SPECIFIC_TYPE *)
Definition: TypeContainerFunctions.h:104
ContainerUnorderedMap< OBJECT_TYPES, KEY_TYPE > & GetElements()
Definition: TypeContainer.h:136
bool Insert(KEY_TYPE const &handle, SPECIFIC_TYPE *obj)
Definition: TypeContainer.h:119
bool insert(SPECIFIC_TYPE *obj)
inserts a specific object into the container
Definition: TypeContainer.h:93
size_t Count() const
Definition: TypeContainer.h:89
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: TypeList.h:31
SPECIFIC_TYPE * Find(KEY_TYPE const &handle)
Definition: TypeContainer.h:131
Definition: TypeContainer.h:115
Definition: TypeContainer.h:86
ContainerUnorderedMap< OBJECT_TYPES, KEY_TYPE > _elements
Definition: TypeContainer.h:140
const ContainerMapList< OBJECT_TYPES > & GetElements(void) const
Definition: TypeContainer.h:108
ContainerMapList< H > _elements
Definition: TypeContainer.h:54
ContainerMapList< OBJECT_TYPES > & GetElements(void)
Removes the object from the container, and returns the removed object.
Definition: TypeContainer.h:107
ContainerUnorderedMap< T, KEY_TYPE > _TailElements
Definition: TypeContainer.h:73
ContainerUnorderedMap< OBJECT_TYPES, KEY_TYPE > const & GetElements() const
Definition: TypeContainer.h:137
#define H(x, y, z)
Definition: GridReference.h:25
size_t Count(ContainerMapList< SPECIFIC_TYPE > const &elements, SPECIFIC_TYPE *)
Definition: TypeContainerFunctions.h:132
ContainerUnorderedMap< H, KEY_TYPE > _elements
Definition: TypeContainer.h:72
GridRefManager< OBJECT > _element
Definition: TypeContainer.h:43
bool Insert(ContainerUnorderedMap< SPECIFIC_TYPE, KEY_TYPE > &elements, KEY_TYPE const &handle, SPECIFIC_TYPE *obj)
Definition: TypeContainerFunctions.h:38
SPECIFIC_TYPE * Find(ContainerUnorderedMap< SPECIFIC_TYPE, KEY_TYPE > const &elements, KEY_TYPE const &handle, SPECIFIC_TYPE *)
Definition: TypeContainerFunctions.h:74
Definition: TypeContainer.h:59
bool Remove(KEY_TYPE const &handle)
Definition: TypeContainer.h:125
std::unordered_map< KEY_TYPE, OBJECT * > _element
Definition: TypeContainer.h:61
Definition: TypeContainer.h:40
ContainerMapList< T > _TailElements
Definition: TypeContainer.h:55
ContainerMapList< OBJECT_TYPES > i_elements
Definition: TypeContainer.h:111