From 1d8a75f050f54ccb837ac13530d53c03fca38798 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 17 Apr 2021 23:59:42 +0100 Subject: Move json persistance into lib --- lib/jsonParse-persistance.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 lib/jsonParse-persistance.cpp (limited to 'lib/jsonParse-persistance.cpp') 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 + inline void + JsonParsePersistance::PushValue(T && value) + { + current()->beforeValue(stk); + (*current())(value); + stk.pop(); + } + + inline SelectionPtr & + JsonParsePersistance::current() + { + return stk.top(); + } +} -- cgit v1.2.3