Explorar o código

* apt-pkg/cacheset.{cc,h}:
- add simple wrapper around std::set for cache structures

David Kalnischkies %!s(int64=16) %!d(string=hai) anos
pai
achega
d4489d4983
Modificáronse 4 ficheiros con 52 adicións e 9 borrados
  1. 2 2
      apt-pkg/cacheiterators.h
  2. 46 3
      apt-pkg/cacheset.h
  3. 1 1
      apt-pkg/pkgcache.cc
  4. 3 3
      debian/changelog

+ 2 - 2
apt-pkg/cacheiterators.h

@@ -205,8 +205,8 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
 	inline PrvIterator ProvidesList() const;
 	inline PrvIterator ProvidesList() const;
 	inline VerFileIterator FileList() const;
 	inline VerFileIterator FileList() const;
 	bool Downloadable() const;
 	bool Downloadable() const;
-	inline const char *PriorityType() {return Owner->Priority(S->Priority);};
-	string RelStr();
+	inline const char *PriorityType() const {return Owner->Priority(S->Priority);};
+	string RelStr() const;
 
 
 	bool Automatic() const;
 	bool Automatic() const;
 	bool Pseudo() const;
 	bool Pseudo() const;

+ 46 - 3
apt-pkg/cacheset.h

@@ -17,12 +17,12 @@
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/pkgcache.h>
 									/*}}}*/
 									/*}}}*/
 namespace APT {
 namespace APT {
+class PackageSet : public std::set<pkgCache::PkgIterator> {		/*{{{*/
 /** \class APT::PackageSet
 /** \class APT::PackageSet
 
 
     Simple wrapper around a std::set to provide a similar interface to
     Simple wrapper around a std::set to provide a similar interface to
     a set of packages as to the complete set of all packages in the
     a set of packages as to the complete set of all packages in the
     pkgCache. */
     pkgCache. */
-class PackageSet : public std::set<pkgCache::PkgIterator> {		/*{{{*/
 public:									/*{{{*/
 public:									/*{{{*/
 	/** \brief smell like a pkgCache::PkgIterator */
 	/** \brief smell like a pkgCache::PkgIterator */
 	class const_iterator : public std::set<pkgCache::PkgIterator>::const_iterator {
 	class const_iterator : public std::set<pkgCache::PkgIterator>::const_iterator {
@@ -86,11 +86,54 @@ public:									/*{{{*/
 		std::ostream out (std::ofstream("/dev/null").rdbuf());
 		std::ostream out (std::ofstream("/dev/null").rdbuf());
 		return APT::PackageSet::FromCommandLine(Cache, cmdline, out);
 		return APT::PackageSet::FromCommandLine(Cache, cmdline, out);
 	}
 	}
+									/*}}}*/
+};									/*}}}*/
+class VersionSet : public std::set<pkgCache::VerIterator> {		/*{{{*/
+/** \class APT::VersionSet
 
 
+    Simple wrapper around a std::set to provide a similar interface to
+    a set of versions as to the complete set of all versions in the
+    pkgCache. */
+public:									/*{{{*/
+	/** \brief smell like a pkgCache::VerIterator */
+	class const_iterator : public std::set<pkgCache::VerIterator>::const_iterator {
+	public:
+		const_iterator(std::set<pkgCache::VerIterator>::const_iterator x) :
+			 std::set<pkgCache::VerIterator>::const_iterator(x) {}
 
 
+		operator pkgCache::VerIterator(void) { return **this; }
+
+		inline pkgCache *Cache() const { return (**this).Cache(); };
+		inline unsigned long Index() const {return (**this).Index();};
+		// we have only valid iterators here
+		inline bool end() const { return false; };
+
+		inline pkgCache::Version const * operator->() const {
+			return &***this;
+		};
+
+		inline int CompareVer(const pkgCache::VerIterator &B) const { return (**this).CompareVer(B); };
+		inline const char *VerStr() const { return (**this).VerStr(); };
+		inline const char *Section() const { return (**this).Section(); };
+		inline const char *Arch() const { return (**this).Arch(); };
+		inline const char *Arch(bool const pseudo) const { return (**this).Arch(pseudo); };
+		inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); };
+		inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); };
+		inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); };
+		inline pkgCache::DepIterator DependsList() const { return (**this).DependsList(); };
+		inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); };
+		inline pkgCache::VerFileIterator FileList() const { return (**this).FileList(); };
+		inline bool Downloadable() const { return (**this).Downloadable(); };
+		inline const char *PriorityType() const { return (**this).PriorityType(); };
+		inline string RelStr() const { return (**this).RelStr(); };
+		inline bool Automatic() const { return (**this).Automatic(); };
+		inline bool Pseudo() const { return (**this).Pseudo(); };
+		inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); };
+	};
+	// 103. set::iterator is required to be modifiable, but this allows modification of keys
+	typedef typename APT::VersionSet::const_iterator iterator;
 
 
 									/*}}}*/
 									/*}}}*/
-};
-									/*}}}*/
+};									/*}}}*/
 }
 }
 #endif
 #endif

+ 1 - 1
apt-pkg/pkgcache.cc

@@ -742,7 +742,7 @@ pkgCache::VerFileIterator pkgCache::VerIterator::NewestFile() const
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* This describes the version from a release-centric manner. The output is a 
 /* This describes the version from a release-centric manner. The output is a 
    list of Label:Version/Archive */
    list of Label:Version/Archive */
-string pkgCache::VerIterator::RelStr()
+string pkgCache::VerIterator::RelStr() const
 {
 {
    bool First = true;
    bool First = true;
    string Res;
    string Res;

+ 3 - 3
debian/changelog

@@ -22,8 +22,8 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low
     - correct "Dangerous iterator usage." pointed out by cppcheck
     - correct "Dangerous iterator usage." pointed out by cppcheck
   * ftparchive/writer.h:
   * ftparchive/writer.h:
     - add a virtual destructor to FTWScanner class (for cppcheck)
     - add a virtual destructor to FTWScanner class (for cppcheck)
-  * apt-pkg/cacheset.h:
-    - add a simple wrapper around std::set for packages with it
+  * apt-pkg/cacheset.{cc,h}:
+    - add simple wrapper around std::set for cache structures
     - move regex magic from apt-get to new FromRegEx method
     - move regex magic from apt-get to new FromRegEx method
     - move cmdline parsing from apt-cache to new FromCommandLine method
     - move cmdline parsing from apt-cache to new FromCommandLine method
   * apt-pkg/contrib/cmdline.cc:
   * apt-pkg/contrib/cmdline.cc:
@@ -33,7 +33,7 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low
   * cmdline/apt-cache.cc:
   * cmdline/apt-cache.cc:
     - make the search multiarch compatible by using GrpIterator instead
     - make the search multiarch compatible by using GrpIterator instead
 
 
- -- David Kalnischkies <kalnischkies@gmail.com>  Mon, 31 May 2010 20:00:24 +0200
+ -- David Kalnischkies <kalnischkies@gmail.com>  Mon, 31 May 2010 22:36:35 +0200
 
 
 apt (0.7.26~exp5) experimental; urgency=low
 apt (0.7.26~exp5) experimental; urgency=low