This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/data/XMLserialize.h
2018-10-25 11:50:12 +02:00

55 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#ifndef XMLSERIALIZE_H
#define XMLSERIALIZE_H
#include "XMLload.h"
#include "XMLsave.h"
#include "xml.h"
class XMLserialize : public XMLload, public XMLsave {
public:
void loadXML(const std::string& file) {
XMLDoc doc;
assertOK(doc.LoadFile(file.c_str()), doc, "error while loading file");
XMLElem* root = doc.FirstChildElement("root");
readFromXML(&doc, root);
}
void saveXML(const std::string& file) {
XMLDoc doc;
XMLElem* root = doc.NewElement("root");
doc.InsertFirstChild(root);
writeToXML(&doc, root);
assertOK(doc.SaveFile(file.c_str()), doc, "error while saving file");
}
public:
static void assertOK(XMLErr res, XMLDoc& doc, const std::string& txt) {
if (res != tinyxml2::XMLError::XML_SUCCESS) {
const std::string err = doc.ErrorName();
const std::string add = doc.GetErrorStr1();
throw Exception(txt + ": " + err + " - " + add);
}
}
};
#endif // XMLSERIALIZE_H