From 966f3ef9277062bcfd95908099ff409e2a842c25 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sun, 31 Aug 2014 09:16:37 +0200 Subject: [PATCH] rename ExecItem to RunnableItem and make use of variadic templates --- src/Makefile.am | 2 +- src/{exec_item.h => runnable_item.h} | 20 +++++++++++++------- src/sel_items_adder.cpp | 2 +- src/sel_items_adder.h | 4 ++-- src/sort_playlist.cpp | 2 +- src/sort_playlist.h | 4 ++-- src/utility/comparators.h | 4 ++-- 7 files changed, 22 insertions(+), 16 deletions(-) rename src/{exec_item.h => runnable_item.h} (80%) diff --git a/src/Makefile.am b/src/Makefile.am index ee6e8cdd..f7f70c5c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -73,7 +73,6 @@ noinst_HEADERS = \ display.h \ enums.h \ error.h \ - exec_item.h \ global.h \ help.h \ helpers.h \ @@ -91,6 +90,7 @@ noinst_HEADERS = \ playlist_editor.h \ proxy_song_list.h \ regex_filter.h \ + runnable_item.h \ screen.h \ screen_switcher.h \ screen_type.h \ diff --git a/src/exec_item.h b/src/runnable_item.h similarity index 80% rename from src/exec_item.h rename to src/runnable_item.h index 0344bfb9..fc2dbe9c 100644 --- a/src/exec_item.h +++ b/src/runnable_item.h @@ -23,23 +23,29 @@ #include -template struct ExecItem +template +struct RunnableItem { typedef ItemT Item; - typedef std::function Function; + typedef std::function Function; - ExecItem() { } - ExecItem(const Item &item_, Function f) : m_item(item_), m_exec(f) { } + RunnableItem() { } + template + RunnableItem(Arg1 &&opt, Arg2 &&f) + : m_item(std::forward(opt)), m_f(std::forward(f)) { } - Function &exec() { return m_exec; } - const Function &exec() const { return m_exec; } + template + typename Function::result_type run(Args&&... args) const + { + return m_f(std::forward(args)...); + } Item &item() { return m_item; } const Item &item() const { return m_item; } private: Item m_item; - Function m_exec; + Function m_f; }; #endif // NCMPCPP_EXEC_ITEM_H diff --git a/src/sel_items_adder.cpp b/src/sel_items_adder.cpp index 982d6a2a..fb80616c 100644 --- a/src/sel_items_adder.cpp +++ b/src/sel_items_adder.cpp @@ -163,7 +163,7 @@ std::wstring SelectedItemsAdder::title() void SelectedItemsAdder::enterPressed() { - w->current().value().exec()(); + w->current().value().run(); } void SelectedItemsAdder::mouseButtonPressed(MEVENT me) diff --git a/src/sel_items_adder.h b/src/sel_items_adder.h index 09657387..9366d819 100644 --- a/src/sel_items_adder.h +++ b/src/sel_items_adder.h @@ -21,12 +21,12 @@ #ifndef NCMPCPP_SEL_ITEMS_ADDER_H #define NCMPCPP_SEL_ITEMS_ADDER_H -#include "exec_item.h" +#include "runnable_item.h" #include "interfaces.h" #include "screen.h" #include "song.h" -struct SelectedItemsAdder: Screen> *>, Tabbable +struct SelectedItemsAdder: Screen> *>, Tabbable { typedef SelectedItemsAdder Self; typedef typename std::remove_pointer::type Component; diff --git a/src/sort_playlist.cpp b/src/sort_playlist.cpp index a6c8d3e2..2b04e91c 100644 --- a/src/sort_playlist.cpp +++ b/src/sort_playlist.cpp @@ -110,7 +110,7 @@ std::wstring SortPlaylistDialog::title() void SortPlaylistDialog::enterPressed() { - w.current().value().exec()(); + w.current().value().run(); } void SortPlaylistDialog::mouseButtonPressed(MEVENT me) diff --git a/src/sort_playlist.h b/src/sort_playlist.h index 64998148..32277496 100644 --- a/src/sort_playlist.h +++ b/src/sort_playlist.h @@ -21,13 +21,13 @@ #ifndef NCMPCPP_SORT_PLAYLIST_H #define NCMPCPP_SORT_PLAYLIST_H -#include "exec_item.h" +#include "runnable_item.h" #include "interfaces.h" #include "screen.h" #include "song.h" struct SortPlaylistDialog -: Screen, void()>>>, Tabbable +: Screen, void()>>>, Tabbable { typedef SortPlaylistDialog Self; diff --git a/src/utility/comparators.h b/src/utility/comparators.h index a604ed2c..40d88e6f 100644 --- a/src/utility/comparators.h +++ b/src/utility/comparators.h @@ -22,7 +22,7 @@ #define NCMPCPP_UTILITY_COMPARATORS_H #include -#include "exec_item.h" +#include "runnable_item.h" #include "mpdpp.h" #include "settings.h" #include "menu.h" @@ -60,7 +60,7 @@ public: } template - bool operator()(const ExecItem &a, const ExecItem &b) const { + bool operator()(const RunnableItem &a, const RunnableItem &b) const { return m_cmp(a.item(), b.item()) < 0; } };