13#include <initializer_list>
33 using Array = std::vector<Value>;
34 using Object = std::map<std::string, Value>;
35 using Storage = std::variant<std::monostate, bool, std::int64_t, double, std::string, Array, Object>;
38 enum class Type : std::uint8_t {
83 Type type() const noexcept {
return static_cast<Type>(storage_.index()); }
87 bool isNull() const noexcept {
return type() == Type::Null; }
89 bool isBool() const noexcept {
return type() == Type::Bool; }
91 bool isInt64() const noexcept {
return type() == Type::Int64; }
97 bool isArray() const noexcept {
return type() == Type::Array; }
117 std::int64_t asInt()
const;
119 double asDouble()
const;
123 const std::string& asString()
const;
128 std::size_t arraySize()
const;
144 Value* find(
const std::string&
key)
noexcept;
154 const Value* find(
const std::string&
key)
const noexcept;
156 std::vector<std::string> keys()
const;
159 bool isNumeric() const noexcept {
return isInt64() || isDouble(); }
161 std::string typeName()
const;
163 std::string toString()
const;
181 return std::get_if<T>(&storage_);
195 return std::get_if<T>(&storage_);
205 [[nodiscard]]
static Result<Value> fromJson(std::string_view json);
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Move-only, checked operation results for the common layer.
Move-only operation result carrying either a value or Status.
The canonical owning dynamic value used by data-facing protocols.
Value(std::nullptr_t)
Construct a null value from nullptr.
Value(Object value)
Construct an object value by taking its members.
bool isInt64() const noexcept
Return true when this value is an Int64.
static Value null()
Compatibility factory for a null value.
const Storage & storage() const noexcept
Return the immutable variant storage for visitors.
Type kind() const noexcept
Compatibility spelling for the former dialogue data tree.
Value(Array value)
Construct an array value by taking its elements.
std::map< std::string, Value > Object
bool isNumeric() const noexcept
Return whether this value is an integer or finite number.
Value(std::int64_t value)
Construct an Int64 value without narrowing.
bool isArray() const noexcept
Return true when this value is an array.
Value(bool value)
Construct a boolean value.
Value(double value)
Construct a Double value; non-finite values serialize as errors.
static Value number(double value)
Compatibility factory for a Double value.
Value()=default
Construct a null value.
bool isString() const noexcept
Return true when this value is a string.
static Value string(std::string value)
Compatibility factory for a string value.
Type
Runtime kind of the owned value.
static Value array(Array value)
Compatibility factory for an array value.
Value(int value)
Construct an integer value using the canonical Int64 type.
std::vector< Value > Array
Storage & storage() noexcept
Return mutable variant storage for owning edits.
static Value integer(std::int64_t value)
Compatibility factory for an Int64 value.
Value(const char *value)
Construct a string value, copying the supplied text.
std::variant< std::monostate, bool, std::int64_t, double, std::string, Array, Object > Storage
bool isNull() const noexcept
Return true when this value is null.
static Value boolean(bool value)
Compatibility factory for a boolean value.
static Value object(Object value)
Compatibility factory for an object value.
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
bool isBool() const noexcept
Return true when this value is a boolean.
bool isObject() const noexcept
Return true when this value is an object.
Value(float value)
Construct a Double value from a float.
bool operator==(const Value &) const =default
Compare two values recursively, including their numeric kinds.
Value(std::string value)
Construct a string value by taking the supplied text.
bool isDouble() const noexcept
Return true when this value is a Double.
Type type() const noexcept
Return the active value kind.
T * getIf() noexcept
Return a mutable typed pointer, or nullptr when the kind differs.
Build metadata (engine git commit, build time, third-party version).
enum EVENGINE_API_FOUNDATION Float
OT_FLOAT.
enum EVENGINE_API_FOUNDATION Bool
OT_BOOL.
enum EVENGINE_API_FOUNDATION Integer
OT_INTEGER.
enum EVENGINE_API_FOUNDATION String
OT_STRING.