From a0c0083faf63d12ee09b0dbb623cc94c2bde7397 Mon Sep 17 00:00:00 2001 From: Henry Wilson Date: Sat, 30 Dec 2017 23:52:16 +0000 Subject: [PATCH 12/31] _hotkey_lists ~> std::vector --- src/hotkeys.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp index 870e2cbea..91002dd0f 100644 --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -24,7 +24,7 @@ char *_hotkeys_file; * List of all HotkeyLists. * This is a pointer to ensure initialisation order with the various static HotkeyList instances. */ -static SmallVector *_hotkey_lists = NULL; +static std::vector *_hotkey_lists = NULL; /** String representation of a keycode */ struct KeycodeNames { @@ -253,13 +253,13 @@ void Hotkey::AddKeycode(uint16 keycode) HotkeyList::HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler) : global_hotkey_handler(global_hotkey_handler), ini_group(ini_group), items(items) { - if (_hotkey_lists == NULL) _hotkey_lists = new SmallVector(); - *_hotkey_lists->Append() = this; + if (_hotkey_lists == NULL) _hotkey_lists = new std::vector(); + _hotkey_lists->push_back(this); } HotkeyList::~HotkeyList() { - _hotkey_lists->Erase(_hotkey_lists->Find(this)); + Exclude(*_hotkey_lists, this); } /** @@ -313,11 +313,11 @@ static void SaveLoadHotkeys(bool save) IniFile *ini = new IniFile(); ini->LoadFromDisk(_hotkeys_file, NO_DIRECTORY); - for (HotkeyList **list = _hotkey_lists->Begin(); list != _hotkey_lists->End(); ++list) { + for (auto &list : *_hotkey_lists) { if (save) { - (*list)->Save(ini); + list->Save(ini); } else { - (*list)->Load(ini); + list->Load(ini); } } @@ -340,11 +340,11 @@ void SaveHotkeysToConfig() void HandleGlobalHotkeys(WChar key, uint16 keycode) { - for (HotkeyList **list = _hotkey_lists->Begin(); list != _hotkey_lists->End(); ++list) { - if ((*list)->global_hotkey_handler == NULL) continue; + for (auto &list : *_hotkey_lists) { + if (list->global_hotkey_handler == NULL) continue; - int hotkey = (*list)->CheckMatch(keycode, true); - if (hotkey >= 0 && ((*list)->global_hotkey_handler(hotkey) == ES_HANDLED)) return; + int hotkey = list->CheckMatch(keycode, true); + if (hotkey >= 0 && (list->global_hotkey_handler(hotkey) == ES_HANDLED)) return; } } -- 2.14.1