[gxml] * add support for detecthing duplicate objects at deserialisation
- From: Richard Hans Schwarting <rschwart src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] * add support for detecthing duplicate objects at deserialisation
- Date: Mon, 13 Aug 2012 19:52:31 +0000 (UTC)
commit cf5eda34ef85450ffa75e50e3a8c2ac82b758779
Author: Richard Schwarting <aquarichy gmail com>
Date: Mon Aug 13 15:50:23 2012 -0400
* add support for detecthing duplicate objects at deserialisation
gxml/Serialization.vala | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/gxml/Serialization.vala b/gxml/Serialization.vala
index f8ddf11..79ae485 100644
--- a/gxml/Serialization.vala
+++ b/gxml/Serialization.vala
@@ -192,6 +192,7 @@ namespace GXml {
root = doc.create_element ("Object");
doc.append_child (root);
root.set_attribute ("otype", object.get_type ().name ());
+ root.set_attribute ("oid", "%p".printf (object));
/* TODO: make sure we don't use an out param for our returned list
size in our interface's list_properties (), using
@@ -318,6 +319,7 @@ namespace GXml {
Element obj_elem;
string otype;
+ string oid;
Type type;
Object obj;
unowned ObjectClass obj_class;
@@ -327,6 +329,15 @@ namespace GXml {
obj_elem = (Element)node;
+ oid = obj_elem.get_attribute ("oid");
+
+ if (Serialization.cache == null) {
+ Serialization.cache = new HashTable<string,Object> (str_hash, str_equal);
+ }
+ if (Serialization.cache.contains (oid)) {
+ return Serialization.cache.get (oid);
+ }
+
// Get the object's type
// TODO: wish there was a g_object_class_from_name () method
otype = obj_elem.get_attribute ("otype");
@@ -339,6 +350,8 @@ namespace GXml {
obj = Object.newv (type, new Parameter[] {}); // TODO: causes problems with Enums when 0 isn't a valid enum value (e.g. starts from 2 or something)
obj_class = obj.get_class ();
+ cache.set (oid, obj);
+
if (type.is_a (typeof (Serializable))) {
serializable = (Serializable)obj;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]