diff --git a/src/actions.cpp b/src/actions.cpp index 539db316..109112b3 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -72,7 +73,9 @@ namespace {// enum class Find { Forward, Backward }; -std::map AvailableActions; +boost::array< + Actions::BaseAction *, static_cast(Actions::Type::_numberOfActions) +> AvailableActions; void populateActions(); @@ -285,9 +288,9 @@ bool isMPDMusicDirSet() BaseAction &get(Actions::Type at) { - if (AvailableActions.empty()) + if (AvailableActions[1] == nullptr) populateActions(); - BaseAction *action = AvailableActions[at]; + BaseAction *action = AvailableActions[static_cast(at)]; // action should be always present if action type in queried assert(action != nullptr); return *action; @@ -296,13 +299,13 @@ BaseAction &get(Actions::Type at) BaseAction *get(const std::string &name) { BaseAction *result = 0; - if (AvailableActions.empty()) + if (AvailableActions[1] == nullptr) populateActions(); for (auto it = AvailableActions.begin(); it != AvailableActions.end(); ++it) { - if (it->second->name() == name) + if (*it != nullptr && (*it)->name() == name) { - result = it->second; + result = *it; break; } } @@ -2407,7 +2410,7 @@ namespace {// void populateActions() { auto insert_action = [](Actions::BaseAction *a) { - AvailableActions[a->type()] = a; + AvailableActions[static_cast(a->type())] = a; }; insert_action(new Actions::Dummy()); insert_action(new Actions::MouseEvent()); diff --git a/src/actions.h b/src/actions.h index 474eefc1..26b324dd 100644 --- a/src/actions.h +++ b/src/actions.h @@ -29,7 +29,7 @@ namespace Actions {// enum class Type { - MacroUtility, + MacroUtility = 0, Dummy, MouseEvent, ScrollUp, ScrollDown, ScrollUpArtist, ScrollUpAlbum, ScrollDownArtist, ScrollDownAlbum, PageUp, PageDown, MoveHome, MoveEnd, ToggleInterface, JumpToParentDirectory, PressEnter, PressSpace, PreviousColumn, @@ -56,7 +56,8 @@ enum class Type ShowPlaylist, ShowBrowser, ChangeBrowseMode, ShowSearchEngine, ResetSearchEngine, ShowMediaLibrary, ToggleMediaLibraryColumnsMode, ShowPlaylistEditor, ShowTagEditor, ShowOutputs, ShowVisualizer, - ShowClock, ShowServerInfo + ShowClock, ShowServerInfo, + _numberOfActions // needed to dynamically calculate size of action array }; void validateScreenSize();