-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml.h
50 lines (36 loc) · 879 Bytes
/
xml.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#include <istream>
#include <sstream>
#include <vector>
#include <string>
#include <string_view>
#include <unordered_map>
using namespace std;
class Node {
public:
Node(string name, unordered_map<string, string> attrs);
const vector<Node>& Children() const;
void AddChild(Node node);
string_view Name() const;
template <typename T>
T AttributeValue(const string& name) const;
private:
string name;
vector<Node> children;
unordered_map<string, string> attrs;
};
class Document {
public:
explicit Document(Node root);
const Node& GetRoot() const;
private:
Node root;
};
Document Load(istream& input);
template <typename T>
inline T Node::AttributeValue(const string& name) const {
istringstream attr_input(attrs.at(name));
T result;
attr_input >> result;
return result;
}