summaryrefslogtreecommitdiff
path: root/lib/jsonParse-persistance.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-04-17 23:59:42 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-11-07 16:41:37 +0000
commit1d8a75f050f54ccb837ac13530d53c03fca38798 (patch)
treee2fda09ddf8e0f9b0e917da7d34e0fa056025a9b /lib/jsonParse-persistance.cpp
parentSecond swing persistance (diff)
downloadilt-1d8a75f050f54ccb837ac13530d53c03fca38798.tar.bz2
ilt-1d8a75f050f54ccb837ac13530d53c03fca38798.tar.xz
ilt-1d8a75f050f54ccb837ac13530d53c03fca38798.zip
Move json persistance into lib
Diffstat (limited to 'lib/jsonParse-persistance.cpp')
-rw-r--r--lib/jsonParse-persistance.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/lib/jsonParse-persistance.cpp b/lib/jsonParse-persistance.cpp
new file mode 100644
index 0000000..89887da
--- /dev/null
+++ b/lib/jsonParse-persistance.cpp
@@ -0,0 +1,81 @@
+#include "jsonParse-persistance.h"
+
+namespace Persistanace {
+ JsonParsePersistance::JsonParsePersistance(std::istream & in) : json::jsonParser {&in} { }
+
+ void
+ JsonParsePersistance::loadState()
+ {
+ yy_push_state(0);
+ yylex();
+ }
+
+ void
+ JsonParsePersistance::BeginObject()
+ {
+ stk.push(current()->BeginObject());
+ }
+
+ void
+ JsonParsePersistance::BeginArray()
+ {
+ current()->BeginArray(stk);
+ }
+
+ void
+ JsonParsePersistance::PushBoolean(bool value)
+ {
+ PushValue(value);
+ }
+
+ void
+ JsonParsePersistance::PushNumber(float value)
+ {
+ PushValue(value);
+ }
+
+ void
+ JsonParsePersistance::PushNull()
+ {
+ PushValue(nullptr);
+ }
+
+ void
+ JsonParsePersistance::PushText(std::string && value)
+ {
+ PushValue(value);
+ }
+
+ void
+ JsonParsePersistance::PushKey(std::string && k)
+ {
+ stk.push(current()->select(k));
+ }
+
+ void
+ JsonParsePersistance::EndArray()
+ {
+ stk.pop();
+ }
+
+ void
+ JsonParsePersistance::EndObject()
+ {
+ stk.pop();
+ }
+
+ template<typename T>
+ inline void
+ JsonParsePersistance::PushValue(T && value)
+ {
+ current()->beforeValue(stk);
+ (*current())(value);
+ stk.pop();
+ }
+
+ inline SelectionPtr &
+ JsonParsePersistance::current()
+ {
+ return stk.top();
+ }
+}