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);
|
2019-06-18 06:55:58 +00:00
|
|
|
JsonValue(unsigned);
|
2019-06-17 17:47:35 +00:00
|
|
|
JsonValue(double);
|
|
|
|
JsonValue(bool);
|
2019-06-18 07:11:31 +00:00
|
|
|
JsonValue(const char*);
|
2019-06-17 17:47:35 +00:00
|
|
|
JsonValue(const String&);
|
|
|
|
JsonValue(const JsonArray&);
|
|
|
|
JsonValue(const JsonObject&);
|
|
|
|
|
2019-06-18 07:37:47 +00:00
|
|
|
String serialized() const;
|
|
|
|
void serialize(StringBuilder&) const;
|
2019-06-17 17:47:35 +00:00
|
|
|
|
2019-06-18 06:55:58 +00:00
|
|
|
String as_string() const
|
|
|
|
{
|
|
|
|
if (m_type == Type::String)
|
|
|
|
return *m_value.as_string;
|
|
|
|
return { };
|
|
|
|
}
|
|
|
|
|
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;
|