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.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 lib/saxParse-persistence.cpp (limited to 'lib/saxParse-persistence.cpp') diff --git a/lib/saxParse-persistence.cpp b/lib/saxParse-persistence.cpp new file mode 100644 index 0000000..a6a0d23 --- /dev/null +++ b/lib/saxParse-persistence.cpp @@ -0,0 +1,50 @@ +#include "saxParse-persistence.h" + +namespace Persistence { + + void + SAXParsePersistence::loadStateInternal(FILE * in) + { + stk.top()->beforeValue(stk); + stk.top()->beginObject(stk); + parseFile(in); + stk.pop(); + stk.pop(); + } + + void + SAXParsePersistence::elementOpen(mxml_node_t * n) + { + stk.push(stk.top()->select(mxmlGetElement(n))); + stk.top()->beforeValue(stk); + stk.top()->beginObject(stk); + for (int attrCount = mxmlElementGetAttrCount(n), attrIdx {0}; attrIdx < attrCount; ++attrIdx) { + const char *name, *value = mxmlElementGetAttrByIndex(n, attrIdx, &name); + auto sel = stk.top()->select(name); + sel->beforeValue(stk); + sel->setValue(std::string {value}); + } + } + + void + SAXParsePersistence::elementClose(mxml_node_t *) + { + stk.top()->endObject(stk); + stk.top()->endObject(stk); + } + + void + SAXParsePersistence::data(mxml_node_t *) + { + } + + void + SAXParsePersistence::directive(mxml_node_t *) + { + } + + void + SAXParsePersistence::cdata(mxml_node_t *) + { + } +} -- cgit v1.2.3