Update StringIdPool to use AZ::u32 instead of uint32
Signed-off-by: Chris Burel <burelc@amazon.com>
This commit is contained in:
@@ -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<char>*& 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<const StringIdPoolIndex*>(classPtr)->m_index;
|
||||
if (index == MCORE_INVALIDINDEX32)
|
||||
const AZ::u32 index = static_cast<const StringIdPoolIndex*>(classPtr)->m_index;
|
||||
if (index == InvalidIndex32)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user