Explorar o código

Merge pull request #413 from natelo/screenrewrite

Added setBoolValue and getBoolValue so param can be evaluated when neede...
Ivan Safrin %!s(int64=12) %!d(string=hai) anos
pai
achega
d1ab4ee321
Modificáronse 2 ficheiros con 28 adicións e 2 borrados
  1. 15 0
      Core/Contents/Include/PolyConfig.h
  2. 13 2
      Core/Contents/Source/PolyConfig.cpp

+ 15 - 0
Core/Contents/Include/PolyConfig.h

@@ -91,6 +91,21 @@ namespace Polycode {
 		* @param key String key of the value.
 		*/						
 		const String& getStringValue(const String& configNamespace, const String& key);
+
+		/**
+		* Sets a string value that represents boolean (true|false) key.
+		* @param configNamespace Namespace to set value in.
+		* @param key String key of the value.
+		* @param value The string value to save.
+		*/
+		void setBoolValue(const String& configNamespace, const String& key, bool value);
+
+		/**
+		* Returns a boolean value by eveluating a string key (true|1 = true).
+		* @param configNamespace Namespace to get the value from.
+		* @param key String key of the value.
+		*/
+		bool getBoolValue(const String& configNamespace, const String& key);
 		
 	private:
 		

+ 13 - 2
Core/Contents/Source/PolyConfig.cpp

@@ -112,7 +112,6 @@ void Config::setNumericValue(const String& configNamespace, const String& key, N
 	getEntry(configNamespace, key)->isString = false;		
 }
 
-
 Number Config::getNumericValue(const String& configNamespace, const String& key) {
 	return getEntry(configNamespace, key)->numVal;
 }
@@ -121,4 +120,16 @@ const String& Config::getStringValue(const String& configNamespace, const String
 	return getEntry(configNamespace, key)->stringVal;	
 }
 
-
+void Config::setBoolValue(const String& configNamespace, const String& key, bool value) {
+	getEntry(configNamespace, key)->stringVal = (!value ? "false" : "true");
+	getEntry(configNamespace, key)->isString = true;
+}
+
+bool Config::getBoolValue(const String& configNamespace, const String& key) {
+	const String& str = getEntry(configNamespace, key)->stringVal;
+
+	if (str == "true" || str == "1") {
+		return true;
+	}		
+	return false;
+}