TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TypeContainerVisitor.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_TYPECONTAINERVISITOR_H
20 #define TRINITY_TYPECONTAINERVISITOR_H
21 
22 /*
23  * @class TypeContainerVisitor is implemented as a visitor pattern. It is
24  * a visitor to the TypeContainerList or TypeContainerMapList. The visitor has
25  * to overload its types as a visit method is called.
26  */
27 
28 #include "Define.h"
29 #include "Dynamic/TypeContainer.h"
30 
31 // forward declaration
32 template<class T, class Y> class TypeContainerVisitor;
33 
34 // visitor helper
35 template<class VISITOR, class TYPE_CONTAINER> void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c)
36 {
37  v.Visit(c);
38 }
39 
40 // terminate condition container map list
41 template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerMapList<TypeNull> &/*c*/) { }
42 
43 template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerMapList<T> &c)
44 {
45  v.Visit(c._element);
46 }
47 
48 // recursion container map list
49 template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerMapList<TypeList<H, T> > &c)
50 {
51  VisitorHelper(v, c._elements);
52  VisitorHelper(v, c._TailElements);
53 }
54 
55 // for TypeMapContainer
56 template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR &v, TypeMapContainer<OBJECT_TYPES> &c)
57 {
58  VisitorHelper(v, c.GetElements());
59 }
60 
61 // TypeUnorderedMapContainer
62 template<class VISITOR, class KEY_TYPE>
64 
65 template<class VISITOR, class KEY_TYPE, class T>
67 {
68  v.Visit(c._element);
69 }
70 
71 template<class VISITOR, class KEY_TYPE, class H, class T>
72 void VisitorHelper(VISITOR& v, ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE>& c)
73 {
74  VisitorHelper(v, c._elements);
75  VisitorHelper(v, c._TailElements);
76 }
77 
78 template<class VISITOR, class OBJECT_TYPES, class KEY_TYPE>
80 {
81  VisitorHelper(v, c.GetElements());
82 }
83 
84 template<class VISITOR, class TYPE_CONTAINER>
86 {
87  public:
88  TypeContainerVisitor(VISITOR &v) : i_visitor(v) { }
89 
90  void Visit(TYPE_CONTAINER &c)
91  {
93  }
94 
95  void Visit(const TYPE_CONTAINER &c) const
96  {
98  }
99 
100  private:
101  VISITOR &i_visitor;
102 };
103 #endif
104 
ContainerUnorderedMap< OBJECT_TYPES, KEY_TYPE > & GetElements()
Definition: TypeContainer.h:136
void Visit(TYPE_CONTAINER &c)
Definition: TypeContainerVisitor.h:90
Definition: TypeContainerVisitor.h:32
VISITOR & i_visitor
Definition: TypeContainerVisitor.h:101
Definition: TypeList.h:31
Definition: TypeContainer.h:115
Definition: TypeContainer.h:47
Definition: TypeContainer.h:86
ContainerMapList< OBJECT_TYPES > & GetElements(void)
Removes the object from the container, and returns the removed object.
Definition: TypeContainer.h:107
void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c)
Definition: TypeContainerVisitor.h:35
Definition: TypeContainer.h:65
GridRefManager< OBJECT > _element
Definition: TypeContainer.h:43
TypeContainerVisitor(VISITOR &v)
Definition: TypeContainerVisitor.h:88
std::unordered_map< KEY_TYPE, OBJECT * > _element
Definition: TypeContainer.h:61
void Visit(const TYPE_CONTAINER &c) const
Definition: TypeContainerVisitor.h:95