[glibmm] Remove Glib::WeakRef



commit 650453a800e6c3ad0c934ce2675298a7d90cc6b8
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Dec 11 20:57:37 2016 +0100

    Remove Glib::WeakRef
    
    Now that RefPtr is really a std::shared_ptr<>, we should use
    std::weak_ref<> instead.
    
    Note that a std::weak_ptr<> tells you nothing about whether
    the underlying GObject is still alive, which Glib::RefPtr did.
    It just tells you whether our std::shared_ptr<> still holds
    a reference to it. That's why I removed one of the checks in
    tests/giomm_listmodel/main.cc.

 glib/glibmm.h                 |    1 -
 glib/glibmm/filelist.am       |    1 -
 glib/glibmm/object.cc         |   22 --
 glib/glibmm/weakref.h         |  463 -----------------------------------------
 tests/Makefile.am             |    1 -
 tests/giomm_listmodel/main.cc |   30 +--
 tests/glibmm_weakref/main.cc  |  165 ---------------
 7 files changed, 10 insertions(+), 673 deletions(-)
---
diff --git a/glib/glibmm.h b/glib/glibmm.h
index 1b2b2db..a9e90e0 100644
--- a/glib/glibmm.h
+++ b/glib/glibmm.h
@@ -140,7 +140,6 @@
 #include <glibmm/variantiter.h>
 #include <glibmm/varianttype.h>
 #include <glibmm/vectorutils.h>
-#include <glibmm/weakref.h>
 #include <glibmm/wrap.h>
 
 #endif /* _GLIBMM_H */
diff --git a/glib/glibmm/filelist.am b/glib/glibmm/filelist.am
index 10964e6..d0aeaf0 100644
--- a/glib/glibmm/filelist.am
+++ b/glib/glibmm/filelist.am
@@ -71,7 +71,6 @@ glibmm_files_extra_h =                        \
        value.h                         \
        value_custom.h                  \
        vectorutils.h                   \
-       weakref.h                       \
        wrap.h                          \
        wrap_init.h
 
diff --git a/glib/glibmm/object.cc b/glib/glibmm/object.cc
index 173d30e..58166b7 100644
--- a/glib/glibmm/object.cc
+++ b/glib/glibmm/object.cc
@@ -27,28 +27,6 @@
 
 #include <string.h>
 
