MCPcopy Create free account
hub / github.com/N64Recomp/N64Recomp / read_toml_value

Function read_toml_value

RecompModTool/main.cpp:167–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165
166template <typename T>
167static T read_toml_value(const toml::table& data, std::string_view key, bool required) {
168 const toml::node* value_node = data.get(key);
169
170 if (value_node == nullptr) {
171 if (required) {
172 throw toml::parse_error(("Missing required field \"" + std::string{key} + "\"").c_str(), data.source());
173 }
174 else {
175 return T{};
176 }
177 }
178
179 std::optional<T> opt = value_node->value_exact<T>();
180 if (opt.has_value()) {
181 return opt.value();
182 }
183 else {
184 throw toml::parse_error(("Incorrect type for field \"" + std::string{key} + "\"").c_str(), data.source());
185 }
186}
187
188static const toml::array& read_toml_array(const toml::table& data, std::string_view key, bool required) {
189 static const toml::array empty_array = toml::array{};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected