#pragma once #include #include #include #include namespace updater { class Json { public: enum Type { Null, Bool, Number, String, Array, Object }; Json(); explicit Json(Type type); Type type() const { return type_; } bool isNull() const { return type_ == Null; } bool isBool() const { return type_ == Bool; } bool isNumber() const { return type_ == Number; } bool isString() const { return type_ == String; } bool isArray() const { return type_ == Array; } bool isObject() const { return type_ == Object; } bool boolValue(bool def = false) const; double numberValue(double def = 0.0) const; long long intValue(long long def = 0) const; std::string stringValue(const std::string& def = "") const; const Json& operator[](const char* key) const; const Json& operator[](const std::string& key) const; const Json& operator[](size_t index) const; bool contains(const char* key) const; size_t arraySize() const; static bool Parse(const std::string& text, Json& out, std::string& err); private: struct Impl; std::shared_ptr impl_; Type type_; friend struct JsonAccess; }; }