Nix 2.26.3
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 <iostream>
5#include <string>
6#include <list>
7#include <map>
8
9
10namespace nix {
11
12
13typedef std::map<std::string, std::string> XMLAttrs;
14
15
16class XMLWriter
17{
18private:
19
20 std::ostream & output;
21
22 bool indent;
23 bool closed;
24
25 std::list<std::string> pendingElems;
26
27public:
28
29 XMLWriter(bool indent, std::ostream & output);
30 ~XMLWriter();
31
32 void close();
33
34 void openElement(std::string_view name,
35 const XMLAttrs & attrs = XMLAttrs());
36 void closeElement();
37
38 void writeEmptyElement(std::string_view name,
39 const XMLAttrs & attrs = XMLAttrs());
40
41private:
42 void writeAttrs(const XMLAttrs & attrs);
43
44 void indent_(size_t depth);
45};
46
47
48class XMLOpenElement
49{
50private:
51 XMLWriter & writer;
52public:
53 XMLOpenElement(XMLWriter & writer, std::string_view name,
54 const XMLAttrs & attrs = XMLAttrs())
55 : writer(writer)
56 {
57 writer.openElement(name, attrs);
58 }
59 ~XMLOpenElement()
60 {
61 writer.closeElement();
62 }
63};
64
65
66}
Definition xml-writer.hh:17
const std::string_view & name
Definition lexer.l:1709