1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 10:50:24 -04:00
nix/src/libutil/xml-writer.hh

67 lines
1 KiB
C++
Raw Normal View History

#pragma once
///@file
#include <iostream>
#include <string>
#include <list>
#include <map>
namespace nix {
2022-02-25 07:39:38 -05:00
typedef std::map<std::string, std::string> XMLAttrs;
class XMLWriter
{
private:
2014-02-26 12:55:18 -05:00
std::ostream & output;
bool indent;
bool closed;
2022-02-25 07:39:38 -05:00
std::list<std::string> pendingElems;
public:
XMLWriter(bool indent, std::ostream & output);
~XMLWriter();
void close();
2022-02-25 07:39:38 -05:00
void openElement(std::string_view name,
const XMLAttrs & attrs = XMLAttrs());
void closeElement();
2022-02-25 07:39:38 -05:00
void writeEmptyElement(std::string_view name,
const XMLAttrs & attrs = XMLAttrs());
private:
void writeAttrs(const XMLAttrs & attrs);
2018-05-02 07:56:34 -04:00
void indent_(size_t depth);
};
class XMLOpenElement
{
private:
XMLWriter & writer;
public:
2022-02-25 07:39:38 -05:00
XMLOpenElement(XMLWriter & writer, std::string_view name,
const XMLAttrs & attrs = XMLAttrs())
: writer(writer)
{
writer.openElement(name, attrs);
}
~XMLOpenElement()
{
writer.closeElement();
}
};
2014-02-26 12:55:18 -05:00
}