[gtkmm] TreePath: All constructors guarantee that gobject_ != 0.



commit 9ee7dceee345bf4adb8b0ffec623859d02227225
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Thu Apr 5 18:09:13 2012 +0200

    TreePath: All constructors guarantee that gobject_ != 0.
    
    * gtk/src/treepath.[hg|ccg]: Use the new m4 macro _CUSTOM_CTOR_CAST.
    Hand-coded constructors never construct an object with gobject_ == 0.
    This requires the latest glibmm from git master. Bug #511136, comment 21.

 ChangeLog            |    8 ++++++++
 gtk/src/treepath.ccg |   21 ++++++++++++++++-----
 gtk/src/treepath.hg  |    2 ++
 3 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e0da5fc..c88d2cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-04-05  Kjell Ahlstedt  <kjell ahlstedt bredband net>
+
+	TreePath: All constructors guarantee that gobject_ != 0.
+
+	* gtk/src/treepath.[hg|ccg]: Use the new m4 macro _CUSTOM_CTOR_CAST.
+	Hand-coded constructors never construct an object with gobject_ == 0.
+	This requires the latest glibmm from git master. Bug #511136, comment 21.
+
 2012-04-10  Adrian Bunk <bunk stusta de>
 
 	Remove the Maemo Extensions API.
diff --git a/gtk/src/treepath.ccg b/gtk/src/treepath.ccg
index 4684eb8..cfd03b8 100644
--- a/gtk/src/treepath.ccg
+++ b/gtk/src/treepath.ccg
@@ -26,6 +26,14 @@
 namespace Gtk
 {
 
+TreePath::TreePath(GtkTreePath* gobject, bool make_a_copy)
+:
+  // For BoxedType wrappers, make_a_copy is true by default.  The static
+  // BoxedType wrappers must always take a copy, thus make_a_copy = true
+  // ensures identical behaviour if the default argument is used.
+  gobject_ (gobject ? (make_a_copy ? gtk_tree_path_copy(gobject) : gobject) : gtk_tree_path_new())
+{}
+
 TreePath::TreePath(TreePath::size_type n, TreePath::value_type value)
 :
   gobject_(gtk_tree_path_new())
@@ -37,13 +45,19 @@ TreePath::TreePath(TreePath::size_type n, TreePath::value_type value)
 TreePath::TreePath(const Glib::ustring& path)
 :
   gobject_ (gtk_tree_path_new_from_string(path.c_str()))
-{}
+{
+  if (!gobject_)
+    gobject_ = gtk_tree_path_new();
+}
 
 TreePath::TreePath(const TreeModel::iterator& iter)
 :
   // The GtkTreePath* is always newly created.
   gobject_ (gtk_tree_model_get_path(iter.get_model_gobject(), const_cast<GtkTreeIter*>(iter.gobj())))
-{}
+{
+  if (!gobject_)
+    gobject_ = gtk_tree_path_new();
+}
 
 TreePath& TreePath::operator=(const TreeModel::iterator& iter)
 {
@@ -70,9 +84,6 @@ TreePath::operator const void*() const
 
 bool TreePath::empty() const
 {
-  if(!gobject_)
-    return true;
-
   return (gtk_tree_path_get_depth(gobject_) == 0);
 }
 
diff --git a/gtk/src/treepath.hg b/gtk/src/treepath.hg
index c95827a..0687810 100644
--- a/gtk/src/treepath.hg
+++ b/gtk/src/treepath.hg
@@ -72,6 +72,8 @@ public:
 
 #endif /* GLIBMM_HAVE_SUN_REVERSE_ITERATOR */
 
+  _CUSTOM_CTOR_CAST()
+  explicit TreePath(GtkTreePath* gobject, bool make_a_copy = true);
   explicit TreePath(size_type n, value_type value = 0);
   explicit TreePath(const Glib::ustring& path);
   explicit TreePath(const TreeModel::iterator& iter);



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