summaryrefslogtreecommitdiff
path: root/lib/jsonParse-persistence.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-05-07 20:50:48 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-11-07 16:41:37 +0000
commitce5c689a5f9e544d724b2a41fda2f752ccc4a4ae (patch)
tree33f2c53d2cb1b67f3c7024bbec2366be875b57d9 /lib/jsonParse-persistence.h
parentFixup clang, cppcheck and iwyu warnings (diff)
downloadilt-ce5c689a5f9e544d724b2a41fda2f752ccc4a4ae.tar.bz2
ilt-ce5c689a5f9e544d724b2a41fda2f752ccc4a4ae.tar.xz
ilt-ce5c689a5f9e544d724b2a41fda2f752ccc4a4ae.zip
Initial commit where writing objects back out to JSON
It's not perfect, writes explicit nulls, doesn't do shared @id
Diffstat (limited to 'lib/jsonParse-persistence.h')
-rw-r--r--lib/jsonParse-persistence.h28
1 files changed, 28 insertions, 0 deletions
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 <iosfwd>
#include <memory>
#include <string>
+#include <string_view>
namespace Persistence {
class JsonParsePersistence : public json::jsonParser {
@@ -39,6 +40,33 @@ namespace Persistence {
template<typename T> inline void pushValue(T && value);
inline SelectionPtr & current();
};
+
+ class JsonWritePersistence : public Writer {
+ public:
+ explicit JsonWritePersistence(std::ostream & s);
+
+ template<typename T>
+ inline void
+ saveState(T & t) const
+ {
+ SelectionT<T> {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