15 #ifndef BORNAGAIN_GUI_SUPPORT_XML_STREAMER_H
16 #define BORNAGAIN_GUI_SUPPORT_XML_STREAMER_H
18 #include "Base/Util/Assert.h"
19 #include <QXmlStreamWriter>
21 #include <heinz/Vectors3D.h>
25 constexpr
auto Id(
"id");
57 template <
typename Catalog>
58 void write(
const QString& tag,
typename Catalog::CatalogedType* p);
60 template <
typename Catalog,
typename... Args>
61 void read(
const QString& tag,
typename Catalog::CatalogedType*& p, Args... argsForConstructor);
67 void start(
const QString& tag);
68 void finish(
const QString& tag);
73 QXmlStreamWriter*
m_w =
nullptr;
74 QXmlStreamReader*
m_r =
nullptr;
81 template <
typename Catalog>
85 m_w->writeStartElement(tag);
86 m_w->writeAttribute(
"type", QString::number(
static_cast<uint8_t
>(Catalog::type(p))));
89 m_w->writeEndElement();
92 template <
typename Catalog,
typename... Args>
94 Args... argsForConstructor)
98 const auto type =
static_cast<typename Catalog::Type
>(
m_r->attributes().value(
"type").toUInt());
99 p = Catalog::create(type, argsForConstructor...);
Supports serialization to or deserialization from QXmlStream.
void gotoEndElementOfTag(const QString &tag)
void start(const QString &tag)
void write(const QString &tag, typename Catalog::CatalogedType *p)
Streamer(QXmlStreamWriter *w)
Streamer(QXmlStreamReader *r)
void assertCurrentTag(const QString &expectedTag) const
void writeVersion(unsigned version) const
As writer, serializes the given version number. As reader, does nothing.
void assertCurrentToken(QXmlStreamReader::TokenType token) const
void gotoStartElementOfTag(const QString &tag)
QXmlStreamWriter * xmlWriter()
Returns stream writer or nullptr.
QXmlStreamReader * xmlReader()
Returns stream reader or nullptr.
void read(const QString &tag, typename Catalog::CatalogedType *&p, Args... argsForConstructor)
void finish(const QString &tag)
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...