[gtkmm] Use a BoolExpr typedef to make operator const void* clearer.



commit 7dff74cca47827d6e34bc8f239674bf044ddedaa
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Apr 4 11:38:25 2011 +0200

    Use a BoolExpr typedef to make operator const void* clearer.
    
    * gtk/gtkmm/stockid.[h|cc]:
    * gtk/src/iconinfo.hg:
    * gtk/src/papersize.hg:
    * gtk/src/textiter.hg:
    * gtk/src/treeiter.hg:
    * gtk/src/treepath.hg:
    * gtk/src/treerowreference.hg: Use a BoolExpr typedef and add documentation
    because not all people will know the purpose of operator const void*.
      This was suggested by Daniel Elstner.

 ChangeLog                   |   14 ++++++++++++++
 gtk/gtkmm/stockid.h         |   12 +++++++++++-
 gtk/src/iconinfo.hg         |   15 +++++++++++++--
 gtk/src/papersize.hg        |   13 ++++++++++++-
 gtk/src/textiter.hg         |   17 ++++++++++++++---
 gtk/src/treeiter.hg         |   39 ++++++++++++++++++++++++++++++++++++---
 gtk/src/treepath.hg         |   13 ++++++++++++-
 gtk/src/treerowreference.hg |   15 +++++++++++++--
 8 files changed, 125 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 70e9457..8535ad6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2011-04-04  Murray Cumming  <murrayc murrayc com>
 
+	Use a BoolExpr typedef to make operator const void* clearer.
+
+	* gtk/gtkmm/stockid.[h|cc]:
+	* gtk/src/iconinfo.hg:
+	* gtk/src/papersize.hg:
+	* gtk/src/textiter.hg:
+	* gtk/src/treeiter.hg:
+	* gtk/src/treepath.hg:
+	* gtk/src/treerowreference.hg: Use a BoolExpr typedef and add documentation
+	because not all people will know the purpose of operator const void*.
+  This was suggested by Daniel Elstner.
+
+2011-04-04  Murray Cumming  <murrayc murrayc com>
+
 	Remove RecentInfo::operator const void*.
 
 	* gtk/src/recentinfo.[hg|ccg]: Remove operator const void* (previously
diff --git a/gtk/gtkmm/stockid.h b/gtk/gtkmm/stockid.h
index 1d46dbc..f3ac943 100644
--- a/gtk/gtkmm/stockid.h
+++ b/gtk/gtkmm/stockid.h
@@ -68,9 +68,19 @@ public:
    */
   StockID& operator=(const StockID& other);
 
+  /** This typedef is just to make it more obvious that 
+   * our operator const void* should be used like operator bool().
+   */ 
+  typedef const void* BoolExpr;
+
   /** Tests whether the StockID is not empty.
+   * For instance,
+   * @code
+   * if(stockid)
+   *   do_something()
+   * @endcode
    */
-  operator const void*() const;
+  operator BoolExpr() const;
 
   /** Check if two StockIDs are equal.
    * @param rhs Another StockID.
diff --git a/gtk/src/iconinfo.hg b/gtk/src/iconinfo.hg
index 820b8a7..7a805d5 100644
--- a/gtk/src/iconinfo.hg
+++ b/gtk/src/iconinfo.hg
@@ -41,8 +41,19 @@ public:
   IconInfo(const Glib::RefPtr<IconTheme>& icon_theme, const Glib::RefPtr<Gdk::Pixbuf>& pixbuf);
   _IGNORE(gtk_icon_info_new_for_pixbuf)
 
-  ///Tests whether the IconInfo is valid.
-  operator const void*() const;
+  /** This typedef is just to make it more obvious that 
+   * our operator const void* should be used like operator bool().
+   */ 
+  typedef const void* BoolExpr;
+
+  /** Tests whether the IconInfo is valid.
+   * For instance,
+   * @code
+   * if(iconinfo)
+   *   do_something()
+   * @endcode
+   */
+  operator BoolExpr() const;
 
   _WRAP_METHOD(int get_base_size() const, gtk_icon_info_get_base_size)
   _WRAP_METHOD(Glib::ustring get_filename() const, gtk_icon_info_get_filename)
diff --git a/gtk/src/papersize.hg b/gtk/src/papersize.hg
index eff6304..3ce403f 100644
--- a/gtk/src/papersize.hg
+++ b/gtk/src/papersize.hg
@@ -68,10 +68,21 @@ public:
   _IGNORE(gtk_paper_size_copy, gtk_paper_size_free, gtk_paper_size_is_equal)
   bool equal(const PaperSize& other) const;
 
+  /** This typedef is just to make it more obvious that 
+   * our operator const void* should be used like operator bool().
+   */ 
+  typedef const void* BoolExpr;
+
   /** Returns true if the PaperSize is a valid object.
+   * For instance,
+   * @code
+   * if(papersize)
+   *   do_something()
+   * @endcode
+   *
    * @newin{2,12}
    */
-  operator const void*() const;
+  operator BoolExpr() 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 1cef6f6..e5acc04 100644
--- a/gtk/src/textiter.hg
+++ b/gtk/src/textiter.hg
@@ -75,8 +75,19 @@ public:
   /** Alias for get_char(). */
   inline value_type operator*() const;
 
-  /** Alias for !is_end(). */
-  inline operator const void*() const;
+  /** This typedef is just to make it more obvious that 
+   * our operator const void* should be used like operator bool().
+   */ 
+  typedef const void* BoolExpr;
+
+  /** Alias for !is_end()
+   * For instance,
+   * @code
+   * if(textiter)
+   *   do_something()
+   * @endcode
+   */
+  inline operator BoolExpr() const;
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 
@@ -325,7 +336,7 @@ TextIter::value_type TextIter::operator*() const
 }
 
 inline
