fix input

This commit is contained in:
MihailRis 2025-03-18 19:15:15 +03:00
parent bccdeec7b8
commit 611c6fa444
2 changed files with 13 additions and 4 deletions

View File

@ -239,6 +239,13 @@ const Binding& Bindings::require(const std::string& name) const {
throw std::runtime_error("binding '" + name + "' does not exist"); throw std::runtime_error("binding '" + name + "' does not exist");
} }
Binding& Bindings::require(const std::string& name) {
if (const auto found = get(name)) {
return *found;
}
throw std::runtime_error("binding '" + name + "' does not exist");
}
void Bindings::read(const dv::value& map, BindType bindType) { void Bindings::read(const dv::value& map, BindType bindType) {
for (auto& [sectionName, section] : map.asObject()) { for (auto& [sectionName, section] : map.asObject()) {
for (auto& [name, value] : section.asObject()) { for (auto& [name, value] : section.asObject()) {

View File

@ -204,7 +204,11 @@ public:
} }
Binding* get(const std::string& name) { Binding* get(const std::string& name) {
return const_cast<Bindings*>(this)->get(name); const auto found = bindings.find(name);
if (found == bindings.end()) {
return nullptr;
}
return &found->second;
} }
const Binding* get(const std::string& name) const { const Binding* get(const std::string& name) const {
@ -215,9 +219,7 @@ public:
return &found->second; return &found->second;
} }
Binding& require(const std::string& name) { Binding& require(const std::string& name);
return const_cast<Bindings*>(this)->require(name);
}
const Binding& require(const std::string& name) const; const Binding& require(const std::string& name) const;