[glibmm/glibmm-2-52] Glib::VariantType: Deprecate first() and next(). Add get_item_types()



commit 0fb72be491466cf4b20e90aea169d122b21858bd
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri May 5 16:01:27 2017 +0200

    Glib::VariantType: Deprecate first() and next(). Add get_item_types()
    
    Bug 775741

 glib/src/varianttype.ccg |   13 +++++++++++++
 glib/src/varianttype.hg  |   23 ++++++++++++++++++++---
 2 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/glib/src/varianttype.ccg b/glib/src/varianttype.ccg
index 8274c93..d4032c1 100644
--- a/glib/src/varianttype.ccg
+++ b/glib/src/varianttype.ccg
@@ -122,4 +122,17 @@ VariantType::get_string() const
 {
   return std::string(g_variant_type_peek_string(gobj()), g_variant_type_get_string_length(gobj()));
 }
+
+std::vector<VariantType> VariantType::get_item_types() const
+{
+  std::vector<VariantType> result;
+  auto next_item_type = g_variant_type_first(gobj());
+  while (next_item_type)
+  {
+    result.emplace_back(const_cast<GVariantType*>(next_item_type), true);
+    next_item_type = g_variant_type_next(next_item_type);
+  }
+  return result;
 }
+
+} // namespace GLib
diff --git a/glib/src/varianttype.hg b/glib/src/varianttype.hg
index 19327ab..0cac0fe 100644
--- a/glib/src/varianttype.hg
+++ b/glib/src/varianttype.hg
@@ -162,15 +162,32 @@ public:
   _WRAP_METHOD(bool is_subtype_of(const VariantType& supertype) const, g_variant_type_is_subtype_of)
 
 // It's necessary to take an extra reference of the 'const GVariantType*'
-// returned by g_variant_type_element() because it doesn't do that already.
+// returned by g_variant_type_element(), g_variant_type_key() and
+// g_variant_type_value() because they don't do that already.
 #m4 _CONVERSION(`const GVariantType*',`VariantType',`Glib::wrap(const_cast<GVariantType*>($3), true)')
   _WRAP_METHOD(VariantType element() const, g_variant_type_element)
-  _WRAP_METHOD(VariantType first() const, g_variant_type_first)
-  _WRAP_METHOD(VariantType next () const, g_variant_type_next)
+  _WRAP_METHOD(VariantType first() const, g_variant_type_first, deprecated "Use get_item_types() instead.")
+  _WRAP_METHOD(VariantType next () const, g_variant_type_next, deprecated "Use get_item_types() instead.")
   _WRAP_METHOD(gsize n_items() const, g_variant_type_n_items)
   _WRAP_METHOD(VariantType key() const, g_variant_type_key)
   _WRAP_METHOD(VariantType value() const, g_variant_type_value)
 
+  /** Determines the item types of a tuple or dictionary entry type.
+   *
+   * This function may only be used with tuple or dictionary entry types,
+   * but must not be used with the generic tuple type VARIANT_TYPE_TUPLE.
+   *
+   * In the case of a dictionary entry type, returns a vector with
+   * 2 elements, the type of the key followed by the value type.
+   *
+   * An empty vector is returned in case of this %VariantType being VARIANT_TYPE_UNIT.
+   *
+   * @newin{2,52}
+   *
+   * @return The item types of this %VariantType, or an empty vector.
+   */
+  std::vector<VariantType> get_item_types() const;
+
   // This function is part of unexposed API in gvarianttypeinfo.{h,c} for an
   // also unexposed GVariantTypeInfo structure of glib.
   _IGNORE(g_variant_type_info_get)


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