[gxml] API/ABI set to 0.16. Fixed bug GomCollection.
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] API/ABI set to 0.16. Fixed bug GomCollection.
- Date: Mon, 12 Jun 2017 17:49:43 +0000 (UTC)
commit 0ea6899fd6a46d8860c87a2210f2fb899450c06e
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Jun 12 10:18:29 2017 -0500
API/ABI set to 0.16. Fixed bug GomCollection.
Initial work for API/ABI stabilization
Fixed bug on GomCollection on remove nodes
requiring to search() for nodes to add in
collections
configure.ac | 4 ++--
gxml/GomCollections.vala | 39 ++++++++++++++++++++++++++++++++++++++-
gxml/GomElement.vala | 2 ++
meson.build | 2 +-
po/meson.build | 2 +-
test/GomElementTest.vala | 16 ++++++++++++++++
test/GomSerializationTest.vala | 9 +++++++++
7 files changed, 69 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3070f80..bb4ffa2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,7 +35,7 @@ m4_define([project_full_version],
# You should set project_released to one in order to mark this as a released version
# and to avoid date on version number
-m4_define(project_released, [1])
+m4_define(project_released, [0])
m4_define([project_maybe_datestamp],
m4_if(project_released, [1],
[], [m4_esyscmd([date +.%Y%m%d | tr -d '\n\r'])]))
@@ -93,7 +93,7 @@ AC_SUBST([PROJECT_MAJOR_MINOR_VERSION])
# - If new versions are compatible with the actual one, just leave this untouched
# - If new version breaks API change it in order to allow paralled installations
# with old versions. Change name of pc files to use a new API too.
-API_VERSION=0.14
+API_VERSION=0.16
AC_SUBST([API_VERSION])
GXML_VERSION=project_base_version
diff --git a/gxml/GomCollections.vala b/gxml/GomCollections.vala
index 0294910..03136c6 100644
--- a/gxml/GomCollections.vala
+++ b/gxml/GomCollections.vala
@@ -30,10 +30,12 @@ public interface GXml.GomCollection : Object
/**
* A list of child {@link DomElement} objects of {@link element}
*/
+ [CCode (ordering = 0)]
public abstract GLib.Queue<int> nodes_index { get; }
/**
* A {@link GomElement} with all child elements in collection.
*/
+ [CCode (ordering = 1)]
public abstract GomElement element { get; construct set; }
/**
* Local name of {@link DomElement} objects of {@link element}, which could be
@@ -41,6 +43,7 @@ public interface GXml.GomCollection : Object
*
* Used when reading to add elements to collection.
*/
+ [CCode (ordering = 2)]
public abstract string items_name { get; }
/**
* A {@link GLib.Type} of {@link DomElement} child objects of {@link element},
@@ -48,16 +51,19 @@ public interface GXml.GomCollection : Object
*
* Type should be an {@link GomObject}.
*/
+ [CCode (ordering = 3)]
public abstract Type items_type { get; construct set; }
/**
* Search and add references to all {@link GomObject} nodes as child of
* {@link element} with same, case insensitive, name of {@link items_name}
*/
+ [CCode (ordering = 4)]
public abstract void search () throws GLib.Error;
/**
* Gets a child {@link DomElement} of {@link element} referenced in
* {@link nodes_index}.
*/
+ [CCode (ordering = 5)]
public virtual DomElement? get_item (int index) throws GLib.Error {
if (nodes_index.length == 0)
return null;
@@ -80,10 +86,12 @@ public interface GXml.GomCollection : Object
* collection, this method will take information from node to initialize
* how to find it.
*/
+ [CCode (ordering = 6)]
public abstract void append (DomElement node) throws GLib.Error;
/**
* Number of items referenced in {@link nodes_index}
*/
+ [CCode (ordering = 7)]
public virtual int length { get { return (int) nodes_index.get_length (); } }
/**
* Initialize collection to use a given {@link GomElement} derived type.
@@ -93,6 +101,7 @@ public interface GXml.GomCollection : Object
* This method can be used at construction time of classes implementing
* {@link GomCollection} to initialize object type to refer in collection.
*/
+ [CCode (ordering = 8)]
public abstract void initialize (GLib.Type t) throws GLib.Error;
/**
* Creates a new instance of {@link items_type}, with same
@@ -102,6 +111,7 @@ public interface GXml.GomCollection : Object
*
* Returns: a new instance object or null if type is not a {@link GomElement} or no parent has been set
*/
+ [CCode (ordering = 9)]
public virtual GomElement? create_item () {
if (items_type.is_a (GLib.Type.INVALID)) return null;
if (!items_type.is_a (typeof (GomElement))) return null;
@@ -118,7 +128,13 @@ public interface GXml.GomCollection : Object
*
* Return: true if node and index should be added to collection.
*/
+ [CCode (ordering = 10)]
public abstract bool validate_append (int index, DomElement element) throws GLib.Error;
+ /**
+ * Clear this collection in prepareation for a search
+ */
+ [CCode (ordering = 11)]
+ public abstract void clear () throws GLib.Error;
}
/**
@@ -233,12 +249,13 @@ public abstract class GXml.BaseCollection : Object {
/**
* Search for all child nodes in {@link element} of type {@link GomElement}
* with a {@link GomElement.local_name} equal to {@link GomCollection.items_name},
- * to add it to collection.
+ * to add it to collection. This method calls {@link clear} first.
*
* Implementations could add additional restrictions to add element to collection.
*/
public void search () throws GLib.Error {
_nodes_index.clear ();
+ clear ();
if (_element == null)
throw new DomError.INVALID_NODE_TYPE_ERROR
(_("Parent Element is invalid"));
@@ -256,6 +273,17 @@ public abstract class GXml.BaseCollection : Object {
* {@inheritDoc}
*/
public abstract bool validate_append (int index, DomElement element) throws GLib.Error;
+ /**
+ * {@inheritDoc}
+ */
+ public virtual void clear () throws GLib.Error {}
+
+ // Internal for future expansions
+ internal new virtual void reserved0() {}
+ internal new virtual void reserved1() {}
+ internal new virtual void reserved2() {}
+ internal new virtual void reserved3() {}
+ internal new virtual void reserved4() {}
}
/**
@@ -430,6 +458,9 @@ public class GXml.GomHashMap : GXml.BaseCollection, GXml.GomCollection {
_hashtable.insert (key, index);
return true;
}
+ public override void clear () {
+ _hashtable = new HashTable<string,int> (str_hash,str_equal);
+ }
}
@@ -635,6 +666,9 @@ public class GXml.GomHashPairedMap : GXml.BaseCollection, GXml.GomCollection {
ht.set (skey, index);
return true;
}
+ public override void clear () {
+ _hashtable = new HashMap<string,HashMap<string,int>> ();
+ }
}
@@ -909,4 +943,7 @@ public class GXml.GomHashThreeMap : GXml.BaseCollection, GXml.GomCollection {
hte.set (tkey, index);
return true;
}
+ public override void clear () {
+ _hashtable = new HashMap<string,HashMap<string,HashMap<string,int>>> ();
+ }
}
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index 2b09b4f..f1224db 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -158,6 +158,8 @@ public class GXml.GomElement : GomNode,
public void remove () {
if (parent_node != null) {
var i = parent_node.child_nodes.index_of (this);
+ if (i < 0 || i > parent_node.child_nodes.length)
+ warning (_("Can't locate child node to remove"));
parent_node.child_nodes.remove_at (i);
}
}
diff --git a/meson.build b/meson.build
index a6279c8..2019c77 100644
--- a/meson.build
+++ b/meson.build
@@ -1,7 +1,7 @@
project('gxml', [ 'vala', 'c'], version : '0.15.0')
PROJECT_NAME = 'gxml'
-API_VERSION = '0.14'
+API_VERSION = '0.16'
PROJECT_VERSION = '0.15.0'
VERSIONED_PROJECT_NAME = PROJECT_NAME+'-'+API_VERSION
CAMEL_CASE_NAME = 'GXml'
diff --git a/po/meson.build b/po/meson.build
index 4b355bf..d47982f 100644
--- a/po/meson.build
+++ b/po/meson.build
@@ -1,2 +1,2 @@
i18n = import('i18n')
-i18n.gettext(CAMEL_CASE_NAME, preset : 'glib')
+i18n.gettext(VERSIONED_CAMEL_CASE_NAME, preset : 'glib')
diff --git a/test/GomElementTest.vala b/test/GomElementTest.vala
index 23e1f27..a36f24d 100644
--- a/test/GomElementTest.vala
+++ b/test/GomElementTest.vala
@@ -204,6 +204,22 @@ class GomElementTest : GXmlTest {
assert_not_reached ();
}
});
+ Test.add_func ("/gxml/gom-element/remove", () => {
+ try {
+ var doc = new GomDocument.from_string ("<root><child/></root>");
+ assert (doc.document_element != null);
+ assert (doc.document_element.parent_node is GXml.DomNode);
+ assert (doc.document_element.parent_node is GXml.DomDocument);
+ assert (doc.document_element.child_nodes.length == 1);
+ assert (doc.document_element.child_nodes[0] is DomChildNode);
+ (doc.document_element.child_nodes[0] as DomChildNode).remove ();
+ assert (doc.document_element.child_nodes.length == 0);
+ assert ("<root/>" in doc.write_string ());
+ } catch (GLib.Error e) {
+ GLib.message ("Error: "+e.message);
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/gom-element/parsed-delayed", () => {
try {
var n = new ParsedDelayed ();
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index 3496f23..f6a6c73 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -1241,6 +1241,11 @@ class GomSerializationTest : GXmlTest {
var skeys1 = ops.map.get_secondary_keys ("a1");
foreach (string pk in skeys1) { message (pk); }
assert (skeys1.length () == 2);
+ op4.remove ();
+ ops.map.search ();
+ assert (ops.map.length == 3);
+ var op3t = ops.map.get ("a2", "b1");
+ assert (op3t != null);
} catch (GLib.Error e) {
GLib.message ("ERROR: "+e.message);
assert_not_reached ();
@@ -1293,6 +1298,10 @@ class GomSerializationTest : GXmlTest {
var skeys1 = ks.map.get_secondary_keys ("a1");
foreach (string pk in skeys1) { message (pk); }
assert (skeys1.length () == 2);
+ k4.remove ();
+ ks.map.search ();
+ var k3t = ks.map.get ("a2", "b1", "name3");
+ assert (k3t != null);
} catch (GLib.Error e) {
GLib.message ("ERROR: "+e.message);
assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]