[gtkmm] C++11: Deprecate operator void*(), replacing them with explicit operator bool().



commit 6663c5e81de3912b553a9d767f0d843710bd4686
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Apr 10 15:43:34 2016 +0200

    C++11: Deprecate operator void*(), replacing them with explicit operator bool().
    
    See https://bugzilla.gnome.org/show_bug.cgi?id=626858#c4

 gtk/src/iconinfo.ccg         |    7 ++++++
 gtk/src/iconinfo.hg          |   12 +++++++++++
 gtk/src/papersize.ccg        |    9 +++++++-
 gtk/src/papersize.hg         |   17 +++++++++++++++
 gtk/src/textiter.hg          |   25 +++++++++++++++++++++++
 gtk/src/treeiter.ccg         |   16 ++++++++++++++
 gtk/src/treeiter.hg          |   45 ++++++++++++++++++++++++++++++++++++++++++
 gtk/src/treepath.ccg         |    7 ++++++
 gtk/src/treepath.hg          |   17 +++++++++++++++
 gtk/src/treerowreference.ccg |    7 ++++++
 gtk/src/treerowreference.hg  |   17 +++++++++++++++
 11 files changed, 178 insertions(+), 1 deletions(-)
---
diff --git a/gtk/src/iconinfo.ccg b/gtk/src/iconinfo.ccg
index 3dfd10d..cfdff73 100644
--- a/gtk/src/iconinfo.ccg
+++ b/gtk/src/iconinfo.ccg
@@ -77,10 +77,17 @@ std::vector<Gdk::Point> IconInfo::get_attach_points() const
 G_GNUC_END_IGNORE_DEPRECATIONS
 _DEPRECATE_IFDEF_END
 
+_DEPRECATE_IFDEF_START
 IconInfo::operator const void*() const
 {
   return gobj() ? GINT_TO_POINTER(1) : nullptr;
 }
+_DEPRECATE_IFDEF_END
+
+IconInfo::operator bool() const
+{
+  return gobj();
+}
 
 
 Glib::RefPtr<Gdk::Pixbuf> IconInfo::load_symbolic(const Gdk::RGBA& fg, const Gdk::RGBA& success_color, const 
Gdk::RGBA& warning_color, const Gdk::RGBA& error_color, bool& was_symbolic) const
diff --git a/gtk/src/iconinfo.hg b/gtk/src/iconinfo.hg
index 9403221..ba56958 100644
--- a/gtk/src/iconinfo.hg
+++ b/gtk/src/iconinfo.hg
@@ -41,8 +41,11 @@ public:
   IconInfo(const Glib::RefPtr<IconTheme>& icon_theme, const Glib::RefPtr<Gdk::Pixbuf>& pixbuf);
   _IGNORE(gtk_icon_info_new_for_pixbuf)
 
+_DEPRECATE_IFDEF_START
   /** This typedef is just to make it more obvious that
    * our operator const void* should be used like operator bool().
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   typedef const void* BoolExpr;
 
@@ -52,8 +55,17 @@ public:
    * if(iconinfo)
    *   do_something()
    * @endcode
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   operator BoolExpr() const;
+_DEPRECATE_IFDEF_END
+
+   /** Tests whether the IconInfo is valid.
+    *
+    * @newin{3,22}
+    */
+   explicit operator bool() const;
 
   _WRAP_METHOD(int get_base_size() const, gtk_icon_info_get_base_size)
   _WRAP_METHOD(int get_base_scale() const, gtk_icon_info_get_base_scale)
diff --git a/gtk/src/papersize.ccg b/gtk/src/papersize.ccg
index c0c1bf7..0bc106b 100644
--- a/gtk/src/papersize.ccg
+++ b/gtk/src/papersize.ccg
@@ -57,7 +57,7 @@ PaperSize::PaperSize(const Glib::ustring& name, const Glib::ustring& display_nam
                                      GtkUnit(unit)))
 {}
 
