summaryrefslogtreecommitdiff
path: root/lib/saxParse-persistence.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-02-21 00:57:37 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-02-21 00:57:37 +0000
commit15d7196bf3a3244f078f63645783c4c3f2534d92 (patch)
tree3b49a3d2968057c5f600afb37b6b19e25323dc29 /lib/saxParse-persistence.h
parentAdd checked_fopen wrapper and FileStar container (diff)
downloadilt-15d7196bf3a3244f078f63645783c4c3f2534d92.tar.bz2
ilt-15d7196bf3a3244f078f63645783c4c3f2534d92.tar.xz
ilt-15d7196bf3a3244f078f63645783c4c3f2534d92.zip
Implement XML deserializer with SAXParse
Diffstat (limited to 'lib/saxParse-persistence.h')
-rw-r--r--lib/saxParse-persistence.h43
1 files changed, 43 insertions, 0 deletions
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 <cstdio>
+#include <mxml.h>
+
+namespace Persistence {
+ class SAXParsePersistence : public SAXParse {
+ private:
+ template<typename T> struct Root : public Persistable {
+ T t {};
+ bool
+ persist(PersistenceStore & store)
+ {
+ return STORE_TYPE && STORE_NAME_MEMBER("ilt", t);
+ }
+ };
+
+ void loadStateInternal(FILE * in);
+
+ public:
+ template<typename T>
+ auto
+ loadState(FILE * in)
+ {
+ std::unique_ptr<Root<T>> root;
+ stk.push(std::make_unique<SelectionT<decltype(root)>>(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;
+ };
+}