actions: use shared_ptr to store actions

This commit is contained in:
Andrzej Rybczak
2016-12-07 19:02:47 +01:00
parent 59197f23d0
commit 56cb940a12
8 changed files with 47 additions and 35 deletions

View File

@@ -33,7 +33,7 @@ std::wstring keyToWString(const NC::Key::Type key);
/// Represents either single action or chain of actions bound to a certain key
struct Binding
{
typedef std::vector<Actions::BaseAction *> ActionChain;
typedef std::vector<std::shared_ptr<Actions::BaseAction>> ActionChain;
template <typename ArgT>
Binding(ArgT &&actions_)
@@ -41,7 +41,7 @@ struct Binding
assert(!m_actions.empty());
}
Binding(Actions::Type at)
: Binding(ActionChain({&Actions::get(at)})) { }
: Binding(ActionChain({Actions::get_(at)})) { }
bool execute() const {
return std::all_of(m_actions.begin(), m_actions.end(),
@@ -53,9 +53,10 @@ struct Binding
return m_actions.size() == 1;
}
Actions::BaseAction *action() const {
Actions::BaseAction &action() const {
assert(isSingle());
return m_actions[0];
assert(m_actions[0] != nullptr);
return *m_actions[0];
}
const ActionChain &actions() const {