-// Weak references:
-// I'm not sure what the point of these are apart from being a hacky way out of circular references,
-// but maybe we could make it easier to use them by making a Java Reference Object -style class like
-// so:
-// Glib::WeakRef<SomeDerivedObject> weakrefSomeObject(object1);
-// ...
-// if(weakrefSomeObject->isStillAlive())
-// {
-//   weakrefSomeObject->some_method();
-// }
-// else
-// {
-//   //Deal with it, maybe recreating the object.
-// }
-//
-// Without this, the coder has to define his own signal handler which sets his own isStillAlive
-// boolean.
-// weakrefSomeObject<> could still have its own signal_destroyed signal so that coders can choose to
-// deal
-// with the destruction as soon as it happens instead of just checking later before they try to use
-// it.
-
 namespace Glib
 {
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a3d7803..1955a42 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -45,7 +45,6 @@ check_PROGRAMS =                              \
        glibmm_null_vectorutils/test            \
        glibmm_refptr/test              \
        glibmm_refptr_sigc_bind/test            \
-       glibmm_weakref/test             \
        glibmm_bytearray/test                   \
        glibmm_ustring_make_valid/test
 
diff --git a/tests/giomm_listmodel/main.cc b/tests/giomm_listmodel/main.cc
index cd8667d..1024a05 100644
--- a/tests/giomm_listmodel/main.cc
+++ b/tests/giomm_listmodel/main.cc
@@ -39,7 +39,7 @@ void test_store_boundaries()
 {
   auto store = Gio::ListStore<Gio::MenuItem>::create();
   auto item = Gio::MenuItem::create("", "");
-  auto weakref_item = Glib::WeakRef<Gio::MenuItem>(item);
+  std::weak_ptr<Gio::MenuItem> weakref_item = item;
 
   // Remove an item from an empty list.
   store->remove(0);
@@ -84,7 +84,7 @@ void test_store_boundaries()
 
   store.reset();
   item.reset();
-  if (weakref_item)
+  if (weakref_item.lock())
   {
     result = EXIT_FAILURE;
     std::cerr << "test_store_boundaries(), 10: weakref_item is not null" << std::endl;
@@ -116,16 +116,16 @@ void test_store_refcounts()
 
   const std::size_t n_items = 10;
   std::vector<Glib::RefPtr<Gio::MenuItem>> items;
-  std::vector<Glib::WeakRef<Gio::MenuItem>> weakref_items;
+  std::vector<std::weak_ptr<Gio::MenuItem>> weakref_items;
   for (std::size_t i = 0; i < n_items; ++i)
   {
     items.push_back(Gio::MenuItem::create("", ""));
-    weakref_items.push_back(Glib::WeakRef<Gio::MenuItem>(items[i]));
+    weakref_items.emplace_back(items[i]);
     store->append(items[i]);
   }
   check_store_refcounts_n_items(2, store, n_items);
 
-  if (store->get_item(3).operator->() != items[3].operator->())
+  if (store->get_item(3).get() != items[3].get())
   {
     result = EXIT_FAILURE;
     std::cerr << "test_store_refcounts(), 3: get_item(3) != items[3]" << std::endl;
@@ -134,25 +134,15 @@ void test_store_refcounts()
   for (std::size_t i = 0; i < n_items; ++i)
   {
     items[i].reset();
-    if (!weakref_items[i])
-    {
-      result = EXIT_FAILURE;
-      std::cerr << "test_store_refcounts(), 4: weakref_items[" << i << "] is null" << std::endl;
-    }
   }
 
   store->remove(4);
-  if (weakref_items[4])
-  {
-    result = EXIT_FAILURE;
-    std::cerr << "test_store_refcounts(), 5: weakref_items[4] is not null" << std::endl;
-  }
   check_store_refcounts_n_items(6, store, n_items-1);
 
   store.reset();
   for (std::size_t i = 0; i < n_items; ++i)
   {
-    if (weakref_items[i])
+    if (weakref_items[i].lock())
     {
       result = EXIT_FAILURE;
       std::cerr << "test_store_refcounts(), 7: weakref_items[" << i << "] is not null" << std::endl;
@@ -228,7 +218,7 @@ void test_store_sorted1()
       result = EXIT_FAILURE;
       std::cerr << "test_store_sorted1(), 2: i=" << i << ", items are not equal" << std::endl;
     }
-    if (a.operator->() == b.operator->())
+    if (a.get() == b.get())
     {
       result = EXIT_FAILURE;
       std::cerr << "test_store_sorted1(), 3: i=" << i << ", items are the same" << std::endl;
@@ -237,7 +227,7 @@ void test_store_sorted1()
     if (i > 0)
     {
       auto c = store->get_item(i * 2 - 1);
-      if (c.operator->() == a.operator->() || c.operator->() == b.operator->())
+      if (c.get() == a.get() || c.get() == b.get())
       {
         result = EXIT_FAILURE;
         std::cerr << "test_store_sorted1(), 4: i=" << i << ", items are the same" << std::endl;
@@ -311,7 +301,7 @@ void test_store_sorted2()
       result = EXIT_FAILURE;
       std::cerr << "test_store_sorted2(), 2: i=" << i << ", items are not equal" << std::endl;
     }
-    if (a.operator->() == b.operator->())
+    if (a.get() == b.get())
     {
       result = EXIT_FAILURE;
       std::cerr << "test_store_sorted2(), 3: i=" << i << ", items are the same" << std::endl;
@@ -320,7 +310,7 @@ void test_store_sorted2()
     if (i > 0)
     {
       auto c = store->get_item(i * 2 - 1);
-      if (c.operator->() == a.operator->() || c.operator->() == b.operator->())
+      if (c.get() == a.get() || c.get() == b.get())
       {
         result = EXIT_FAILURE;
         std::cerr << "test_store_sorted2(), 4: i=" << i << ", items are the same" << std::endl;


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