Add some Value documentation

Signed-off-by: Nicholas Van Sickle <nvsickle@amazon.com>
monroegm-disable-blank-issue-2
Nicholas Van Sickle 4 years ago
parent 0216d0ae9f
commit 8da04f15d3

@ -144,12 +144,9 @@ namespace AZ::Dom
case Type::Null:
// Null is the default initialized value
break;
case Type::False:
case Type::Bool:
m_value = false;
break;
case Type::True:
m_value = true;
break;
case Type::Object:
SetObject();
break;
@ -159,8 +156,14 @@ namespace AZ::Dom
case Type::String:
SetString("");
break;
case Type::Number:
m_value = 0.0;
case Type::Int64:
m_value = int64_t{};
break;
case Type::Uint64:
m_value = uint64_t{};
break;
case Type::Double:
m_value = double{};
break;
case Type::Node:
SetNode("");
@ -227,11 +230,13 @@ namespace AZ::Dom
case 0: // AZStd::monostate
return Type::Null;
case 1: // int64_t
return Type::Int64;
case 2: // uint64_t
return Type::Uint64;
case 3: // double
return Type::Number;
return Type::Double;
case 4: // bool
return AZStd::get<bool>(m_value) ? Type::True : Type::False;
return Type::Bool;
case 5: // AZStd::string_view
case 6: // AZStd::shared_ptr<const AZStd::string>
case 7: // ShortStringType
@ -256,12 +261,12 @@ namespace AZ::Dom
bool Value::IsFalse() const
{
return GetType() == Type::False;
return IsBool() && !AZStd::get<bool>(m_value);
}
bool Value::IsTrue() const
{
return GetType() == Type::True;
return IsBool() && AZStd::get<bool>(m_value);
}
bool Value::IsBool() const
@ -291,7 +296,16 @@ namespace AZ::Dom
bool Value::IsNumber() const
{
return GetType() == Type::Number;
switch (GetType())
{
case Type::Int64:
[[fallthrough]];
case Type::Uint64:
[[fallthrough]];
case Type::Double:
return true;
}
return false;
}
bool Value::IsInt() const

