[gxml] Sync Node interface with xNode and BackedNode



commit 047dc918e925a93d51f406ab4e7643d079975038
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Apr 15 14:08:35 2015 -0500

    Sync Node interface with xNode and BackedNode
    
    * Removed owned from child_nodes property in Node
    * Changed type of Node interface properties: childs and namespaces
      to BidirList

 gxml/Node.vala              |    4 ++--
 gxml/libxml-Attr.vala       |   10 ++++++----
 gxml/libxml-BackedNode.vala |   17 ++++++++++-------
 gxml/libxml-Document.vala   |    6 ++++--
 gxml/libxml-Entity.vala     |    9 +++++----
 gxml/libxml-Node.vala       |    3 +--
 test/DocumentTest.vala      |    3 +--
 7 files changed, 29 insertions(+), 23 deletions(-)
---
diff --git a/gxml/Node.vala b/gxml/Node.vala
index 6380d1f..462f2a9 100644
--- a/gxml/Node.vala
+++ b/gxml/Node.vala
@@ -24,8 +24,8 @@ using Gee;
 
 public interface GXml.Node : Object
 {
-  public abstract Gee.LinkedList<GXml.Namespace> namespaces { get; }
-  public abstract Gee.LinkedList<GXml.Node> childs { get; }
+  public abstract Gee.BidirList<GXml.Namespace> namespaces { get; }
+  public abstract Gee.BidirList<GXml.Node> childs { get; }
   public abstract Gee.Map<string,GXml.Node> attrs { get; }
   public abstract string name { get; construct set; }
   public abstract string @value { get; set; }
diff --git a/gxml/libxml-Attr.vala b/gxml/libxml-Attr.vala
index 7806a4e..ef89001 100644
--- a/gxml/libxml-Attr.vala
+++ b/gxml/libxml-Attr.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
 /* Attr.vala
  *
  * Copyright (C) 2011-2013  Richard Schwarting <aquarichy gmail com>
@@ -57,8 +57,9 @@ namespace GXml {
         */
        public class Attr : BackedNode {
                /** Private properties */
-               internal new Xml.Attr *node;
                /* this displaces BackedNode's xmlNode node */
+               internal new Xml.Attr *node;
+               internal AttrChildNodeList _attr_list;
 
                /** Constructors */
                internal Attr (Xml.Attr *node, xDocument doc) {
@@ -67,6 +68,7 @@ namespace GXml {
                        base ((Xml.Node*)node, doc);
                        this.node = node;
                        this.specified = true;
+                       _attr_list = new AttrChildNodeList (this.node, this.owner_document);
                }
 
                /* Public properties (Node general) */
@@ -158,13 +160,13 @@ namespace GXml {
                 * { inheritDoc}
                 */
                public override NodeList? child_nodes {
-                       owned get {
+                       get {
                                /* TODO: always create a new one?
                                       no, this is broken, if we keep creating new ones
                                       then changes are lost each time we call one
                                       unless AttrChildNodeList makes changes to the underlying
                                       one ugh, how are we even passing tests right now? */
-                               return new AttrChildNodeList (this.node, this.owner_document);
+                               return _attr_list;
                        }
                        internal set {
                        }
diff --git a/gxml/libxml-BackedNode.vala b/gxml/libxml-BackedNode.vala
index 8e1653b..f123f64 100644
--- a/gxml/libxml-BackedNode.vala
+++ b/gxml/libxml-BackedNode.vala
@@ -25,6 +25,8 @@
 
 // NOTE: be careful about what extra data subclasses keep
 
+using Gee;
+
 namespace GXml {
        /**
         * An internal class for nodes whose content is stored in a
@@ -36,6 +38,7 @@ namespace GXml {
        public class BackedNode : xNode {
                /** Private properties */
                internal Xml.Node *node;
+               protected NodeList _child_nodes;
 
                internal void set_xmlnode (Xml.Node *node, xDocument owner) {
                        this.node = node;
@@ -50,6 +53,7 @@ namespace GXml {
                        this.set_xmlnode (node, owner);
                        // TODO: Consider checking whether the Xml.Node* is already recorded.  It shouldn't 
be.
                        // TODO: BackedNodes' memory are freed when their owner document is freed; let's make 
sure that when we move a node between documents, that we make sure they'll still be freed
+                       _child_nodes = new NodeChildNodeList (this.node, this.owner_document);
                }
 
 
@@ -229,9 +233,8 @@ namespace GXml {
                 * { inheritDoc}
                 */
                public override NodeList? child_nodes {
-                       owned get {
-                               // TODO: always create a new one?
-                               return new NodeChildNodeList (this.node, this.owner_document);
+                       get {
+                               return _child_nodes;
                        }
                        internal set {
                        }
@@ -364,17 +367,17 @@ namespace GXml {
                        return str;
                }
                // GXml.Node interface implementations
-               public Gee.LinkedList<GXml.Namespace> namespaces
+               public Gee.BidirList<GXml.Namespace> namespaces
                {
                        get {
                                return _namespace_definitions;
                        }
                }
                /*
-               public Gee.LinkedList<GXml.Node> childs
+               public Gee.BidirList<GXml.Node> childs
                {
-                       get {
-                               
+                       owned get {
+                               return (Gee.BidirList) child_nodes;
                        }
                }
                public Gee.Map<string,GXml.Node> attrs { get; }
diff --git a/gxml/libxml-Document.vala b/gxml/libxml-Document.vala
index 5c1b20c..ffda819 100644
--- a/gxml/libxml-Document.vala
+++ b/gxml/libxml-Document.vala
@@ -88,6 +88,7 @@ namespace GXml {
                   separately compiled TestDocument : xDocument class,
                   and it couldn't access the internal xmldoc. */
                internal Xml.Doc *xmldoc;
+               internal NodeChildNodeList _node_list;
 
                /* *** Private methods *** */
                internal unowned Attr? lookup_attr (Xml.Attr *xmlattr) {
@@ -505,6 +506,7 @@ namespace GXml {
 
                        doc = new Xml.Doc ();
                        this.from_libxml2 (doc, false);
+                       _node_list = new NodeChildNodeList ((Xml.Node*)this.xmldoc, this.owner_document);
                }
 
                /**
@@ -886,10 +888,10 @@ namespace GXml {
                 * { inheritDoc}
                 */
                public override NodeList? child_nodes {
-                       owned get {
+                       get {
                                // TODO: always create a new one?
                                // TODO: xmlDoc and xmlNode are very similar, but perhaps we shouldn't do 
this :D
-                               return new NodeChildNodeList ((Xml.Node*)this.xmldoc, this.owner_document);
+                               return _node_list;
                        }
                        internal set {
                        }
diff --git a/gxml/libxml-Entity.vala b/gxml/libxml-Entity.vala
index c82d2cb..1648dc1 100644
--- a/gxml/libxml-Entity.vala
+++ b/gxml/libxml-Entity.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
 /* Entity.vala
  *
  * Copyright (C) 2011-2013  Richard Schwarting <aquarichy gmail com>
@@ -31,6 +31,7 @@ namespace GXml {
         */
        public class Entity : xNode {
                private Xml.Entity *entity;
+               private NodeList _entity_list;
 
                /**
                 * A public identifier for the entity. %NULL when unspecified.
@@ -72,8 +73,8 @@ namespace GXml {
 
                internal Entity (Xml.Entity *entity, xDocument doc) {
                        base (NodeType.ENTITY, doc);
-
                        this.entity = entity;
+                       _entity_list = new EntityChildNodeList (this.entity, this.owner_document);
                }
 
                /* Public properties (xNode-specific) */
@@ -99,10 +100,10 @@ namespace GXml {
                // node_value == null
 
                public override NodeList? child_nodes {
-                       owned get {
+                       get {
                                // TODO: always create a new one?
                                //       probably not a good idea; want to create one local one
-                               return new EntityChildNodeList (this.entity, this.owner_document);
+                               return _entity_list;
                        }
                        internal set {
                        }
diff --git a/gxml/libxml-Node.vala b/gxml/libxml-Node.vala
index f5cf47c..68a0fb6 100644
--- a/gxml/libxml-Node.vala
+++ b/gxml/libxml-Node.vala
@@ -261,8 +261,7 @@ namespace GXml {
                 * URL: [[http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-1451460987]]
                 */
                public virtual NodeList? child_nodes {
-                       // TODO: need to implement NodeList
-                       owned get { return null; }
+                       get { return null; }
                        internal set {}
                }
 
diff --git a/test/DocumentTest.vala b/test/DocumentTest.vala
index d3c4dd6..c02b8db 100644
--- a/test/DocumentTest.vala
+++ b/test/DocumentTest.vala
@@ -417,7 +417,6 @@ class DocumentTest : GXmlTest {
        }
 
        public static void print_node (GXml.xNode node) {
-               List<GXml.xNode> children = (List<GXml.xNode>)node.child_nodes;
 
                if (node.node_type != 3)
                        GLib.stdout.printf ("<%s", node.node_name);
@@ -430,7 +429,7 @@ class DocumentTest : GXmlTest {
                GLib.stdout.printf (">");
                if (node.node_value != null)
                        GLib.stdout.printf ("%s", node.node_value);
-               foreach (GXml.xNode child in children) {
+               foreach (GXml.xNode child in node.child_nodes) {
                        // TODO: want a stringification method for Nodes?
                        print_node (child);
                }


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