From 85a7d5ce9ac68b30da2277cc91d4b70358f1880d Mon Sep 17 00:00:00 2001 From: ariel- Date: Mon, 19 Jun 2017 23:20:06 -0300 Subject: Core: ported headers cleanup from master branch --- src/server/shared/Dynamic/FactoryHolder.h | 2 +- src/server/shared/Dynamic/LinkedList.h | 12 +- .../shared/Dynamic/LinkedReference/Reference.h | 12 +- src/server/shared/Dynamic/ObjectRegistry.h | 2 + src/server/shared/Dynamic/TypeContainer.h | 143 -------------- src/server/shared/Dynamic/TypeContainerFunctions.h | 217 --------------------- src/server/shared/Dynamic/TypeContainerVisitor.h | 104 ---------- 7 files changed, 15 insertions(+), 477 deletions(-) delete mode 100644 src/server/shared/Dynamic/TypeContainer.h delete mode 100644 src/server/shared/Dynamic/TypeContainerFunctions.h delete mode 100644 src/server/shared/Dynamic/TypeContainerVisitor.h (limited to 'src/server/shared/Dynamic') diff --git a/src/server/shared/Dynamic/FactoryHolder.h b/src/server/shared/Dynamic/FactoryHolder.h index 9c9e2ada5e0..9e67fe11467 100644 --- a/src/server/shared/Dynamic/FactoryHolder.h +++ b/src/server/shared/Dynamic/FactoryHolder.h @@ -20,8 +20,8 @@ #define TRINITY_FACTORY_HOLDER #include "Define.h" -#include "Dynamic/TypeList.h" #include "ObjectRegistry.h" +#include "TypeList.h" /** FactoryHolder holds a factory object of a specific type */ diff --git a/src/server/shared/Dynamic/LinkedList.h b/src/server/shared/Dynamic/LinkedList.h index 0d64c337cbe..74f4ca553f4 100644 --- a/src/server/shared/Dynamic/LinkedList.h +++ b/src/server/shared/Dynamic/LinkedList.h @@ -165,13 +165,13 @@ class LinkedListHead { // construct with node pointer _Pnode } - Iterator& operator=(Iterator const &_Right) + Iterator& operator=(Iterator const& _Right) { _Ptr = _Right._Ptr; return *this; } - Iterator& operator=(const_pointer const &_Right) + Iterator& operator=(const_pointer const& _Right) { _Ptr = pointer(_Right); return *this; @@ -213,22 +213,22 @@ class LinkedListHead return (_Tmp); } - bool operator==(Iterator const &_Right) const + bool operator==(Iterator const& _Right) const { // test for iterator equality return (_Ptr == _Right._Ptr); } - bool operator!=(Iterator const &_Right) const + bool operator!=(Iterator const& _Right) const { // test for iterator inequality return (!(*this == _Right)); } - bool operator==(pointer const &_Right) const + bool operator==(pointer const& _Right) const { // test for pointer equality return (_Ptr != _Right); } - bool operator!=(pointer const &_Right) const + bool operator!=(pointer const& _Right) const { // test for pointer equality return (!(*this == _Right)); } diff --git a/src/server/shared/Dynamic/LinkedReference/Reference.h b/src/server/shared/Dynamic/LinkedReference/Reference.h index c0c4ec21a80..4002de2d584 100644 --- a/src/server/shared/Dynamic/LinkedReference/Reference.h +++ b/src/server/shared/Dynamic/LinkedReference/Reference.h @@ -40,7 +40,7 @@ template class Reference : public LinkedListElement // Tell our refFrom (source) object, that the link is cut (Target destroyed) virtual void sourceObjectDestroyLink() = 0; public: - Reference() { iRefTo = NULL; iRefFrom = NULL; } + Reference() { iRefTo = nullptr; iRefFrom = nullptr; } virtual ~Reference() { } // Create new link @@ -49,7 +49,7 @@ template class Reference : public LinkedListElement ASSERT(fromObj); // fromObj MUST not be NULL if (isValid()) unlink(); - if (toObj != NULL) + if (toObj != nullptr) { iRefTo = toObj; iRefFrom = fromObj; @@ -63,8 +63,8 @@ template class Reference : public LinkedListElement { targetObjectDestroyLink(); delink(); - iRefTo = NULL; - iRefFrom = NULL; + iRefTo = nullptr; + iRefFrom = nullptr; } // Link is invalid due to destruction of referenced target object. Call comes from the refTo object @@ -73,12 +73,12 @@ template class Reference : public LinkedListElement { sourceObjectDestroyLink(); delink(); - iRefTo = NULL; + iRefTo = nullptr; } bool isValid() const // Only check the iRefTo { - return iRefTo != NULL; + return iRefTo != nullptr; } Reference * next() { return((Reference *) LinkedListElement::next()); } diff --git a/src/server/shared/Dynamic/ObjectRegistry.h b/src/server/shared/Dynamic/ObjectRegistry.h index 5f614819b13..8ed72c476e8 100644 --- a/src/server/shared/Dynamic/ObjectRegistry.h +++ b/src/server/shared/Dynamic/ObjectRegistry.h @@ -82,6 +82,8 @@ class ObjectRegistry final // non instanceable, only static ObjectRegistry() { } ~ObjectRegistry() { } + ObjectRegistry(ObjectRegistry const&) = delete; + ObjectRegistry& operator=(ObjectRegistry const&) = delete; }; #endif 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 - * Copyright (C) 2005-2009 MaNGOS - * - * 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 . - */ - -#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 -#include -#include -#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 -struct ContainerMapList -{ - //std::map _element; - GridRefManager _element; -}; - -template<> -struct ContainerMapList /* nothing is in type null */ -{ -}; - -template -struct ContainerMapList > -{ - ContainerMapList _elements; - ContainerMapList _TailElements; -}; - -template -struct ContainerUnorderedMap -{ - std::unordered_map _element; -}; - -template -struct ContainerUnorderedMap -{ -}; - -template -struct ContainerUnorderedMap, KEY_TYPE> -{ - ContainerUnorderedMap _elements; - ContainerUnorderedMap _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 TypeMapContainer -{ - public: - template size_t Count() const { return Trinity::Count(i_elements, (SPECIFIC_TYPE*)NULL); } - - /// inserts a specific object into the container - template - 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 - //bool remove(SPECIFIC_TYPE* obj) - //{ - // SPECIFIC_TYPE* t = Trinity::Remove(i_elements, obj); - // return (t != NULL); - //} - - ContainerMapList & GetElements(void) { return i_elements; } - const ContainerMapList & GetElements(void) const { return i_elements;} - - private: - ContainerMapList i_elements; -}; - -template -class TypeUnorderedMapContainer -{ -public: - template - bool Insert(KEY_TYPE const& handle, SPECIFIC_TYPE* obj) - { - return Trinity::Insert(_elements, handle, obj); - } - - template - bool Remove(KEY_TYPE const& handle) - { - return Trinity::Remove(_elements, handle, (SPECIFIC_TYPE*)NULL); - } - - template - SPECIFIC_TYPE* Find(KEY_TYPE const& handle) - { - return Trinity::Find(_elements, handle, (SPECIFIC_TYPE*)NULL); - } - - ContainerUnorderedMap& GetElements() { return _elements; } - ContainerUnorderedMap const& GetElements() const { return _elements; } - -private: - ContainerUnorderedMap _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 - * Copyright (C) 2005-2009 MaNGOS - * - * 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 . - */ - -#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 -#include - -namespace Trinity -{ - // Helpers - // Insert helpers - template - bool Insert(ContainerUnorderedMap& 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 - bool Insert(ContainerUnorderedMap& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; - } - - template - bool Insert(ContainerUnorderedMap& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; - } - - template - bool Insert(ContainerUnorderedMap, 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 - SPECIFIC_TYPE* Find(ContainerUnorderedMap 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 - SPECIFIC_TYPE* Find(ContainerUnorderedMap const& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; - } - - template - SPECIFIC_TYPE* Find(ContainerUnorderedMap const& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; - } - - template - SPECIFIC_TYPE* Find(ContainerUnorderedMap, 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 - bool Remove(ContainerUnorderedMap& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) - { - elements._element.erase(handle); - return true; - } - - template - bool Remove(ContainerUnorderedMap& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; - } - - template - bool Remove(ContainerUnorderedMap& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) - { - return false; - } - - template - bool Remove(ContainerUnorderedMap, 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 - size_t Count(ContainerMapList const& elements, SPECIFIC_TYPE* /*fake*/) - { - return elements._element.getSize(); - } - - template - size_t Count(ContainerMapList const& /*elements*/, SPECIFIC_TYPE* /*fake*/) - { - return 0; - } - - template - size_t Count(ContainerMapList const& /*elements*/, SPECIFIC_TYPE* /*fake*/) - { - return 0; - } - - template - size_t Count(ContainerMapList> const& elements, SPECIFIC_TYPE* fake) - { - return Count(elements._elements, fake); - } - - template - size_t Count(ContainerMapList> const& elements, SPECIFIC_TYPE* fake) - { - return Count(elements._TailElements, fake); - } - - // non-const insert functions - template - SPECIFIC_TYPE* Insert(ContainerMapList& elements, SPECIFIC_TYPE* obj) - { - //elements._element[hdl] = obj; - obj->AddToGrid(elements._element); - return obj; - } - - template - SPECIFIC_TYPE* Insert(ContainerMapList& /*elements*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; - } - - // this is a missed - template - SPECIFIC_TYPE* Insert(ContainerMapList& /*elements*/, SPECIFIC_TYPE* /*obj*/) - { - return nullptr; // a missed - } - - // Recursion - template - SPECIFIC_TYPE* Insert(ContainerMapList>& elements, SPECIFIC_TYPE* obj) - { - SPECIFIC_TYPE* t = Insert(elements._elements, obj); - return (t != nullptr ? t : Insert(elements._TailElements, obj)); - } - - //// non-const remove method - //template SPECIFIC_TYPE* Remove(ContainerMapList & /*elements*/, SPECIFIC_TYPE *obj) - //{ - // obj->GetGridRef().unlink(); - // return obj; - //} - - //template SPECIFIC_TYPE* Remove(ContainerMapList &/*elements*/, SPECIFIC_TYPE * /*obj*/) - //{ - // return nullptr; - //} - - //// this is a missed - //template SPECIFIC_TYPE* Remove(ContainerMapList &/*elements*/, SPECIFIC_TYPE * /*obj*/) - //{ - // return nullptr; // a missed - //} - - //template SPECIFIC_TYPE* Remove(ContainerMapList > &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 - * Copyright (C) 2005-2009 MaNGOS - * - * 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 . - */ - -#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 TypeContainerVisitor; - -// visitor helper -template void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c) -{ - v.Visit(c); -} - -// terminate condition container map list -template void VisitorHelper(VISITOR &/*v*/, ContainerMapList &/*c*/) { } - -template void VisitorHelper(VISITOR &v, ContainerMapList &c) -{ - v.Visit(c._element); -} - -// recursion container map list -template void VisitorHelper(VISITOR &v, ContainerMapList > &c) -{ - VisitorHelper(v, c._elements); - VisitorHelper(v, c._TailElements); -} - -// for TypeMapContainer -template void VisitorHelper(VISITOR &v, TypeMapContainer &c) -{ - VisitorHelper(v, c.GetElements()); -} - -// TypeUnorderedMapContainer -template -void VisitorHelper(VISITOR& /*v*/, ContainerUnorderedMap& /*c*/) { } - -template -void VisitorHelper(VISITOR& v, ContainerUnorderedMap& c) -{ - v.Visit(c._element); -} - -template -void VisitorHelper(VISITOR& v, ContainerUnorderedMap, KEY_TYPE>& c) -{ - VisitorHelper(v, c._elements); - VisitorHelper(v, c._TailElements); -} - -template -void VisitorHelper(VISITOR& v, TypeUnorderedMapContainer& c) -{ - VisitorHelper(v, c.GetElements()); -} - -template -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 - -- cgit v1.2.3