nsWeakRef
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 68 49c5ee4b50b4e29f7da5e637a83b47436455034d
permissions -rw-r--r--
State as of now

diff --git a/xpcom/glue/nsIWeakReferenceUtils.h b/xpcom/glue/nsIWeakReferenceUtils.h
--- a/xpcom/glue/nsIWeakReferenceUtils.h
+++ b/xpcom/glue/nsIWeakReferenceUtils.h
@@ -1,4 +1,4 @@
-/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
@@ -43,7 +43,48 @@
 #include "nsCOMPtr.h"
 #endif
 
-typedef nsCOMPtr<nsIWeakReference> nsWeakPtr;
+// XXXbsmedberg: this is a very thin wrapper for the old nsWeakPtr
+// we should really global-replace old stack instances of nsWeakPtr with
+// nsIWeakReference*
+
+struct nsWeakPtr
+{
+  nsWeakPtr(nsIWeakReference* weak = nsnull) : mWeak(weak) { }
+  ~nsWeakPtr() { }
+
+  nsIWeakReference* operator=(nsIWeakReference* weak)
+  {
+    return mWeak = weak;
+  }
+
+  nsIWeakReference* operator->() const
+  {
+    return mWeak;
+  }
+
+  operator nsIWeakReference*() const
+  {
+    return mWeak;
+  }
+
+  nsIWeakReference* get() const
+  {
+    return mWeak;
+  }
+
+  nsIWeakReference** operator&()
+  {
+    return &mWeak;
+  }
+
+private:
+  nsIWeakReference* mWeak;
+};
+
+inline nsIWeakReference** getter_AddRefs(nsWeakPtr &weak)
+{
+  return &weak;
+}
 
 /**
  *