summaryrefslogtreecommitdiff
path: root/lib/saxParse-persistence.h
blob: 91daeccabeb865e5e4ff04207c7e1450a4ddf4b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
	};
}