OregonCore  revision be9e804-git
Your Favourite TBC server
TypeContainerFunctions.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 #ifndef TYPECONTAINER_FUNCTIONS_H
18 #define TYPECONTAINER_FUNCTIONS_H
19 
20 /*
21  * Here you'll find a list of helper functions to make
22  * the TypeContainer usefull. Without it, its hard
23  * to access or mutate the container.
24  */
25 
26 #include "Platform/Define.h"
27 #include "Utilities/TypeList.h"
28 #include <map>
29 
30 namespace Oregon
31 {
32 /* ContainerMapList Helpers */
33 // count functions
34 template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<SPECIFIC_TYPE>& elements, SPECIFIC_TYPE* /*fake*/)
35 {
36  return elements._element.getSize();
37 };
38 
39 template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<TypeNull>& /*elements*/, SPECIFIC_TYPE* /*fake*/)
40 {
41  return 0;
42 }
43 
44 template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<T>& /*elements*/, SPECIFIC_TYPE* /*fake*/)
45 {
46  return 0;
47 }
48 
49 template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<TypeList<SPECIFIC_TYPE, T> >& elements, SPECIFIC_TYPE* fake)
50 {
51  return Count(elements._elements, fake);
52 }
53 
54 template<class SPECIFIC_TYPE, class H, class T> size_t Count(const ContainerMapList<TypeList<H, T> >& elements, SPECIFIC_TYPE* fake)
55 {
56  return Count(elements._TailElements, fake);
57 }
58 
59 // non-const insert functions
60 template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Insert(ContainerMapList<SPECIFIC_TYPE>& elements, SPECIFIC_TYPE* obj)
61 {
62  //elements._element[hdl] = obj;
63  obj->AddToGrid(elements._element);
64  return obj;
65 };
66 
67 template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Insert(ContainerMapList<TypeNull>& /*elements*/, SPECIFIC_TYPE* /*obj*/)
68 {
69  return NULL;
70 }
71 
72 // this is a missed
73 template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Insert(ContainerMapList<T>& /*elements*/, SPECIFIC_TYPE* /*obj*/)
74 {
75  return NULL; // a missed
76 }
77 
78 // Recursion
79 template<class SPECIFIC_TYPE, class H, class T> SPECIFIC_TYPE* Insert(ContainerMapList<TypeList<H, T> >& elements, SPECIFIC_TYPE* obj)
80 {
81  SPECIFIC_TYPE* t = Insert(elements._elements, obj);
82  return (t != NULL ? t : Insert(elements._TailElements, obj));
83 }
84 
85 }
86 #endif
87 
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)