-TextIter::operator const void*() const
+TextIter::operator BoolExpr() const
 {
   return (const void*)!is_end();
 }
diff --git a/gtk/src/treeiter.hg b/gtk/src/treeiter.hg
index 007291d..ebcbbbf 100644
--- a/gtk/src/treeiter.hg
+++ b/gtk/src/treeiter.hg
@@ -118,9 +118,19 @@ public:
 
   bool equal(const TreeIter& other) const;
 
+  /** This typedef is just to make it more obvious that 
+   * our operator const void* should be used like operator bool().
+   */ 
+  typedef const void* BoolExpr;
+
   /** Discover whether the iterator is valid, and not equal to end().
+   * For instance,
+   * @code
+   * if(treeiter)
+   *   do_something()
+   * @endcode
    */
-  operator const void*() const;
+  operator BoolExpr() 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.
@@ -286,9 +296,19 @@ public:
    */
   TreeIter parent() const;
 
+  /** This typedef is just to make it more obvious that 
+   * our operator const void* should be used like operator bool().
+   */ 
+  typedef const void* BoolExpr;
+
   /** Discover whether this is a valid row.
+   * For instance,
+   * @code
+   * if(treeiter)
+   *   do_something()
+   * @endcode
    */
-  operator const void*() const;
+  operator BoolExpr() const;
 
   /// Provides access to the underlying C GObject.  
   GtkTreeIter*       gobj()       { return TreeIter::gobj(); }
@@ -349,7 +369,20 @@ public:
 
   size_type size() const;
   bool empty() const;
-  operator const void*() const { return (const void*)!empty(); }
+
+  /** This typedef is just to make it more obvious that 
+   * our operator const void* should be used like operator bool().
+   */ 
+  typedef const void* BoolExpr;
+
+  /** Discover whether this is a valid TreeNodeChildren.
+   * For instance,
+   * @code
+   * if(children)
+   *   do_something()
+   * @endcode
+   */
+  operator BoolExpr() const { return (const void*)!empty(); }
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 
diff --git a/gtk/src/treepath.hg b/gtk/src/treepath.hg
index c9ecb7a..7fecef7 100644
--- a/gtk/src/treepath.hg
+++ b/gtk/src/treepath.hg
@@ -83,10 +83,21 @@ public:
   // I think it's OK for this assignment to be implicit.  It's very useful.
   TreePath& operator=(const TreeModel::iterator& iter);
 
+  /** This typedef is just to make it more obvious that 
+   * our operator const void* should be used like operator bool().
+   */ 
+  typedef const void* BoolExpr;
+
   /** Checks that the path is not empty, by calling empty().
+   * For instance,
+   * @code
+   * if(treepath)
+   *   do_something()
+   * @endcode
+   *
    * @newin{2,16}
    */
-  operator const void*() const;
+  operator BoolExpr() 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.hg b/gtk/src/treerowreference.hg
index 3736b3a..3b35bfd 100644
--- a/gtk/src/treerowreference.hg
+++ b/gtk/src/treerowreference.hg
@@ -39,8 +39,19 @@ class TreeRowReference
 public:
   TreeRowReference(const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path);
 
-  ///The same as is_valid().
-  operator const void*() const;
+  /** This typedef is just to make it more obvious that 
+   * our operator const void* should be used like operator bool().
+   */ 
+  typedef const void* BoolExpr;
+
+  /** The same as is_valid().
+   * For instance,
+   * @code
+   * if(treerowreference)
+   *   do_something()
+   * @endcode
+   */
+  operator BoolExpr() 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]