diff --git a/src/window/input.cpp b/src/window/input.cpp index d84bc618..56c19cfd 100644 --- a/src/window/input.cpp +++ b/src/window/input.cpp @@ -239,6 +239,13 @@ const Binding& Bindings::require(const std::string& name) const { 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) { for (auto& [sectionName, section] : map.asObject()) { for (auto& [name, value] : section.asObject()) { diff --git a/src/window/input.hpp b/src/window/input.hpp index ba858770..0c1ea008 100644 --- a/src/window/input.hpp +++ b/src/window/input.hpp @@ -204,7 +204,11 @@ public: } Binding* get(const std::string& name) { - return const_cast(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 { @@ -215,9 +219,7 @@ public: return &found->second; } - Binding& require(const std::string& name) { - return const_cast(this)->require(name); - } + Binding& require(const std::string& name); const Binding& require(const std::string& name) const;