[glibmm] RefPtr: Make it work with sorted containers (e.g. std::set<RefPtr<T> >).



commit 450deabc66956bd50def67fffcee6aa225ca792b
Author: David Kozub <zub linux fjfi cvut cz>
Date:   Wed Dec 22 23:20:24 2010 +0100

    RefPtr: Make it work with sorted containers (e.g. std::set<RefPtr<T> >).
    
    	* glib/glibmm/refptr.h: Add operators <, <=, >, >=
    	that compare RefPtrs by their underlying pointer.
    	This makes RefPtr work with sorted containers (e.g. std::set<RefPtr<T> >)

 ChangeLog            |   10 ++++++++++
 glib/glibmm/refptr.h |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fda4c42..25d4e14 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-08-10  David Kozub  <zub linux fjfi cvut cz>
+
+	RefPtr: Make it work with sorted containers (e.g. std::set<RefPtr<T> >).
+
+	* glib/glibmm/refptr.h: Add operators <, <=, >, >=
+	that compare RefPtrs by their underlying pointer.
+	This makes RefPtr work with sorted containers (e.g. std::set<RefPtr<T> >)
+
 2010-12-22  Yannick Guesnet  <Yannick Guesnet univ-rouen fr>
 
 	giomm: Application: Add the open signal.
@@ -5,6 +13,8 @@
 	* gio/src/application.[hg|ccg]: Add signal_open(), by hand-coding instead of 
 	using _WRAP_SIGNAL(), because we need to change the number of parameters.
 
+2.27.5:
+
 2010-12-22  Murray Cumming  <murrayc murrayc com>
 
 	Variant: Fix compiler warnings.
diff --git a/glib/glibmm/refptr.h b/glib/glibmm/refptr.h
index b262edd..f6312f0 100644
--- a/glib/glibmm/refptr.h
+++ b/glib/glibmm/refptr.h
@@ -155,6 +155,26 @@ public:
   template <class T_CastFrom>
   static inline RefPtr<T_CppObject> cast_const(const RefPtr<T_CastFrom>& src);
 
+  /** Compare based on the underlying instance address.
+   *
+   * This is needed in code that requires an ordering on
+   * RefPtr<T_CppObject> instances, e.g. std::set<RefPtr<T_CppObject> >.
+   *
+   * Without these, comparing two RefPtr<T_CppObject> instances
+   * is still syntactically possible, but the result is semantically
+   * wrong, as p1 REL_OP p2 is interpreted as (bool)p1 REL_OP (bool)p2.
+   */
+  inline bool operator<(const RefPtr<T_CppObject>& src) const;
+
+  /// See operator<().
+  inline bool operator<=(const RefPtr<T_CppObject>& src) const;
+
+  /// See operator<().
+  inline bool operator>(const RefPtr<T_CppObject>& src) const;
+
+  /// See operator<().
+  inline bool operator>=(const RefPtr<T_CppObject>& src) const;
+
 private:
   T_CppObject* pCppObject_;
 };
@@ -338,6 +358,30 @@ RefPtr<T_CppObject> RefPtr<T_CppObject>::cast_const(const RefPtr<T_CastFrom>& sr
   return RefPtr<T_CppObject>(pCppObject);
 }
 
+template <class T_CppObject> inline
+bool RefPtr<T_CppObject>::operator<(const RefPtr<T_CppObject>& src) const
+{
+  return (pCppObject_ < src.pCppObject_);
+}
+
+template <class T_CppObject> inline
+bool RefPtr<T_CppObject>::operator<=(const RefPtr<T_CppObject>& src) const
+{
+  return (pCppObject_ <= src.pCppObject_);
+}
+
+template <class T_CppObject> inline
+bool RefPtr<T_CppObject>::operator>(const RefPtr<T_CppObject>& src) const
+{
+  return (pCppObject_ > src.pCppObject_);
+}
+
+template <class T_CppObject> inline
+bool RefPtr<T_CppObject>::operator>=(const RefPtr<T_CppObject>& src) const
+{
+  return (pCppObject_ >= src.pCppObject_);
+}
+
 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
 /** @relates Glib::RefPtr */



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