From c3ff3f342d594df853c10c33efc2a557a40fef78 Mon Sep 17 00:00:00 2001 From: Chris Burel Date: Mon, 24 May 2021 12:03:41 -0700 Subject: [PATCH] Update StringIdPool to use AZ::u32 instead of uint32 Signed-off-by: Chris Burel --- .../Code/MCore/Source/StringIdPool.cpp | 22 +++++-------------- .../Code/MCore/Source/StringIdPool.h | 21 +++++------------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/Gems/EMotionFX/Code/MCore/Source/StringIdPool.cpp b/Gems/EMotionFX/Code/MCore/Source/StringIdPool.cpp index 7c934084ce..279a7aec1e 100644 --- a/Gems/EMotionFX/Code/MCore/Source/StringIdPool.cpp +++ b/Gems/EMotionFX/Code/MCore/Source/StringIdPool.cpp @@ -29,10 +29,9 @@ namespace MCore { Lock(); - const size_t numStrings = mStrings.size(); - for (size_t i = 0; i < numStrings; ++i) + for (AZStd::basic_string*& mString : mStrings) { - delete mStrings[i]; + delete mString; } mStrings.clear(); @@ -69,24 +68,15 @@ namespace MCore } - const AZStd::string& StringIdPool::GetName(uint32 id) + const AZStd::string& StringIdPool::GetName(AZ::u32 id) { Lock(); - MCORE_ASSERT(id != MCORE_INVALIDINDEX32); + MCORE_ASSERT(id != InvalidIndex32); const AZStd::string* stringAddress = mStrings[id]; Unlock(); return *stringAddress; } - const AZStd::string& StringIdPool::GetStringById(AZ::u32 id) - { - Lock(); - MCORE_ASSERT(id != MCORE_INVALIDINDEX32); - AZStd::string* stringAddress = mStrings[id]; - Unlock(); - return *stringAddress; - } - void StringIdPool::Reserve(size_t numStrings) { @@ -132,8 +122,8 @@ namespace MCore size_t Save(const void* classPtr, AZ::IO::GenericStream& stream, bool /*isDataBigEndian = false*/) { // Look up the string to save - const uint32 index = static_cast(classPtr)->m_index; - if (index == MCORE_INVALIDINDEX32) + const AZ::u32 index = static_cast(classPtr)->m_index; + if (index == InvalidIndex32) { return 0; } diff --git a/Gems/EMotionFX/Code/MCore/Source/StringIdPool.h b/Gems/EMotionFX/Code/MCore/Source/StringIdPool.h index 30ea434331..9f58adf028 100644 --- a/Gems/EMotionFX/Code/MCore/Source/StringIdPool.h +++ b/Gems/EMotionFX/Code/MCore/Source/StringIdPool.h @@ -50,14 +50,7 @@ namespace MCore * @param id The unique id to search for the name. * @return The name of the given object. */ - const AZStd::string& GetName(uint32 id); - - /** - * Return the name of the given id. - * @param id The unique id to search for the name. - * @return The name of the given object. - */ - const AZStd::string& GetStringById(AZ::u32 id); + const AZStd::string& GetName(AZ::u32 id); /** * Reserve space for a given amount of strings. @@ -84,17 +77,15 @@ namespace MCore /** * The StringIdPoolIndex is a helper class to aid with serialization of * class members that store indexes into the StringIdPool. Members of this - * type will serialize to a string, and deserialize to a uint32, while + * type will serialize to a string, and deserialize to a AZ::u32, while * allowing the StringIdPool to deduplicate the strings. */ struct StringIdPoolIndex { - AZ::u32 m_index; + AZ::u32 m_index{}; - StringIdPoolIndex() : m_index(0) {} - StringIdPoolIndex(uint32 index) : m_index(index) {} - operator uint32() const { return m_index; } - bool operator==(uint32 rhs) const { return m_index == rhs; } + operator AZ::u32() const { return m_index; } + bool operator==(AZ::u32 rhs) const { return m_index == rhs; } static void Reflect(AZ::ReflectContext* context); }; @@ -104,4 +95,4 @@ namespace MCore namespace AZ { AZ_TYPE_INFO_SPECIALIZE(MCore::StringIdPoolIndex, "{C374F051-8323-49DB-A1BD-C6B6CF0333C0}") -} +} // namespace AZ