diff options
Diffstat (limited to 'src/libs/3rdparty/yaml-cpp/src/setting.h')
-rw-r--r-- | src/libs/3rdparty/yaml-cpp/src/setting.h | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/src/libs/3rdparty/yaml-cpp/src/setting.h b/src/libs/3rdparty/yaml-cpp/src/setting.h index b78d40e2e8..4960bbf75c 100644 --- a/src/libs/3rdparty/yaml-cpp/src/setting.h +++ b/src/libs/3rdparty/yaml-cpp/src/setting.h @@ -7,17 +7,24 @@ #pragma once #endif +#include "yaml-cpp/noexcept.h" #include <memory> +#include <utility> #include <vector> -#include "yaml-cpp/noncopyable.h" namespace YAML { -class SettingChangeBase; + +class SettingChangeBase { + public: + virtual ~SettingChangeBase() = default; + virtual void pop() = 0; +}; template <typename T> class Setting { public: Setting() : m_value() {} + Setting(const T& value) : m_value() { set(value); } const T get() const { return m_value; } std::unique_ptr<SettingChangeBase> set(const T& value); @@ -27,21 +34,19 @@ class Setting { T m_value; }; -class SettingChangeBase { - public: - virtual ~SettingChangeBase() {} - virtual void pop() = 0; -}; - template <typename T> class SettingChange : public SettingChangeBase { public: - SettingChange(Setting<T>* pSetting) : m_pCurSetting(pSetting) { - // copy old setting to save its state - m_oldSetting = *pSetting; - } + SettingChange(Setting<T>* pSetting) + : m_pCurSetting(pSetting), + m_oldSetting(*pSetting) // copy old setting to save its state + {} + SettingChange(const SettingChange&) = delete; + SettingChange(SettingChange&&) = delete; + SettingChange& operator=(const SettingChange&) = delete; + SettingChange& operator=(SettingChange&&) = delete; - virtual void pop() { m_pCurSetting->restore(m_oldSetting); } + void pop() override { m_pCurSetting->restore(m_oldSetting); } private: Setting<T>* m_pCurSetting; @@ -55,41 +60,41 @@ inline std::unique_ptr<SettingChangeBase> Setting<T>::set(const T& value) { return pChange; } -class SettingChanges : private noncopyable { +class SettingChanges { public: - SettingChanges() {} + SettingChanges() : m_settingChanges{} {} + SettingChanges(const SettingChanges&) = delete; + SettingChanges(SettingChanges&&) YAML_CPP_NOEXCEPT = default; + SettingChanges& operator=(const SettingChanges&) = delete; + SettingChanges& operator=(SettingChanges&& rhs) YAML_CPP_NOEXCEPT { + if (this == &rhs) + return *this; + + clear(); + std::swap(m_settingChanges, rhs.m_settingChanges); + + return *this; + } ~SettingChanges() { clear(); } - void clear() { + void clear() YAML_CPP_NOEXCEPT { restore(); m_settingChanges.clear(); } - void restore() { - for (setting_changes::const_iterator it = m_settingChanges.begin(); - it != m_settingChanges.end(); ++it) - (*it)->pop(); + void restore() YAML_CPP_NOEXCEPT { + for (const auto& setting : m_settingChanges) + setting->pop(); } void push(std::unique_ptr<SettingChangeBase> pSettingChange) { m_settingChanges.push_back(std::move(pSettingChange)); } - // like std::unique_ptr - assignment is transfer of ownership - SettingChanges& operator=(SettingChanges&& rhs) { - if (this == &rhs) - return *this; - - clear(); - std::swap(m_settingChanges, rhs.m_settingChanges); - - return *this; - } - private: - typedef std::vector<std::unique_ptr<SettingChangeBase>> setting_changes; + using setting_changes = std::vector<std::unique_ptr<SettingChangeBase>>; setting_changes m_settingChanges; }; -} +} // namespace YAML #endif // SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66 |