From 48bdfbeb03319eb21b5e73e69f525ba298af975c Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sun, 19 Oct 2025 00:08:49 +0200 Subject: json: Add new module Only has methods for writing JSON for now. Will let you create invalid json, but should assert if you do. --- src/json.hh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/json.hh (limited to 'src/json.hh') diff --git a/src/json.hh b/src/json.hh new file mode 100644 index 0000000..d872dde --- /dev/null +++ b/src/json.hh @@ -0,0 +1,46 @@ +#ifndef JSON_HH +#define JSON_HH + +#include +#include +#include +#include +#include + +namespace json { + +class Writer { + public: + virtual ~Writer() = default; + + virtual void value(std::string_view value) = 0; + virtual void value(int64_t value) = 0; + virtual void value(uint64_t value) = 0; + virtual void value(float value) = 0; + virtual void value(double value) = 0; + virtual void value(bool value) = 0; + + void value(char const* value); + void value(int value); + + virtual void start_array() = 0; + virtual void end_array() = 0; + + virtual void start_object() = 0; + virtual void key(std::string_view name) = 0; + virtual void end_object() = 0; + + virtual void clear() = 0; + + protected: + Writer() = default; + Writer(Writer const&) = delete; + Writer& operator=(Writer const&) = delete; +}; + +std::unique_ptr writer(std::string& out); +std::unique_ptr writer(std::ostream& out); + +} // namespace json + +#endif // JSON_HH -- cgit v1.2.3-70-g09d2