diff options
Diffstat (limited to 'heading.h')
-rw-r--r-- | heading.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/heading.h b/heading.h new file mode 100644 index 0000000..1b1781b --- /dev/null +++ b/heading.h | |||
@@ -0,0 +1,41 @@ | |||
1 | #ifndef HEADING_H | ||
2 | #define HEADING_H | ||
3 | |||
4 | #include <map> | ||
5 | #include <string> | ||
6 | #include <string_view> | ||
7 | #include <variant> | ||
8 | |||
9 | struct ResourceRef { | ||
10 | bool internal = false; | ||
11 | int id; | ||
12 | }; | ||
13 | |||
14 | class Heading { | ||
15 | public: | ||
16 | using keyval_t = std::variant<std::string, int, ResourceRef>; | ||
17 | |||
18 | Heading() = default; | ||
19 | |||
20 | explicit Heading(std::string_view line); | ||
21 | |||
22 | const std::string& type() const { return type_; } | ||
23 | |||
24 | void set_type(std::string_view type) { type_ = std::string(type); } | ||
25 | |||
26 | const keyval_t& GetKeyval(std::string_view key) const { | ||
27 | return keyvals_.at(std::string(key)); | ||
28 | } | ||
29 | |||
30 | void SetKeyval(std::string_view key, const keyval_t& value) { | ||
31 | keyvals_[std::string(key)] = value; | ||
32 | } | ||
33 | |||
34 | std::string ToString() const; | ||
35 | |||
36 | private: | ||
37 | std::string type_; | ||
38 | std::map<std::string, keyval_t> keyvals_; | ||
39 | }; | ||
40 | |||
41 | #endif /* HEADING_H */ | ||