diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-03-01 08:03:50 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-03-03 09:00:30 (GMT) |
commit | fde71bd59b1412ae475c06f2d4100ce088e86af6 (patch) | |
tree | 4f3d85c700942d666c5ac5d032c757bc45bb1593 /Swift/Controllers/Settings/SettingsProviderHierachy.cpp | |
parent | 5271144cb6c0ecf3dc237af25197fa72a8737c09 (diff) | |
download | swift-contrib-fde71bd59b1412ae475c06f2d4100ce088e86af6.zip swift-contrib-fde71bd59b1412ae475c06f2d4100ce088e86af6.tar.bz2 |
Unit tests for SettingsProviderHierachy
Also fixing up errors they found and an uninitialised read left-over from the original patch.
Diffstat (limited to 'Swift/Controllers/Settings/SettingsProviderHierachy.cpp')
-rw-r--r-- | Swift/Controllers/Settings/SettingsProviderHierachy.cpp | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/Swift/Controllers/Settings/SettingsProviderHierachy.cpp b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp index 3b7d13c..40a9025 100644 --- a/Swift/Controllers/Settings/SettingsProviderHierachy.cpp +++ b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp @@ -13,14 +13,27 @@ namespace Swift { SettingsProviderHierachy::~SettingsProviderHierachy() { } +bool SettingsProviderHierachy::hasSetting(const std::string& key) { + foreach (SettingsProvider* provider, providers_) { + if (provider->hasSetting(key)) { + return true; + } + } + return false; +} + std::string SettingsProviderHierachy::getSetting(const Setting<std::string>& setting) { + std::string value = setting.getDefaultValue(); foreach (SettingsProvider* provider, providers_) { std::string providerSetting = provider->getSetting(setting); - if (providerSetting != setting.getDefaultValue()) { - return providerSetting; + if (provider->hasSetting(setting.getKey())) { + value = providerSetting; + } + if (provider->getIsSettingFinal(setting.getKey())) { + return value; } } - return setting.getDefaultValue(); + return value; } void SettingsProviderHierachy::storeSetting(const Setting<std::string>& setting, const std::string& settingValue) { @@ -30,13 +43,17 @@ void SettingsProviderHierachy::storeSetting(const Setting<std::string>& setting, } bool SettingsProviderHierachy::getSetting(const Setting<bool>& setting) { + bool value = setting.getDefaultValue(); foreach (SettingsProvider* provider, providers_) { bool providerSetting = provider->getSetting(setting); - if (providerSetting != setting.getDefaultValue()) { - return providerSetting; + if (provider->hasSetting(setting.getKey())) { + value = providerSetting; + if (provider->getIsSettingFinal(setting.getKey())) { + return providerSetting; + } } } - return setting.getDefaultValue(); + return value; } void SettingsProviderHierachy::storeSetting(const Setting<bool>& setting, const bool& settingValue) { @@ -46,13 +63,17 @@ void SettingsProviderHierachy::storeSetting(const Setting<bool>& setting, const } int SettingsProviderHierachy::getSetting(const Setting<int>& setting) { + int value = setting.getDefaultValue(); foreach (SettingsProvider* provider, providers_) { int providerSetting = provider->getSetting(setting); - if (providerSetting != setting.getDefaultValue()) { - return providerSetting; + if (provider->hasSetting(setting.getKey())) { + value = providerSetting; + if (provider->getIsSettingFinal(setting.getKey())) { + return providerSetting; + } } } - return setting.getDefaultValue(); + return value; } void SettingsProviderHierachy::storeSetting(const Setting<int>& setting, const int& settingValue) { |