From 065d403b729a1fd84c5fd076d303187cd2d37ce1 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Wed, 23 Jun 2021 22:28:41 +0200 Subject: [PATCH] feat(Core/Misc): Add .Size() to TypeUnorderedMapContainer for stats/debugging (#6080) * cherry-picked commit (TrinityCore/TrinityCore@d53a2de) Co-Authored-By: Shauren --- src/common/Dynamic/TypeContainer.h | 8 ++++++ src/common/Dynamic/TypeContainerFunctions.h | 27 +++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/common/Dynamic/TypeContainer.h b/src/common/Dynamic/TypeContainer.h index 49963da53..677113e3e 100644 --- a/src/common/Dynamic/TypeContainer.h +++ b/src/common/Dynamic/TypeContainer.h @@ -138,6 +138,14 @@ public: return Acore::Find(_elements, handle, (SPECIFIC_TYPE*)nullptr); } + template + std::size_t Size() const + { + std::size_t size = 0; + Acore::Size(_elements, &size, (SPECIFIC_TYPE*)nullptr); + return size; + } + ContainerUnorderedMap& GetElements() { return _elements; } ContainerUnorderedMap const& GetElements() const { return _elements; } diff --git a/src/common/Dynamic/TypeContainerFunctions.h b/src/common/Dynamic/TypeContainerFunctions.h index 96e2f8ed6..0e83787d1 100644 --- a/src/common/Dynamic/TypeContainerFunctions.h +++ b/src/common/Dynamic/TypeContainerFunctions.h @@ -114,6 +114,33 @@ namespace Acore return ret ? ret : Remove(elements._TailElements, handle, (SPECIFIC_TYPE*)nullptr); } + // Count helpers + template + bool Size(ContainerUnorderedMap const& elements, std::size_t* size, SPECIFIC_TYPE* /*obj*/) + { + *size = elements._element.size(); + return true; + } + + template + bool Size(ContainerUnorderedMap const& /*elements*/, std::size_t* /*size*/, SPECIFIC_TYPE* /*obj*/) + { + return false; + } + + template + bool Size(ContainerUnorderedMap const& /*elements*/, std::size_t* /*size*/, SPECIFIC_TYPE* /*obj*/) + { + return false; + } + + template + bool Size(ContainerUnorderedMap, KEY_TYPE> const& elements, std::size_t* size, SPECIFIC_TYPE* /*obj*/) + { + bool ret = Size(elements._elements, size, (SPECIFIC_TYPE*)nullptr); + return ret ? ret : Size(elements._TailElements, size, (SPECIFIC_TYPE*)nullptr); + } + /* ContainerMapList Helpers */ // count functions template