[glib] GVariant: add g_variant_default_value()



commit b205dc77cb14f67818eaac23d0eb3f5d1b867921
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Jun 16 15:56:51 2010 -0400

    GVariant: add g_variant_default_value()
    
    Returns various kinds of false, zero, empty arrays, etc.

 docs/reference/glib/glib-sections.txt |    1 +
 glib/glib.symbols                     |    1 +
 glib/gvariant.c                       |   32 ++++++++++++++++++++++++++++++--
 glib/gvariant.h                       |    1 +
 4 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index ec4892d..d4a5ece 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -2813,6 +2813,7 @@ g_variant_get_type_string
 g_variant_is_of_type
 g_variant_is_container
 g_variant_compare
+g_variant_default_value
 
 <SUBSECTION>
 g_variant_classify
diff --git a/glib/glib.symbols b/glib/glib.symbols
index cb1318f..ffc4d8e 100644
--- a/glib/glib.symbols
+++ b/glib/glib.symbols
@@ -1725,6 +1725,7 @@ g_variant_is_of_type
 g_variant_is_container
 g_variant_classify
 g_variant_compare
+g_variant_default_value
 
 g_variant_new_boolean
 g_variant_new_byte
diff --git a/glib/gvariant.c b/glib/gvariant.c
index 3b5fd8c..4ffa7e5 100644
--- a/glib/gvariant.c
+++ b/glib/gvariant.c
@@ -1377,7 +1377,7 @@ g_variant_dup_strv (GVariant *value,
   return strv;
 }
 
-/* Type checking and querying {{{1 */
+/* Type checking, querying, default value {{{1 */
 /**
  * g_variant_get_type:
  * @value: a #GVariant
@@ -1455,7 +1455,6 @@ g_variant_is_container (GVariant *value)
   return g_variant_type_is_container (g_variant_get_type (value));
 }
 
-
 /**
  * g_variant_classify:
  * @value: a #GVariant
@@ -1500,6 +1499,35 @@ g_variant_classify (GVariant *value)
   return *g_variant_get_type_string (value);
 }
 
+/**
+ * g_variant_default_value:
+ * @type: a definite #GVariantType
+ * @returns: a reference to a #GVariant of the requested type
+ *
+ * Returns the "default value" for @type.  The default boolean instance
+ * is false, the default value for any numeric type is (positive) zero,
+ * the default array is empty and the default maybe instance is Nothing.
+ * The default value for a tuple type is the tuple containing the
+ * default value for each child.  This is roughly equivalent to the
+ * values produced by the serialiser when it detects invalid data.
+ *
+ * Since: 2.26
+ **/
+GVariant *
+g_variant_default_value (const GVariantType *type)
+{
+  GVariant *broken, *fixed;
+
+  g_return_val_if_fail (g_variant_type_is_definite (type), NULL);
+
+  /* let the serialiser figure it out */
+  broken = g_variant_new_from_data (type, NULL, 0, FALSE, NULL, NULL);
+  fixed = g_variant_get_normal_form (broken);
+  g_variant_unref (broken);
+
+  return fixed;
+}
+
 /* Pretty printer {{{1 */
 /**
  * g_variant_print_string:
diff --git a/glib/gvariant.h b/glib/gvariant.h
index e4a80c0..87bf588 100644
--- a/glib/gvariant.h
+++ b/glib/gvariant.h
@@ -62,6 +62,7 @@ gboolean                        g_variant_is_of_type                    (GVarian
                                                                          const GVariantType   *type);
 gboolean                        g_variant_is_container                  (GVariant             *value);
 GVariantClass                   g_variant_classify                      (GVariant             *value);
+GVariant *                      g_variant_default_value                 (const GVariantType   *type);
 GVariant *                      g_variant_new_boolean                   (gboolean              boolean);
 GVariant *                      g_variant_new_byte                      (guchar                byte);
 GVariant *                      g_variant_new_int16                     (gint16                int16);



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