fix: tidy statics, instance, stretch43, fill/find_if ranges, NOLINT externs

This commit is contained in:
2026-05-16 15:17:38 +02:00
parent ae359f4a1e
commit b984e6041e
15 changed files with 77 additions and 74 deletions
+28 -28
View File
@@ -11,13 +11,13 @@
namespace KeyConfig {
namespace {
std::vector<KeyEntry> entries_;
std::unordered_map<std::string, size_t> index_;
std::string overrides_path_;
std::vector<KeyEntry> key_entries;
std::unordered_map<std::string, size_t> index_table;
std::string overrides_path;
auto findIndex(const std::string& id) -> size_t {
auto it = index_.find(id);
if (it == index_.end()) {
auto it = index_table.find(id);
if (it == index_table.end()) {
return SIZE_MAX;
}
return it->second;
@@ -52,10 +52,10 @@ namespace KeyConfig {
entry.scancode = sc;
entry.default_scancode = sc;
index_[entry.id] = entries_.size();
entries_.push_back(std::move(entry));
index_table[entry.id] = key_entries.size();
key_entries.push_back(std::move(entry));
}
std::cout << "KeyConfig: " << entries_.size() << " tecles carregades de "
std::cout << "KeyConfig: " << key_entries.size() << " tecles carregades de "
<< defaults_resource_path << '\n';
} catch (const fkyaml::exception& e) {
std::cerr << "KeyConfig: error parsejant YAML: " << e.what() << '\n';
@@ -93,8 +93,8 @@ namespace KeyConfig {
<< "' per '" << id << "'\n";
continue;
}
entries_[idx].scancode = sc;
entries_[idx].code = code;
key_entries[idx].scancode = sc;
key_entries[idx].code = code;
applied++;
}
if (applied > 0) {
@@ -109,20 +109,20 @@ namespace KeyConfig {
void init(const std::string& defaults_resource_path,
const std::string& user_overrides_disk_path) {
entries_.clear();
index_.clear();
overrides_path_ = user_overrides_disk_path;
key_entries.clear();
index_table.clear();
overrides_path = user_overrides_disk_path;
loadDefaults(defaults_resource_path);
if (!overrides_path_.empty()) {
applyOverrides(overrides_path_);
if (!overrides_path.empty()) {
applyOverrides(overrides_path);
}
}
void destroy() {
entries_.clear();
index_.clear();
overrides_path_.clear();
key_entries.clear();
index_table.clear();
overrides_path.clear();
}
auto scancode(const std::string& id) -> SDL_Scancode {
@@ -130,7 +130,7 @@ namespace KeyConfig {
if (idx == SIZE_MAX) {
return SDL_SCANCODE_UNKNOWN;
}
return entries_[idx].scancode;
return key_entries[idx].scancode;
}
auto scancodePtr(const std::string& id) -> SDL_Scancode* {
@@ -138,7 +138,7 @@ namespace KeyConfig {
if (idx == SIZE_MAX) {
return nullptr;
}
return &entries_[idx].scancode;
return &key_entries[idx].scancode;
}
void setScancode(const std::string& id, SDL_Scancode sc) {
@@ -146,38 +146,38 @@ namespace KeyConfig {
if (idx == SIZE_MAX) {
return;
}
entries_[idx].scancode = sc;
key_entries[idx].scancode = sc;
const char* name = SDL_GetScancodeName(sc);
entries_[idx].code = (name != nullptr) ? name : "";
key_entries[idx].code = (name != nullptr) ? name : "";
}
auto isGuiKey(SDL_Scancode sc) -> bool {
if (sc == SDL_SCANCODE_UNKNOWN) {
return false;
}
return std::ranges::any_of(entries_, [sc](const auto& e) { return e.scancode == sc; });
return std::ranges::any_of(key_entries, [sc](const auto& e) { return e.scancode == sc; });
}
auto entries() -> const std::vector<KeyEntry>& {
return entries_;
return key_entries;
}
auto saveOverrides() -> bool {
if (overrides_path_.empty()) {
if (overrides_path.empty()) {
return false;
}
// Recull només les entrades remapeades.
std::vector<const KeyEntry*> changed;
for (const auto& e : entries_) {
for (const auto& e : key_entries) {
if (e.scancode != e.default_scancode) {
changed.push_back(&e);
}
}
std::ofstream file(overrides_path_);
std::ofstream file(overrides_path);
if (!file.is_open()) {
std::cerr << "KeyConfig: no es pot escriure " << overrides_path_ << '\n';
std::cerr << "KeyConfig: no es pot escriure " << overrides_path << '\n';
return false;
}