From 15d7196bf3a3244f078f63645783c4c3f2534d92 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 21 Feb 2023 00:57:37 +0000 Subject: Implement XML deserializer with SAXParse --- lib/saxParse-persistence.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/saxParse-persistence.h (limited to 'lib/saxParse-persistence.h') diff --git a/lib/saxParse-persistence.h b/lib/saxParse-persistence.h new file mode 100644 index 0000000..91daecc --- /dev/null +++ b/lib/saxParse-persistence.h @@ -0,0 +1,43 @@ +#pragma once + +#include "persistence.h" +#include "saxParse.h" +#include +#include + +namespace Persistence { + class SAXParsePersistence : public SAXParse { + private: + template struct Root : public Persistable { + T t {}; + bool + persist(PersistenceStore & store) + { + return STORE_TYPE && STORE_NAME_MEMBER("ilt", t); + } + }; + + void loadStateInternal(FILE * in); + + public: + template + auto + loadState(FILE * in) + { + std::unique_ptr> root; + stk.push(std::make_unique>(std::ref(root))); + loadStateInternal(in); + return std::move(root->t); + } + + protected: + void elementOpen(mxml_node_t * n) override; + void elementClose(mxml_node_t *) override; + void data(mxml_node_t *) override; + void directive(mxml_node_t *) override; + void cdata(mxml_node_t *) override; + + private: + Stack stk; + }; +} -- cgit v1.2.3