[json-glib] serializable: Add methods proxying default implementations



commit 63dc03da507a216c0764bc0e50fc62b2b77dc1b2
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Thu Nov 12 12:38:29 2009 +0000

    serializable: Add methods proxying default implementations
    
    If you want to use the default implementation of serialize_property()
    and/or deserialize_property() from an object class implementing
    JsonSerializable you currently have to peek the interface vtable and
    then call the vfunc pointers.
    
    We can expose the default implementation through functions ourselves and
    simplify the required code.

 doc/reference/json-glib-sections.txt |    4 ++
 json-glib/json-gobject.h             |   28 +++++++---
 json-glib/json-serializable.c        |   92 ++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+), 9 deletions(-)
---
diff --git a/doc/reference/json-glib-sections.txt b/doc/reference/json-glib-sections.txt
index e47c309..5d6ff06 100644
--- a/doc/reference/json-glib-sections.txt
+++ b/doc/reference/json-glib-sections.txt
@@ -199,6 +199,10 @@ JsonSerializableIface
 json_serializable_serialize_property
 json_serializable_deserialize_property
 
+<SUBSECTION>
+json_serializable_default_serialize_property
+json_serializable_default_deserialize_property
+
 <SUBSECTION Standard>
 JSON_TYPE_SERIALIZABLE
 JSON_SERIALIZABLE
diff --git a/json-glib/json-gobject.h b/json-glib/json-gobject.h
index 89e8957..69ae4e2 100644
--- a/json-glib/json-gobject.h
+++ b/json-glib/json-gobject.h
@@ -69,15 +69,25 @@ struct _JsonSerializableIface
 
 GType     json_serializable_get_type (void) G_GNUC_CONST;
 
-JsonNode *json_serializable_serialize_property   (JsonSerializable *serializable,
-                                                  const gchar      *property_name,
-                                                  const GValue     *value,
-                                                  GParamSpec       *pspec);
-gboolean  json_serializable_deserialize_property (JsonSerializable *serializable,
-                                                  const gchar      *property_name,
-                                                  GValue           *value,
-                                                  GParamSpec       *pspec,
-                                                  JsonNode         *property_node);
+JsonNode *json_serializable_serialize_property           (JsonSerializable *serializable,
+                                                          const gchar      *property_name,
+                                                          const GValue     *value,
+                                                          GParamSpec       *pspec);
+gboolean  json_serializable_deserialize_property         (JsonSerializable *serializable,
+                                                          const gchar      *property_name,
+                                                          GValue           *value,
+                                                          GParamSpec       *pspec,
+                                                          JsonNode         *property_node);
+
+JsonNode *json_serializable_default_serialize_property   (JsonSerializable *serializable,
+                                                          const gchar      *property_name,
+                                                          const GValue     *value,
+                                                          GParamSpec       *pspec);
+gboolean  json_serializable_default_deserialize_property (JsonSerializable *serializable,
+                                                          const gchar      *property_name,
+                                                          GValue           *value,
+                                                          GParamSpec       *pspec,
+                                                          JsonNode         *property_node);
 
 /**
  * JsonBoxedSerializeFunc:
diff --git a/json-glib/json-serializable.c b/json-glib/json-serializable.c
index 1f596e1..43ada37 100644
--- a/json-glib/json-serializable.c
+++ b/json-glib/json-serializable.c
@@ -155,3 +155,95 @@ json_serializable_get_type (void)
 
   return iface_type;
 }
+
+/**
+ * json_serializable_default_serialize_property:
+ * @serializable: a #JsonSerializable object
+ * @property_name: the name of the property
+ * @value: the value of the property
+ * @pspec: a #GParamSpec
+ *
+ * Calls the default implementation of the #JsonSerializable
+ * serialize_property() virtual function
+ *
+ * This function can be used inside a custom implementation
+ * of the serialize_property() virtual function in lieu of:
+ *
+ * |[
+ *   JsonSerializable *iface;
+ *   JsonNode *node;
+ *
+ *   iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
+ *   node = iface->serialize_property (serializable, property_name,
+ *                                     value,
+ *                                     pspec);
+ * ]|
+ *
+ * Return value: (transfer full): a #JsonNode containing the serialized
+ *   property
+ *
+ * Since: 0.10
+ */
+JsonNode *
+json_serializable_default_serialize_property (JsonSerializable *serializable,
+                                              const gchar      *property_name,
+                                              const GValue     *value,
+                                              GParamSpec       *pspec)
+{
+  g_return_val_if_fail (JSON_IS_SERIALIZABLE (serializable), NULL);
+  g_return_val_if_fail (property_name != NULL, NULL);
+  g_return_val_if_fail (value != NULL, NULL);
+  g_return_val_if_fail (pspec != NULL, NULL);
+
+  return json_serializable_real_serialize (serializable,
+                                           property_name,
+                                           value, pspec);
+}
+
+/**
+ * json_serializable_default_deserialize_property:
+ * @serializable: a #JsonSerializable
+ * @property_name: the name of the property
+ * @value: a pointer to an uninitialized #GValue
+ * @pspec: a #GParamSpec
+ * @property_node: a #JsonNode containing the serialized property
+ *
+ * Calls the default implementation of the #JsonSerializable
+ * deserialize_property() virtual function
+ *
+ * This function can be used inside a custom implementation
+ * of the deserialize_property() virtual function in lieu of:
+ *
+ * |[
+ *   JsonSerializable *iface;
+ *   gboolean res;
+ *
+ *   iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
+ *   res = iface->deserialize_property (serializable, property_name,
+ *                                      value,
+ *                                      pspec,
+ *                                      property_node);
+ * ]|
+ *
+ * Return value: %TRUE if the property was successfully deserialized.
+ *
+ * Since: 0.10
+ */
+gboolean
+json_serializable_default_deserialize_property (JsonSerializable *serializable,
+                                                const gchar      *property_name,
+                                                GValue           *value,
+                                                GParamSpec       *pspec,
+                                                JsonNode         *property_node)
+{
+  g_return_val_if_fail (JSON_IS_SERIALIZABLE (serializable), FALSE);
+  g_return_val_if_fail (property_name != NULL, FALSE);
+  g_return_val_if_fail (value != NULL, FALSE);
+  g_return_val_if_fail (pspec != NULL, FALSE);
+  g_return_val_if_fail (property_node != NULL, FALSE);
+
+  return json_serializable_real_deserialize (serializable,
+                                             property_name,
+                                             value, pspec,
+                                             property_node);
+}



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