summaryrefslogtreecommitdiff
path: root/src/tag.hh
blob: ce7f149930596c6d863d63a7f42675cc1409a9e3 (plain)
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
#ifndef TAG_HH
#define TAG_HH

#include <memory>
#include <string>
#include <string_view>

class Renderable {
public:
  virtual ~Renderable() = default;

  virtual void render(std::string* out) const = 0;

protected:
  Renderable() = default;
};

class Tag : public virtual Renderable {
public:
  static std::unique_ptr<Tag> create(std::string name,
                                     std::string content = std::string());

  virtual std::string_view name() const = 0;
  virtual bool empty() const = 0;
  virtual bool has_attr(std::string const& name) const = 0;

  virtual Tag* attr(std::string name, std::string value) = 0;
  virtual Tag* add(std::string content) = 0;
  // Does not clear attributes.
  virtual Tag* clear_content() = 0;

  // These return the new child tag, not this.
  virtual Tag* add(std::unique_ptr<Tag> tag) = 0;
  virtual Tag* add_tag(std::string name, std::string content = std::string());

protected:
  Tag() = default;
  Tag(Tag const&) = delete;
  Tag& operator=(Tag const&) = delete;
};

#endif  // TAG_HH