actions: keep actions in array instead of map
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <boost/array.hpp>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/locale/conversion.hpp>
|
#include <boost/locale/conversion.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
@@ -72,7 +73,9 @@ namespace {//
|
|||||||
|
|
||||||
enum class Find { Forward, Backward };
|
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();
|
void populateActions();
|
||||||
|
|
||||||
@@ -285,9 +288,9 @@ bool isMPDMusicDirSet()
|
|||||||
|
|
||||||
BaseAction &get(Actions::Type at)
|
BaseAction &get(Actions::Type at)
|
||||||
{
|
{
|
||||||
if (AvailableActions.empty())
|
if (AvailableActions[1] == nullptr)
|
||||||
populateActions();
|
populateActions();
|
||||||
BaseAction *action = AvailableActions[at];
|
BaseAction *action = AvailableActions[static_cast<size_t>(at)];
|
||||||
// action should be always present if action type in queried
|
// action should be always present if action type in queried
|
||||||
assert(action != nullptr);
|
assert(action != nullptr);
|
||||||
return *action;
|
return *action;
|
||||||
@@ -296,13 +299,13 @@ BaseAction &get(Actions::Type at)
|
|||||||
BaseAction *get(const std::string &name)
|
BaseAction *get(const std::string &name)
|
||||||
{
|
{
|
||||||
BaseAction *result = 0;
|
BaseAction *result = 0;
|
||||||
if (AvailableActions.empty())
|
if (AvailableActions[1] == nullptr)
|
||||||
populateActions();
|
populateActions();
|
||||||
for (auto it = AvailableActions.begin(); it != AvailableActions.end(); ++it)
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2407,7 +2410,7 @@ namespace {//
|
|||||||
void populateActions()
|
void populateActions()
|
||||||
{
|
{
|
||||||
auto insert_action = [](Actions::BaseAction *a) {
|
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::Dummy());
|
||||||
insert_action(new Actions::MouseEvent());
|
insert_action(new Actions::MouseEvent());
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace Actions {//
|
|||||||
|
|
||||||
enum class Type
|
enum class Type
|
||||||
{
|
{
|
||||||
MacroUtility,
|
MacroUtility = 0,
|
||||||
Dummy, MouseEvent, ScrollUp, ScrollDown, ScrollUpArtist, ScrollUpAlbum,
|
Dummy, MouseEvent, ScrollUp, ScrollDown, ScrollUpArtist, ScrollUpAlbum,
|
||||||
ScrollDownArtist, ScrollDownAlbum, PageUp, PageDown, MoveHome, MoveEnd,
|
ScrollDownArtist, ScrollDownAlbum, PageUp, PageDown, MoveHome, MoveEnd,
|
||||||
ToggleInterface, JumpToParentDirectory, PressEnter, PressSpace, PreviousColumn,
|
ToggleInterface, JumpToParentDirectory, PressEnter, PressSpace, PreviousColumn,
|
||||||
@@ -56,7 +56,8 @@ enum class Type
|
|||||||
ShowPlaylist, ShowBrowser, ChangeBrowseMode, ShowSearchEngine,
|
ShowPlaylist, ShowBrowser, ChangeBrowseMode, ShowSearchEngine,
|
||||||
ResetSearchEngine, ShowMediaLibrary, ToggleMediaLibraryColumnsMode,
|
ResetSearchEngine, ShowMediaLibrary, ToggleMediaLibraryColumnsMode,
|
||||||
ShowPlaylistEditor, ShowTagEditor, ShowOutputs, ShowVisualizer,
|
ShowPlaylistEditor, ShowTagEditor, ShowOutputs, ShowVisualizer,
|
||||||
ShowClock, ShowServerInfo
|
ShowClock, ShowServerInfo,
|
||||||
|
_numberOfActions // needed to dynamically calculate size of action array
|
||||||
};
|
};
|
||||||
|
|
||||||
void validateScreenSize();
|
void validateScreenSize();
|
||||||
|
|||||||
Reference in New Issue
Block a user