diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-10-19 00:08:49 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-10-19 00:22:11 +0200 |
| commit | 48bdfbeb03319eb21b5e73e69f525ba298af975c (patch) | |
| tree | 9d189fe570b408e27d82bd434a83b9f0a3bae18e /src/json.hh | |
| parent | df56d2eb26b34b0af590f3aedfda7896f4b103dd (diff) | |
json: Add new module
Only has methods for writing JSON for now.
Will let you create invalid json, but should assert if you do.
Diffstat (limited to 'src/json.hh')
| -rw-r--r-- | src/json.hh | 46 |
1 files changed, 46 insertions, 0 deletions
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 <cstdint> +#include <iosfwd> +#include <memory> +#include <string> +#include <string_view> + +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> writer(std::string& out); +std::unique_ptr<Writer> writer(std::ostream& out); + +} // namespace json + +#endif // JSON_HH |
