rename ExecItem to RunnableItem and make use of variadic templates
This commit is contained in:
@@ -73,7 +73,6 @@ noinst_HEADERS = \
|
|||||||
display.h \
|
display.h \
|
||||||
enums.h \
|
enums.h \
|
||||||
error.h \
|
error.h \
|
||||||
exec_item.h \
|
|
||||||
global.h \
|
global.h \
|
||||||
help.h \
|
help.h \
|
||||||
helpers.h \
|
helpers.h \
|
||||||
@@ -91,6 +90,7 @@ noinst_HEADERS = \
|
|||||||
playlist_editor.h \
|
playlist_editor.h \
|
||||||
proxy_song_list.h \
|
proxy_song_list.h \
|
||||||
regex_filter.h \
|
regex_filter.h \
|
||||||
|
runnable_item.h \
|
||||||
screen.h \
|
screen.h \
|
||||||
screen_switcher.h \
|
screen_switcher.h \
|
||||||
screen_type.h \
|
screen_type.h \
|
||||||
|
|||||||
@@ -23,23 +23,29 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
template <typename ItemT, typename FunType> struct ExecItem
|
template <typename ItemT, typename FunctionT>
|
||||||
|
struct RunnableItem
|
||||||
{
|
{
|
||||||
typedef ItemT Item;
|
typedef ItemT Item;
|
||||||
typedef std::function<FunType> Function;
|
typedef std::function<FunctionT> Function;
|
||||||
|
|
||||||
ExecItem() { }
|
RunnableItem() { }
|
||||||
ExecItem(const Item &item_, Function f) : m_item(item_), m_exec(f) { }
|
template <typename Arg1, typename Arg2>
|
||||||
|
RunnableItem(Arg1 &&opt, Arg2 &&f)
|
||||||
|
: m_item(std::forward<Arg1>(opt)), m_f(std::forward<Arg2>(f)) { }
|
||||||
|
|
||||||
Function &exec() { return m_exec; }
|
template <typename... Args>
|
||||||
const Function &exec() const { return m_exec; }
|
typename Function::result_type run(Args&&... args) const
|
||||||
|
{
|
||||||
|
return m_f(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
Item &item() { return m_item; }
|
Item &item() { return m_item; }
|
||||||
const Item &item() const { return m_item; }
|
const Item &item() const { return m_item; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Item m_item;
|
Item m_item;
|
||||||
Function m_exec;
|
Function m_f;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NCMPCPP_EXEC_ITEM_H
|
#endif // NCMPCPP_EXEC_ITEM_H
|
||||||
@@ -163,7 +163,7 @@ std::wstring SelectedItemsAdder::title()
|
|||||||
|
|
||||||
void SelectedItemsAdder::enterPressed()
|
void SelectedItemsAdder::enterPressed()
|
||||||
{
|
{
|
||||||
w->current().value().exec()();
|
w->current().value().run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectedItemsAdder::mouseButtonPressed(MEVENT me)
|
void SelectedItemsAdder::mouseButtonPressed(MEVENT me)
|
||||||
|
|||||||
@@ -21,12 +21,12 @@
|
|||||||
#ifndef NCMPCPP_SEL_ITEMS_ADDER_H
|
#ifndef NCMPCPP_SEL_ITEMS_ADDER_H
|
||||||
#define NCMPCPP_SEL_ITEMS_ADDER_H
|
#define NCMPCPP_SEL_ITEMS_ADDER_H
|
||||||
|
|
||||||
#include "exec_item.h"
|
#include "runnable_item.h"
|
||||||
#include "interfaces.h"
|
#include "interfaces.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
|
|
||||||
struct SelectedItemsAdder: Screen<NC::Menu<ExecItem<std::string, void()>> *>, Tabbable
|
struct SelectedItemsAdder: Screen<NC::Menu<RunnableItem<std::string, void()>> *>, Tabbable
|
||||||
{
|
{
|
||||||
typedef SelectedItemsAdder Self;
|
typedef SelectedItemsAdder Self;
|
||||||
typedef typename std::remove_pointer<WindowType>::type Component;
|
typedef typename std::remove_pointer<WindowType>::type Component;
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ std::wstring SortPlaylistDialog::title()
|
|||||||
|
|
||||||
void SortPlaylistDialog::enterPressed()
|
void SortPlaylistDialog::enterPressed()
|
||||||
{
|
{
|
||||||
w.current().value().exec()();
|
w.current().value().run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SortPlaylistDialog::mouseButtonPressed(MEVENT me)
|
void SortPlaylistDialog::mouseButtonPressed(MEVENT me)
|
||||||
|
|||||||
@@ -21,13 +21,13 @@
|
|||||||
#ifndef NCMPCPP_SORT_PLAYLIST_H
|
#ifndef NCMPCPP_SORT_PLAYLIST_H
|
||||||
#define NCMPCPP_SORT_PLAYLIST_H
|
#define NCMPCPP_SORT_PLAYLIST_H
|
||||||
|
|
||||||
#include "exec_item.h"
|
#include "runnable_item.h"
|
||||||
#include "interfaces.h"
|
#include "interfaces.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
|
|
||||||
struct SortPlaylistDialog
|
struct SortPlaylistDialog
|
||||||
: Screen<NC::Menu<ExecItem<std::pair<std::string, MPD::Song::GetFunction>, void()>>>, Tabbable
|
: Screen<NC::Menu<RunnableItem<std::pair<std::string, MPD::Song::GetFunction>, void()>>>, Tabbable
|
||||||
{
|
{
|
||||||
typedef SortPlaylistDialog Self;
|
typedef SortPlaylistDialog Self;
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#define NCMPCPP_UTILITY_COMPARATORS_H
|
#define NCMPCPP_UTILITY_COMPARATORS_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "exec_item.h"
|
#include "runnable_item.h"
|
||||||
#include "mpdpp.h"
|
#include "mpdpp.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
@@ -60,7 +60,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename ItemT, typename FunT>
|
template <typename ItemT, typename FunT>
|
||||||
bool operator()(const ExecItem<ItemT, FunT> &a, const ExecItem<ItemT, FunT> &b) const {
|
bool operator()(const RunnableItem<ItemT, FunT> &a, const RunnableItem<ItemT, FunT> &b) const {
|
||||||
return m_cmp(a.item(), b.item()) < 0;
|
return m_cmp(a.item(), b.item()) < 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user