[gxml] Added GomArrayString and GomFixedArrayString



commit 19af4c56ec71481ed7ab992cf02715cc9ce65a8b
Author: Daniel Espinosa <esodan gmail com>
Date:   Sat Jan 21 20:27:42 2017 -0600

    Added GomArrayString and GomFixedArrayString

 gxml/GomProperty.vala |   86 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)
---
diff --git a/gxml/GomProperty.vala b/gxml/GomProperty.vala
index dae2d69..04fa1fb 100644
--- a/gxml/GomProperty.vala
+++ b/gxml/GomProperty.vala
@@ -108,6 +108,92 @@ public class GXml.GomString : GomBaseProperty {
 }
 
 /**
+ * Convenient class to handle a {@link GomElement}'s attribute
+ * using a list of pre-defined and mutable values.
+ * Values can be added or removed.
+ */
+public class GXml.GomArrayString : GomBaseProperty {
+  protected string _value = "";
+  protected GLib.Array<string> _values = null;
+  /**
+   * Array of values to  choose from
+   * or to be validated from using {@link is_valid_value}
+   */
+  public GLib.Array<string> values {
+    get { return _values; }
+    set { _values = value; }
+  }
+  /**
+   * Convenient method to initialize array of values from an array of strings.
+   */
+  public void initialize_strings (string[] strs) {
+    if (strs.length == 0) return;
+    if (_values == null) _values = new GLib.Array<string> ();
+    _values.append_vals (strs, strs.length);
+  }
+  /**
+   * Returns true if current value in property is included
+   * in the array of values.
+   */
+  public bool is_valid_value () {
+    if (_values == null) return true;
+    for (int i = 0; i < _values.length; i++) {
+      if (_values.index (i) == value) return true;
+    }
+    return false;
+  }
+  public override string value {
+    owned get {
+      return _value;
+    }
+    set {
+      if (validate_value (value))
+        _value = value;
+    }
+  }
+}
+
+/**
+ * Convenient class to handle a {@link GomElement}'s attribute
+ * using a list of pre-defined and unmutable values.
+ */
+public class GXml.GomFixedArrayString : GomBaseProperty {
+  protected string _value = "";
+  protected string[] _values = null;
+  public unowned string[] get_values () {
+    return _values;
+  }
+  /**
+   * Convenient method to initialize array of values from an array of strings.
+   * Values are taken and should not be freed after call initialization.
+   */
+  public void initialize_strings (owned string[] strs) {
+    if (strs.length == 0) return;
+    _values = strs;
+  }
+  /**
+   * Returns true if current value in attribute is included
+   * in the array of values.
+   */
+  public bool is_valid_value () {
+    if (_values == null) return true;
+    foreach (string s in _values) {
+      if (s == value) return true;
+    }
+    return false;
+  }
+  public override string value {
+    owned get {
+      return _value;
+    }
+    set {
+      if (validate_value (value))
+        _value = value;
+    }
+  }
+}
+
+/**
  * Convenient class to handle {@link GomElement}'s attributes
  * using double pressition floats as sources of values.
  *


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