TrinityCore
TypeContainerVisitor.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore 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 <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_TYPECONTAINERVISITOR_H
19#define TRINITY_TYPECONTAINERVISITOR_H
20
21/*
22 * @class TypeContainerVisitor is implemented as a visitor pattern. It is
23 * a visitor to the TypeContainerList or TypeContainerMapList. The visitor has
24 * to overload its types as a visit method is called.
25 */
26
28
29// forward declaration
30template<class T, class Y> class TypeContainerVisitor;
31
32// visitor helper
33template<class VISITOR, class TYPE_CONTAINER> void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c)
34{
35 v.Visit(c);
36}
37
38// terminate condition container map list
39template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerMapList<TypeNull> &/*c*/) { }
40
41template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerMapList<T> &c)
42{
43 v.Visit(c._element);
44}
45
46// recursion container map list
47template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerMapList<TypeList<H, T> > &c)
48{
49 VisitorHelper(v, c._elements);
50 VisitorHelper(v, c._TailElements);
51}
52
53// for TypeMapContainer
54template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR &v, TypeMapContainer<OBJECT_TYPES> &c)
55{
57}
58
59// TypeUnorderedMapContainer
60template<class VISITOR, class KEY_TYPE>
62
63template<class VISITOR, class KEY_TYPE, class T>
65{
66 v.Visit(c._element);
67}
68
69template<class VISITOR, class KEY_TYPE, class H, class T>
70void VisitorHelper(VISITOR& v, ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE>& c)
71{
72 VisitorHelper(v, c._elements);
73 VisitorHelper(v, c._TailElements);
74}
75
76template<class VISITOR, class OBJECT_TYPES, class KEY_TYPE>
78{
80}
81
82template<class VISITOR, class TYPE_CONTAINER>
84{
85 public:
86 TypeContainerVisitor(VISITOR &v) : i_visitor(v) { }
87
88 void Visit(TYPE_CONTAINER& c)
89 {
91 }
92
93 void Visit(TYPE_CONTAINER const& c) const
94 {
96 }
97
98 private:
99 VISITOR &i_visitor;
100};
101#endif
void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c)
void Visit(TYPE_CONTAINER const &c) const
void Visit(TYPE_CONTAINER &c)
ContainerMapList< OBJECT_TYPES > & GetElements(void)
Removes the object from the container, and returns the removed object.
ContainerUnorderedMap< OBJECT_TYPES, KEY_TYPE > & GetElements()
GridRefManager< OBJECT > _element
Definition: TypeContainer.h:39
std::unordered_map< KEY_TYPE, OBJECT * > _element
Definition: TypeContainer.h:57