| 66 | } |
| 67 | |
| 68 | class TomlChecker { |
| 69 | const TomlBasicValue &m_v; |
| 70 | tsl::ordered_set<toml::key> m_visited; |
| 71 | tsl::ordered_set<toml::key> m_conditionVisited; |
| 72 | |
| 73 | public: |
| 74 | TomlChecker(const TomlBasicValue &v, const toml::key &ky) : m_v(toml::find(v, ky)) { |
| 75 | } |
| 76 | explicit TomlChecker(const TomlBasicValue &v) : m_v(v) { |
| 77 | } |
| 78 | TomlChecker(const TomlChecker &) = delete; |
| 79 | TomlChecker(TomlChecker &&) = delete; |
| 80 | |
| 81 | template <typename T> |
| 82 | void optional(const toml::key &ky, Condition<T> &destination) { |
| 83 | // TODO: this algorithm in O(n) over the amount of keys, kinda bad |
| 84 | const auto &table = m_v.as_table(); |
| 85 | for (const auto &itr : table) { |
| 86 | const auto &key = itr.first; |
| 87 | const auto &value = itr.second; |
| 88 | if (value.is_table()) { |
| 89 | if (value.contains(ky)) { |
| 90 | destination[key] = toml::find<T>(value, ky); |
| 91 | } |
| 92 | } else if (key == ky) { |
| 93 | destination[""] = toml::find<T>(m_v, ky); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // Handle visiting logic |
| 98 | for (const auto &itr : destination) { |
| 99 | if (!itr.first.empty()) { |
| 100 | m_conditionVisited.emplace(itr.first); |
| 101 | } |
| 102 | } |
| 103 | visit(ky); |
| 104 | } |
| 105 | |
| 106 | template <typename T> |
| 107 | void optional(const toml::key &ky, T &destination) { |
| 108 | // TODO: this currently doesn't allow you to get an optional map<string, X> |
| 109 | if (m_v.contains(ky)) { |
| 110 | destination = toml::find<T>(m_v, ky); |
| 111 | } |
| 112 | visit(ky); |
| 113 | } |
| 114 | |
| 115 | template <typename T> |
| 116 | void required(const toml::key &ky, T &destination) { |
| 117 | destination = toml::find<T>(m_v, ky); |
| 118 | visit(ky); |
| 119 | } |
| 120 | |
| 121 | bool contains(const toml::key &ky) { |
| 122 | visit(ky); |
| 123 | return m_v.contains(ky); |
| 124 | } |
| 125 |
nothing calls this directly
no outgoing calls
no test coverage detected