Loading...
Searching...
No Matches
SettingsCommand.hpp
1#pragma once
2#include <score/command/Command.hpp>
3
4#include <boost/call_traits.hpp>
5namespace score
6{
14class SCORE_LIB_BASE_EXPORT SettingsCommandBase
15{
16public:
17 virtual ~SettingsCommandBase();
18 virtual void undo() const = 0;
19 virtual void redo() const = 0;
20};
21
22template <typename T>
30{
31public:
32 using model_t = typename T::model_type;
33 using parameter_t = T;
34 using parameter_pass_t =
35 typename boost::call_traits<typename T::param_type>::param_type;
36 SettingsCommand() = delete;
37 SettingsCommand(model_t& obj, parameter_pass_t newval)
38 : m_model{obj}
39 , m_new{newval}
40 {
41 m_old = (m_model.*T::get)();
42 }
43
44 virtual ~SettingsCommand() = default;
45
46 void undo() const final override { (m_model.*T::set)(m_old); }
47
48 void redo() const final override { (m_model.*T::set)(m_new); }
49
50 void update(model_t&, parameter_pass_t newval) { m_new = newval; }
51
52private:
53 model_t& m_model;
54 typename T::param_type m_old, m_new;
55};
56}
57
62#define SCORE_SETTINGS_COMMAND_DECL(name) \
63public: \
64 using score::SettingsCommand<parameter_t>::SettingsCommand; \
65 name() = delete; \
66 static const CommandKey& static_key() \
67 { \
68 static const CommandKey var{#name}; \
69 return var; \
70 } \
71 \
72private:
Base class for commands to be used with the Settings system.
Definition SettingsCommand.hpp:15
A Command class that modifies a parameter given its trait class.
Definition SettingsCommand.hpp:30
Base toolkit upon which the software is built.
Definition Application.cpp:90