blob: 9b549daaf9d41c7fdd0621d669a5185d68ecd77c (
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
43
44
45
46
47
48
49
50
51
52
53
54
|
#pragma once
#include "cru/common/Base.hpp"
#include "cru/common/String.hpp"
#include <optional>
#include <unordered_map>
namespace cru::toml {
class TomlSection {
public:
CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(TomlSection)
CRU_DEFAULT_COPY(TomlSection)
CRU_DEFAULT_MOVE(TomlSection)
public:
std::optional<String> GetValue(const String& key) const;
void SetValue(const String& key, String value);
void DeleteValue(const String& key);
auto begin() { return values_.begin(); }
auto end() { return values_.end(); }
auto begin() const { return values_.begin(); }
auto end() const { return values_.end(); }
auto cbegin() const { return values_.cbegin(); }
auto cend() const { return values_.cend(); }
private:
std::unordered_map<String, String> values_;
};
class TomlDocument {
public:
CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(TomlDocument)
CRU_DEFAULT_COPY(TomlDocument)
CRU_DEFAULT_MOVE(TomlDocument)
public:
TomlSection* GetSection(const String& name);
const TomlSection* GetSection(const String& name) const;
void SetSection(const String& name, TomlSection section);
void DeleteSection(const String& name);
auto begin() { return sections_.begin(); }
auto end() { return sections_.end(); }
auto begin() const { return sections_.begin(); }
auto end() const { return sections_.end(); }
auto cbegin() const { return sections_.cbegin(); }
auto cend() const { return sections_.cend(); }
private:
std::unordered_map<String, TomlSection> sections_;
};
} // namespace cru::toml
|