2026-03-29 15:46:36 +02:00

71 lines
1.6 KiB
C++

#ifndef JSON_HPP
#define JSON_HPP
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
namespace json {
enum class Type {
Null = 1,
False = 2,
True = 3,
Int = 4,
Float = 5,
String = 6,
Array = 7,
Object = 8,
};
class Underlying;
class Value {
public:
Value(const Value&) = delete;
Value(Value&&) = delete;
Value& operator=(const Value&) = delete;
Value& operator=(Value&&) = delete;
explicit Value(std::unique_ptr<Underlying> underlying)
: m_underlying(std::move(underlying)) { };
~Value() = default;
auto is(Type type) const -> bool;
auto get_type() const -> Type;
auto get_bool() const -> bool;
auto get_int() const -> std::int64_t;
auto get_float() const -> double;
auto get_string() const -> std::string_view;
void set_null();
void set_bool(bool val);
void set_int(int64_t val);
void set_float(double val);
void set_string(std::string_view val);
auto count() const -> std::size_t;
auto get(std::size_t idx) -> std::unique_ptr<Value>;
auto get(std::size_t idx) const -> std::unique_ptr<const Value>;
void push(std::unique_ptr<Value> value);
auto get(std::string_view key) -> std::unique_ptr<Value>;
auto get(std::string_view key) const -> std::unique_ptr<const Value>;
void set(std::string_view key, std::unique_ptr<Value> value);
auto query(const std::string& query) -> std::unique_ptr<Value>;
private:
std::unique_ptr<Underlying> m_underlying;
};
auto parse(std::string_view text) -> std::unique_ptr<Value>;
}
#endif