diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-04-17 23:59:42 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-11-07 16:41:37 +0000 |
commit | 1d8a75f050f54ccb837ac13530d53c03fca38798 (patch) | |
tree | e2fda09ddf8e0f9b0e917da7d34e0fa056025a9b /lib/jsonParse-persistance.h | |
parent | Second swing persistance (diff) | |
download | ilt-1d8a75f050f54ccb837ac13530d53c03fca38798.tar.bz2 ilt-1d8a75f050f54ccb837ac13530d53c03fca38798.tar.xz ilt-1d8a75f050f54ccb837ac13530d53c03fca38798.zip |
Move json persistance into lib
Diffstat (limited to 'lib/jsonParse-persistance.h')
-rw-r--r-- | lib/jsonParse-persistance.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/jsonParse-persistance.h b/lib/jsonParse-persistance.h new file mode 100644 index 0000000..d5c76ed --- /dev/null +++ b/lib/jsonParse-persistance.h @@ -0,0 +1,45 @@ +#ifndef JSONPARSE_PERSISTANCE +#define JSONPARSE_PERSISTANCE + +#include "jsonParse.h" // IWYU pragma: export +#include "persistance.h" // IWYU pragma: export +#include <functional> +#include <iosfwd> +#include <memory> +#include <string> + +namespace Persistanace { + class JsonParsePersistance : public json::jsonParser { + public: + explicit JsonParsePersistance(std::istream & in); + + template<typename T> + void + loadState(T & t) + { + stk.push(std::make_unique<SelectionT<T>>(std::ref(t))); + loadState(); + } + + protected: + void loadState(); + + 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; + + private: + Stack stk; + + template<typename T> inline void PushValue(T && value); + inline SelectionPtr & current(); + }; +} + +#endif |