]> git.saurik.com Git - apt.git/commitdiff
* apt-pkg/contrib/weakptr.h:
authorJulian Andres Klode <jak@debian.org>
Tue, 4 May 2010 15:05:23 +0000 (17:05 +0200)
committerJulian Andres Klode <jak@debian.org>
Tue, 4 May 2010 15:05:23 +0000 (17:05 +0200)
  - add a class WeakPointable which allows one to register weak pointers to
    an object which will be set to NULL when the object is deallocated.
* [ABI break] apt-pkg/acquire{-worker,-item,}.h:
  - subclass pkgAcquire::{Worker,Item,ItemDesc} from WeakPointable.

apt-pkg/acquire-item.h
apt-pkg/acquire-worker.h
apt-pkg/acquire.h
apt-pkg/contrib/weakptr.h [new file with mode: 0644]
apt-pkg/makefile
debian/changelog

index bafa8263a8f38fe7ed7d2c2702bedd07d71caef8..b338b2a4199f9fe60cc437b2e298876a171e291c 100644 (file)
@@ -27,6 +27,7 @@
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/indexrecords.h>
 #include <apt-pkg/hashes.h>
+#include <apt-pkg/weakptr.h>
 
 /** \addtogroup acquire
  *  @{
@@ -46,7 +47,7 @@
  *
  *  \see pkgAcquire
  */
-class pkgAcquire::Item
+class pkgAcquire::Item : public WeakPointable
 {  
    protected:
    
index 2942df69fd8460ff8a81df14912c94277e25b21e..06283922e5e4dbe41c951b083d2eefd866ee68e7 100644 (file)
@@ -20,6 +20,7 @@
 #define PKGLIB_ACQUIRE_WORKER_H
 
 #include <apt-pkg/acquire.h>
+#include <apt-pkg/weakptr.h>
 
 
 /** \brief A fetch subprocess.
@@ -41,7 +42,7 @@
  *
  *  \sa pkgAcqMethod, pkgAcquire::Item, pkgAcquire
  */
-class pkgAcquire::Worker
+class pkgAcquire::Worker : public WeakPointable
 {
    friend class pkgAcquire;
    
index 9e91a9f67c7fc26ca5b38bfed736d160b0410958..8e2c21151af135fd9b7c6c19dfdff3ffd663174a 100644 (file)
@@ -67,6 +67,7 @@
 #define PKGLIB_ACQUIRE_H
 
 #include <apt-pkg/macros.h>
+#include <apt-pkg/weakptr.h>
 
 #include <vector>
 #include <string>
@@ -376,7 +377,7 @@ class pkgAcquire
  *
  *  An item may have several assocated ItemDescs over its lifetime.
  */
-struct pkgAcquire::ItemDesc
+struct pkgAcquire::ItemDesc : public WeakPointable
 {
    /** \brief The URI from which to download this item. */
    string URI;
diff --git a/apt-pkg/contrib/weakptr.h b/apt-pkg/contrib/weakptr.h
new file mode 100644 (file)
index 0000000..5158e39
--- /dev/null
@@ -0,0 +1,62 @@
+/* weakptr.h - An object which supports weak pointers.
+ *
+ * Copyright (C) 2010 Julian Andres Klode <jak@debian.org>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#ifndef WEAK_POINTER_H
+#define WEAK_POINTER_H
+
+#include <set>
+/**
+ * Class for objects providing support for weak pointers.
+ *
+ * This class allows for the registration of certain pointers as weak,
+ * which will cause them to be set to NULL when the destructor of the
+ * object is called.
+ */
+class WeakPointable {
+private:
+    std::set<WeakPointable**> pointers;
+
+public:
+
+    /**
+     * Add a new weak pointer.
+     */
+    inline void AddWeakPointer(WeakPointable** weakptr) {
+       pointers.insert(weakptr);
+    }
+
+    /**
+     * Remove the weak pointer from the list of weak pointers.
+     */
+    inline void RemoveWeakPointer(WeakPointable **weakptr) {
+       pointers.erase(weakptr);
+    }
+
+    /**
+     * Deconstruct the object, set all weak pointers to NULL.
+     */
+    ~WeakPointable() {
+        std::set<WeakPointable**>::iterator iter = pointers.begin();
+        while (iter != pointers.end())
+            **(iter++) = NULL;
+    }
+};
+
+#endif // WEAK_POINTER_H
index bdd49c08903730574ab442313719716cac9ac995..148ad581b367a9258cca3066e8dd6f32a7762d99 100644 (file)
@@ -25,7 +25,7 @@ SOURCE = contrib/mmap.cc contrib/error.cc contrib/strutl.cc \
         contrib/fileutl.cc 
 HEADERS = mmap.h error.h configuration.h fileutl.h  cmndline.h netrc.h\
          md5.h crc-16.h cdromutl.h strutl.h sptr.h sha1.h sha256.h hashes.h \
-         macros.h
+         macros.h weakptr.h
 
 # Source code for the core main library
 SOURCE+= pkgcache.cc version.cc depcache.cc \
index 97e15326ccd630fa6a066b18cd98e504802f7f87..b316f95480dd56079e883c0cbb3dc159088aae3e 100644 (file)
@@ -59,6 +59,13 @@ apt (0.7.26~exp4) UNRELEASEDexperimental; urgency=low
     - Add test for Esperanto that has nocounty associated with them
       (LP: #560956)
 
+  [ Julian Andres Klode ]
+  * apt-pkg/contrib/weakptr.h:
+    - add a class WeakPointable which allows one to register weak pointers to
+      an object which will be set to NULL when the object is deallocated.
+  * [ABI break] apt-pkg/acquire{-worker,-item,}.h:
+    - subclass pkgAcquire::{Worker,Item,ItemDesc} from WeakPointable.
+
  -- David Kalnischkies <kalnischkies@gmail.com>  Sat, 03 Apr 2010 14:58:39 +0200
 
 apt (0.7.26~exp3) experimental; urgency=low