OregonCore  revision be9e804-git
Your Favourite TBC server
TypeContainer.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef OREGON_TYPECONTAINER_H
19 #define OREGON_TYPECONTAINER_H
20 
21 /*
22  * Here, you'll find a series of containers that allow you to hold multiple
23  * types of object at the same time.
24  */
25 
26 #include <map>
27 #include <vector>
28 #include "Platform/Define.h"
29 #include "Utilities/TypeList.h"
31 
32 /*
33  * ContainerMapList is a mulit-type container for map elements
34  * By itself its meaningless but collaborate along with TypeContainers,
35  * it become the most powerfully container in the whole system.
36  */
37 
38 template<class OBJECT> struct ContainerMapList
39 {
41 };
42 
43 template<> struct ContainerMapList<TypeNull> /* nothing is in type null */
44 {
45 };
46 template<class H, class T> struct ContainerMapList<TypeList<H, T> >
47 {
50 };
51 
52 
53 #include "TypeContainerFunctions.h"
54 
55 /*
56  * TypeMapContainer contains a fixed number of types and is
57  * determined at compile time. This is probably the most complicated
58  * class and do its simplest thing, that is, holds objects
59  * of different types.
60  */
61 
62 template<class OBJECT_TYPES>
64 {
65  public:
66  template<class SPECIFIC_TYPE> size_t Count() const
67  {
68  return Oregon::Count(i_elements, (SPECIFIC_TYPE*)NULL);
69  }
70 
71  // inserts a specific object into the container
72  template<class SPECIFIC_TYPE> bool insert(SPECIFIC_TYPE* obj)
73  {
74  SPECIFIC_TYPE* t = Oregon::Insert(i_elements, obj);
75  return (t != NULL);
76  }
77 
79  {
80  return i_elements;
81  }
83  {
84  return i_elements;
85  }
86 
87  private:
89 };
90 #endif
91 
bool insert(SPECIFIC_TYPE *obj)
Definition: TypeContainer.h:72
size_t Count() const
Definition: TypeContainer.h:66
const ContainerMapList< OBJECT_TYPES > & GetElements(void) const
Definition: TypeContainer.h:82
ContainerMapList< OBJECT_TYPES > & GetElements(void)
Definition: TypeContainer.h:78
size_t Count(const ContainerMapList< SPECIFIC_TYPE > &elements, SPECIFIC_TYPE *)
GridRefManager< OBJECT > _element
Definition: TypeContainer.h:40
SPECIFIC_TYPE * Insert(ContainerMapList< SPECIFIC_TYPE > &elements, SPECIFIC_TYPE *obj)
ContainerMapList< T > _TailElements
Definition: TypeContainer.h:49
ContainerMapList< OBJECT_TYPES > i_elements
Definition: TypeContainer.h:88