1 #ifndef SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
11 #include "yaml-cpp/noncopyable.h"
15 class SettingChangeBase
;
21 Setting(): m_value() {}
23 const T
get() const { return m_value
; }
24 std::auto_ptr
<SettingChangeBase
> set(const T
& value
);
25 void restore(const Setting
<T
>& oldSetting
) {
26 m_value
= oldSetting
.get();
33 class SettingChangeBase
36 virtual ~SettingChangeBase() {}
37 virtual void pop() = 0;
41 class SettingChange
: public SettingChangeBase
44 SettingChange(Setting
<T
> *pSetting
): m_pCurSetting(pSetting
) {
45 // copy old setting to save its state
46 m_oldSetting
= *pSetting
;
50 m_pCurSetting
->restore(m_oldSetting
);
54 Setting
<T
> *m_pCurSetting
;
55 Setting
<T
> m_oldSetting
;
59 inline std::auto_ptr
<SettingChangeBase
> Setting
<T
>::set(const T
& value
) {
60 std::auto_ptr
<SettingChangeBase
> pChange(new SettingChange
<T
> (this));
65 class SettingChanges
: private noncopyable
69 ~SettingChanges() { clear(); }
74 for(setting_changes::const_iterator it
=m_settingChanges
.begin();it
!=m_settingChanges
.end();++it
)
76 m_settingChanges
.clear();
80 for(setting_changes::const_iterator it
=m_settingChanges
.begin();it
!=m_settingChanges
.end();++it
)
84 void push(std::auto_ptr
<SettingChangeBase
> pSettingChange
) {
85 m_settingChanges
.push_back(pSettingChange
.release());
88 // like std::auto_ptr - assignment is transfer of ownership
89 SettingChanges
& operator = (SettingChanges
& rhs
) {
94 m_settingChanges
= rhs
.m_settingChanges
;
95 rhs
.m_settingChanges
.clear();
100 typedef std::vector
<SettingChangeBase
*> setting_changes
;
101 setting_changes m_settingChanges
;
105 #endif // SETTING_H_62B23520_7C8E_11DE_8A39_0800200C9A66