From 0724047fbbbf02e053e2686299d726fcb2c7d295 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 20 Feb 2023 18:42:30 +0000 Subject: Add SAXParse base class --- Jamroot.jam | 2 ++ lib/saxParse.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ lib/saxParse.h | 21 +++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 lib/saxParse.cpp create mode 100644 lib/saxParse.h diff --git a/Jamroot.jam b/Jamroot.jam index 16c22ac..27db410 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -12,6 +12,7 @@ pkg-config.import sdl2 ; pkg-config.import glew ; pkg-config.import freetype2 ; pkg-config.import glib-2.0 ; +pkg-config.import mxml ; lib pthread ; lib OpenMeshCore ; @@ -112,6 +113,7 @@ lib ilt : glew freetype2 glib-2.0 + mxml pthread OpenMeshCore : : diff --git a/lib/saxParse.cpp b/lib/saxParse.cpp new file mode 100644 index 0000000..d592a1f --- /dev/null +++ b/lib/saxParse.cpp @@ -0,0 +1,41 @@ +#include "saxParse.h" +#include "mxml.h" + +namespace Persistence { + void + SAXParse::comment(mxml_node_t *) + { + // Default to just ignore comments + } + + void + SAXParse::parseFile(FILE * file) + { + mxmlSAXLoadFile( + nullptr, file, MXML_TEXT_CALLBACK, + [](mxml_node_t * n, mxml_sax_event_t e, void * data) { + SAXParse * self = static_cast(data); + switch (e) { + case MXML_SAX_ELEMENT_OPEN: + return self->elementOpen(n); + break; + case MXML_SAX_ELEMENT_CLOSE: + return self->elementClose(n); + break; + case MXML_SAX_COMMENT: + return self->comment(n); + break; + case MXML_SAX_DATA: + return self->data(n); + break; + case MXML_SAX_DIRECTIVE: + return self->directive(n); + break; + case MXML_SAX_CDATA:; + return self->cdata(n); + break; + } + }, + this); + } +} diff --git a/lib/saxParse.h b/lib/saxParse.h new file mode 100644 index 0000000..d5baaca --- /dev/null +++ b/lib/saxParse.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +typedef struct _mxml_node_s mxml_node_t; + +namespace Persistence { + class SAXParse { + public: + virtual ~SAXParse() = default; + + virtual void elementOpen(mxml_node_t *) = 0; + virtual void elementClose(mxml_node_t *) = 0; + virtual void comment(mxml_node_t *); + virtual void data(mxml_node_t *) = 0; + virtual void directive(mxml_node_t *) = 0; + virtual void cdata(mxml_node_t *) = 0; + + void parseFile(FILE * file); + }; +} -- cgit v1.2.3