-//TODO: Add an operator const void*() so we can detect if this succeeded:
+//TODO: Add an operator bool() so we can detect if this succeeded:
 //TODO: No, throw the error/exception instead.
 PaperSize::PaperSize(const Glib::KeyFile& key_file, const Glib::ustring& group_name)
 :
@@ -70,10 +70,17 @@ bool PaperSize::equal(const PaperSize& other) const
                                                     const_cast<GtkPaperSize*>(other.gobj()))));
 }
 
+_DEPRECATE_IFDEF_START
 PaperSize::operator const void*() const
 {
   return gobj() ? GINT_TO_POINTER(1) : nullptr;
 }
+_DEPRECATE_IFDEF_END
+
+PaperSize::operator bool() const
+{
+  return gobj();
+}
 
 void PaperSize::save_to_key_file(Glib::KeyFile& key_file)
 {
diff --git a/gtk/src/papersize.hg b/gtk/src/papersize.hg
index 28ac9a3..01e9947 100644
--- a/gtk/src/papersize.hg
+++ b/gtk/src/papersize.hg
@@ -68,8 +68,11 @@ public:
   _IGNORE(gtk_paper_size_copy, gtk_paper_size_free, gtk_paper_size_is_equal)
   bool equal(const PaperSize& other) const;
 
+_DEPRECATE_IFDEF_START
   /** This typedef is just to make it more obvious that
    * our operator const void* should be used like operator bool().
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   typedef const void* BoolExpr;
 
@@ -80,9 +83,23 @@ public:
    *   do_something()
    * @endcode
    *
+   * @deprecated Use the explicit operator bool() instead.
+   *
    * @newin{2,12}
    */
   operator BoolExpr() const;
+_DEPRECATE_IFDEF_END
+
+   /** Returns true if the PaperSize is a valid object.
+    * For instance,
+    * @code
+    * if(papersize)
+    *   do_something()
+    * @endcode
+    *
+    * @newin{3,22}
+    */
+   explicit operator bool() const;
 
   #m4 _CONVERSION(`GList*', `std::vector<PaperSize>',`Glib::ListHandler<PaperSize, 
PaperSizeTraits>::list_to_vector($3, Glib::OWNERSHIP_DEEP)')
   _WRAP_METHOD(static std::vector<PaperSize> get_paper_sizes(bool include_custom = true), 
gtk_paper_size_get_paper_sizes)
diff --git a/gtk/src/textiter.hg b/gtk/src/textiter.hg
index d35b063..341e45b 100644
--- a/gtk/src/textiter.hg
+++ b/gtk/src/textiter.hg
@@ -74,8 +74,11 @@ public:
   /** Alias for get_char(). */
   inline value_type operator*() const;
 
+_DEPRECATE_IFDEF_START
   /** This typedef is just to make it more obvious that
    * our operator const void* should be used like operator bool().
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   typedef const void* BoolExpr;
 
@@ -85,8 +88,22 @@ public:
    * if(textiter)
    *   do_something()
    * @endcode
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   inline operator BoolExpr() const;
+_DEPRECATE_IFDEF_END
+
+   /** Alias for !is_end()
+   * For instance,
+   * @code
+   * if(textiter)
+   *   do_something()
+   * @endcode
+    *
+    * @newin{3,22}
+    */
+   explicit operator bool() const;
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 
@@ -341,11 +358,19 @@ TextIter::value_type TextIter::operator*() const
   return get_char();
 }
 
+_DEPRECATE_IFDEF_START
 inline
 TextIter::operator BoolExpr() const
 {
   return !is_end() ? GINT_TO_POINTER(1) : nullptr;
 }
+_DEPRECATE_IFDEF_END
+
+inline
+TextIter::operator bool() const
+{
+  return !is_end();
+}
 
 template <class Predicate>
 bool TextIter::forward_find_char(const Predicate& predicate, const TextIter& limit)
diff --git a/gtk/src/treeiter.ccg b/gtk/src/treeiter.ccg
index e415a4b..c808e75 100644
--- a/gtk/src/treeiter.ccg
+++ b/gtk/src/treeiter.ccg
@@ -134,6 +134,7 @@ bool TreeIter::equal(const TreeIter& other) const
          (gobject_.user_data3 == other.gobject_.user_data3);
 }
 
