1 #ifndef SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 #define SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66 4 #if defined(_MSC_VER) || \ 5 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 10 #include "yaml-cpp/noexcept.h" 17 class SettingChangeBase {
19 virtual ~SettingChangeBase() =
default;
20 virtual void pop() = 0;
26 Setting() : m_value() {}
27 Setting(
const T& value) : m_value() {
set(value); }
29 const T
get()
const {
return m_value; }
30 std::unique_ptr<SettingChangeBase>
set(
const T& value);
31 void restore(
const Setting<T>& oldSetting) { m_value = oldSetting.get(); }
38 class SettingChange :
public SettingChangeBase {
40 SettingChange(Setting<T>* pSetting)
41 : m_pCurSetting(pSetting),
42 m_oldSetting(*pSetting)
44 SettingChange(
const SettingChange&) =
delete;
45 SettingChange(SettingChange&&) =
delete;
46 SettingChange& operator=(
const SettingChange&) =
delete;
47 SettingChange& operator=(SettingChange&&) =
delete;
49 void pop()
override { m_pCurSetting->restore(m_oldSetting); }
52 Setting<T>* m_pCurSetting;
53 Setting<T> m_oldSetting;
57 inline std::unique_ptr<SettingChangeBase> Setting<T>::set(
const T& value) {
58 std::unique_ptr<SettingChangeBase> pChange(
new SettingChange<T>(
this));
63 class SettingChanges {
65 SettingChanges() : m_settingChanges{} {}
66 SettingChanges(
const SettingChanges&) =
delete;
67 SettingChanges(SettingChanges&&) YAML_CPP_NOEXCEPT = default;
68 SettingChanges& operator=(const SettingChanges&) = delete;
69 SettingChanges& operator=(SettingChanges&& rhs) YAML_CPP_NOEXCEPT {
74 std::swap(m_settingChanges, rhs.m_settingChanges);
78 ~SettingChanges() { clear(); }
80 void clear() YAML_CPP_NOEXCEPT {
82 m_settingChanges.clear();
85 void restore() YAML_CPP_NOEXCEPT {
86 for (
const auto& setting : m_settingChanges)
90 void push(std::unique_ptr<SettingChangeBase> pSettingChange) {
91 m_settingChanges.push_back(std::move(pSettingChange));
95 using setting_changes = std::vector<std::unique_ptr<SettingChangeBase>>;
96 setting_changes m_settingChanges;
100 #endif // SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66