[vala/wip/attributes: 107/119] New attributes helper methods



commit 4f9fca181b287629bf36502b453b988c2472814b
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun Jul 3 13:04:13 2011 +0200

    New attributes helper methods

 vala/valaattribute.vala |   12 ++++++------
 vala/valacodenode.vala  |   18 +++++++++---------
 2 files changed, 15 insertions(+), 15 deletions(-)
---
diff --git a/vala/valaattribute.vala b/vala/valaattribute.vala
index c4e72d6..63258e1 100644
--- a/vala/valaattribute.vala
+++ b/vala/valaattribute.vala
@@ -92,11 +92,11 @@ public class Vala.Attribute : CodeNode {
 	 * @param name argument name
 	 * @return     integer value
 	 */
-	public int get_integer (string name) {
+	public int get_integer (string name, int default_value = 0) {
 		string value = args.get (name);
 
 		if (value == null) {
-			return 0;
+			return default_value;
 		}
 
 		return int.parse (value);
@@ -108,11 +108,11 @@ public class Vala.Attribute : CodeNode {
 	 * @param name argument name
 	 * @return     double value
 	 */
-	public double get_double (string name) {
+	public double get_double (string name, double default_value = 0) {
 		string value = args.get (name);
 
 		if (value == null) {
-			return 0;
+			return default_value;
 		}
 
 		return double.parse (value);
@@ -124,11 +124,11 @@ public class Vala.Attribute : CodeNode {
 	 * @param name argument name
 	 * @return     boolean value
 	 */
-	public bool get_bool (string name) {
+	public bool get_bool (string name, bool default_value = false) {
 		string value = args.get (name);
 
 		if (value == null) {
-			return false;
+			return default_value;
 		}
 
 		return bool.parse (value);
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index b4830f8..ed5ee79 100644
--- a/vala/valacodenode.vala
+++ b/vala/valacodenode.vala
@@ -207,12 +207,12 @@ public abstract class Vala.CodeNode {
 	 * @param argument  argument name
 	 * @return          integer value
 	 */
-	public int get_attribute_integer (string attribute, string argument) {
+	public int get_attribute_integer (string attribute, string argument, int default_value = 0) {
 		var a = get_attribute (attribute);
 		if (a == null) {
-			return 0;
+			return default_value;
 		}
-		return a.get_integer (argument);
+		return a.get_integer (argument, default_value);
 	}
 
 	/**
@@ -222,12 +222,12 @@ public abstract class Vala.CodeNode {
 	 * @param argument  argument name
 	 * @return          double value
 	 */
-	public double get_attribute_double (string attribute, string argument) {
+	public double get_attribute_double (string attribute, string argument, double default_value = 0) {
 		var a = get_attribute (attribute);
 		if (a == null) {
-			return 0;
+			return default_value;
 		}
-		return a.get_double (argument);
+		return a.get_double (argument, default_value);
 	}
 
 	/**
@@ -237,12 +237,12 @@ public abstract class Vala.CodeNode {
 	 * @param argument  argument name
 	 * @return          bool value
 	 */
-	public bool get_attribute_bool (string attribute, string argument) {
+	public bool get_attribute_bool (string attribute, string argument, bool default_value) {
 		var a = get_attribute (attribute);
 		if (a == null) {
-			return false;
+			return default_value;
 		}
-		return a.get_bool (argument);
+		return a.get_bool (argument, default_value);
 	}
 
 	/**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]