rename ExecItem to RunnableItem and make use of variadic templates

master
Andrzej Rybczak 12 years ago
parent 5d6d390f77
commit 966f3ef927
  1. 2
      src/Makefile.am
  2. 20
      src/runnable_item.h
  3. 2
      src/sel_items_adder.cpp
  4. 4
      src/sel_items_adder.h
  5. 2
      src/sort_playlist.cpp
  6. 4
      src/sort_playlist.h
  7. 4
      src/utility/comparators.h

@ -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 \

@ -23,23 +23,29 @@
#include <functional>
template <typename ItemT, typename FunType> struct ExecItem
template <typename ItemT, typename FunctionT>
struct RunnableItem
{
typedef ItemT Item;
typedef std::function<FunType> Function;
typedef std::function<FunctionT> Function;
ExecItem() { }
ExecItem(const Item &item_, Function f) : m_item(item_), m_exec(f) { }
RunnableItem() { }
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; }
const Function &exec() const { return m_exec; }
template <typename... Args>
typename Function::result_type run(Args&&... args) const
{
return m_f(std::forward<Args>(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

@ -163,7 +163,7 @@ std::wstring SelectedItemsAdder::title()
void SelectedItemsAdder::enterPressed()
{
w->current().value().exec()();
w->current().value().run();
}
void SelectedItemsAdder::mouseButtonPressed(MEVENT me)

@ -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<NC::Menu<ExecItem<std::string, void()>> *>, Tabbable
struct SelectedItemsAdder: Screen<NC::Menu<RunnableItem<std::string, void()>> *>, Tabbable
{
typedef SelectedItemsAdder Self;
typedef typename std::remove_pointer<WindowType>::type Component;

@ -110,7 +110,7 @@ std::wstring SortPlaylistDialog::title()
void SortPlaylistDialog::enterPressed()
{
w.current().value().exec()();
w.current().value().run();
}
void SortPlaylistDialog::mouseButtonPressed(MEVENT me)

@ -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<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;

@ -22,7 +22,7 @@
#define NCMPCPP_UTILITY_COMPARATORS_H
#include <string>
#include "exec_item.h"
#include "runnable_item.h"
#include "mpdpp.h"
#include "settings.h"
#include "menu.h"
@ -60,7 +60,7 @@ public:
}
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;
}
};

Loading…
Cancel
Save