mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 02:25:38 +01:00
Map local guids 6.x -> 4.3.4
Ported the following commits:ca83e14f8bee1c1b97be18e4ab6911bf37446b3ccb854a2b7b
This commit is contained in:
@@ -92,6 +92,19 @@ namespace Trinity
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class K, class V, template<class, class, class...> class M, class... Rest>
|
||||
void MultimapErasePair(M<K, V, Rest...>& multimap, K const& key, V const& value)
|
||||
{
|
||||
auto range = multimap.equal_range(key);
|
||||
for (auto itr = range.first; itr != range.second; )
|
||||
{
|
||||
if (itr->second == value)
|
||||
itr = multimap.erase(itr);
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
//! namespace Containers
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "Define.h"
|
||||
#include "Dynamic/TypeList.h"
|
||||
@@ -35,54 +36,41 @@
|
||||
* By itself its meaningless but collaborate along with TypeContainers,
|
||||
* it become the most powerfully container in the whole system.
|
||||
*/
|
||||
template<class OBJECT> struct ContainerMapList
|
||||
template<class OBJECT>
|
||||
struct ContainerMapList
|
||||
{
|
||||
//std::map<OBJECT_HANDLE, OBJECT *> _element;
|
||||
GridRefManager<OBJECT> _element;
|
||||
};
|
||||
|
||||
template<> struct ContainerMapList<TypeNull> /* nothing is in type null */
|
||||
template<>
|
||||
struct ContainerMapList<TypeNull> /* nothing is in type null */
|
||||
{
|
||||
};
|
||||
template<class H, class T> struct ContainerMapList<TypeList<H, T> >
|
||||
|
||||
template<class H, class T>
|
||||
struct ContainerMapList<TypeList<H, T> >
|
||||
{
|
||||
ContainerMapList<H> _elements;
|
||||
ContainerMapList<T> _TailElements;
|
||||
};
|
||||
|
||||
/*
|
||||
* @class ContaierArrayList is a multi-type container for
|
||||
* array of elements.
|
||||
*/
|
||||
template<class OBJECT> struct ContainerArrayList
|
||||
template<class OBJECT, class KEY_TYPE>
|
||||
struct ContainerUnorderedMap
|
||||
{
|
||||
std::vector<OBJECT> _element;
|
||||
std::unordered_map<KEY_TYPE, OBJECT*> _element;
|
||||
};
|
||||
|
||||
// termination condition
|
||||
template<> struct ContainerArrayList<TypeNull> { };
|
||||
// recursion
|
||||
template<class H, class T> struct ContainerArrayList<TypeList<H, T> >
|
||||
template<class KEY_TYPE>
|
||||
struct ContainerUnorderedMap<TypeNull, KEY_TYPE>
|
||||
{
|
||||
ContainerArrayList<H> _elements;
|
||||
ContainerArrayList<T> _TailElements;
|
||||
};
|
||||
|
||||
/*
|
||||
* @class ContainerList is a simple list of different types of elements
|
||||
*
|
||||
*/
|
||||
template<class OBJECT> struct ContainerList
|
||||
template<class H, class T, class KEY_TYPE>
|
||||
struct ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE>
|
||||
{
|
||||
OBJECT _element;
|
||||
};
|
||||
|
||||
/* TypeNull is underfined */
|
||||
template<> struct ContainerList<TypeNull> { };
|
||||
template<class H, class T> struct ContainerList<TypeList<H, T> >
|
||||
{
|
||||
ContainerList<H> _elements;
|
||||
ContainerMapList<T> _TailElements;
|
||||
ContainerUnorderedMap<H, KEY_TYPE> _elements;
|
||||
ContainerUnorderedMap<T, KEY_TYPE> _tailElements;
|
||||
};
|
||||
|
||||
#include "TypeContainerFunctions.h"
|
||||
@@ -101,14 +89,16 @@ class TypeMapContainer
|
||||
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)
|
||||
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)
|
||||
//template<class SPECIFIC_TYPE>
|
||||
//bool remove(SPECIFIC_TYPE* obj)
|
||||
//{
|
||||
// SPECIFIC_TYPE* t = Trinity::Remove(i_elements, obj);
|
||||
// return (t != NULL);
|
||||
@@ -120,5 +110,35 @@ class TypeMapContainer
|
||||
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*)nullptr);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE>
|
||||
SPECIFIC_TYPE* Find(KEY_TYPE const& handle)
|
||||
{
|
||||
return Trinity::Find(_elements, handle, (SPECIFIC_TYPE*)nullptr);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -28,60 +28,163 @@
|
||||
#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 i->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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(const ContainerMapList<SPECIFIC_TYPE> &elements, SPECIFIC_TYPE* /*fake*/)
|
||||
template<class SPECIFIC_TYPE>
|
||||
size_t Count(const ContainerMapList<SPECIFIC_TYPE> &elements, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return elements._element.getSize();
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE* /*fake*/)
|
||||
template<class SPECIFIC_TYPE>
|
||||
size_t Count(const ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE* /*fake*/)
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
size_t Count(const ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE* /*fake*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<TypeList<SPECIFIC_TYPE, T> >&elements, SPECIFIC_TYPE* fake)
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
size_t Count(const ContainerMapList<TypeList<SPECIFIC_TYPE, T> >&elements, SPECIFIC_TYPE* fake)
|
||||
{
|
||||
return Count(elements._elements, fake);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_TYPE, class H, class T> size_t Count(const ContainerMapList<TypeList<H, T> >&elements, SPECIFIC_TYPE* fake)
|
||||
template<class SPECIFIC_TYPE, class H, class T>
|
||||
size_t Count(const ContainerMapList<TypeList<H, T> >&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)
|
||||
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*/)
|
||||
template<class SPECIFIC_TYPE>
|
||||
SPECIFIC_TYPE* Insert(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// this is a missed
|
||||
template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Insert(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
template<class SPECIFIC_TYPE, class T>
|
||||
SPECIFIC_TYPE* Insert(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
{
|
||||
return NULL; // a missed
|
||||
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 != NULL ? t : Insert(elements._TailElements, obj));
|
||||
return (t != nullptr ? t : Insert(elements._TailElements, obj));
|
||||
}
|
||||
|
||||
//// non-const remove method
|
||||
@@ -93,20 +196,20 @@ namespace Trinity
|
||||
|
||||
//template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
//{
|
||||
// return NULL;
|
||||
// return nullptr;
|
||||
//}
|
||||
|
||||
//// this is a missed
|
||||
//template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Remove(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/)
|
||||
//{
|
||||
// return NULL; // a missed
|
||||
// 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 != NULL ? t : Remove(elements._TailElements, obj) );
|
||||
// return (t != nullptr ? t : Remove(elements._TailElements, obj) );
|
||||
//}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -37,21 +37,6 @@ template<class VISITOR, class TYPE_CONTAINER> void VisitorHelper(VISITOR &v, TYP
|
||||
v.Visit(c);
|
||||
}
|
||||
|
||||
// terminate condition for container list
|
||||
template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerList<TypeNull> &/*c*/) { }
|
||||
|
||||
template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerList<T> &c)
|
||||
{
|
||||
v.Visit(c._element);
|
||||
}
|
||||
|
||||
// recursion for container list
|
||||
template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerList<TypeList<H, T> > &c)
|
||||
{
|
||||
VisitorHelper(v, c._elements);
|
||||
VisitorHelper(v, c._TailElements);
|
||||
}
|
||||
|
||||
// terminate condition container map list
|
||||
template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerMapList<TypeNull> &/*c*/) { }
|
||||
|
||||
@@ -67,23 +52,31 @@ template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, Contain
|
||||
VisitorHelper(v, c._TailElements);
|
||||
}
|
||||
|
||||
// array list
|
||||
template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerArrayList<T> &c)
|
||||
// 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> void VisitorHelper(VISITOR &/*v*/, ContainerArrayList<TypeNull> &/*c*/) { }
|
||||
|
||||
// recursion
|
||||
template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerArrayList<TypeList<H, T> > &c)
|
||||
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);
|
||||
VisitorHelper(v, c._tailElements);
|
||||
}
|
||||
|
||||
// for TypeMapContainer
|
||||
template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR &v, TypeMapContainer<OBJECT_TYPES> &c)
|
||||
template<class VISITOR, class OBJECT_TYPES, class KEY_TYPE>
|
||||
void VisitorHelper(VISITOR& v, TypeUnorderedMapContainer<OBJECT_TYPES, KEY_TYPE>& c)
|
||||
{
|
||||
VisitorHelper(v, c.GetElements());
|
||||
}
|
||||
|
||||
@@ -35,10 +35,11 @@ struct TypeList
|
||||
};
|
||||
|
||||
// enough for now.. can be expand at any point in time as needed
|
||||
#define TYPELIST_1(T1) TypeList<T1, TypeNull>
|
||||
#define TYPELIST_2(T1, T2) TypeList<T1, TYPELIST_1(T2) >
|
||||
#define TYPELIST_3(T1, T2, T3) TypeList<T1, TYPELIST_2(T2, T3) >
|
||||
#define TYPELIST_4(T1, T2, T3, T4) TypeList<T1, TYPELIST_3(T2, T3, T4) >
|
||||
#define TYPELIST_5(T1, T2, T3, T4, T5) TypeList<T1, TYPELIST_4(T2, T3, T4, T5) >
|
||||
#define TYPELIST_1(T1) TypeList<T1, TypeNull>
|
||||
#define TYPELIST_2(T1, T2) TypeList<T1, TYPELIST_1(T2) >
|
||||
#define TYPELIST_3(T1, T2, T3) TypeList<T1, TYPELIST_2(T2, T3) >
|
||||
#define TYPELIST_4(T1, T2, T3, T4) TypeList<T1, TYPELIST_3(T2, T3, T4) >
|
||||
#define TYPELIST_5(T1, T2, T3, T4, T5) TypeList<T1, TYPELIST_4(T2, T3, T4, T5) >
|
||||
#define TYPELIST_6(T1, T2, T3, T4, T5, T6) TypeList<T1, TYPELIST_5(T2, T3, T4, T5, T6) >
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user