[gxml] Fixed compilation for DomNode implementation of GNode
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Fixed compilation for DomNode implementation of GNode
- Date: Mon, 18 Jul 2016 05:44:37 +0000 (UTC)
commit 23e363cff1b158817491b3ae3eec0d19b7a0f600
Author: Daniel Espinosa <esodan gmail com>
Date: Mon May 9 19:43:06 2016 -0500
Fixed compilation for DomNode implementation of GNode
gxml/DomNode.vala | 24 +++++-----
gxml/GXmlListChildren.vala | 4 +-
gxml/GXmlNode.vala | 109 ++++++++++++++++++++++++--------------------
gxml/Makefile.am | 1 +
gxml/xlibxml.c | 7 +++
gxml/xlibxml.h | 1 +
test/Makefile.am | 1 +
test/test.xml | 15 ------
vapi/xlibxml-1.0.vapi | 2 +
9 files changed, 86 insertions(+), 78 deletions(-)
---
diff --git a/gxml/DomNode.vala b/gxml/DomNode.vala
index c012582..81401e8 100644
--- a/gxml/DomNode.vala
+++ b/gxml/DomNode.vala
@@ -34,21 +34,21 @@ public interface GXml.DomNode : GLib.Object, GXml.DomEventTarget {
public const ushort DOCUMENT_FRAGMENT_NODE = 11;
public const ushort NOTATION_NODE = 12; // historical
public abstract GXml.NodeType node_type { get; }
- public abstract string node_name { get; }
+ public abstract string node_name { owned get; }
public abstract string? base_uri { get; }
public abstract DomDocument? owner_document { get; }
- public abstract DomNode? parent_node { get; }
- public abstract DomElement? parent_element { get; }
- public abstract DomNodeList child_nodes { get; }
- public abstract DomNode? first_child { get; }
- public abstract DomNode? last_child { get; }
- public abstract DomNode? previous_sibling { get; }
- public abstract DomNode? next_sibling { get; }
+ public abstract DomNode? parent_node { owned get; }
+ public abstract DomElement? parent_element { owned get; }
+ public abstract DomNodeList child_nodes { owned get; }
+ public abstract DomNode? first_child { owned get; }
+ public abstract DomNode? last_child { owned get; }
+ public abstract DomNode? previous_sibling { owned get; }
+ public abstract DomNode? next_sibling { owned get; }
- public abstract string? node_value { get; set; }
- public abstract string? text_content { get; set; }
+ public abstract string? node_value { owned get; set; }
+ public abstract string? text_content { owned get; set; }
public abstract bool has_child_nodes ();
public abstract void normalize ();
@@ -57,7 +57,7 @@ public interface GXml.DomNode : GLib.Object, GXml.DomEventTarget {
public abstract bool is_equal_node (DomNode? node);
[Flags]
- public enum DocumenPosition {
+ public enum DocumentPosition {
DISCONNECTED,
PRECEDING,
FOLLOWING,
@@ -65,7 +65,7 @@ public interface GXml.DomNode : GLib.Object, GXml.DomEventTarget {
CONTAINED_BY,
IMPLEMENTATION_SPECIFIC
}
- public abstract DocumenPosition compare_document_position (DomNode other);
+ public abstract DocumentPosition compare_document_position (DomNode other);
public abstract bool contains (DomNode? other);
public abstract string? lookup_prefix (string? nspace);
diff --git a/gxml/GXmlListChildren.vala b/gxml/GXmlListChildren.vala
index c864cad..7952038 100644
--- a/gxml/GXmlListChildren.vala
+++ b/gxml/GXmlListChildren.vala
@@ -70,7 +70,7 @@ public class GXml.GListChildren : AbstractBidirList<GXml.Node>, DomNodeList
public override void insert (int index, GXml.Node item) {
var n = @get (index);
if (n == null) return;
- n.get_internal_node ()->add_prev_sibling (item.get_internal_node ());
+ (n as GXml.GNode).get_internal_node ()->add_prev_sibling ((item as GXml.GNode).get_internal_node ());
}
public override Gee.ListIterator<GXml.Node> list_iterator () { return new Iterator (_doc, _node); }
/**
@@ -79,7 +79,7 @@ public class GXml.GListChildren : AbstractBidirList<GXml.Node>, DomNodeList
public override GXml.Node remove_at (int index) {
var n = @get (index);
if (n == null) return null;
- n.get_internal_node ()->unlink_node ();
+ (n as GXml.GNode).get_internal_node ()->unlink ();
return n;
}
/**
diff --git a/gxml/GXmlNode.vala b/gxml/GXmlNode.vala
index e7ed183..33dcb40 100644
--- a/gxml/GXmlNode.vala
+++ b/gxml/GXmlNode.vala
@@ -105,40 +105,40 @@ public abstract class GXml.GNode : Object, GXml.Node
return null;
}
// DomNode Implementation
- public string node_name { get { return name; } }
+ public string node_name { owned get { return name; } }
protected string _base_uri = null;
public string? base_uri { get { return _base_uri; } }
- public DomDocument? owner_document { get { return document; } }
- public DomNode? parent_node { get { return parent; } }
+ public DomDocument? owner_document { get { return (GXml.DomDocument?) document; } }
+ public DomNode? parent_node { owned get { return parent as DomNode?; } }
public DomElement? parent_element {
- get {
- if (parent is DomElement) return parent;
+ owned get {
+ if (parent is DomElement) return parent as DomElement?;
return null;
}
}
- public DomNodeList child_nodes { get { return children; } }
- public DomNode? first_child { get { return children.itirator ().first (); } }
- public DomNode? last_child { get { return children.itirator ().last (); } }
+ public DomNodeList child_nodes { owned get { return children as DomNodeList; } }
+ public DomNode? first_child { owned get { return children.first () as DomNode?; } }
+ public DomNode? last_child { owned get { return children.last () as DomNode?; } }
public DomNode? previous_sibling {
- get {
+ owned get {
if (_node == null) return null;
if (_node->prev == null) return null;
- return GNode.to_gnode (_doc, _node->prev);
+ return GNode.to_gnode (_doc, _node->prev) as DomNode?;
}
}
public DomNode? next_sibling {
- get {
+ owned get {
if (_node == null) return null;
if (_node->next == null) return null;
- return GNode.to_gnode (_doc, _node->next);
+ return GNode.to_gnode (_doc, _node->next) as DomNode?;
}
}
- public string? node_value { get { return @value; } set { this.@value = value; } }
+ public string? node_value { owned get { return @value; } set { this.@value = value; } }
public string? text_content {
- get {
+ owned get {
string t = null;
if (this is GXml.Text) return this.@value;
if (this is GXml.ProcessingInstruction) return this.@value;
@@ -156,7 +156,7 @@ public abstract class GXml.GNode : Object, GXml.Node
set {
if (this is GXml.Document || this is GXml.Element) {
var t = this.document.create_text (value);
- this.document.add (t);
+ this.document.children.add (t);
}
if (!(this is GXml.Text || this is GXml.Comment || this is GXml.ProcessingInstruction)) return;
this.@value = value;
@@ -165,7 +165,7 @@ public abstract class GXml.GNode : Object, GXml.Node
public bool has_child_nodes () { return (children.size > 0); }
public void normalize () {
- GXml.Text t = null;
+ GXml.DomText t = null;
int[] r = {};
for (int i = 0; i < children.size; i++) {
var n = children.get (i);
@@ -175,10 +175,10 @@ public abstract class GXml.GNode : Object, GXml.Node
continue;
}
if (t == null) {
- t = n;
+ t = (GXml.DomText) n;
continue;
} else {
- t.@value += n.value;
+ t.data += n.value;
}
}
}
@@ -190,40 +190,50 @@ public abstract class GXml.GNode : Object, GXml.Node
public DomNode clone_node (bool deep = false) {
Xml.Node *n = null;
if (deep)
- n = _node->copy_node (2);
+ n = _node->copy (1);
else
- n = _node->copy_prop_list (_node->properties);
+ n = _node->copy (2);
if (n == null) return null;
- return Node.to_gnode (_doc, n);
+ return (DomNode) GNode.to_gnode (_doc, n);
}
public bool is_equal_node (DomNode? node) {
+ if (!(node is GXml.Node)) return false;
if (node == null) return false;
- if (this.children.size != node.children.size) return false;
- foreach (Attribute a in attrs.values) {
- if (!node.attrs.has_key (a.name)) return false;
- if (a.value != node.attrs.get (a.name).value) return false;
+ if (this.children.size != (node as Node).children.size) return false;
+ foreach (GXml.Node a in attrs.values) {
+ if (!(node as GXml.Node?).attrs.has_key (a.name)) return false;
+ if (a.value != (node as GXml.Node).attrs.get (a.name).value) return false;
}
for (int i=0; i < children.size; i++) {
- if (!children[i].is_equal_node (node.children[i])) return false;
+ if (!(children[i] as GXml.DomNode).is_equal_node ((node as GXml.Node?).children[i] as GXml.DomNode?))
return false;
}
+ return true;
}
- public DocumenPosition compare_document_position (DomNode other) {
- if (this == other) return (DocumenPosition) 0;
- if (this.document != (other as GXml.Node).document)
- return DocumenPosition.DISCONNECTED & DocumenPosition.IMPLEMENTATION_SPECIFIC
- & (this > other) ? DocumentPosition.PRECEDING : DocumentPosition.FOLLOWING;
- if (other.parent == this)
- return DocumenPosition.CONTAINS & DocumenPosition.PRECEDING;
- if (this.parent == other)
- return DocumenPosition.CONTAINED_BY & DocumenPosition.FOLLOWING;
- if (other < this) return DocumenPosition.PRECEDING;
- return DocumenPosition.FOLLOWING;
+ public DomNode.DocumentPosition compare_document_position (DomNode other) {
+ if ((&this as GXml.DomNode) == &other) return (DomNode.DocumentPosition) 0;
+ if (this.document != (other as GXml.Node).document) {
+ var p = DomNode.DocumentPosition.DISCONNECTED & DomNode.DocumentPosition.IMPLEMENTATION_SPECIFIC;
+ if ((&this) > (&other))
+ p = p & DomNode.DocumentPosition.PRECEDING;
+ else
+ p = p & DomNode.DocumentPosition.FOLLOWING;
+ return p;
+ }
+ if ((&other as GXml.Node).parent == &this)
+ return DomNode.DocumentPosition.CONTAINS & DomNode.DocumentPosition.PRECEDING;
+ var op = this.parent as DomNode;
+ if (&other == &op)
+ return DomNode.DocumentPosition.CONTAINED_BY & DomNode.DocumentPosition.FOLLOWING;
+ if (&other < &this) return DomNode.DocumentPosition.PRECEDING;
+ return DomNode.DocumentPosition.FOLLOWING;
}
public bool contains (DomNode? other) {
if (other == null) return false;
- if (other == this) return true;
- if (other.parent == this) return true;
+ var o = other as GXml.Node;
+ if (&o == &this) return true;
+ var op = o.parent;
+ if (&this == &op) return true;
return false;
}
@@ -242,7 +252,7 @@ public abstract class GXml.GNode : Object, GXml.Node
else return null;
}
}
- return this.parent.lookup_prefix (nspace);
+ return (this.parent as GXml.DomNode).lookup_prefix (nspace);
}
public string? lookup_namespace_uri (string? prefix) {
if (prefix == null) return null;
@@ -255,11 +265,11 @@ public abstract class GXml.GNode : Object, GXml.Node
if (this is GXml.Element) {
if (namespaces.size > 0) {
var ns = namespaces[0];
- if (ns.prefix == nspace) return ns.uri;
+ if (ns.prefix == prefix) return ns.uri;
else return null;
}
}
- return this.parent.lookup_namespace_uri (prefix);
+ return (this.parent as GXml.DomNode).lookup_namespace_uri (prefix);
}
public bool is_default_namespace (string? nspace) {
if (nspace == null) return false;
@@ -269,22 +279,23 @@ public abstract class GXml.GNode : Object, GXml.Node
}
public DomNode insert_before (DomNode node, DomNode? child) {
- int i = children.index_of (child);
- children.insert (i, node);
+ int i = children.index_of (child as GXml.Node);
+ children.insert (i, (node as GXml.Node));
return node;
}
public DomNode append_child (DomNode node) {
- children.add (node);
+ children.add ((node as GXml.Node));
return node;
}
public DomNode replace_child (DomNode node, DomNode child) {
- int i = children.index_of (child);
+ int i = children.index_of ((child as GXml.Node));
children.remove_at (i);
- children.insert (node, i);
+ children.insert (i, (node as GXml.Node));
+ return child;
}
public DomNode remove_child (DomNode child) {
- int i = children.index_of (child);
- return children.remove_at (i);
+ int i = children.index_of ((child as GXml.Node));
+ return (DomNode) children.remove_at (i);
}
}
diff --git a/gxml/Makefile.am b/gxml/Makefile.am
index bad2df4..a462772 100644
--- a/gxml/Makefile.am
+++ b/gxml/Makefile.am
@@ -147,6 +147,7 @@ endif
# library flags
AM_VALAFLAGS += \
+ --vapidir=$(VAPIDIR) \
$(ERROR_VALAFLAGS) \
--library=gxml-0.10 \
$(top_srcdir)/vapi/config.vapi \
diff --git a/gxml/xlibxml.c b/gxml/xlibxml.c
index cd2416d..f7c4cdb 100644
--- a/gxml/xlibxml.c
+++ b/gxml/xlibxml.c
@@ -99,3 +99,10 @@ gint gxml_text_writer_write_pi (xmlTextWriterPtr tw, const xmlChar* target, cons
return xmlTextWriterWritePI (tw, target, data);
}
+
+void gxml_copy_props (xmlNodePtr src, xmlNodePtr dst)
+{
+ g_return_if_fail (src != NULL);
+ g_return_if_fail (dst != NULL);
+ xmlCopyProp (dst, src->properties);
+}
diff --git a/gxml/xlibxml.h b/gxml/xlibxml.h
index 09c5280..20df378 100644
--- a/gxml/xlibxml.h
+++ b/gxml/xlibxml.h
@@ -38,5 +38,6 @@ xmlTextWriterPtr gxml_new_text_writer_doc (xmlDoc** doc);
xmlTextWriterPtr gxml_new_text_writer_memory (xmlBufferPtr buffer, gint compression);
gint gxml_text_writer_write_cdata (xmlTextWriter* tw, const xmlChar* text);
gint gxml_text_writer_write_pi (xmlTextWriter* tw, const xmlChar* target, const xmlChar*
data);
+void gxml_copy_props (xmlNodePtr src, xmlNodePtr dst);
#endif
diff --git a/test/Makefile.am b/test/Makefile.am
index 3ea62a6..39e87e8 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -92,6 +92,7 @@ $(sources:.vala=.c): vala-stamp
gxml_test_SOURCES = $(sources:.vala=.c)
AM_VALAFLAGS = \
+ --vapidir=$(VAPIDIR) \
$(top_srcdir)/vapi/config.vapi \
$(top_srcdir)/vapi/gxml-test.vapi \
--vapidir=$(top_srcdir)/vapi \
diff --git a/vapi/xlibxml-1.0.vapi b/vapi/xlibxml-1.0.vapi
index 9eb9c61..66c44e9 100644
--- a/vapi/xlibxml-1.0.vapi
+++ b/vapi/xlibxml-1.0.vapi
@@ -51,4 +51,6 @@ namespace Xmlx {
public static int text_writer_write_cdata (Xml.TextWriter tw, string text);
[CCode (cname = "gxml_text_writer_write_pi", cheader_filename = "gxml/xlibxml.h")]
public static int text_writer_write_pi (Xml.TextWriter tw, string target, string data);
+ [CCode (cname = "gxml_copy_props", cheader_filename = "gxml/xlibxml.h")]
+ public static int copy_props (Xml.Node src, Xml.Node dst);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]