ekiga r7383 - trunk/lib/gmref



Author: jpuydt
Date: Tue Nov 18 20:04:19 2008
New Revision: 7383
URL: http://svn.gnome.org/viewvc/ekiga?rev=7383&view=rev

Log:
Slight reorganization of the gmref_ptr code

Modified:
   trunk/lib/gmref/gmref.h

Modified: trunk/lib/gmref/gmref.h
==============================================================================
--- trunk/lib/gmref/gmref.h	(original)
+++ trunk/lib/gmref/gmref.h	Tue Nov 18 20:04:19 2008
@@ -70,58 +70,63 @@
 {
 public:
 
+  gmref_ptr ();
+
+  ~gmref_ptr ();
+
   explicit gmref_ptr (T* obj_);
 
-  gmref_ptr (const gmref_ptr<T>& ptr);
+  gmref_ptr (const gmref_ptr& ptr);
 
   template<typename Tprim> gmref_ptr (const gmref_ptr<Tprim>& ptr);
 
-  ~gmref_ptr ();
-
   gmref_ptr& operator= (const gmref_ptr& other);
 
   T* operator-> () const;
 
   T& operator* () const;
 
-  operator bool () const;
-
-  bool operator==(const gmref_ptr& other) const;
+  T* get () const;
 
-  bool operator!=(const gmref_ptr& other) const;
+  void reset ();
 
-  bool operator<(const gmref_ptr& other) const;
+  operator bool () const;
 
 private:
 
   template<typename Tprim> friend class gmref_ptr;
-  template<typename Tprim> friend void gmref_inc (gmref_ptr<Tprim> ptr);
-  template<typename Tprim> friend void gmref_dec (gmref_ptr<Tprim> ptr);
-
-  void reset ();
 
   T* obj;
 };
 
-/* extended api */
+template<typename T> bool operator==(const gmref_ptr<T>& a,
+				     const gmref_ptr<T>& b);
+
+template<typename T> bool operator!=(const gmref_ptr<T>& a,
+				     const gmref_ptr<T>& b);
+
+template<typename T> bool operator<(const gmref_ptr<T>& a,
+				    const gmref_ptr<T>& b);
+
+
+template<typename T> void gmref_inc (const gmref_ptr<T>& obj);
+template<typename T> void gmref_dec (const gmref_ptr<T>& obj);
+
+/* implementation of the templates */
 
 template<typename T>
-void gmref_inc (gmref_ptr<T> ptr)
+gmref_ptr<T>::gmref_ptr (): obj(0)
 {
-  gmref_inc (ptr.obj);
 }
 
 template<typename T>
-void gmref_dec (gmref_ptr<T> ptr)
+gmref_ptr<T>::~gmref_ptr ()
 {
-  gmref_dec (ptr.obj);
+  reset ();
 }
 
-
-/* implementation of the templates */
-
 template<typename T>
-gmref_ptr<T>::gmref_ptr (T* obj_ = 0): obj(obj_)
+gmref_ptr<T>::gmref_ptr (T* obj_): obj(obj_)
 {
   gmref_inc (obj);
 }
@@ -140,12 +145,6 @@
 }
 
 template<typename T>
-gmref_ptr<T>::~gmref_ptr ()
-{
-  reset ();
-}
-
-template<typename T>
 gmref_ptr<T>&
 gmref_ptr<T>::operator= (const gmref_ptr<T>& other)
 {
@@ -174,38 +173,59 @@
 }
 
 template<typename T>
+T*
+gmref_ptr<T>::get () const
+{
+  return obj;
+}
+
+template<typename T>
 gmref_ptr<T>::operator bool () const
 {
   return obj != 0;
 }
 
 template<typename T>
-bool
-gmref_ptr<T>::operator==(const gmref_ptr<T>& other) const
+void
+gmref_ptr<T>::reset ()
 {
-  return obj == other.obj;
+  gmref_dec (obj);
+  obj = 0;
 }
 
 template<typename T>
 bool
-gmref_ptr<T>::operator!=(const gmref_ptr<T>& other) const
+operator==(const gmref_ptr<T>& a,
+	   const gmref_ptr<T>& b)
 {
-  return !operator==(other);
+  return a.get () == b.get ();
+}
+
+template<typename T>
+bool operator!=(const gmref_ptr<T>& a,
+		const gmref_ptr<T>& b)
+{
+  return !operator==(a, b);
 }
 
 template<typename T>
 bool
-gmref_ptr<T>::operator<(const gmref_ptr<T>& other) const
+operator<(const gmref_ptr<T>& a,
+	  const gmref_ptr<T>& b)
 {
-  return obj < other.obj;
+  return a.get () < b.get ();
 }
 
 template<typename T>
-void
-gmref_ptr<T>::reset ()
+void gmref_inc (const gmref_ptr<T>& obj)
 {
-  gmref_dec (obj);
-  obj = 0;
+  gmref_inc (obj.get ());
+}
+
+template<typename T>
+void gmref_dec (const gmref_ptr<T>& obj)
+{
+  gmref_dec (obj.get ());
 }
 
 #endif



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