summary refs log tree commit diff stats
path: root/heading.h
blob: 1b1781b5b4a1630704fd23a02ced01422eb9b039 (plain) (blame)
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
#ifndef HEADING_H
#define HEADING_H

#include <map>
#include <string>
#include <string_view>
#include <variant>

struct ResourceRef {
  bool internal = false;
  int id;
};

class Heading {
 public:
  using keyval_t = std::variant<std::string, int, ResourceRef>;

  Heading() = default;

  explicit Heading(std::string_view line);

  const std::string& type() const { return type_; }

  void set_type(std::string_view type) { type_ = std::string(type); }

  const keyval_t& GetKeyval(std::string_view key) const {
    return keyvals_.at(std::string(key));
  }

  void SetKeyval(std::string_view key, const keyval_t& value) {
    keyvals_[std::string(key)] = value;
  }

  std::string ToString() const;

 private:
  std::string type_;
  std::map<std::string, keyval_t> keyvals_;
};

#endif /* HEADING_H */