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 --- test/test-persistance.cpp | 87 ++--------------------------------------------- 1 file changed, 2 insertions(+), 85 deletions(-) (limited to 'test') diff --git a/test/test-persistance.cpp b/test/test-persistance.cpp index b6bde3f..101c2d2 100644 --- a/test/test-persistance.cpp +++ b/test/test-persistance.cpp @@ -2,96 +2,13 @@ #include -#include #include #include -#include +#include #include -#include #include #include -struct TestObject; - -namespace Persistanace { - struct JsonLoadPersistanceStore : public json::jsonParser { - explicit JsonLoadPersistanceStore(std::istream & in) : json::jsonParser {&in} { } - - Stack stk; - - inline SelectionPtr & - current() - { - return stk.top(); - } - - template - void - loadState(std::unique_ptr & t) - { - stk.push(std::make_unique>>(std::ref(t))); - yy_push_state(0); - yylex(); - } - void - BeginObject() override - { - stk.push(current()->BeginObject()); - } - void - BeginArray() override - { - current()->BeginArray(stk); - } - template - inline void - PushValue(T && value) - { - current()->beforeValue(stk); - (*current())(value); - stk.pop(); - } - void - PushBoolean(bool value) override - { - PushValue(value); - } - void - PushNumber(float value) override - { - PushValue(value); - } - void - PushNull() override - { - PushValue(nullptr); - } - void - PushText(std::string && value) override - { - PushValue(value); - } - void - PushKey(std::string && k) override - { - stk.push(current()->select(k)); - } - void - EndArray() override - { - stk.pop(); - } - void - EndObject() override - { - stk.pop(); - } - }; -} - -#define STORE_TYPE store.persistType(typeid(*this)) -#define STORE_MEMBER(mbr) store.persistValue(#mbr, mbr) - struct TestObject : public Persistanace::Persistable { TestObject() = default; @@ -132,7 +49,7 @@ BOOST_AUTO_TEST_CASE(load_object) { Persistanace::Persistable::addFactory("TestObject", std::make_unique); std::stringstream ss {input}; - Persistanace::JsonLoadPersistanceStore jlps {ss}; + Persistanace::JsonParsePersistance jlps {ss}; std::unique_ptr to; jlps.loadState(to); -- cgit v1.2.3