2019-06-17 17:47:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/AKString.h>
|
|
|
|
|
2019-06-17 19:34:12 +00:00
|
|
|
namespace AK {
|
|
|
|
|
2019-06-17 17:47:35 +00:00
|
|
|
class JsonArray;
|
|
|
|
class JsonObject;
|
2019-06-17 19:34:12 +00:00
|
|
|
class StringBuilder;
|
2019-06-17 17:47:35 +00:00
|
|
|
|
|
|
|
class JsonValue {
|
|
|
|
public:
|
|
|
|
enum class Type {
|
|
|
|
Undefined,
|
|
|
|
Null,
|
|
|
|
Int,
|
|
|
|
Double,
|
|
|
|
Bool,
|
|
|
|
String,
|
|
|
|
Array,
|
|
|
|
Object,
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit JsonValue(Type = Type::Null);
|
|
|
|
~JsonValue() { clear(); }
|
|
|
|
|
|
|
|
JsonValue(const JsonValue&);
|
|
|
|
JsonValue(JsonValue&&);
|
|
|
|
|
|
|
|
JsonValue& operator=(const JsonValue&);
|
|
|
|
JsonValue& operator=(JsonValue&&);
|
|
|
|
|
|
|
|
JsonValue(int);
|
|
|
|
JsonValue(double);
|
|
|
|
JsonValue(bool);
|
|
|
|
JsonValue(const String&);
|
|
|
|
JsonValue(const JsonArray&);
|
|
|
|
JsonValue(const JsonObject&);
|
|
|
|
|
|
|
|
String to_string() const;
|
2019-06-17 19:34:12 +00:00
|
|
|
void to_string(StringBuilder&) const;
|
2019-06-17 17:47:35 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void clear();
|
|
|
|
void copy_from(const JsonValue&);
|
|
|
|
|
|
|
|
Type m_type { Type::Undefined };
|
|
|
|
|
|
|
|
union {
|
|
|
|
StringImpl* as_string { nullptr };
|
|
|
|
JsonArray* as_array;
|
|
|
|
JsonObject* as_object;
|
|
|
|
double as_double;
|
|
|
|
int as_int;
|
|
|
|
bool as_bool;
|
|
|
|
} m_value;
|
|
|
|
};
|
2019-06-17 19:34:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::JsonValue;
|