-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig_node_with_preset_.hpp
More file actions
81 lines (56 loc) · 2.22 KB
/
Copy pathconfig_node_with_preset_.hpp
File metadata and controls
81 lines (56 loc) · 2.22 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
#pragma once
#include "./config_node.hpp"
namespace sim {
class ConfigNodeWithPresetExpected;
// Config node that supports preset inheritance.
class ConfigNodeWithPreset {
public:
explicit ConfigNodeWithPreset(
ConfigNode a_node,
std::optional<ConfigNode> a_presets_node = std::nullopt,
std::optional<ConfigNode> a_preset = std::nullopt);
ConfigNodeWithPresetExpected operator[](std::string_view key) const;
[[nodiscard]] bool IsMap() const noexcept;
friend std::ostream& operator<<(std::ostream& out,
const ConfigNodeWithPreset& node);
// Returns the base config node.
const ConfigNode& get_node() const noexcept;
[[nodiscard]] const std::optional<std::string>& get_name() const;
// Converts m_node to type T. Probably this method will return message about
// error
template <typename T>
[[nodiscard]] utils::StrExpected<T> as() const noexcept {
return m_node.as<T>();
}
template <typename T>
T as_or_throw() const {
return as<T>().value_or_throw();
}
[[nodiscard]] const std::string& get_name_or_throw() const;
const std::optional<ConfigNode> get_presets_node() const noexcept;
std::runtime_error create_parsing_error(std::string_view error) const;
class Iterator {
public:
Iterator(YAML::const_iterator a_it);
Iterator& operator++();
Iterator operator++(int);
bool operator==(const Iterator& rhs) const;
bool operator!=(const Iterator& rhs) const;
ConfigNodeWithPreset operator*() const;
private:
// Invariant: m_stacktrace_node is not null
YAML::const_iterator m_iterator;
};
Iterator begin() const;
Iterator end() const;
private:
// m_node contains information about config node and probably preset name
// m_preset - preset node which that is used to supplement fields of m_node
// m_presets_node - node it which preset node should be searched (id it
// needs)
const ConfigNode m_node;
const std::optional<ConfigNode> m_presets_node;
mutable std::optional<ConfigNode> m_preset;
};
ConfigNodeWithPreset load_file_with_presets(std::filesystem::path path);
} // namespace sim