[gxml] libxml-ChildNodeList class ported to Gee.Collection
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] libxml-ChildNodeList class ported to Gee.Collection
- Date: Wed, 15 Apr 2015 21:51:23 +0000 (UTC)
commit eeba83fed6a4048d297d5fa7ae25b2806fce02fd
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Apr 15 11:28:33 2015 -0500
libxml-ChildNodeList class ported to Gee.Collection
* ChildNodeList now implements directly Gee.Collection and
its pre-requisites
gxml/libxml-ChildNodeList.vala | 77 ++++++++++++++++++++++++++-------------
1 files changed, 51 insertions(+), 26 deletions(-)
---
diff --git a/gxml/libxml-ChildNodeList.vala b/gxml/libxml-ChildNodeList.vala
index 50278a9..7652b08 100644
--- a/gxml/libxml-ChildNodeList.vala
+++ b/gxml/libxml-ChildNodeList.vala
@@ -23,7 +23,8 @@
using Gee;
-internal abstract class GXml.ChildNodeList : Gee.AbstractCollection<GXml.xNode>, NodeList
+internal abstract class GXml.ChildNodeList : Object,
+ Traversable<xNode>, Iterable<xNode>, Gee.Collection<GXml.xNode>, NodeList
{
/* TODO: must be live
if this reflects children of a node, then must always be current
@@ -45,34 +46,37 @@ internal abstract class GXml.ChildNodeList : Gee.AbstractCollection<GXml.xNode>
protected set { }
}
- public override bool add (xNode item)
- {
- append_child (item);
- return true;
- }
- public override void clear () {}
- public override bool contains (xNode item) { return false; }
- public override bool remove (xNode item) { return false; }
- public override bool read_only { get { return true; } }
- public override int size {
- get {
- if (head != null) {
- //GLib.warning ("At NodeChildNodeList: get_size");
- int len = 1;
- var cur = head;
- while (cur->next != null) {
- cur = cur->next;
- len++;
- }
- return len;
- }
- return 0;
- }
+
+ public Gee.Collection<xNode> read_only_view { owned get { return new ChildNodeListReadOnly
(this); } }
+
+ public bool add (xNode item)
+ {
+ append_child (item);
+ return true;
+ }
+ public void clear () {}
+ public bool contains (xNode item) { return false; }
+ public bool remove (xNode item) { return false; }
+ public bool read_only { get { return true; } }
+ public int size {
+ get {
+ if (head != null) {
+ //GLib.warning ("At NodeChildNodeList: get_size");
+ int len = 1;
+ var cur = head;
+ while (cur->next != null) {
+ cur = cur->next;
+ len++;
+ }
+ return len;
}
- public override Gee.Iterator<xNode> iterator () {
+ return 0;
+ }
+ }
+ public Gee.Iterator<xNode> iterator () {
return new NodeListIterator (this);
}
- public override bool @foreach (ForallFunc<xNode> func) {
+ public bool @foreach (ForallFunc<xNode> func) {
return iterator ().foreach (func);
}
@@ -231,3 +235,24 @@ internal abstract class GXml.ChildNodeList : Gee.AbstractCollection<GXml.xNode>
}
}
}
+
+ internal class GXml.ChildNodeListReadOnly : Object,
+ Traversable<xNode>, Iterable<xNode>, Collection<GXml.xNode>
+ {
+ public GXml.ChildNodeList list;
+ public Gee.Collection<xNode> read_only_view { owned get { return new ChildNodeListReadOnly
(list); } }
+ public ChildNodeListReadOnly (ChildNodeList list)
+ {
+ this.list = list;
+ }
+ public bool add (xNode item) { return false; }
+ public void clear () {}
+ public bool contains (xNode item) { return list.contains (item); }
+ public bool remove (xNode item) { return false; }
+ public bool read_only { get { return true; } }
+ public int size { get { return list.size; } }
+ public Gee.Iterator<xNode> iterator () { return list.iterator (); }
+ public bool @foreach (ForallFunc<xNode> func) {
+ return iterator ().foreach (func);
+ }
+ }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]