+_DEPRECATE_IFDEF_START
 TreeIter::operator const void*() const
 {
   // Test whether the GtkTreeIter is valid and not an end iterator.  This check
@@ -141,6 +142,15 @@ TreeIter::operator const void*() const
   // gtktreestore.c.
   return (!is_end_ && gobject_.stamp) ? GINT_TO_POINTER(1) : nullptr;
 }
+_DEPRECATE_IFDEF_END
+
+TreeIter::operator bool() const
+{
+  // Test whether the GtkTreeIter is valid and not an end iterator.  This check
+  // is almost the same as the private VALID_ITER() macro in gtkliststore.c and
+  // gtktreestore.c.
+  return !is_end_ && gobject_.stamp;
+}
 
 void TreeIter::setup_end_iterator(const TreeIter& last_valid)
 {
@@ -212,12 +222,18 @@ void TreeRow::get_value_impl(int column, Glib::ValueBase& value) const
   model_->get_value_impl(*this, column, value);
 }
 
+_DEPRECATE_IFDEF_START
 TreeRow::operator const void*() const
 {
   return TreeIter::operator const void*();
 }
+_DEPRECATE_IFDEF_END
 
+TreeRow::operator bool() const
+{
+  return TreeIter::operator bool();
 
+}
 /**** Gtk::TreeNodeChildren ************************************************/
 
 TreeNodeChildren::iterator TreeNodeChildren::begin()
diff --git a/gtk/src/treeiter.hg b/gtk/src/treeiter.hg
index 544fe1f..a6a5b0e 100644
--- a/gtk/src/treeiter.hg
+++ b/gtk/src/treeiter.hg
@@ -119,8 +119,11 @@ public:
 
   bool equal(const TreeIter& other) const;
 
+_DEPRECATE_IFDEF_START
   /** This typedef is just to make it more obvious that
    * our operator const void* should be used like operator bool().
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   typedef const void* BoolExpr;
 
@@ -130,8 +133,22 @@ public:
    * if(treeiter)
    *   do_something()
    * @endcode
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   operator BoolExpr() const;
+_DEPRECATE_IFDEF_END
+
+  /** Discover whether the iterator is valid, and not equal to end().
+   * For instance,
+   * @code
+   * if(treeiter)
+   *   do_something()
+   * @endcode
+   *
+   * @newin{3,22}
+   */
+  explicit operator bool() const;
 
   /** This is only useful when implementing a custom Gtk::TreeModel class.
    * Compare the iterator's stamp with your model's stamp to discover whether it is valid.
@@ -297,8 +314,11 @@ public:
    */
   TreeIter parent() const;
 
+_DEPRECATE_IFDEF_START
   /** This typedef is just to make it more obvious that
    * our operator const void* should be used like operator bool().
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   typedef const void* BoolExpr;
 
@@ -308,8 +328,22 @@ public:
    * if(treeiter)
    *   do_something()
    * @endcode
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   operator BoolExpr() const;
+_DEPRECATE_IFDEF_END
+
+  /** Discover whether this is a valid row.
+   * For instance,
+   * @code
+   * if(treeiter)
+   *   do_something()
+   * @endcode
+   *
+   * @newin{3,22}
+   */
+  explicit operator bool() const;
 
   /// Provides access to the underlying C GObject.
   GtkTreeIter*       gobj()       { return TreeIter::gobj(); }
@@ -371,8 +405,11 @@ public:
   size_type size() const;
   bool empty() const;
 
