summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Settings')
-rw-r--r--Swift/Controllers/Settings/DummySettingsProvider.h76
-rw-r--r--Swift/Controllers/Settings/SettingsProvider.h102
-rw-r--r--Swift/Controllers/Settings/SettingsProviderHierachy.cpp120
-rw-r--r--Swift/Controllers/Settings/SettingsProviderHierachy.h56
-rw-r--r--Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp118
-rw-r--r--Swift/Controllers/Settings/XMLSettingsProvider.cpp114
-rw-r--r--Swift/Controllers/Settings/XMLSettingsProvider.h68
7 files changed, 327 insertions, 327 deletions
diff --git a/Swift/Controllers/Settings/DummySettingsProvider.h b/Swift/Controllers/Settings/DummySettingsProvider.h
index 605153e..63c0767 100644
--- a/Swift/Controllers/Settings/DummySettingsProvider.h
+++ b/Swift/Controllers/Settings/DummySettingsProvider.h
@@ -13,44 +13,44 @@
namespace Swift {
class DummySettingsProvider : public SettingsProvider {
- public:
- virtual ~DummySettingsProvider() {}
- virtual std::string getSetting(const Setting<std::string>& setting) {
- return stringValues.find(setting.getKey()) != stringValues.end() ? stringValues[setting.getKey()] : setting.getDefaultValue();
- }
- virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) {
- stringValues[setting.getKey()] = value;
- onSettingChanged(setting.getKey());
- }
- virtual bool getSetting(const Setting<bool>& setting) {
- return boolValues.find(setting.getKey()) != boolValues.end() ? boolValues[setting.getKey()] : setting.getDefaultValue();
- }
- virtual void storeSetting(const Setting<bool>& setting, const bool& value) {
- boolValues[setting.getKey()] = value;
- onSettingChanged(setting.getKey());
- }
- virtual int getSetting(const Setting<int>& setting) {
- return intValues.find(setting.getKey()) != intValues.end() ? intValues[setting.getKey()] : setting.getDefaultValue();
- }
- virtual void storeSetting(const Setting<int>& setting, const int& value) {
- intValues[setting.getKey()] = value;
- onSettingChanged(setting.getKey());
- }
- virtual std::vector<std::string> getAvailableProfiles() {return std::vector<std::string>();}
- virtual void createProfile(const std::string& ) {}
- virtual void removeProfile(const std::string& ) {}
- virtual bool getIsSettingFinal(const std::string& settingPath) {return finals.count(settingPath);}
- void setFinal(const std::string& settingPath) {
- finals.insert(settingPath);
- }
- virtual bool hasSetting(const std::string& key) {
- return stringValues.find(key) != stringValues.end() || intValues.find(key) != intValues.end() || boolValues.find(key) != boolValues.end();
- }
- private:
- std::map<std::string, std::string> stringValues;
- std::map<std::string, int> intValues;
- std::map<std::string, bool> boolValues;
- std::set<std::string> finals;
+ public:
+ virtual ~DummySettingsProvider() {}
+ virtual std::string getSetting(const Setting<std::string>& setting) {
+ return stringValues.find(setting.getKey()) != stringValues.end() ? stringValues[setting.getKey()] : setting.getDefaultValue();
+ }
+ virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) {
+ stringValues[setting.getKey()] = value;
+ onSettingChanged(setting.getKey());
+ }
+ virtual bool getSetting(const Setting<bool>& setting) {
+ return boolValues.find(setting.getKey()) != boolValues.end() ? boolValues[setting.getKey()] : setting.getDefaultValue();
+ }
+ virtual void storeSetting(const Setting<bool>& setting, const bool& value) {
+ boolValues[setting.getKey()] = value;
+ onSettingChanged(setting.getKey());
+ }
+ virtual int getSetting(const Setting<int>& setting) {
+ return intValues.find(setting.getKey()) != intValues.end() ? intValues[setting.getKey()] : setting.getDefaultValue();
+ }
+ virtual void storeSetting(const Setting<int>& setting, const int& value) {
+ intValues[setting.getKey()] = value;
+ onSettingChanged(setting.getKey());
+ }
+ virtual std::vector<std::string> getAvailableProfiles() {return std::vector<std::string>();}
+ virtual void createProfile(const std::string& ) {}
+ virtual void removeProfile(const std::string& ) {}
+ virtual bool getIsSettingFinal(const std::string& settingPath) {return finals.count(settingPath);}
+ void setFinal(const std::string& settingPath) {
+ finals.insert(settingPath);
+ }
+ virtual bool hasSetting(const std::string& key) {
+ return stringValues.find(key) != stringValues.end() || intValues.find(key) != intValues.end() || boolValues.find(key) != boolValues.end();
+ }
+ private:
+ std::map<std::string, std::string> stringValues;
+ std::map<std::string, int> intValues;
+ std::map<std::string, bool> boolValues;
+ std::set<std::string> finals;
};
}
diff --git a/Swift/Controllers/Settings/SettingsProvider.h b/Swift/Controllers/Settings/SettingsProvider.h
index 29e26b5..a804235 100644
--- a/Swift/Controllers/Settings/SettingsProvider.h
+++ b/Swift/Controllers/Settings/SettingsProvider.h
@@ -15,57 +15,57 @@ namespace Swift {
class SettingsProvider {
- public:
- template <typename T>
- class Setting {
- public:
- Setting(const std::string& key, const T& defaultValue) : key(key), defaultValue(defaultValue) {
-
- }
-
- const std::string& getKey() const {
- return key;
- }
-
- const T& getDefaultValue() const {
- return defaultValue;
- }
-
- private:
- std::string key;
- T defaultValue;
- };
-
- public:
- virtual ~SettingsProvider() {}
- virtual std::string getSetting(const Setting<std::string>& setting) = 0;
- virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) = 0;
- virtual bool getSetting(const Setting<bool>& setting) = 0;
- virtual void storeSetting(const Setting<bool>& setting, const bool& value) = 0;
- virtual int getSetting(const Setting<int>& setting) = 0;
- virtual void storeSetting(const Setting<int>& setting, const int& value) = 0;
-
- virtual std::vector<std::string> getAvailableProfiles() = 0;
- virtual void createProfile(const std::string& profile) = 0;
- virtual void removeProfile(const std::string& profile) = 0;
- /** A final setting is one that this settings provider says may not be overriden by lower priority profiles.
- * e.g. An Administrator-set configuration to disallow saving user passwords could not be overridden by the user.
- */
- template<typename T>
- bool getIsSettingFinal(const Setting<T>& setting) {
- return getIsSettingFinal(setting.getKey());
- }
- virtual bool hasSetting(const std::string& key) = 0;
-
- friend class SettingsProviderHierachy;
- protected:
- virtual bool getIsSettingFinal(const std::string& settingPath) = 0;
-
- public:
- /**
- * Emitted when a setting is changed.
- */
- boost::signal<void (const std::string& /*Setting's Path*/)> onSettingChanged;
+ public:
+ template <typename T>
+ class Setting {
+ public:
+ Setting(const std::string& key, const T& defaultValue) : key(key), defaultValue(defaultValue) {
+
+ }
+
+ const std::string& getKey() const {
+ return key;
+ }
+
+ const T& getDefaultValue() const {
+ return defaultValue;
+ }
+
+ private:
+ std::string key;
+ T defaultValue;
+ };
+
+ public:
+ virtual ~SettingsProvider() {}
+ virtual std::string getSetting(const Setting<std::string>& setting) = 0;
+ virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) = 0;
+ virtual bool getSetting(const Setting<bool>& setting) = 0;
+ virtual void storeSetting(const Setting<bool>& setting, const bool& value) = 0;
+ virtual int getSetting(const Setting<int>& setting) = 0;
+ virtual void storeSetting(const Setting<int>& setting, const int& value) = 0;
+
+ virtual std::vector<std::string> getAvailableProfiles() = 0;
+ virtual void createProfile(const std::string& profile) = 0;
+ virtual void removeProfile(const std::string& profile) = 0;
+ /** A final setting is one that this settings provider says may not be overriden by lower priority profiles.
+ * e.g. An Administrator-set configuration to disallow saving user passwords could not be overridden by the user.
+ */
+ template<typename T>
+ bool getIsSettingFinal(const Setting<T>& setting) {
+ return getIsSettingFinal(setting.getKey());
+ }
+ virtual bool hasSetting(const std::string& key) = 0;
+
+ friend class SettingsProviderHierachy;
+ protected:
+ virtual bool getIsSettingFinal(const std::string& settingPath) = 0;
+
+ public:
+ /**
+ * Emitted when a setting is changed.
+ */
+ boost::signal<void (const std::string& /*Setting's Path*/)> onSettingChanged;
};
}
diff --git a/Swift/Controllers/Settings/SettingsProviderHierachy.cpp b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
index a349417..5156d14 100644
--- a/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
+++ b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
@@ -14,102 +14,102 @@ SettingsProviderHierachy::~SettingsProviderHierachy() {
}
bool SettingsProviderHierachy::hasSetting(const std::string& key) {
- foreach (SettingsProvider* provider, providers_) {
- if (provider->hasSetting(key)) {
- return true;
- }
- }
- return false;
+ 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 (provider->hasSetting(setting.getKey())) {
- value = providerSetting;
- }
- if (provider->getIsSettingFinal(setting.getKey())) {
- return value;
- }
- }
- return value;
+ std::string value = setting.getDefaultValue();
+ foreach (SettingsProvider* provider, providers_) {
+ std::string providerSetting = provider->getSetting(setting);
+ if (provider->hasSetting(setting.getKey())) {
+ value = providerSetting;
+ }
+ if (provider->getIsSettingFinal(setting.getKey())) {
+ return value;
+ }
+ }
+ return value;
}
void SettingsProviderHierachy::storeSetting(const Setting<std::string>& setting, const std::string& settingValue) {
- if (!getIsSettingFinal(setting.getKey())) {
- getWritableProvider()->storeSetting(setting, settingValue);
- }
+ if (!getIsSettingFinal(setting.getKey())) {
+ getWritableProvider()->storeSetting(setting, settingValue);
+ }
}
bool SettingsProviderHierachy::getSetting(const Setting<bool>& setting) {
- bool value = setting.getDefaultValue();
- foreach (SettingsProvider* provider, providers_) {
- bool providerSetting = provider->getSetting(setting);
- if (provider->hasSetting(setting.getKey())) {
- value = providerSetting;
- if (provider->getIsSettingFinal(setting.getKey())) {
- return providerSetting;
- }
- }
- }
- return value;
+ bool value = setting.getDefaultValue();
+ foreach (SettingsProvider* provider, providers_) {
+ bool providerSetting = provider->getSetting(setting);
+ if (provider->hasSetting(setting.getKey())) {
+ value = providerSetting;
+ if (provider->getIsSettingFinal(setting.getKey())) {
+ return providerSetting;
+ }
+ }
+ }
+ return value;
}
void SettingsProviderHierachy::storeSetting(const Setting<bool>& setting, const bool& settingValue) {
- if (!getIsSettingFinal(setting.getKey())) {
- getWritableProvider()->storeSetting(setting, settingValue);
- }
+ if (!getIsSettingFinal(setting.getKey())) {
+ getWritableProvider()->storeSetting(setting, settingValue);
+ }
}
int SettingsProviderHierachy::getSetting(const Setting<int>& setting) {
- int value = setting.getDefaultValue();
- foreach (SettingsProvider* provider, providers_) {
- int providerSetting = provider->getSetting(setting);
- if (provider->hasSetting(setting.getKey())) {
- value = providerSetting;
- if (provider->getIsSettingFinal(setting.getKey())) {
- return providerSetting;
- }
- }
- }
- return value;
+ int value = setting.getDefaultValue();
+ foreach (SettingsProvider* provider, providers_) {
+ int providerSetting = provider->getSetting(setting);
+ if (provider->hasSetting(setting.getKey())) {
+ value = providerSetting;
+ if (provider->getIsSettingFinal(setting.getKey())) {
+ return providerSetting;
+ }
+ }
+ }
+ return value;
}
void SettingsProviderHierachy::storeSetting(const Setting<int>& setting, const int& settingValue) {
- if (!getIsSettingFinal(setting.getKey())) {
- getWritableProvider()->storeSetting(setting, settingValue);
- }
+ if (!getIsSettingFinal(setting.getKey())) {
+ getWritableProvider()->storeSetting(setting, settingValue);
+ }
}
std::vector<std::string> SettingsProviderHierachy::getAvailableProfiles() {
- /* Always pull profiles from the topmost */
- return getWritableProvider()->getAvailableProfiles();
+ /* Always pull profiles from the topmost */
+ return getWritableProvider()->getAvailableProfiles();
}
void SettingsProviderHierachy::createProfile(const std::string& profile) {
- return getWritableProvider()->createProfile(profile);
+ return getWritableProvider()->createProfile(profile);
}
void SettingsProviderHierachy::removeProfile(const std::string& profile) {
- return getWritableProvider()->removeProfile(profile);
+ return getWritableProvider()->removeProfile(profile);
}
bool SettingsProviderHierachy::getIsSettingFinal(const std::string& settingPath) {
- bool isFinal = false;
- foreach (SettingsProvider* provider, providers_) {
- isFinal |= provider->getIsSettingFinal(settingPath);
- }
- return isFinal;
+ bool isFinal = false;
+ foreach (SettingsProvider* provider, providers_) {
+ isFinal |= provider->getIsSettingFinal(settingPath);
+ }
+ return isFinal;
}
SettingsProvider* SettingsProviderHierachy::getWritableProvider() {
- return providers_.back();
+ return providers_.back();
}
void SettingsProviderHierachy::addProviderToTopOfStack(SettingsProvider* provider) {
- providers_.push_back(provider);
- provider->onSettingChanged.connect(onSettingChanged);
+ providers_.push_back(provider);
+ provider->onSettingChanged.connect(onSettingChanged);
}
}
diff --git a/Swift/Controllers/Settings/SettingsProviderHierachy.h b/Swift/Controllers/Settings/SettingsProviderHierachy.h
index 9efbdcb..a68ff36 100644
--- a/Swift/Controllers/Settings/SettingsProviderHierachy.h
+++ b/Swift/Controllers/Settings/SettingsProviderHierachy.h
@@ -11,34 +11,34 @@
namespace Swift {
class SettingsProviderHierachy : public SettingsProvider {
- public:
- virtual ~SettingsProviderHierachy();
- virtual std::string getSetting(const Setting<std::string>& setting);
- virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
- virtual bool getSetting(const Setting<bool>& setting);
- virtual void storeSetting(const Setting<bool>& setting, const bool& value);
- virtual int getSetting(const Setting<int>& setting);
- virtual void storeSetting(const Setting<int>& setting, const int& value);
- virtual std::vector<std::string> getAvailableProfiles();
- virtual void createProfile(const std::string& profile);
- virtual void removeProfile(const std::string& profile);
- virtual bool hasSetting(const std::string& key);
- protected:
- virtual bool getIsSettingFinal(const std::string& settingPath);
-
- public:
- /**
- * Adds a provider less significant than any already added.
- * This means that if an existing provider has a setting, this provider won't be asked.
- * Any settings will be pushed into the topmost (least significant) provider.
- * Does not take ownership of provider.
- */
- void addProviderToTopOfStack(SettingsProvider* provider);
- private:
- SettingsProvider* getWritableProvider();
- private:
- /* Start/Left is most significant (lowest), left overrides right.*/
- std::vector<SettingsProvider*> providers_;
+ public:
+ virtual ~SettingsProviderHierachy();
+ virtual std::string getSetting(const Setting<std::string>& setting);
+ virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
+ virtual bool getSetting(const Setting<bool>& setting);
+ virtual void storeSetting(const Setting<bool>& setting, const bool& value);
+ virtual int getSetting(const Setting<int>& setting);
+ virtual void storeSetting(const Setting<int>& setting, const int& value);
+ virtual std::vector<std::string> getAvailableProfiles();
+ virtual void createProfile(const std::string& profile);
+ virtual void removeProfile(const std::string& profile);
+ virtual bool hasSetting(const std::string& key);
+ protected:
+ virtual bool getIsSettingFinal(const std::string& settingPath);
+
+ public:
+ /**
+ * Adds a provider less significant than any already added.
+ * This means that if an existing provider has a setting, this provider won't be asked.
+ * Any settings will be pushed into the topmost (least significant) provider.
+ * Does not take ownership of provider.
+ */
+ void addProviderToTopOfStack(SettingsProvider* provider);
+ private:
+ SettingsProvider* getWritableProvider();
+ private:
+ /* Start/Left is most significant (lowest), left overrides right.*/
+ std::vector<SettingsProvider*> providers_;
};
}
diff --git a/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp b/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp
index 11d5c11..5822add 100644
--- a/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp
+++ b/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp
@@ -15,77 +15,77 @@ using namespace Swift;
using namespace std;
class SettingsProviderHierachyTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(SettingsProviderHierachyTest);
- CPPUNIT_TEST(testEmpty);
- CPPUNIT_TEST(testTop);
- CPPUNIT_TEST(testBottom);
- CPPUNIT_TEST(testBoth);
- CPPUNIT_TEST(testTopDefault);
- CPPUNIT_TEST(testBottomOverrides);
- CPPUNIT_TEST(testFinal);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(SettingsProviderHierachyTest);
+ CPPUNIT_TEST(testEmpty);
+ CPPUNIT_TEST(testTop);
+ CPPUNIT_TEST(testBottom);
+ CPPUNIT_TEST(testBoth);
+ CPPUNIT_TEST(testTopDefault);
+ CPPUNIT_TEST(testBottomOverrides);
+ CPPUNIT_TEST(testFinal);
+ CPPUNIT_TEST_SUITE_END();
public:
- SettingsProviderHierachyTest() : setting1("somekey", 42) {}
+ SettingsProviderHierachyTest() : setting1("somekey", 42) {}
- void setUp() {
- bottom = new DummySettingsProvider();
- top = new DummySettingsProvider();
- testling = new SettingsProviderHierachy();
- testling->addProviderToTopOfStack(bottom);
- testling->addProviderToTopOfStack(top);
- }
+ void setUp() {
+ bottom = new DummySettingsProvider();
+ top = new DummySettingsProvider();
+ testling = new SettingsProviderHierachy();
+ testling->addProviderToTopOfStack(bottom);
+ testling->addProviderToTopOfStack(top);
+ }
- void tearDown() {
- delete testling;
- delete top;
- delete bottom;
- }
+ void tearDown() {
+ delete testling;
+ delete top;
+ delete bottom;
+ }
- void testEmpty() {
- CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1));
- }
+ void testEmpty() {
+ CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1));
+ }
- void testTop() {
- top->storeSetting(setting1, 37);
- CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1));
- }
+ void testTop() {
+ top->storeSetting(setting1, 37);
+ CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1));
+ }
- void testBottom() {
- bottom->storeSetting(setting1, 17);
- CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
- }
+ void testBottom() {
+ bottom->storeSetting(setting1, 17);
+ CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
+ }
- void testBoth() {
- bottom->storeSetting(setting1, 17);
- top->storeSetting(setting1, 37);
- CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1));
- }
+ void testBoth() {
+ bottom->storeSetting(setting1, 17);
+ top->storeSetting(setting1, 37);
+ CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1));
+ }
- void testTopDefault() {
- bottom->storeSetting(setting1, 17);
- top->storeSetting(setting1, 42);
- CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1));
- }
+ void testTopDefault() {
+ bottom->storeSetting(setting1, 17);
+ top->storeSetting(setting1, 42);
+ CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1));
+ }
- void testBottomOverrides() {
- bottom->storeSetting(setting1, 17);
- bottom->setFinal(setting1.getKey());
- top->storeSetting(setting1, 5);
- CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
- }
+ void testBottomOverrides() {
+ bottom->storeSetting(setting1, 17);
+ bottom->setFinal(setting1.getKey());
+ top->storeSetting(setting1, 5);
+ CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
+ }
- void testFinal() {
- bottom->storeSetting(setting1, 17);
- bottom->setFinal(setting1.getKey());
- testling->storeSetting(setting1, 5);
- CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
- }
+ void testFinal() {
+ bottom->storeSetting(setting1, 17);
+ bottom->setFinal(setting1.getKey());
+ testling->storeSetting(setting1, 5);
+ CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
+ }
private:
- SettingsProviderHierachy* testling;
- DummySettingsProvider* bottom;
- DummySettingsProvider* top;
- SettingsProvider::Setting<int> setting1;
+ SettingsProviderHierachy* testling;
+ DummySettingsProvider* bottom;
+ DummySettingsProvider* top;
+ SettingsProvider::Setting<int> setting1;
};
CPPUNIT_TEST_SUITE_REGISTRATION(SettingsProviderHierachyTest);
diff --git a/Swift/Controllers/Settings/XMLSettingsProvider.cpp b/Swift/Controllers/Settings/XMLSettingsProvider.cpp
index 548f36f..4dfb8bd 100644
--- a/Swift/Controllers/Settings/XMLSettingsProvider.cpp
+++ b/Swift/Controllers/Settings/XMLSettingsProvider.cpp
@@ -16,20 +16,20 @@
namespace Swift {
XMLSettingsProvider::XMLSettingsProvider(const std::string& xmlConfig) : level_(0) {
- if (!xmlConfig.empty()) {
- PlatformXMLParserFactory factory;
- XMLParser* parser = factory.createXMLParser(this);
- if (parser->parse(xmlConfig)) {
- SWIFT_LOG(debug) << "Found and parsed system config" << std::endl;
- }
- else {
- SWIFT_LOG(debug) << "Found invalid system config" << std::endl;
- }
- delete parser;
- }
- else {
- SWIFT_LOG(debug) << "No system config found" << std::endl;
- }
+ if (!xmlConfig.empty()) {
+ PlatformXMLParserFactory factory;
+ XMLParser* parser = factory.createXMLParser(this);
+ if (parser->parse(xmlConfig)) {
+ SWIFT_LOG(debug) << "Found and parsed system config" << std::endl;
+ }
+ else {
+ SWIFT_LOG(debug) << "Found invalid system config" << std::endl;
+ }
+ delete parser;
+ }
+ else {
+ SWIFT_LOG(debug) << "No system config found" << std::endl;
+ }
}
XMLSettingsProvider::~XMLSettingsProvider() {
@@ -37,89 +37,89 @@ XMLSettingsProvider::~XMLSettingsProvider() {
}
bool XMLSettingsProvider::hasSetting(const std::string& key) {
- return (values_.find(key) != values_.end());
+ return (values_.find(key) != values_.end());
}
std::string XMLSettingsProvider::getSetting(const Setting<std::string>& setting) {
- if (values_.find(setting.getKey()) != values_.end()) {
- std::string value = values_[setting.getKey()];
- return value;
- }
- return setting.getDefaultValue();
+ if (values_.find(setting.getKey()) != values_.end()) {
+ std::string value = values_[setting.getKey()];
+ return value;
+ }
+ return setting.getDefaultValue();
}
void XMLSettingsProvider::storeSetting(const Setting<std::string>& /*settingPath*/, const std::string& /*settingValue*/) {
- assert(false);
+ assert(false);
}
bool XMLSettingsProvider::getSetting(const Setting<bool>& setting) {
- if (values_.find(setting.getKey()) != values_.end()) {
- std::string value = values_[setting.getKey()];
- return boost::iequals(value, "true") || value == "1";
- }
- return setting.getDefaultValue();
+ if (values_.find(setting.getKey()) != values_.end()) {
+ std::string value = values_[setting.getKey()];
+ return boost::iequals(value, "true") || value == "1";
+ }
+ return setting.getDefaultValue();
}
void XMLSettingsProvider::storeSetting(const Setting<bool>& /*settingPath*/, const bool& /*settingValue*/) {
- assert(false);
+ assert(false);
}
int XMLSettingsProvider::getSetting(const Setting<int>& setting) {
- if (values_.find(setting.getKey()) != values_.end()) {
- std::string value = values_[setting.getKey()];
- try {
- return value.empty() ? setting.getDefaultValue() : boost::lexical_cast<int>(value);;
- }
- catch(boost::bad_lexical_cast &) {}
- }
- return setting.getDefaultValue();
+ if (values_.find(setting.getKey()) != values_.end()) {
+ std::string value = values_[setting.getKey()];
+ try {
+ return value.empty() ? setting.getDefaultValue() : boost::lexical_cast<int>(value);;
+ }
+ catch(boost::bad_lexical_cast &) {}
+ }
+ return setting.getDefaultValue();
}
void XMLSettingsProvider::storeSetting(const Setting<int>& /*settingPath*/, const int& /*settingValue*/) {
- assert(false);
+ assert(false);
}
std::vector<std::string> XMLSettingsProvider::getAvailableProfiles() {
- assert(false);
- return std::vector<std::string>();
+ assert(false);
+ return std::vector<std::string>();
}
void XMLSettingsProvider::createProfile(const std::string& /*profile*/) {
- assert(false);
+ assert(false);
}
void XMLSettingsProvider::removeProfile(const std::string& /*profile*/) {
- assert(false);
+ assert(false);
}
bool XMLSettingsProvider::getIsSettingFinal(const std::string& settingPath) {
- return finals_.count(settingPath);
+ return finals_.count(settingPath);
}
void XMLSettingsProvider::handleStartElement(const std::string& element, const std::string& /*ns*/, const AttributeMap& attributes) {
- level_++;
- if (level_ == SettingLevel) {
- if (attributes.getBoolAttribute("final", false)) {
- finals_.insert(element);
- }
- currentElement_ = element;
- currentText_ = "";
- }
+ level_++;
+ if (level_ == SettingLevel) {
+ if (attributes.getBoolAttribute("final", false)) {
+ finals_.insert(element);
+ }
+ currentElement_ = element;
+ currentText_ = "";
+ }
}
void XMLSettingsProvider::handleEndElement(const std::string& /*element*/, const std::string& /*ns*/) {
- if (level_ == SettingLevel) {
- values_[currentElement_] = currentText_;
- SWIFT_LOG(debug) << "Setting value of " << currentElement_ << " to " << currentText_ << std::endl;
- }
- level_--;
+ if (level_ == SettingLevel) {
+ values_[currentElement_] = currentText_;
+ SWIFT_LOG(debug) << "Setting value of " << currentElement_ << " to " << currentText_ << std::endl;
+ }
+ level_--;
}
void XMLSettingsProvider::handleCharacterData(const std::string& data) {
- if (level_ >= SettingLevel) {
- currentText_ += data;
- }
+ if (level_ >= SettingLevel) {
+ currentText_ += data;
+ }
}
diff --git a/Swift/Controllers/Settings/XMLSettingsProvider.h b/Swift/Controllers/Settings/XMLSettingsProvider.h
index 2dbb23c..5fd82cf 100644
--- a/Swift/Controllers/Settings/XMLSettingsProvider.h
+++ b/Swift/Controllers/Settings/XMLSettingsProvider.h
@@ -16,40 +16,40 @@
namespace Swift {
class XMLSettingsProvider : public SettingsProvider, public XMLParserClient {
- public:
- XMLSettingsProvider(const std::string& xmlConfig);
- virtual ~XMLSettingsProvider();
- virtual std::string getSetting(const Setting<std::string>& setting);
- virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
- virtual bool getSetting(const Setting<bool>& setting);
- virtual void storeSetting(const Setting<bool>& setting, const bool& value);
- virtual int getSetting(const Setting<int>& setting);
- virtual void storeSetting(const Setting<int>& setting, const int& value);
- virtual std::vector<std::string> getAvailableProfiles();
- virtual void createProfile(const std::string& profile);
- virtual void removeProfile(const std::string& profile);
- virtual bool hasSetting(const std::string& key);
-
-
- virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes);
- virtual void handleEndElement(const std::string& element, const std::string& ns);
- virtual void handleCharacterData(const std::string& data);
-
- protected:
- virtual bool getIsSettingFinal(const std::string& settingPath);
- private:
- std::map<std::string /*settingPath*/, std::string /*settingValue*/> values_;
- /* Settings that are final*/
- std::set<std::string /*settingPath*/> finals_;
-
- enum Level {
- TopLevel = 0,
- SettingLevel = 2
- };
-
- int level_;
- std::string currentElement_;
- std::string currentText_;
+ public:
+ XMLSettingsProvider(const std::string& xmlConfig);
+ virtual ~XMLSettingsProvider();
+ virtual std::string getSetting(const Setting<std::string>& setting);
+ virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
+ virtual bool getSetting(const Setting<bool>& setting);
+ virtual void storeSetting(const Setting<bool>& setting, const bool& value);
+ virtual int getSetting(const Setting<int>& setting);
+ virtual void storeSetting(const Setting<int>& setting, const int& value);
+ virtual std::vector<std::string> getAvailableProfiles();
+ virtual void createProfile(const std::string& profile);
+ virtual void removeProfile(const std::string& profile);
+ virtual bool hasSetting(const std::string& key);
+
+
+ virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes);
+ virtual void handleEndElement(const std::string& element, const std::string& ns);
+ virtual void handleCharacterData(const std::string& data);
+
+ protected:
+ virtual bool getIsSettingFinal(const std::string& settingPath);
+ private:
+ std::map<std::string /*settingPath*/, std::string /*settingValue*/> values_;
+ /* Settings that are final*/
+ std::set<std::string /*settingPath*/> finals_;
+
+ enum Level {
+ TopLevel = 0,
+ SettingLevel = 2
+ };
+
+ int level_;
+ std::string currentElement_;
+ std::string currentText_;
};
}