summaryrefslogtreecommitdiff
path: root/json-glib/json-serializable.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@linux.intel.com>2009-11-12 12:38:29 +0000
committerEmmanuele Bassi <ebassi@linux.intel.com>2009-11-12 12:38:29 +0000
commit63dc03da507a216c0764bc0e50fc62b2b77dc1b2 (patch)
treeec233b1722658b2fe1aaae1bdf055fa034fc7203 /json-glib/json-serializable.c
parent5f484d8c274a2b866f9a3d38eebe2baa1939b7ac (diff)
downloadjson-glib-63dc03da507a216c0764bc0e50fc62b2b77dc1b2.tar.gz
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.
Diffstat (limited to 'json-glib/json-serializable.c')
-rw-r--r--json-glib/json-serializable.c92
1 files changed, 92 insertions, 0 deletions
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);
+}