summaryrefslogtreecommitdiff
path: root/lib/jsonParse-persistence.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-04-30 01:03:42 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-11-07 16:41:37 +0000
commita31858d29048735b812d385f75db4ed6a6a94556 (patch)
treefffd08d958c4970be617b3ad36905b54f2445bad /lib/jsonParse-persistence.h
parentImplement shared_ptr support (diff)
downloadilt-a31858d29048735b812d385f75db4ed6a6a94556.tar.bz2
ilt-a31858d29048735b812d385f75db4ed6a6a94556.tar.xz
ilt-a31858d29048735b812d385f75db4ed6a6a94556.zip
Fix the fact I've been spelling persistence wrong this whole time
Diffstat (limited to 'lib/jsonParse-persistence.h')
-rw-r--r--lib/jsonParse-persistence.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/jsonParse-persistence.h b/lib/jsonParse-persistence.h
new file mode 100644
index 0000000..6449f7b
--- /dev/null
+++ b/lib/jsonParse-persistence.h
@@ -0,0 +1,44 @@
+#ifndef JSONPARSE_PERSISTANCE
+#define JSONPARSE_PERSISTANCE
+
+#include "jsonParse.h" // IWYU pragma: export
+#include "persistence.h" // IWYU pragma: export
+#include <functional>
+#include <iosfwd>
+#include <memory>
+#include <string>
+
+namespace Persistence {
+ class JsonParsePersistence : public json::jsonParser {
+ public:
+ template<typename T>
+ inline T
+ loadState(std::istream & in)
+ {
+ T t {};
+ stk.push(std::make_unique<SelectionT<T>>(std::ref(t)));
+ loadState(in);
+ return t;
+ }
+
+ protected:
+ void loadState(std::istream & in);
+
+ void beginObject() override;
+ void beginArray() override;
+ void pushBoolean(bool value) override;
+ void pushNumber(float value) override;
+ void pushNull() override;
+ void pushText(std::string && value) override;
+ void pushKey(std::string && k) override;
+ void endArray() override;
+ void endObject() override;
+
+ Stack stk;
+
+ template<typename T> inline void pushValue(T && value);
+ inline SelectionPtr & current();
+ };
+}
+
+#endif