Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
xml-writer.hh
Go to the documentation of this file.
1#pragma once
3
4#include <iosfwd>
5#include <string>
6#include <list>
7#include <map>
8
9namespace nix {
10
11typedef std::map<std::string, std::string, std::less<>> XMLAttrs;
12
13class XMLWriter
14{
15private:
16
17 std::ostream & output;
18
19 bool indent;
20 bool closed;
21
22 std::list<std::string> pendingElems;
23
24public:
25
26 XMLWriter(bool indent, std::ostream & output);
27 ~XMLWriter();
28
29 void close();
30
31 void openElement(std::string_view name, const XMLAttrs & attrs = XMLAttrs());
32 void closeElement();
33
34 void writeEmptyElement(std::string_view name, const XMLAttrs & attrs = XMLAttrs());
35
36private:
37 void writeAttrs(const XMLAttrs & attrs);
38
39 void indent_(size_t depth);
40};
41
42class XMLOpenElement
43{
44private:
45 XMLWriter & writer;
46public:
47 XMLOpenElement(XMLWriter & writer, std::string_view name, const XMLAttrs & attrs = XMLAttrs())
48 : writer(writer)
49 {
50 writer.openElement(name, attrs);
51 }
52
53 XMLOpenElement(XMLOpenElement &&) = delete;
54 XMLOpenElement(const XMLOpenElement &) = delete;
55 XMLOpenElement & operator=(XMLOpenElement &&) = delete;
56 XMLOpenElement & operator=(const XMLOpenElement &) = delete;
57
58 ~XMLOpenElement()
59 {
60 writer.closeElement();
61 }
62};
63
64} // namespace nix
Definition xml-writer.hh:14