Просмотр исходного кода

cleanup Container.erase API to look more like std::containers

C++11 slightly changes the API again to const_iterator, but we are find
with iterators in the C++03 style for now as long as they look and
behave equally to the methods of the standard containers.

Git-Dch: Ignore
David Kalnischkies лет назад: 11
Родитель
Сommit
c687384b7a
3 измененных файлов с 17 добавлено и 16 удалено
  1. 0 1
      apt-pkg/cacheiterators.h
  2. 16 14
      apt-pkg/cacheset.h
  3. 1 1
      cmdline/apt-mark.cc

+ 0 - 1
apt-pkg/cacheiterators.h

@@ -77,7 +77,6 @@ template<typename Str, typename Itr> class pkgCache::Iterator :
 	inline pkgCache *Cache() const {return Owner;}
 
 	// Mixed stuff
-	inline void operator =(const Itr &B) {S = B.S; Owner = B.Owner;}
 	inline bool IsGood() const { return S && Owner && ! end();}
 	inline unsigned long Index() const {return S - OwnerPointer();}
 

+ 16 - 14
apt-pkg/cacheset.h

@@ -346,13 +346,10 @@ public:									/*{{{*/
 
 	bool empty() const { return _cont.empty(); }
 	void clear() { return _cont.clear(); }
-	//FIXME: on ABI break, replace the first with the second without bool
-	void erase(iterator position) { _cont.erase((typename Container::iterator)position); }
-	iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }
-	size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); }
-	void erase(iterator first, iterator last) { _cont.erase(first, last); }
 	size_t size() const { return _cont.size(); }
-
+	iterator erase( iterator pos ) { return iterator(_cont.erase(pos)); }
+	iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first, last)); }
+	size_t erase(pkgCache::PkgIterator const & P) { size_t oldsize = size(); _cont.erase(std::remove(_cont.begin(), _cont.end(), P), _cont.end()); return oldsize - size(); }
 	const_iterator begin() const { return const_iterator(_cont.begin()); }
 	const_iterator end() const { return const_iterator(_cont.end()); }
 	iterator begin() { return iterator(_cont.begin()); }
@@ -578,9 +575,9 @@ private:
 	void insert(const_iterator, const_iterator) { }
 
 	void clear() { }
-	iterator& erase(iterator &iter) { return iter; }
-	size_t erase(const pkgCache::PkgIterator) { return 0; }
-	void erase(iterator, iterator) { }
+	iterator erase( iterator pos );
+	iterator erase( iterator first, iterator last );
+	size_t erase(pkgCache::PkgIterator const & P);
 };
 									/*}}}*/
 typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
@@ -780,12 +777,10 @@ public:									/*{{{*/
 	void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }
 	bool empty() const { return _cont.empty(); }
 	void clear() { return _cont.clear(); }
-	//FIXME: on ABI break, replace the first with the second without bool
-	void erase(iterator position) { _cont.erase((typename Container::iterator)position); }
-	iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }
-	size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); }
-	void erase(iterator first, iterator last) { _cont.erase(first, last); }
 	size_t size() const { return _cont.size(); }
+	iterator erase( iterator pos ) { return iterator(_cont.erase(pos)); }
+	iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first, last)); }
+	size_t erase(pkgCache::VerIterator const & V) { size_t oldsize = size(); _cont.erase(std::remove(_cont.begin(), _cont.end(), V), _cont.end()); return oldsize - size(); }
 
 	const_iterator begin() const { return const_iterator(_cont.begin()); }
 	const_iterator end() const { return const_iterator(_cont.end()); }
@@ -989,6 +984,13 @@ template<> inline void VersionContainer<std::vector<pkgCache::VerIterator> >::in
 }
 									/*}}}*/
 
+template<> inline size_t PackageContainer<std::set<pkgCache::PkgIterator> >::erase(pkgCache::PkgIterator const &P) {
+	return _cont.erase(P);
+}
+template<> inline size_t VersionContainer<std::set<pkgCache::VerIterator> >::erase(pkgCache::VerIterator const &V) {
+	return _cont.erase(V);
+}
+
 template<> template<class Compare> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::sort(Compare Comp) {
 	std::sort(_cont.begin(), _cont.end(), Comp);
 	return true;

+ 1 - 1
cmdline/apt-mark.cc

@@ -238,7 +238,7 @@ static bool DoHold(CommandLine &CmdL)
 	    ioprintf(c1out,_("%s was already set on hold.\n"), Pkg.FullName(true).c_str());
 	 else
 	    ioprintf(c1out,_("%s was already not hold.\n"), Pkg.FullName(true).c_str());
-	 Pkg = pkgset.erase(Pkg, true);
+	 Pkg = pkgset.erase(Pkg);
       }
       else
 	 ++Pkg;