Convert MCore Attribute classes uint32 -> size_t

Signed-off-by: Chris Burel <burelc@amazon.com>
This commit is contained in:
Chris Burel
2021-05-24 12:03:46 -07:00
parent a04a0965cc
commit b8695742d9
15 changed files with 54 additions and 61 deletions
@@ -68,8 +68,8 @@ namespace EMotionFX
}
bool InitFromString(const AZStd::string& valueString) override { MCORE_UNUSED(valueString); return false; } // unsupported
bool ConvertToString(AZStd::string& outString) const override { MCORE_UNUSED(outString); return false; } // unsupported
uint32 GetClassSize() const override { return sizeof(AttributePose); }
uint32 GetDefaultInterfaceType() const override { return MCore::ATTRIBUTE_INTERFACETYPE_DEFAULT; }
size_t GetClassSize() const override { return sizeof(AttributePose); }
AZ::u32 GetDefaultInterfaceType() const override { return MCore::ATTRIBUTE_INTERFACETYPE_DEFAULT; }
private:
AnimGraphPose* mValue;
@@ -116,8 +116,8 @@ namespace EMotionFX
}
bool InitFromString(const AZStd::string& valueString) override { MCORE_UNUSED(valueString); return false; } // unsupported
bool ConvertToString(AZStd::string& outString) const override { MCORE_UNUSED(outString); return false; } // unsupported
uint32 GetClassSize() const override { return sizeof(AttributeMotionInstance); }
uint32 GetDefaultInterfaceType() const override { return MCore::ATTRIBUTE_INTERFACETYPE_DEFAULT; }
size_t GetClassSize() const override { return sizeof(AttributeMotionInstance); }
AZ::u32 GetDefaultInterfaceType() const override { return MCore::ATTRIBUTE_INTERFACETYPE_DEFAULT; }
private:
MotionInstance* mValue;
@@ -8,12 +8,10 @@
#include "Attribute.h"
#include "AttributeFactory.h"
#include "AttributeString.h"
#include "StringConversions.h"
namespace MCore
{
Attribute::Attribute(uint32 typeID)
Attribute::Attribute(AZ::u32 typeID)
{
mTypeID = typeID;
}
+6 -6
View File
@@ -28,7 +28,7 @@ namespace MCore
class AttributeSettings;
// the attribute interface types
enum : uint32
enum : AZ::u32
{
ATTRIBUTE_INTERFACETYPE_FLOATSPINNER = 0, // MCore::AttributeFloat
ATTRIBUTE_INTERFACETYPE_FLOATSLIDER = 1, // MCore::AttributeFloat
@@ -55,20 +55,20 @@ namespace MCore
virtual Attribute* Clone() const = 0;
virtual const char* GetTypeString() const = 0;
MCORE_INLINE uint32 GetType() const { return mTypeID; }
MCORE_INLINE AZ::u32 GetType() const { return mTypeID; }
virtual bool InitFromString(const AZStd::string& valueString) = 0;
virtual bool ConvertToString(AZStd::string& outString) const = 0;
virtual bool InitFrom(const Attribute* other) = 0;
virtual uint32 GetClassSize() const = 0;
virtual uint32 GetDefaultInterfaceType() const = 0;
virtual size_t GetClassSize() const = 0;
virtual AZ::u32 GetDefaultInterfaceType() const = 0;
Attribute& operator=(const Attribute& other);
virtual void NetworkSerialize(EMotionFX::Network::AnimGraphSnapshotChunkSerializer&) {};
protected:
uint32 mTypeID; /**< The unique type ID of the attribute class. */
AZ::u32 mTypeID; /**< The unique type ID of the attribute class. */
Attribute(uint32 typeID);
Attribute(AZ::u32 typeID);
};
} // namespace MCore
@@ -39,7 +39,7 @@ namespace MCore
MCORE_INLINE void SetValue(bool value) { mValue = value; }
MCORE_INLINE uint8* GetRawDataPointer() { return reinterpret_cast<uint8*>(&mValue); }
MCORE_INLINE uint32 GetRawDataSize() const { return sizeof(bool); }
MCORE_INLINE size_t GetRawDataSize() const { return sizeof(bool); }
// overloaded from the attribute base class
Attribute* Clone() const override { return AttributeBool::Create(mValue); }
@@ -50,8 +50,8 @@ namespace MCore
return AzFramework::StringFunc::LooksLikeBool(valueString.c_str(), &mValue);
}
bool ConvertToString(AZStd::string& outString) const override { outString = AZStd::string::format("%d", (mValue) ? 1 : 0); return true; }
uint32 GetClassSize() const override { return sizeof(AttributeBool); }
uint32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_CHECKBOX; }
size_t GetClassSize() const override { return sizeof(AttributeBool); }
AZ::u32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_CHECKBOX; }
private:
bool mValue; /**< The boolean value, false on default. */
@@ -42,7 +42,7 @@ namespace MCore
MCORE_INLINE void SetValue(const RGBAColor& value) { mValue = value; }
MCORE_INLINE uint8* GetRawDataPointer() { return reinterpret_cast<uint8*>(&mValue); }
MCORE_INLINE uint32 GetRawDataSize() const { return sizeof(RGBAColor); }
MCORE_INLINE size_t GetRawDataSize() const { return sizeof(RGBAColor); }
// overloaded from the attribute base class
Attribute* Clone() const override { return AttributeColor::Create(mValue); }
@@ -67,8 +67,8 @@ namespace MCore
return true;
}
bool ConvertToString(AZStd::string& outString) const override { AZStd::to_string(outString, AZ::Vector4(mValue.r, mValue.g, mValue.b, mValue.a)); return true; }
uint32 GetClassSize() const override { return sizeof(AttributeColor); }
uint32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_COLOR; }
size_t GetClassSize() const override { return sizeof(AttributeColor); }
AZ::u32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_COLOR; }
private:
RGBAColor mValue; /**< The color value. */
@@ -54,8 +54,8 @@ namespace MCore
void AttributeFactory::RegisterAttribute(Attribute* attribute)
{
// check first if the type hasn't already been registered
const uint32 attribIndex = FindAttributeIndexByType(attribute->GetType());
if (attribIndex != MCORE_INVALIDINDEX32)
const size_t attribIndex = FindAttributeIndexByType(attribute->GetType());
if (attribIndex != InvalidIndex)
{
MCore::LogWarning("MCore::AttributeFactory::RegisterAttribute() - There is already an attribute of the same type registered (typeID %d vs %d - typeString '%s' vs '%s')", attribute->GetType(), mRegistered[attribIndex]->GetType(), attribute->GetTypeString(), mRegistered[attribIndex]->GetTypeString());
return;
@@ -68,8 +68,8 @@ namespace MCore
void AttributeFactory::UnregisterAttribute(Attribute* attribute, bool delFromMem)
{
// check first if the type hasn't already been registered
const uint32 attribIndex = FindAttributeIndexByType(attribute->GetType());
if (attribIndex == MCORE_INVALIDINDEX32)
const size_t attribIndex = FindAttributeIndexByType(attribute->GetType());
if (attribIndex == InvalidIndex)
{
MCore::LogWarning("MCore::AttributeFactory::UnregisterAttribute() - No attribute with the given type found (typeID=%d - typeString='%s'", attribute->GetType(), attribute->GetTypeString());
return;
@@ -84,26 +84,21 @@ namespace MCore
}
uint32 AttributeFactory::FindAttributeIndexByType(uint32 typeID) const
size_t AttributeFactory::FindAttributeIndexByType(size_t typeID) const
{
const size_t numAttributes = mRegistered.size();
for (size_t i = 0; i < numAttributes; ++i)
const auto foundAttribute = AZStd::find_if(begin(mRegistered), end(mRegistered), [typeID](const Attribute* registeredAttribute)
{
if (mRegistered[i]->GetType() == typeID) // we found one with the same type
{
return static_cast<uint32>(i);
}
}
return registeredAttribute->GetType() == typeID;
});
// no attribute of this type found
return MCORE_INVALIDINDEX32;
return foundAttribute != end(mRegistered) ? AZStd::distance(begin(mRegistered), foundAttribute) : InvalidIndex;
}
Attribute* AttributeFactory::CreateAttributeByType(uint32 typeID) const
Attribute* AttributeFactory::CreateAttributeByType(size_t typeID) const
{
const uint32 attribIndex = FindAttributeIndexByType(typeID);
if (attribIndex == MCORE_INVALIDINDEX32)
const size_t attribIndex = FindAttributeIndexByType(typeID);
if (attribIndex == InvalidIndex)
{
return nullptr;
}
@@ -31,10 +31,10 @@ namespace MCore
void RegisterStandardTypes();
size_t GetNumRegisteredAttributes() const { return mRegistered.size(); }
Attribute* GetRegisteredAttribute(uint32 index) const { return mRegistered[index]; }
Attribute* GetRegisteredAttribute(size_t index) const { return mRegistered[index]; }
uint32 FindAttributeIndexByType(uint32 typeID) const;
Attribute* CreateAttributeByType(uint32 typeID) const;
size_t FindAttributeIndexByType(size_t typeID) const;
Attribute* CreateAttributeByType(size_t typeID) const;
private:
AZStd::vector<Attribute*> mRegistered;
@@ -40,7 +40,7 @@ namespace MCore
MCORE_INLINE void SetValue(float value) { mValue = value; }
MCORE_INLINE uint8* GetRawDataPointer() { return reinterpret_cast<uint8*>(&mValue); }
MCORE_INLINE uint32 GetRawDataSize() const { return sizeof(float); }
MCORE_INLINE size_t GetRawDataSize() const { return sizeof(float); }
// overloaded from the attribute base class
Attribute* Clone() const override { return AttributeFloat::Create(mValue); }
@@ -51,8 +51,8 @@ namespace MCore
return AzFramework::StringFunc::LooksLikeFloat(valueString.c_str(), &mValue);
}
bool ConvertToString(AZStd::string& outString) const override { outString = AZStd::string::format("%.8f", mValue); return true; }
uint32 GetClassSize() const override { return sizeof(AttributeFloat); }
uint32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_FLOATSPINNER; }
size_t GetClassSize() const override { return sizeof(AttributeFloat); }
AZ::u32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_FLOATSPINNER; }
private:
float mValue; /**< The float value. */
@@ -40,7 +40,7 @@ namespace MCore
MCORE_INLINE void SetValue(int32 value) { mValue = value; }
MCORE_INLINE uint8* GetRawDataPointer() { return reinterpret_cast<uint8*>(&mValue); }
MCORE_INLINE uint32 GetRawDataSize() const { return sizeof(int32); }
MCORE_INLINE size_t GetRawDataSize() const { return sizeof(int32); }
// overloaded from the attribute base class
Attribute* Clone() const override { return AttributeInt32::Create(mValue); }
@@ -51,8 +51,8 @@ namespace MCore
return AzFramework::StringFunc::LooksLikeInt(valueString.c_str(), &mValue);
}
bool ConvertToString(AZStd::string& outString) const override { outString = AZStd::string::format("%d", mValue); return true; }
uint32 GetClassSize() const override { return sizeof(AttributeInt32); }
uint32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_INTSPINNER; }
size_t GetClassSize() const override { return sizeof(AttributeInt32); }
AZ::u32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_INTSPINNER; }
private:
int32 mValue; /**< The signed integer value. */
@@ -53,8 +53,8 @@ namespace MCore
}
bool InitFromString(const AZStd::string& valueString) override { MCORE_UNUSED(valueString); MCORE_ASSERT(false); return false; } // currently unsupported
bool ConvertToString(AZStd::string& outString) const override { MCORE_UNUSED(outString); MCORE_ASSERT(false); return false; } // currently unsupported
uint32 GetClassSize() const override { return sizeof(AttributePointer); }
uint32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_DEFAULT; }
size_t GetClassSize() const override { return sizeof(AttributePointer); }
AZ::u32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_DEFAULT; }
private:
void* mValue; /**< The pointer value. */
@@ -39,7 +39,7 @@ namespace MCore
static AttributeQuaternion* Create(const AZ::Quaternion& value);
MCORE_INLINE uint8* GetRawDataPointer() { return reinterpret_cast<uint8*>(&mValue); }
MCORE_INLINE uint32 GetRawDataSize() const { return sizeof(AZ::Quaternion); }
MCORE_INLINE size_t GetRawDataSize() const { return sizeof(AZ::Quaternion); }
// adjust values
MCORE_INLINE const AZ::Quaternion& GetValue() const { return mValue; }
@@ -68,8 +68,8 @@ namespace MCore
return true;
}
bool ConvertToString(AZStd::string& outString) const override { AZStd::to_string(outString, mValue); return true; }
uint32 GetClassSize() const override { return sizeof(AttributeQuaternion); }
uint32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_DEFAULT; }
size_t GetClassSize() const override { return sizeof(AttributeQuaternion); }
AZ::u32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_DEFAULT; }
private:
AZ::Quaternion mValue; /**< The Quaternion value. */
@@ -36,7 +36,7 @@ namespace MCore
static AttributeString* Create(const char* value = "");
MCORE_INLINE uint8* GetRawDataPointer() { return reinterpret_cast<uint8*>(mValue.data()); }
MCORE_INLINE uint32 GetRawDataSize() const { return static_cast<uint32>(mValue.size()); }
MCORE_INLINE size_t GetRawDataSize() const { return mValue.size(); }
// adjust values
MCORE_INLINE const char* AsChar() const { return mValue.c_str(); }
@@ -57,7 +57,7 @@ namespace MCore
}
bool InitFromString(const AZStd::string& valueString) override { mValue = valueString; return true; }
bool ConvertToString(AZStd::string& outString) const override { outString = mValue; return true; }
uint32 GetClassSize() const override { return sizeof(AttributeString); }
size_t GetClassSize() const override { return sizeof(AttributeString); }
uint32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_STRING; }
private:
@@ -43,7 +43,7 @@ namespace MCore
static AttributeVector2* Create(float x, float y);
MCORE_INLINE uint8* GetRawDataPointer() { return reinterpret_cast<uint8*>(&mValue); }
MCORE_INLINE uint32 GetRawDataSize() const { return sizeofVector2; }
MCORE_INLINE size_t GetRawDataSize() const { return sizeofVector2; }
// adjust values
MCORE_INLINE const AZ::Vector2& GetValue() const { return mValue; }
@@ -66,8 +66,8 @@ namespace MCore
return AzFramework::StringFunc::LooksLikeVector2(valueString.c_str(), &mValue);
}
bool ConvertToString(AZStd::string& outString) const override { AZStd::to_string(outString, mValue); return true; }
uint32 GetClassSize() const override { return sizeof(AttributeVector2); }
uint32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_VECTOR2; }
size_t GetClassSize() const override { return sizeof(AttributeVector2); }
AZ::u32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_VECTOR2; }
private:
AZ::Vector2 mValue; /**< The Vector2 value. */
@@ -38,7 +38,7 @@ namespace MCore
static AttributeVector3* Create(float x, float y, float z);
MCORE_INLINE uint8* GetRawDataPointer() { return reinterpret_cast<uint8*>(&mValue); }
MCORE_INLINE uint32 GetRawDataSize() const { return sizeof(AZ::Vector3); }
MCORE_INLINE size_t GetRawDataSize() const { return sizeof(AZ::Vector3); }
// adjust values
MCORE_INLINE const AZ::Vector3& GetValue() const { return mValue; }
@@ -67,8 +67,8 @@ namespace MCore
return true;
}
bool ConvertToString(AZStd::string& outString) const override { AZStd::to_string(outString, mValue); return true; }
uint32 GetClassSize() const override { return sizeof(AttributeVector3); }
uint32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_VECTOR3; }
size_t GetClassSize() const override { return sizeof(AttributeVector3); }
AZ::u32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_VECTOR3; }
private:
AZ::Vector3 mValue; /**< The Vector3 value. */
@@ -39,7 +39,7 @@ namespace MCore
static AttributeVector4* Create(float x, float y, float z, float w);
MCORE_INLINE uint8* GetRawDataPointer() { return reinterpret_cast<uint8*>(&mValue); }
MCORE_INLINE uint32 GetRawDataSize() const { return sizeof(AZ::Vector4); }
MCORE_INLINE size_t GetRawDataSize() const { return sizeof(AZ::Vector4); }
// adjust values
MCORE_INLINE const AZ::Vector4& GetValue() const { return mValue; }
@@ -63,8 +63,8 @@ namespace MCore
}
bool ConvertToString(AZStd::string& outString) const override { AZStd::to_string(outString, mValue); return true; }
// void ConvertCoordinateSystem() { GetCoordinateSystem().ConvertVector4(&mValue); }
uint32 GetClassSize() const override { return sizeof(AttributeVector4); }
uint32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_VECTOR4; }
size_t GetClassSize() const override { return sizeof(AttributeVector4); }
AZ::u32 GetDefaultInterfaceType() const override { return ATTRIBUTE_INTERFACETYPE_VECTOR4; }
private:
AZ::Vector4 mValue; /**< The Vector4 value. */