From ce5c689a5f9e544d724b2a41fda2f752ccc4a4ae Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 7 May 2021 20:50:48 +0100 Subject: Initial commit where writing objects back out to JSON It's not perfect, writes explicit nulls, doesn't do shared @id --- lib/jsonParse-persistence.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/jsonParse-persistence.h') diff --git a/lib/jsonParse-persistence.h b/lib/jsonParse-persistence.h index 6449f7b..edb5305 100644 --- a/lib/jsonParse-persistence.h +++ b/lib/jsonParse-persistence.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace Persistence { class JsonParsePersistence : public json::jsonParser { @@ -39,6 +40,33 @@ namespace Persistence { template inline void pushValue(T && value); inline SelectionPtr & current(); }; + + class JsonWritePersistence : public Writer { + public: + explicit JsonWritePersistence(std::ostream & s); + + template + inline void + saveState(T & t) const + { + SelectionT {t}.write(*this); + } + + protected: + void beginObject() const override; + void beginArray() const override; + void pushValue(bool value) const override; + void pushValue(float value) const override; + void pushValue(std::nullptr_t) const override; + void pushValue(const std::string_view value) const override; + void nextValue() const override; + void pushKey(const std::string_view k) const override; + void endArray() const override; + void endObject() const override; + + private: + std::ostream & strm; + }; } #endif -- cgit v1.2.3