Tidy up Type enum

Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
This commit is contained in:
Nicholas Van Sickle
2021-12-12 13:56:10 -08:00
parent cc120c772c
commit d9ac3c2120
5 changed files with 81 additions and 81 deletions
+41 -41
View File
@@ -141,31 +141,31 @@ namespace AZ::Dom
{
switch (type)
{
case Type::NullType:
case Type::Null:
// Null is the default initialized value
break;
case Type::FalseType:
case Type::False:
m_value = false;
break;
case Type::TrueType:
case Type::True:
m_value = true;
break;
case Type::ObjectType:
case Type::Object:
SetObject();
break;
case Type::ArrayType:
case Type::Array:
SetArray();
break;
case Type::StringType:
case Type::String:
SetString("");
break;
case Type::NumberType:
case Type::Number:
m_value = 0.0;
break;
case Type::NodeType:
case Type::Node:
SetNode("");
break;
case Type::OpaqueType:
case Type::Opaque:
AZ_Assert(false, "AZ::Dom::Value may not be constructed with an empty opaque type");
break;
}
@@ -225,43 +225,43 @@ namespace AZ::Dom
switch (m_value.index())
{
case 0: // AZStd::monostate
return Type::NullType;
return Type::Null;
case 1: // int64_t
case 2: // uint64_t
case 3: // double
return Type::NumberType;
return Type::Number;
case 4: // bool
return AZStd::get<bool>(m_value) ? Type::TrueType : Type::FalseType;
return AZStd::get<bool>(m_value) ? Type::True : Type::False;
case 5: // AZStd::string_view
case 6: // AZStd::shared_ptr<AZStd::string>
case 7: // ShortStringType
return Type::StringType;
return Type::String;
case 8: // ObjectPtr
return Type::ObjectType;
return Type::Object;
case 9: // ArrayPtr
return Type::ArrayType;
return Type::Array;
case 10: // NodePtr
return Type::NodeType;
return Type::Node;
case 11: // AZStd::any*
return Type::OpaqueType;
return Type::Opaque;
}
AZ_Assert(false, "AZ::Dom::Value::GetType: m_value has an unexpected type");
return Type::NullType;
return Type::Null;
}
bool Value::IsNull() const
{
return GetType() == Type::NullType;
return GetType() == Type::Null;
}
bool Value::IsFalse() const
{
return GetType() == Type::FalseType;
return GetType() == Type::False;
}
bool Value::IsTrue() const
{
return GetType() == Type::TrueType;
return GetType() == Type::True;
}
bool Value::IsBool() const
@@ -271,27 +271,27 @@ namespace AZ::Dom
bool Value::IsNode() const
{
return GetType() == Type::NodeType;
return GetType() == Type::Node;
}
bool Value::IsObject() const
{
return GetType() == Type::ObjectType;
return GetType() == Type::Object;
}
bool Value::IsArray() const
{
return GetType() == Type::ArrayType;
return GetType() == Type::Array;
}
bool Value::IsOpaqueValue() const
{
return GetType() == Type::OpaqueType;
return GetType() == Type::Opaque;
}
bool Value::IsNumber() const
{
return GetType() == Type::NumberType;
return GetType() == Type::Number;
}
bool Value::IsInt() const
@@ -311,7 +311,7 @@ namespace AZ::Dom
bool Value::IsString() const
{
return GetType() == Type::StringType;
return GetType() == Type::String;
}
Value& Value::SetObject()
@@ -322,13 +322,13 @@ namespace AZ::Dom
const Node& Value::GetNodeInternal() const
{
AZ_Assert(GetType() == Type::NodeType, "AZ::Dom::Value: attempted to retrieve a node from a non-node value");
AZ_Assert(GetType() == Type::Node, "AZ::Dom::Value: attempted to retrieve a node from a non-node value");
return *AZStd::get<NodePtr>(m_value);
}
Node& Value::GetNodeInternal()
{
AZ_Assert(GetType() == Type::NodeType, "AZ::Dom::Value: attempted to retrieve a node from a non-node value");
AZ_Assert(GetType() == Type::Node, "AZ::Dom::Value: attempted to retrieve a node from a non-node value");
return *CheckCopyOnWrite(AZStd::get<NodePtr>(m_value));
}
@@ -336,9 +336,9 @@ namespace AZ::Dom
{
const Type type = GetType();
AZ_Assert(
type == Type::ObjectType || type == Type::NodeType,
type == Type::Object || type == Type::Node,
"AZ::Dom::Value: attempted to retrieve an object from a value that isn't an object or a node");
if (type == Type::ObjectType)
if (type == Type::Object)
{
return AZStd::get<ObjectPtr>(m_value)->m_values;
}
@@ -352,9 +352,9 @@ namespace AZ::Dom
{
const Type type = GetType();
AZ_Assert(
type == Type::ObjectType || type == Type::NodeType,
type == Type::Object || type == Type::Node,
"AZ::Dom::Value: attempted to retrieve an object from a value that isn't an object or a node");
if (type == Type::ObjectType)
if (type == Type::Object)
{
return CheckCopyOnWrite(AZStd::get<ObjectPtr>(m_value))->m_values;
}
@@ -368,9 +368,9 @@ namespace AZ::Dom
{
const Type type = GetType();
AZ_Assert(
type == Type::ArrayType || type == Type::NodeType,
type == Type::Array || type == Type::Node,
"AZ::Dom::Value: attempted to retrieve an array from a value that isn't an array or a node");
if (type == Type::ArrayType)
if (type == Type::Array)
{
return AZStd::get<ArrayPtr>(m_value)->m_values;
}
@@ -384,9 +384,9 @@ namespace AZ::Dom
{
const Type type = GetType();
AZ_Assert(
type == Type::ArrayType || type == Type::NodeType,
type == Type::Array || type == Type::Node,
"AZ::Dom::Value: attempted to retrieve an array from a value that isn't an array or node");
if (type == Type::ArrayType)
if (type == Type::Array)
{
return CheckCopyOnWrite(AZStd::get<ArrayPtr>(m_value))->m_values;
}
@@ -751,13 +751,13 @@ namespace AZ::Dom
void Value::SetNodeValue(Value value)
{
AZ_Assert(GetType() == Type::NodeType, "AZ::Dom::Value: Attempted to set value for non-node type");
AZ_Assert(GetType() == Type::Node, "AZ::Dom::Value: Attempted to set value for non-node type");
Array::ContainerType& nodeChildren = GetArrayInternal();
// Set the first non-node child, if one is found
for (Value& entry : nodeChildren)
{
if (entry.GetType() != Type::NodeType)
if (entry.GetType() != Type::Node)
{
entry = AZStd::move(value);
return;
@@ -770,13 +770,13 @@ namespace AZ::Dom
Value Value::GetNodeValue() const
{
AZ_Assert(GetType() == Type::NodeType, "AZ::Dom::Value: Attempted to get value for non-node type");
AZ_Assert(GetType() == Type::Node, "AZ::Dom::Value: Attempted to get value for non-node type");
const Array::ContainerType& nodeChildren = GetArrayInternal();
// Get the first non-node child, if one is found
for (const Value& entry : nodeChildren)
{
if (entry.GetType() != Type::NodeType)
if (entry.GetType() != Type::Node)
{
return entry;
}
+9 -9
View File
@@ -26,15 +26,15 @@ namespace AZ::Dom
enum class Type
{
NullType = 0,
FalseType = 1,
TrueType = 2,
ObjectType = 3,
ArrayType = 4,
StringType = 5,
NumberType = 6,
NodeType = 7,
OpaqueType = 8,
Null = 0,
False = 1,
True = 2,
Object = 3,
Array = 4,
String = 5,
Number = 6,
Node = 7,
Opaque = 8,
};
class ValueAllocator final : public SimpleSchemaAllocator<AZ::HphaSchema, AZ::HphaSchema::Descriptor, false, false>
@@ -87,13 +87,13 @@ namespace AZ::Dom
const char* endMethodName;
switch (containerType)
{
case Type::ObjectType:
case Type::Object:
endMethodName = "EndObject";
break;
case Type::ArrayType:
case Type::Array:
endMethodName = "EndArray";
break;
case Type::NodeType:
case Type::Node:
endMethodName = "EndNode";
break;
default:
@@ -173,7 +173,7 @@ namespace AZ::Dom
Visitor::Result ValueWriter::EndObject(AZ::u64 attributeCount)
{
return EndContainer(Type::ObjectType, attributeCount, 0);
return EndContainer(Type::Object, attributeCount, 0);
}
Visitor::Result ValueWriter::Key(AZ::Name key)
@@ -199,7 +199,7 @@ namespace AZ::Dom
Visitor::Result ValueWriter::EndArray(AZ::u64 elementCount)
{
return EndContainer(Type::ArrayType, 0, elementCount);
return EndContainer(Type::Array, 0, elementCount);
}
Visitor::Result ValueWriter::StartNode(AZ::Name name)
@@ -217,7 +217,7 @@ namespace AZ::Dom
Visitor::Result ValueWriter::EndNode(AZ::u64 attributeCount, AZ::u64 elementCount)
{
return EndContainer(Type::NodeType, attributeCount, elementCount);
return EndContainer(Type::Node, attributeCount, elementCount);
}
Visitor::Result ValueWriter::FinishWrite()
@@ -46,7 +46,7 @@ namespace AZ::Dom::Benchmark
Value GenerateDomBenchmarkPayload(int64_t entryCount, int64_t stringTemplateLength)
{
Value root(Type::ObjectType);
Value root(Type::Object);
AZStd::string entryTemplate;
while (entryTemplate.size() < static_cast<size_t>(stringTemplateLength))
@@ -63,18 +63,18 @@ namespace AZ::Dom::Benchmark
auto createEntry = [&](int n) -> Value
{
Value entry(Type::ObjectType);
Value entry(Type::Object);
entry.AddMember("string", createString(n));
entry.AddMember("int", n);
entry.AddMember("double", static_cast<double>(n) * 0.5);
entry.AddMember("bool", n % 2 == 0);
entry.AddMember("null", Value(Type::NullType));
entry.AddMember("null", Value(Type::Null));
return entry;
};
auto createArray = [&]() -> Value
{
Value array(Type::ArrayType);
Value array(Type::Array);
for (int i = 0; i < entryCount; ++i)
{
array.PushBack(createEntry(i));
@@ -176,7 +176,7 @@ namespace AZ::Dom::Benchmark
BENCHMARK_DEFINE_F(DomValueBenchmark, LookupMemberByName)(benchmark::State& state)
{
Value value(Type::ObjectType);
Value value(Type::Object);
AZStd::vector<AZ::Name> keys;
for (int64_t i = 0; i < state.range(0); ++i)
{
@@ -199,7 +199,7 @@ namespace AZ::Dom::Benchmark
BENCHMARK_DEFINE_F(DomValueBenchmark, LookupMemberByString)(benchmark::State& state)
{
Value value(Type::ObjectType);
Value value(Type::Object);
AZStd::vector<AZStd::string> keys;
for (int64_t i = 0; i < state.range(0); ++i)
{
@@ -79,7 +79,7 @@ namespace AZ::Dom::Tests
m_value.SetArray();
for (int j = 0; j < 5; ++j)
{
Value nestedArray(Type::ArrayType);
Value nestedArray(Type::Array);
for (int i = 0; i < 5; ++i)
{
nestedArray.PushBack(Value(i));
@@ -127,7 +127,7 @@ namespace AZ::Dom::Tests
m_value.SetObject();
for (int j = 0; j < 3; ++j)
{
Value nestedObject(Type::ObjectType);
Value nestedObject(Type::Object);
for (int i = 0; i < 5; ++i)
{
nestedObject.AddMember(AZStd::string::format("Key%i", i), Value(i));
@@ -189,7 +189,7 @@ namespace AZ::Dom::Tests
for (int i = 0; i < 5; ++i)
{
Value childNode(Type::NodeType);
Value childNode(Type::Node);
childNode.SetNodeName(childNodeName);
childNode.SetNodeValue(i);
@@ -218,9 +218,9 @@ namespace AZ::Dom::Tests
m_value["int64_min"] = AZStd::numeric_limits<int64_t>::min();
m_value["int64_max"] = AZStd::numeric_limits<int64_t>::max();
EXPECT_EQ(m_value["int64_min"].GetType(), Type::NumberType);
EXPECT_EQ(m_value["int64_min"].GetType(), Type::Number);
EXPECT_EQ(m_value["int64_min"].GetInt64(), AZStd::numeric_limits<int64_t>::min());
EXPECT_EQ(m_value["int64_max"].GetType(), Type::NumberType);
EXPECT_EQ(m_value["int64_max"].GetType(), Type::Number);
EXPECT_EQ(m_value["int64_max"].GetInt64(), AZStd::numeric_limits<int64_t>::max());
PerformValueChecks();
@@ -232,9 +232,9 @@ namespace AZ::Dom::Tests
m_value["uint64_min"] = AZStd::numeric_limits<uint64_t>::min();
m_value["uint64_max"] = AZStd::numeric_limits<uint64_t>::max();
EXPECT_EQ(m_value["uint64_min"].GetType(), Type::NumberType);
EXPECT_EQ(m_value["uint64_min"].GetType(), Type::Number);
EXPECT_EQ(m_value["uint64_min"].GetInt64(), AZStd::numeric_limits<uint64_t>::min());
EXPECT_EQ(m_value["uint64_max"].GetType(), Type::NumberType);
EXPECT_EQ(m_value["uint64_max"].GetType(), Type::Number);
EXPECT_EQ(m_value["uint64_max"].GetInt64(), AZStd::numeric_limits<uint64_t>::max());
PerformValueChecks();
@@ -246,9 +246,9 @@ namespace AZ::Dom::Tests
m_value["double_min"] = AZStd::numeric_limits<double>::min();
m_value["double_max"] = AZStd::numeric_limits<double>::max();
EXPECT_EQ(m_value["double_min"].GetType(), Type::NumberType);
EXPECT_EQ(m_value["double_min"].GetType(), Type::Number);
EXPECT_EQ(m_value["double_min"].GetDouble(), AZStd::numeric_limits<double>::min());
EXPECT_EQ(m_value["double_max"].GetType(), Type::NumberType);
EXPECT_EQ(m_value["double_max"].GetType(), Type::Number);
EXPECT_EQ(m_value["double_max"].GetDouble(), AZStd::numeric_limits<double>::max());
PerformValueChecks();
@@ -257,9 +257,9 @@ namespace AZ::Dom::Tests
TEST_F(DomValueTests, Null)
{
m_value.SetObject();
m_value["null_value"] = Value(Type::NullType);
m_value["null_value"] = Value(Type::Null);
EXPECT_EQ(m_value["null_value"].GetType(), Type::NullType);
EXPECT_EQ(m_value["null_value"].GetType(), Type::Null);
EXPECT_EQ(m_value["null_type"], Value());
PerformValueChecks();
@@ -271,9 +271,9 @@ namespace AZ::Dom::Tests
m_value["true_value"] = true;
m_value["false_value"] = false;
EXPECT_EQ(m_value["true_value"].GetType(), Type::TrueType);
EXPECT_EQ(m_value["true_value"].GetType(), Type::True);
EXPECT_EQ(m_value["true_value"].GetBool(), true);
EXPECT_EQ(m_value["false_value"].GetType(), Type::FalseType);
EXPECT_EQ(m_value["false_value"].GetType(), Type::False);
EXPECT_EQ(m_value["false_value"].GetBool(), false);
PerformValueChecks();
@@ -290,12 +290,12 @@ namespace AZ::Dom::Tests
AZStd::string stringToCopy = s2;
m_value["copy"] = Value(stringToCopy, true);
EXPECT_EQ(m_value["no_copy"].GetType(), Type::StringType);
EXPECT_EQ(m_value["no_copy"].GetType(), Type::String);
EXPECT_EQ(m_value["no_copy"].GetString(), s1);
stringToReference.at(0) = 'F';
EXPECT_NE(m_value["no_copy"].GetString(), s1);
EXPECT_EQ(m_value["copy"].GetType(), Type::StringType);
EXPECT_EQ(m_value["copy"].GetType(), Type::String);
EXPECT_EQ(m_value["copy"].GetString(), s2);
stringToCopy.at(0) = 'F';
EXPECT_EQ(m_value["copy"].GetString(), s2);
@@ -305,10 +305,10 @@ namespace AZ::Dom::Tests
TEST_F(DomValueTests, CopyOnWrite_Object)
{
Value v1(Type::ObjectType);
Value v1(Type::Object);
v1["foo"] = 5;
Value nestedObject(Type::ObjectType);
Value nestedObject(Type::Object);
v1["obj"] = nestedObject;
Value v2 = v1;
@@ -333,11 +333,11 @@ namespace AZ::Dom::Tests
TEST_F(DomValueTests, CopyOnWrite_Array)
{
Value v1(Type::ArrayType);
Value v1(Type::Array);
v1.PushBack(1);
v1.PushBack(2);
Value nestedArray(Type::ArrayType);
Value nestedArray(Type::Array);
v1.PushBack(nestedArray);
Value v2 = v1;