[gxml] Implemented better support for GXml.Node.parent to TwNode
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Implemented better support for GXml.Node.parent to TwNode
- Date: Sat, 20 Feb 2016 17:36:01 +0000 (UTC)
commit f67dc16f1cae0143c25621c05f9ef0b1dfa61cdc
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Feb 18 18:33:43 2016 -0600
Implemented better support for GXml.Node.parent to TwNode
gxml/TwElement.vala | 6 ++++--
gxml/TwNode.vala | 17 +++++++++++++++--
2 files changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/gxml/TwElement.vala b/gxml/TwElement.vala
index c88b596..8721578 100644
--- a/gxml/TwElement.vala
+++ b/gxml/TwElement.vala
@@ -27,7 +27,7 @@ using Gee;
public class GXml.TwElement : GXml.TwNode, GXml.Element
{
protected Gee.HashMap<string,GXml.Node> _attrs;
- protected Gee.ArrayList<GXml.Node> _children;
+ protected TwNode.TwChildrenList _children;
protected Gee.ArrayList<GXml.Node> _namespaces;
private string _content = null;
public TwElement (GXml.Document d, string name)
@@ -53,7 +53,7 @@ public class GXml.TwElement : GXml.TwNode, GXml.Element
}
public override Gee.BidirList<GXml.Node> children {
owned get {
- if (_children == null) _children = new Gee.ArrayList<GXml.Node> ();
+ if (_children == null) _children = new TwChildrenList (this);
return _children.ref () as Gee.BidirList<GXml.Node>;
}
}
@@ -68,6 +68,7 @@ public class GXml.TwElement : GXml.TwNode, GXml.Element
{
if (":" in name) return;
var att = new TwAttribute (document, name, value);
+ att.set_parent (this);
attrs.set (name, att);
}
public GXml.Node get_attr (string name) { return attrs.get (name); }
@@ -82,6 +83,7 @@ public class GXml.TwElement : GXml.TwNode, GXml.Element
public void set_ns_attr (Namespace ns, string name, string value) {
var att = new TwAttribute (document, name, value);
att.set_namespace (ns.uri, ns.prefix);
+ att.set_parent (this);
attrs.set (name, att);
}
public void remove_attr (string name) {
diff --git a/gxml/TwNode.vala b/gxml/TwNode.vala
index c37b85f..0bd0ef3 100644
--- a/gxml/TwNode.vala
+++ b/gxml/TwNode.vala
@@ -29,6 +29,7 @@ public abstract class GXml.TwNode : Object, GXml.Node
protected string _name = null;
protected string _value = null;
protected GXml.Document _doc;
+ protected GXml.Node _parent;
internal Xml.TextWriter *tw;
construct { Init.init (); }
@@ -52,11 +53,23 @@ public abstract class GXml.TwNode : Object, GXml.Node
}
public virtual string to_string () { return get_type ().name (); }
public virtual Gee.Map<string,GXml.Node> attrs { owned get { return new Gee.HashMap<string,GXml.Node> ();
} }
- public virtual Gee.BidirList<GXml.Node> children { owned get { return new Gee.ArrayList<GXml.Node> (); } }
+ public virtual Gee.BidirList<GXml.Node> children { owned get { return new TwChildrenList (this); } }
public virtual GXml.Document document { get { return _doc; } }
public virtual string name { owned get { return _name.dup (); } }
public virtual Gee.List<GXml.Namespace> namespaces { owned get { return new Gee.ArrayList<GXml.Node> (); }
}
public virtual GXml.NodeType type_node { get { return GXml.NodeType.DOCUMENT; } }
public virtual string value { owned get { return _value.dup (); } set { _value = value; } }
- public virtual GXml.Node parent { owned get { return null; } }
+ public virtual GXml.Node parent { owned get { return _parent; } }
+ public virtual void set_parent (GXml.Node node) { _parent = node; }
+
+ protected class TwChildrenList : Gee.ArrayList<GXml.Node> {
+ GXml.Node _parent;
+ protected TwChildrenList (GXml.Node e) {
+ _parent = e;
+ }
+ protected new bool add (GXml.Node node) {
+ (node as GXml.TwNode).set_parent (_parent);
+ return base.add (node);
+ }
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]