//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/Model/Util/UtilXML.h
//! @brief     Defines
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_GUI_MODEL_UTIL_UTILXML_H
#define BORNAGAIN_GUI_MODEL_UTIL_UTILXML_H

#include <QXmlStreamReader> // used in every including file, also provides QXmlStreamWriter
#include <heinz/Complex.h>
#include <heinz/Vectors3D.h>

namespace XML {

constexpr const char* LinkMimeType{"application/org.bornagainproject.fittinglink"};

namespace Attrib {

const QString BA_Version("BA_Version");
const QString binary_version("binary_version");
const QString collapsed("collapsed");
const QString id("id");
const QString index("index");
const QString name("name");
const QString projectName("projectName");
const QString selection_version("selection_version");
const QString size("size");
const QString type("type");
const QString value("value");
const QString version("version");
const QString xPos("xPos");
const QString yPos("yPos");

} // namespace Attrib

void gotoEndElementOfTag(QXmlStreamReader* reader, const QString& tag);

void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, bool b);
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, double d);
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, QString s);
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, QColor c);
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeBaseName, const R3& vec);
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeBaseName, const complex_t& c);
template <typename T>
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, T d)
{
    writer->writeAttribute(attributeName, QString::number(d));
};


bool readBool(QXmlStreamReader* reader, const QString& attributeName);
int readInt(QXmlStreamReader* reader, const QString& attributeName);
unsigned readUInt(QXmlStreamReader* reader, const QString& attributeName);
size_t readSize(QXmlStreamReader* reader, const QString& attributeName);
double readDouble(QXmlStreamReader* reader, const QString& attributeName);
QString readString(QXmlStreamReader* reader, const QString& attributeName);
QColor readColor(QXmlStreamReader* reader, const QString& attributeName);

// TODO: will the following remain unused?
R3 readR3(QXmlStreamReader* reader, const QString& attributeBaseName);
complex_t readC(QXmlStreamReader* reader, const QString& attributeBaseName);

} // namespace XML

#endif // BORNAGAIN_GUI_MODEL_UTIL_UTILXML_H
