[glibmm] Gio::AppInfo::get_all(): Use Glib::wrap_auto_interface()



commit 51d81a9ad4cb5383d938257edeb0e5261f76bd81
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Mon Jul 26 17:10:44 2021 +0200

    Gio::AppInfo::get_all(): Use Glib::wrap_auto_interface()
    
    Applies also to get_all_for_type().
    
    Make a complete specialization of Glib::Container_Helpers::TypeTraits for
    Glib::RefPtr<Gio::AppInfo>, calling Glib::wrap(GAppInfo*, bool) which uses
    Glib::wrap_auto_interface(). The partial specialization in
    containerhandle_shared.h calls Glib::wrap_auto(), which is not acceptable
    if the GAppInfo object does not already have a wrapper, and its class type
    has been wrapped in a C++ class (e.g. GWin32AppInfo or GOsxAppInfo).
    Fixes #94

 gio/src/appinfo.ccg | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
---
diff --git a/gio/src/appinfo.ccg b/gio/src/appinfo.ccg
index 5c4a7170..c0caaca1 100644
--- a/gio/src/appinfo.ccg
+++ b/gio/src/appinfo.ccg
@@ -19,6 +19,38 @@
 #include <giomm/slot_async.h>
 #include <gio/gio.h>
 
+namespace Glib
+{
+namespace Container_Helpers
+{
+/* Specialization for pointers to the GAppInfo interface.
+ * The partial specialization in glibmm/glib/glibmm/containerhandle_shared.h
+ * is not well suited for interfaces which do not already have a wrapper.
+ * Its to_cpp_type() calls Glib::wrap_auto() instead id Glib::wrap_auto_interface().
+ * This specialization is used by Glib::ListHandler<>::list_to_vector() in
+ * Gio::AppInfo::get_all() and Gio::AppInfo::get_all_for_type().
+ */
+template <>
+struct TypeTraits<Glib::RefPtr<Gio::AppInfo>>
+{
+  using T = Gio::AppInfo;
+  using CppType = Glib::RefPtr<T>;
+  using CType = typename T::BaseObjectType*;
+  using CTypeNonConst = typename T::BaseObjectType*;
+
+  static CType to_c_type(const CppType& ptr) { return Glib::unwrap(ptr); }
+  static CType to_c_type(CType ptr) { return ptr; }
+  static CppType to_cpp_type(CType ptr) { return Glib::wrap(ptr, true); }
+
+  static void release_c_type(CType ptr)
+  {
+    GLIBMM_DEBUG_UNREFERENCE(nullptr, ptr);
+    g_object_unref(ptr);
+  }
+};
+} // namespace Container_Helpers
+} // namespace Glib
+
 namespace Gio
 {
 


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