+_DEPRECATE_IFDEF_START
   /** This typedef is just to make it more obvious that
    * our operator const void* should be used like operator bool().
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   typedef const void* BoolExpr;
 
@@ -382,11 +419,19 @@ public:
    * if(children)
    *   do_something()
    * @endcode
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   operator BoolExpr() const
   {
     return !empty() ? GINT_TO_POINTER(1) : nullptr;
   }
+_DEPRECATE_IFDEF_END
+
+  explicit operator bool() const
+  {
+    return !empty();
+  }
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 
diff --git a/gtk/src/treepath.ccg b/gtk/src/treepath.ccg
index a3cbe8d..6b5d327 100644
--- a/gtk/src/treepath.ccg
+++ b/gtk/src/treepath.ccg
@@ -75,10 +75,17 @@ TreePath::size_type TreePath::size() const
   return gtk_tree_path_get_depth(gobject_);
 }
 
+_DEPRECATE_IFDEF_START
 TreePath::operator const void*() const
 {
   return !empty() ? GINT_TO_POINTER(1) : nullptr;
 }
+_DEPRECATE_IFDEF_END
+
+TreePath::operator bool() const
+{
+  return !empty();
+}
 
 bool TreePath::empty() const
 {
diff --git a/gtk/src/treepath.hg b/gtk/src/treepath.hg
index 452d314..233de94 100644
--- a/gtk/src/treepath.hg
+++ b/gtk/src/treepath.hg
@@ -87,8 +87,11 @@ public:
   // I think it's OK for this assignment to be implicit.  It's very useful.
   TreePath& operator=(const TreeModel::iterator& iter);
 
+_DEPRECATE_IFDEF_START
   /** This typedef is just to make it more obvious that
    * our operator const void* should be used like operator bool().
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   typedef const void* BoolExpr;
 
@@ -99,9 +102,23 @@ public:
    *   do_something()
    * @endcode
    *
+   * @deprecated Use the explicit operator bool() instead.
+   *
    * @newin{2,16}
    */
   operator BoolExpr() const;
+_DEPRECATE_IFDEF_END
+
+  /** Checks that the path is not empty, by calling empty().
+   * For instance,
+   * @code
+   * if(treepath)
+   *   do_something()
+   * @endcode
+   *
+   * @newin{3,22}
+   */
+  explicit operator bool() const;
 
   template <class In> inline void assign(In pbegin, In pend);
   template <class In>        void append(In pbegin, In pend);
diff --git a/gtk/src/treerowreference.ccg b/gtk/src/treerowreference.ccg
index 617f3b7..83641f4 100644
--- a/gtk/src/treerowreference.ccg
+++ b/gtk/src/treerowreference.ccg
@@ -26,10 +26,17 @@ TreeRowReference::TreeRowReference(const Glib::RefPtr<TreeModel>& model, const T
   gobject_ ( gtk_tree_row_reference_new(model->gobj(), const_cast<GtkTreePath*>(path.gobj())) )
 {}
 
+_DEPRECATE_IFDEF_START
 TreeRowReference::operator const void*() const
 {
   return is_valid() ? GINT_TO_POINTER(1) : nullptr;
 }
+_DEPRECATE_IFDEF_END
+
+TreeRowReference::operator bool() const
+{
+  return is_valid();
+}
 
 } // namespace Gtk
 
diff --git a/gtk/src/treerowreference.hg b/gtk/src/treerowreference.hg
index 0333b4c..e0edf80 100644
--- a/gtk/src/treerowreference.hg
+++ b/gtk/src/treerowreference.hg
@@ -38,8 +38,11 @@ class TreeRowReference
 public:
   TreeRowReference(const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path);
 
+_DEPRECATE_IFDEF_START
   /** This typedef is just to make it more obvious that
    * our operator const void* should be used like operator bool().
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   typedef const void* BoolExpr;
 
@@ -49,8 +52,22 @@ public:
    * if(treerowreference)
    *   do_something()
    * @endcode
+   *
+   * @deprecated Use the explicit operator bool() instead.
    */
   operator BoolExpr() const;
+_DEPRECATE_IFDEF_END
+
+  /** The same as is_valid().
+   * For instance,
+   * @code
+   * if(treerowreference)
+   *   do_something()
+   * @endcode
+   *
+   * @newin{3,22}
+   */
+  explicit operator bool() const;
 
   _WRAP_METHOD(TreeModel::Path get_path() const,  gtk_tree_row_reference_get_path)
 


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