@ -10,15 +10,15 @@
#include <AzCore/DOM/DomBackend.h>
#include <AzCore/DOM/DomVisitor.h>
#include <AzCore/Memory/HphaSchema.h>
#include <AzCore/Memory/Memory.h>
#include <AzCore/Memory/PoolAllocator.h>
#include <AzCore/Memory/HphaSchema.h>
#include <AzCore/std/containers/array.h>
#include <AzCore/std/containers/stack.h>
#include <AzCore/std/containers/unordered_map.h>
#include <AzCore/std/containers/variant.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/smart_ptr/shared_ptr.h>
#include <AzCore/std/containers/array.h>
namespace AZ::Dom
{
@ -27,19 +27,20 @@ namespace AZ::Dom
//! The type of underlying value stored in a value. \see Value
enum class Type
{
Null = 0,
False = 1,
True = 2,
Object = 3,
Array = 4,
String = 5,
Number = 6,
Node = 7,
Opaque = 8,
Null,
Bool,
Object,
Array,
String,
Int64,
Uint64,
Double,
Node,
Opaque,
};
//! The allocator used by Value.
//! Value heap allocates shared_ptrs for its container storage (Array / Object / Node) alongside
//! Value heap allocates shared_ptrs for its container storage (Array / Object / Node) alongside
class ValueAllocator final : public SimpleSchemaAllocator<AZ::HphaSchema, AZ::HphaSchema::Descriptor, false, false>
{
public:
@ -56,6 +57,7 @@ namespace AZ::Dom
class Value;
//! Internal storage for a Value array: an ordered list of Values.
class Array
{
public:
@ -73,6 +75,7 @@ namespace AZ::Dom
using ArrayPtr = AZStd::shared_ptr<Array>;
using ConstArrayPtr = AZStd::shared_ptr<const Array>;
//! Internal storage for a Value object: an ordered list of Name / Value pairs.
class Object
{
public:
@ -91,6 +94,9 @@ namespace AZ::Dom
using ObjectPtr = AZStd::shared_ptr<Object>;
using ConstObjectPtr = AZStd::shared_ptr<const Object>;
//! Storage for a Value node: a named Value with both properties and children.
//! Properties are stored as an ordered list of Name / Value pairs.
//! Children are stored as an oredered list of Values.
class Node
{
public:
@ -122,6 +128,21 @@ namespace AZ::Dom
using NodePtr = AZStd::shared_ptr<Node>;
using ConstNodePtr = AZStd::shared_ptr<Node>;
//! Value is a typed union of Dom types that can represent the types provdied by AZ::Dom::Visitor.
//! Value can be one of the following types:
//! - Null: a type with no value, this is the default type for Value
//! - Bool: a true or false boolean value
//! - Object: a container with an ordered list of Name/Value pairs, analagous to a JSON object
//! - Array: a container with an ordered list of Values, analagous to a JSON array
//! - String: a UTF-8 string
//! - Int64: a signed, 64-bit integer
//! - Uint64: an unsigned, 64-bit integer
//! - Double: a double precision floating point value
//! - Node: a container with a Name, an ordered list of Name/Values pairs (attributes), and an ordered list of Values (children),
//! analagous to an XML node
//! - Opaque: an arbitrary value stored in an AZStd::any. This is a non-serializable representation of an entry used only for in-memory
//! options. This is intended to be used as an intermediate value over the course of DOM transformation and as a proxy to pass through
//! types of which the DOM has no knowledge to other systems.
class Value
{
public:
@ -327,7 +348,7 @@ namespace AZ::Dom
//! The internal storage type for Value.
//! These types do not correspond one-to-one with the Value's external Type as there may be multiple storage classes
//! for the same type in some instances, such as string storage
//! for the same type in some instances, such as string storage
using ValueType = AZStd::variant<
// NullType
AZStd::monostate,
@ -351,8 +372,7 @@ namespace AZ::Dom
AZStd::any*>;
static_assert(
sizeof(ValueType) == sizeof(AZStd::variant<ShortStringType>),
"ValueType should have no members larger than ShortStringType");
sizeof(ValueType) == sizeof(AZStd::variant<ShortStringType>), "ValueType should have no members larger than ShortStringType");
ValueType m_value;
};

@ -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::Number);
EXPECT_EQ(m_value["int64_min"].GetType(), Type::Int64);
EXPECT_EQ(m_value["int64_min"].GetInt64(), AZStd::numeric_limits<int64_t>::min());
EXPECT_EQ(m_value["int64_max"].GetType(), Type::Number);
EXPECT_EQ(m_value["int64_max"].GetType(), Type::Int64);
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::Number);
EXPECT_EQ(m_value["uint64_min"].GetType(), Type::Uint64);
EXPECT_EQ(m_value["uint64_min"].GetInt64(), AZStd::numeric_limits<uint64_t>::min());
EXPECT_EQ(m_value["uint64_max"].GetType(), Type::Number);
EXPECT_EQ(m_value["uint64_max"].GetType(), Type::Uint64);
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::Number);
EXPECT_EQ(m_value["double_min"].GetType(), Type::Double);
EXPECT_EQ(m_value["double_min"].GetDouble(), AZStd::numeric_limits<double>::min());
EXPECT_EQ(m_value["double_max"].GetType(), Type::Number);
EXPECT_EQ(m_value["double_max"].GetType(), Type::Double);
EXPECT_EQ(m_value["double_max"].GetDouble(), AZStd::numeric_limits<double>::max());
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::True);
EXPECT_EQ(m_value["true_value"].GetType(), Type::Bool);
EXPECT_EQ(m_value["true_value"].GetBool(), true);
EXPECT_EQ(m_value["false_value"].GetType(), Type::False);
EXPECT_EQ(m_value["false_value"].GetType(), Type::Bool);
EXPECT_EQ(m_value["false_value"].GetBool(), false);
PerformValueChecks();

Loading…
Cancel
Save