diff options
| author | Shauren <shauren.trinity@gmail.com> | 2017-05-13 11:49:09 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2017-05-13 11:49:09 +0200 |
| commit | beb3316089b350a43e917d896e682298df8dcfc0 (patch) | |
| tree | 8006c52594009f226d834991d101c97057699594 /src/server/shared/Dynamic | |
| parent | c00316d3d4b57826cc8e38feed24faf84832c04b (diff) | |
Core/Shared: Include cleanup
Diffstat (limited to 'src/server/shared/Dynamic')
| -rw-r--r-- | src/server/shared/Dynamic/TypeContainer.h | 143 | ||||
| -rw-r--r-- | src/server/shared/Dynamic/TypeContainerFunctions.h | 217 | ||||
| -rw-r--r-- | src/server/shared/Dynamic/TypeContainerVisitor.h | 104 |
3 files changed, 0 insertions, 464 deletions
diff --git a/src/server/shared/Dynamic/TypeContainer.h b/src/server/shared/Dynamic/TypeContainer.h deleted file mode 100644 index 7e825136755..00000000000 --- a/src/server/shared/Dynamic/TypeContainer.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef TRINITY_TYPECONTAINER_H -#define TRINITY_TYPECONTAINER_H - -/* - * Here, you'll find a series of containers that allow you to hold multiple - * types of object at the same time. - */ - -#include <map> -#include <unordered_map> -#include <vector> -#include "Define.h" -#include "Dynamic/TypeList.h" -#include "GridRefManager.h" - -/* - * @class ContainerMapList is a mulit-type container for map elements - * By itself its meaningless but collaborate along with TypeContainers, - * it become the most powerfully container in the whole system. - */ -template<class OBJECT> -struct ContainerMapList -{ - //std::map<OBJECT_HANDLE, OBJECT *> _element; - GridRefManager<OBJECT> _element; -}; - -template<> -struct ContainerMapList<TypeNull> /* nothing is in type null */ -{ -}; - -template<class H, class T> -struct ContainerMapList<TypeList<H, T> > -{ - ContainerMapList<H> _elements; - ContainerMapList<T> _TailElements; -}; - -template<class OBJECT, class KEY_TYPE> -struct ContainerUnorderedMap -{ - std::unordered_map<KEY_TYPE, OBJECT*> _element; -}; - -template<class KEY_TYPE> -struct ContainerUnorderedMap<TypeNull, KEY_TYPE> -{ -}; - -template<class H, class T, class KEY_TYPE> -struct ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE> -{ - ContainerUnorderedMap<H, KEY_TYPE> _elements; - ContainerUnorderedMap<T, KEY_TYPE> _TailElements; -}; - -#include "TypeContainerFunctions.h" - -/* - * @class TypeMapContainer contains a fixed number of types and is - * determined at compile time. This is probably the most complicated - * class and do its simplest thing, that is, holds objects - * of different types. - */ - -template<class OBJECT_TYPES> -class TypeMapContainer -{ - public: - template<class SPECIFIC_TYPE> size_t Count() const { return Trinity::Count(i_elements, (SPECIFIC_TYPE*)NULL); } - - /// inserts a specific object into the container - template<class SPECIFIC_TYPE> - bool insert(SPECIFIC_TYPE *obj) - { - SPECIFIC_TYPE* t = Trinity::Insert(i_elements, obj); - return (t != NULL); - } - - /// Removes the object from the container, and returns the removed object - //template<class SPECIFIC_TYPE> - //bool remove(SPECIFIC_TYPE* obj) - //{ - // SPECIFIC_TYPE* t = Trinity::Remove(i_elements, obj); - // return (t != NULL); - //} - - ContainerMapList<OBJECT_TYPES> & GetElements(void) { return i_elements; } - const ContainerMapList<OBJECT_TYPES> & GetElements(void) const { return i_elements;} - - private: - ContainerMapList<OBJECT_TYPES> i_elements; -}; - -template<class OBJECT_TYPES, class KEY_TYPE> -class TypeUnorderedMapContainer -{ -public: - template<class SPECIFIC_TYPE> - bool Insert(KEY_TYPE const& handle, SPECIFIC_TYPE* obj) - { - return Trinity::Insert(_elements, handle, obj); - } - - template<class SPECIFIC_TYPE> - bool Remove(KEY_TYPE const& handle) - { - return Trinity::Remove(_elements, handle, (SPECIFIC_TYPE*)NULL); - } - - template<class SPECIFIC_TYPE> - SPECIFIC_TYPE* Find(KEY_TYPE const& handle) - { - return Trinity::Find(_elements, handle, (SPECIFIC_TYPE*)NULL); - } - - ContainerUnorderedMap<OBJECT_TYPES, KEY_TYPE>& GetElements() { return _elements; } - ContainerUnorderedMap<OBJECT_TYPES, KEY_TYPE> const& GetElements() const { return _elements; } - -private: - ContainerUnorderedMap<OBJECT_TYPES, KEY_TYPE> _elements; -}; - -#endif diff --git a/src/server/shared/Dynamic/TypeContainerFunctions.h b/src/server/shared/Dynamic/TypeContainerFunctions.h deleted file mode 100644 index 97d20922a05..00000000000 --- a/src/server/shared/Dynamic/TypeContainerFunctions.h +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef TYPECONTAINER_FUNCTIONS_H -#define TYPECONTAINER_FUNCTIONS_H - -/* - * Here you'll find a list of helper functions to make - * the TypeContainer usefull. Without it, its hard - * to access or mutate the container. - */ - -#include "Define.h" -#include "Dynamic/TypeList.h" -#include <map> -#include <unordered_map> - -namespace Trinity -{ - // Helpers - // Insert helpers - template<class SPECIFIC_TYPE, class KEY_TYPE> - bool Insert(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* obj) - { - auto i = elements._element.find(handle); - if (i == elements._element.end()) - { - elements._element[handle] = obj; - return true; - } - else - { - ASSERT(i->second == obj, "Object with certain key already in but objects are different!"); - return false; - } - } - - template<class SPECIFIC_TYPE, class KEY_TYPE> - bool Insert(ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; - } - - template<class SPECIFIC_TYPE, class KEY_TYPE, class T> - bool Insert(ContainerUnorderedMap<T, KEY_TYPE>& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; - } - - template<class SPECIFIC_TYPE, class KEY_TYPE, class H, class T> - bool Insert(ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* obj) - { - bool ret = Insert(elements._elements, handle, obj); - return ret ? ret : Insert(elements._TailElements, handle, obj); - } - - // Find helpers - template<class SPECIFIC_TYPE, class KEY_TYPE> - SPECIFIC_TYPE* Find(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE> const& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) - { - auto i = elements._element.find(handle); - if (i == elements._element.end()) - return nullptr; - else - return i->second; - } - - template<class SPECIFIC_TYPE, class KEY_TYPE> - SPECIFIC_TYPE* Find(ContainerUnorderedMap<TypeNull, KEY_TYPE> const& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; - } - - template<class SPECIFIC_TYPE, class KEY_TYPE, class T> - SPECIFIC_TYPE* Find(ContainerUnorderedMap<T, KEY_TYPE> const& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; - } - - template<class SPECIFIC_TYPE, class KEY_TYPE, class H, class T> - SPECIFIC_TYPE* Find(ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE> const& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) - { - SPECIFIC_TYPE* ret = Find(elements._elements, handle, (SPECIFIC_TYPE*)nullptr); - return ret ? ret : Find(elements._TailElements, handle, (SPECIFIC_TYPE*)nullptr); - } - - // Erase helpers - template<class SPECIFIC_TYPE, class KEY_TYPE> - bool Remove(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) - { - elements._element.erase(handle); - return true; - } - - template<class SPECIFIC_TYPE, class KEY_TYPE> - bool Remove(ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; - } - - template<class SPECIFIC_TYPE, class KEY_TYPE, class T> - bool Remove(ContainerUnorderedMap<T, KEY_TYPE>& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; - } - - template<class SPECIFIC_TYPE, class KEY_TYPE, class H, class T> - bool Remove(ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) - { - bool ret = Remove(elements._elements, handle, (SPECIFIC_TYPE*)nullptr); - return ret ? ret : Remove(elements._TailElements, handle, (SPECIFIC_TYPE*)nullptr); - } - - /* ContainerMapList Helpers */ - // count functions - template<class SPECIFIC_TYPE> - size_t Count(ContainerMapList<SPECIFIC_TYPE> const& elements, SPECIFIC_TYPE* /*fake*/) - { - return elements._element.getSize(); - } - - template<class SPECIFIC_TYPE> - size_t Count(ContainerMapList<TypeNull> const& /*elements*/, SPECIFIC_TYPE* /*fake*/) - { - return 0; - } - - template<class SPECIFIC_TYPE, class T> - size_t Count(ContainerMapList<T> const& /*elements*/, SPECIFIC_TYPE* /*fake*/) - { - return 0; - } - - template<class SPECIFIC_TYPE, class T> - size_t Count(ContainerMapList<TypeList<SPECIFIC_TYPE, T>> const& elements, SPECIFIC_TYPE* fake) - { - return Count(elements._elements, fake); - } - - template<class SPECIFIC_TYPE, class H, class T> - size_t Count(ContainerMapList<TypeList<H, T>> const& elements, SPECIFIC_TYPE* fake) - { - return Count(elements._TailElements, fake); - } - - // non-const insert functions - template<class SPECIFIC_TYPE> - SPECIFIC_TYPE* Insert(ContainerMapList<SPECIFIC_TYPE>& elements, SPECIFIC_TYPE* obj) - { - //elements._element[hdl] = obj; - obj->AddToGrid(elements._element); - return obj; - } - - template<class SPECIFIC_TYPE> - SPECIFIC_TYPE* Insert(ContainerMapList<TypeNull>& /*elements*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; - } - - // this is a missed - template<class SPECIFIC_TYPE, class T> - SPECIFIC_TYPE* Insert(ContainerMapList<T>& /*elements*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; // a missed - } - - // Recursion - template<class SPECIFIC_TYPE, class H, class T> - SPECIFIC_TYPE* Insert(ContainerMapList<TypeList<H, T>>& elements, SPECIFIC_TYPE* obj) - { - SPECIFIC_TYPE* t = Insert(elements._elements, obj); - return (t != nullptr ? t : Insert(elements._TailElements, obj)); - } - - //// non-const remove method - //template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerMapList<SPECIFIC_TYPE> & /*elements*/, SPECIFIC_TYPE *obj) - //{ - // obj->GetGridRef().unlink(); - // return obj; - //} - - //template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/) - //{ - // return nullptr; - //} - - //// this is a missed - //template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Remove(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/) - //{ - // return nullptr; // a missed - //} - - //template<class SPECIFIC_TYPE, class T, class H> SPECIFIC_TYPE* Remove(ContainerMapList<TypeList<H, T> > &elements, SPECIFIC_TYPE *obj) - //{ - // // The head element is bad - // SPECIFIC_TYPE* t = Remove(elements._elements, obj); - // return (t != nullptr ? t : Remove(elements._TailElements, obj)); - //} -} -#endif - diff --git a/src/server/shared/Dynamic/TypeContainerVisitor.h b/src/server/shared/Dynamic/TypeContainerVisitor.h deleted file mode 100644 index f15cfe66758..00000000000 --- a/src/server/shared/Dynamic/TypeContainerVisitor.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef TRINITY_TYPECONTAINERVISITOR_H -#define TRINITY_TYPECONTAINERVISITOR_H - -/* - * @class TypeContainerVisitor is implemented as a visitor pattern. It is - * a visitor to the TypeContainerList or TypeContainerMapList. The visitor has - * to overload its types as a visit method is called. - */ - -#include "Define.h" -#include "Dynamic/TypeContainer.h" - -// forward declaration -template<class T, class Y> class TypeContainerVisitor; - -// visitor helper -template<class VISITOR, class TYPE_CONTAINER> void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c) -{ - v.Visit(c); -} - -// terminate condition container map list -template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerMapList<TypeNull> &/*c*/) { } - -template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerMapList<T> &c) -{ - v.Visit(c._element); -} - -// recursion container map list -template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerMapList<TypeList<H, T> > &c) -{ - VisitorHelper(v, c._elements); - VisitorHelper(v, c._TailElements); -} - -// for TypeMapContainer -template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR &v, TypeMapContainer<OBJECT_TYPES> &c) -{ - VisitorHelper(v, c.GetElements()); -} - -// TypeUnorderedMapContainer -template<class VISITOR, class KEY_TYPE> -void VisitorHelper(VISITOR& /*v*/, ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*c*/) { } - -template<class VISITOR, class KEY_TYPE, class T> -void VisitorHelper(VISITOR& v, ContainerUnorderedMap<T, KEY_TYPE>& c) -{ - v.Visit(c._element); -} - -template<class VISITOR, class KEY_TYPE, class H, class T> -void VisitorHelper(VISITOR& v, ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE>& c) -{ - VisitorHelper(v, c._elements); - VisitorHelper(v, c._TailElements); -} - -template<class VISITOR, class OBJECT_TYPES, class KEY_TYPE> -void VisitorHelper(VISITOR& v, TypeUnorderedMapContainer<OBJECT_TYPES, KEY_TYPE>& c) -{ - VisitorHelper(v, c.GetElements()); -} - -template<class VISITOR, class TYPE_CONTAINER> -class TypeContainerVisitor -{ - public: - TypeContainerVisitor(VISITOR &v) : i_visitor(v) { } - - void Visit(TYPE_CONTAINER &c) - { - VisitorHelper(i_visitor, c); - } - - void Visit(const TYPE_CONTAINER &c) const - { - VisitorHelper(i_visitor, c); - } - - private: - VISITOR &i_visitor; -}; -#endif - |
