-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathElement.h
More file actions
93 lines (72 loc) · 1.61 KB
/
Element.h
File metadata and controls
93 lines (72 loc) · 1.61 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// Created by Alone on 2022-8-8.
//
#ifndef MYUTIL_ELEMENT_H
#define MYUTIL_ELEMENT_H
#include<vector>
#include<map>
#include<string>
#include<string_view>
namespace xml
{
using std::vector;
using std::map;
using std::string_view;
using std::string;
class Element
{
public:
using children_t = vector<Element>;
using attrs_t = map<string, string>;
using iterator = vector<Element>::iterator;
using const_iterator = vector<Element>::const_iterator;
string &Name()
{
return m_name;
}
string &Text()
{
return m_text;
}
iterator begin()
{
return m_children.begin();
}
[[nodiscard]] const_iterator begin() const
{
return m_children.begin();
}
iterator end()
{
return m_children.end();
}
[[nodiscard]] const_iterator end() const
{
return m_children.end();
}
void push_back(Element const &element)
{
m_children.push_back(element);
}
void push_back(Element &&element)
{
m_children.push_back(std::move(element));
}
string &operator[](string const &key)
{
return m_attrs[key];
}
string to_string()
{
return _to_string();
}
private:
string _to_string();
private:
string m_name;
string m_text;
children_t m_children;
attrs_t m_attrs;
};
}
#endif //MYUTIL_ELEMENT_H