2012-07-18 18:59:03 +00:00
|
|
|
#pragma once
|
2023-04-01 03:18:41 +00:00
|
|
|
///@file
|
2006-08-03 14:49:57 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2006-08-03 14:49:57 +00:00
|
|
|
|
2022-02-25 12:39:38 +00:00
|
|
|
typedef std::map<std::string, std::string> XMLAttrs;
|
2006-08-03 14:49:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class XMLWriter
|
|
|
|
{
|
|
|
|
private:
|
2014-02-26 17:55:18 +00:00
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
std::ostream & output;
|
2006-08-03 14:49:57 +00:00
|
|
|
|
2006-08-16 10:32:30 +00:00
|
|
|
bool indent;
|
2006-08-03 14:49:57 +00:00
|
|
|
bool closed;
|
|
|
|
|
2022-02-25 12:39:38 +00:00
|
|
|
std::list<std::string> pendingElems;
|
2006-08-03 14:49:57 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
XMLWriter(bool indent, std::ostream & output);
|
2006-08-03 14:49:57 +00:00
|
|
|
~XMLWriter();
|
|
|
|
|
|
|
|
void close();
|
|
|
|
|
2022-02-25 12:39:38 +00:00
|
|
|
void openElement(std::string_view name,
|
2006-08-03 14:49:57 +00:00
|
|
|
const XMLAttrs & attrs = XMLAttrs());
|
|
|
|
void closeElement();
|
|
|
|
|
2022-02-25 12:39:38 +00:00
|
|
|
void writeEmptyElement(std::string_view name,
|
2006-08-03 14:49:57 +00:00
|
|
|
const XMLAttrs & attrs = XMLAttrs());
|
|
|
|
|
|
|
|
private:
|
|
|
|
void writeAttrs(const XMLAttrs & attrs);
|
2006-08-16 10:32:30 +00:00
|
|
|
|
2018-05-02 11:56:34 +00:00
|
|
|
void indent_(size_t depth);
|
2006-08-03 14:49:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class XMLOpenElement
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
XMLWriter & writer;
|
|
|
|
public:
|
2022-02-25 12:39:38 +00:00
|
|
|
XMLOpenElement(XMLWriter & writer, std::string_view name,
|
2006-08-03 14:49:57 +00:00
|
|
|
const XMLAttrs & attrs = XMLAttrs())
|
|
|
|
: writer(writer)
|
|
|
|
{
|
|
|
|
writer.openElement(name, attrs);
|
|
|
|
}
|
|
|
|
~XMLOpenElement()
|
|
|
|
{
|
|
|
|
writer.closeElement();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-26 17:55:18 +00:00
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
}
|