actions: keep actions in array instead of map
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <cassert>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/locale/conversion.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
@@ -72,7 +73,9 @@ namespace {//
|
||||
|
||||
enum class Find { Forward, Backward };
|
||||
|
||||
std::map<Actions::Type, Actions::BaseAction *> AvailableActions;
|
||||
boost::array<
|
||||
Actions::BaseAction *, static_cast<size_t>(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<size_t>(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<size_t>(a->type())] = a;
|
||||
};
|
||||
insert_action(new Actions::Dummy());
|
||||
insert_action(new Actions::MouseEvent());
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user