TrinityCore
Loading...
Searching...
No Matches
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
27#include "Define.h"
29
30// forward declaration
31template<class T, class Y> class TypeContainerVisitor;
32
33// visitor helper
34template<class VISITOR, class TYPE_CONTAINER> void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c)
35{
36 v.Visit(c);
37}
38
39// terminate condition container map list
40template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerMapList<TypeNull> &/*c*/) { }
41
42template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerMapList<T> &c)
43{
44 v.Visit(c._element);
45}
46
47// recursion container map list
48template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerMapList<TypeList<H, T> > &c)
49{
50 VisitorHelper(v, c._elements);
51 VisitorHelper(v, c._TailElements);
52}
53
54// for TypeMapContainer
55template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR &v, TypeMapContainer<OBJECT_TYPES> &c)
56{
58}
59
60// TypeUnorderedMapContainer
61template<class VISITOR, class KEY_TYPE>
63
64template<class VISITOR, class KEY_TYPE, class T>
66{
67 v.Visit(c._element);
68}
69
70template<class VISITOR, class KEY_TYPE, class H, class T>
71void VisitorHelper(VISITOR& v, ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE>& c)
72{
73 VisitorHelper(v, c._elements);
74 VisitorHelper(v, c._TailElements);
75}
76
77template<class VISITOR, class OBJECT_TYPES, class KEY_TYPE>
82
83template<class VISITOR, class TYPE_CONTAINER>
85{
86 public:
87 TypeContainerVisitor(VISITOR &v) : i_visitor(v) { }
88
89 void Visit(TYPE_CONTAINER& c)
90 {
92 }
93
94 void Visit(TYPE_CONTAINER const& c) const
95 {
97 }
98
99 private:
100 VISITOR &i_visitor;
101};
102#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
std::unordered_map< KEY_TYPE, OBJECT * > _element