From: <man...@us...> - 2015-07-10 18:22:55
|
Revision: 5397 http://sourceforge.net/p/modplug/code/5397 Author: manxorist Date: 2015-07-10 18:22:49 +0000 (Fri, 10 Jul 2015) Log Message: ----------- [Ref] Settings: Add Setting<T>::IsDefault() and related helpers. Modified Paths: -------------- trunk/OpenMPT/mptrack/Settings.cpp trunk/OpenMPT/mptrack/Settings.h Modified: trunk/OpenMPT/mptrack/Settings.cpp =================================================================== --- trunk/OpenMPT/mptrack/Settings.cpp 2015-07-10 11:10:11 UTC (rev 5396) +++ trunk/OpenMPT/mptrack/Settings.cpp 2015-07-10 18:22:49 UTC (rev 5397) @@ -146,6 +146,18 @@ return entry->second; } +bool SettingsContainer::IsDefaultSetting(const SettingPath &path) const +{ + ASSERT(theApp.InGuiThread()); + ASSERT(!CMainFrame::GetMainFrame() || (CMainFrame::GetMainFrame() && !CMainFrame::GetMainFrame()->InNotifyHandler())); // This is a slow path, use CachedSetting for stuff that is accessed in notify handler. + SettingsMap::iterator entry = map.find(path); + if(entry == map.end()) + { + return true; + } + return entry->second.IsDefault(); +} + void SettingsContainer::WriteSetting(const SettingPath &path, const SettingValue &val, SettingFlushMode flushMode) { ASSERT(theApp.InGuiThread()); Modified: trunk/OpenMPT/mptrack/Settings.h =================================================================== --- trunk/OpenMPT/mptrack/Settings.h 2015-07-10 11:10:11 UTC (rev 5396) +++ trunk/OpenMPT/mptrack/Settings.h 2015-07-10 18:22:49 UTC (rev 5397) @@ -403,6 +403,10 @@ { return defaultValue; } + bool IsDefault() const + { + return value == defaultValue; + } #endif // MPT_SETTINGS_CACHE_STORE_DEFAULTS bool IsDirty() const { @@ -534,6 +538,7 @@ void BackendsRemoveSetting(const SettingPath &path); void NotifyListeners(const SettingPath &path); SettingValue ReadSetting(const SettingPath &path, const SettingValue &def) const; + bool IsDefaultSetting(const SettingPath &path) const; void WriteSetting(const SettingPath &path, const SettingValue &val, SettingFlushMode flushMode); void ForgetSetting(const SettingPath &path); void RemoveSetting(const SettingPath &path); @@ -553,6 +558,14 @@ { return FromSettingValue<T>(ReadSetting(SettingPath(section, key), ToSettingValue<T>(def))); } + bool IsDefault(const SettingPath &path) const + { + return IsDefaultSetting(path); + } + bool IsDefault(const AnyStringLocale §ion, const AnyStringLocale &key) const + { + return IsDefaultSetting(SettingPath(section, key)); + } template <typename T> void Write(const SettingPath &path, const T &val, SettingFlushMode flushMode = SettingWriteBack) { @@ -657,6 +670,10 @@ { return conf.Read<T>(path); } + bool IsDefault() const + { + conf.IsDefault(path); + } template<typename Trhs> Setting & operator += (const Trhs &rhs) { T tmp = *this; tmp += rhs; *this = tmp; return *this; } template<typename Trhs> Setting & operator -= (const Trhs &rhs) { T tmp = *this; tmp -= rhs; *this = tmp; return *this; } template<typename Trhs> Setting & operator *= (const Trhs &rhs) { T tmp = *this; tmp *= rhs; *this = tmp; return *this; } @@ -722,6 +739,10 @@ { return value; } + bool IsDefault() const + { + conf.IsDefault(path); + } CachedSetting & Update() { value = conf.Read<T>(path); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |