]> git.saurik.com Git - apt.git/blame - apt-pkg/cacheset.h
policy: Remove TODO for replacing old GetCandidateVer()
[apt.git] / apt-pkg / cacheset.h
CommitLineData
e1dbde8d
DK
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
7959c5ed
DK
3/** \file cacheset.h
4 Wrappers around std::set to have set::iterators which behave
5 similar to the Iterators of the cache structures.
e1dbde8d 6
7959c5ed 7 Provides also a few helper methods which work with these sets */
e1dbde8d 8 /*}}}*/
7959c5ed
DK
9#ifndef APT_CACHESET_H
10#define APT_CACHESET_H
e1dbde8d 11// Include Files /*{{{*/
ffee1c2b 12#include <fstream>
9cc83a6f 13#include <map>
ffee1c2b 14#include <set>
ffb081b7
DK
15#if __cplusplus >= 201103L
16#include <unordered_set>
17#include <forward_list>
2fc9d1eb 18#include <initializer_list>
ffb081b7 19#endif
c4cca791 20#include <list>
a0c19a21 21#include <deque>
5c8c7321 22#include <vector>
e1dbde8d 23#include <string>
15fc8636 24#include <iterator>
5c8c7321 25#include <algorithm>
ffee1c2b 26
453b82a3
DK
27#include <stddef.h>
28
472ff00e 29#include <apt-pkg/error.h>
e1dbde8d 30#include <apt-pkg/pkgcache.h>
453b82a3 31#include <apt-pkg/cacheiterators.h>
586d8704 32#include <apt-pkg/macros.h>
b9dadc24
DK
33
34#ifndef APT_8_CLEANER_HEADERS
35#include <apt-pkg/cachefile.h>
453b82a3
DK
36#endif
37#ifndef APT_10_CLEANER_HEADERS
38#include <iostream>
b9dadc24 39#endif
e1dbde8d 40 /*}}}*/
472ff00e
DK
41
42class pkgCacheFile;
43
e1dbde8d 44namespace APT {
15fc8636
DK
45class PackageContainerInterface;
46class VersionContainerInterface;
47
70e706ad
DK
48class CacheSetHelper { /*{{{*/
49/** \class APT::CacheSetHelper
50 Simple base class with a lot of virtual methods which can be overridden
51 to alter the behavior or the output of the CacheSets.
52
53 This helper is passed around by the static methods in the CacheSets and
54 used every time they hit an error condition or something could be
55 printed out.
56*/
57public: /*{{{*/
15fc8636 58 CacheSetHelper(bool const ShowError = true,
c8a4ce6c
DK
59 GlobalError::MsgType ErrorType = GlobalError::ERROR);
60 virtual ~CacheSetHelper();
70e706ad 61
1e064088
DK
62 enum PkgSelector { UNKNOWN, REGEX, TASK, FNMATCH, PACKAGENAME, STRING };
63
64 virtual bool PackageFrom(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);
65
66 virtual bool PackageFromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline);
67
68 struct PkgModifier {
69 enum Position { NONE, PREFIX, POSTFIX };
70 unsigned short ID;
71 const char * const Alias;
72 Position Pos;
73 PkgModifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}
74 };
75 virtual bool PackageFromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
76 pkgCacheFile &Cache, const char * cmdline,
77 std::list<PkgModifier> const &mods);
78
5dd00edb 79 APT_DEPRECATED_MSG("use .PackageFrom(PACKAGENAME, …) instead") pkgCache::PkgIterator PackageFromName(pkgCacheFile &Cache, std::string const &pattern);
fdba4d53
DK
80
81 /** \brief be notified about the package being selected via pattern
82 *
83 * Main use is probably to show a message to the user what happened
84 *
85 * \param pkg is the package which was selected
86 * \param select is the selection method which choose the package
87 * \param pattern is the string used by the selection method to pick the package
88 */
89 virtual void showPackageSelection(pkgCache::PkgIterator const &pkg, PkgSelector const select, std::string const &pattern);
90 // use the method above instead, react only on the type you need and let the base handle the rest if need be
5dd00edb
DK
91 // this allows us to add new selection methods without breaking the ABI constantly with new virtual methods
92 APT_DEPRECATED_MSG("override .showPackageSelection and select with switch") virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
93 APT_DEPRECATED_MSG("override .showPackageSelection and select with switch") virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
94 APT_DEPRECATED_MSG("override .showPackageSelection and select with switch") virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
fdba4d53
DK
95
96 /** \brief be notified if a package can't be found via pattern
97 *
98 * Can be used to show a message as well as to try something else to make it match
99 *
100 * \param select is the method tried for selection
101 * \param pci is the container the package should be inserted in
102 * \param Cache is the package universe available
103 * \param pattern is the string not matching anything
104 */
105 virtual void canNotFindPackage(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);
106 // same as above for showPackageSelection
5dd00edb
DK
107 APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
108 APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
109 APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
110 APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str);
fdba4d53
DK
111
112 /** \brief specifies which version(s) we want to refer to */
113 enum VerSelector {
114 /** by release string */
115 RELEASE,
116 /** by version number string */
117 VERSIONNUMBER,
118 /** All versions */
119 ALL,
120 /** Candidate and installed version */
121 CANDANDINST,
122 /** Candidate version */
123 CANDIDATE,
124 /** Installed version */
125 INSTALLED,
126 /** Candidate or if non installed version */
127 CANDINST,
128 /** Installed or if non candidate version */
129 INSTCAND,
130 /** Newest version */
131 NEWEST
132 };
70e706ad 133
fdba4d53
DK
134 /** \brief be notified about the version being selected via pattern
135 *
136 * Main use is probably to show a message to the user what happened
137 * Note that at the moment this method is only called for RELEASE
138 * and VERSION selections, not for the others.
139 *
140 * \param Pkg is the package which was selected for
141 * \param Ver is the version selected
142 * \param select is the selection method which choose the version
143 * \param pattern is the string used by the selection method to pick the version
144 */
145 virtual void showVersionSelection(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver,
146 enum VerSelector const select, std::string const &pattern);
5dd00edb 147 APT_DEPRECATED_MSG("use .showVersionSelection instead, similar to .showPackageSelection") virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
fdba4d53 148 std::string const &ver, bool const verIsRel);
15fc8636 149
fdba4d53
DK
150 /** \brief be notified if a version can't be found for a package
151 *
152 * Main use is probably to show a message to the user what happened
153 *
154 * \param select is the method tried for selection
155 * \param vci is the container the version should be inserted in
156 * \param Cache is the package universe available
157 * \param Pkg is the package we wanted a version from
158 */
159 virtual void canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
5dd00edb
DK
160 APT_DEPRECATED_MSG("override .canNotFindVersion and select via switch") virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
161 APT_DEPRECATED_MSG("override .canNotFindVersion and select via switch") virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
70e706ad 162 pkgCache::PkgIterator const &Pkg);
5dd00edb 163 APT_DEPRECATED_MSG("override .canNotFindVersion and select via switch") virtual void canNotFindCandInstVer(VersionContainerInterface * const vci,
15fc8636 164 pkgCacheFile &Cache,
cf28bcad 165 pkgCache::PkgIterator const &Pkg);
15fc8636 166
fdba4d53
DK
167 // the difference between canNotFind and canNotGet is that the later is more low-level
168 // and called from other places: In this case looking into the code is the only real answer…
169 virtual pkgCache::VerIterator canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
5dd00edb 170 APT_DEPRECATED_MSG("override .canNotGetVersion and select via switch") virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache,
70e706ad 171 pkgCache::PkgIterator const &Pkg);
5dd00edb 172 APT_DEPRECATED_MSG("override .canNotGetVersion and select via switch") virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache,
70e706ad 173 pkgCache::PkgIterator const &Pkg);
5dd00edb 174 APT_DEPRECATED_MSG("override .canNotGetVersion and select via switch") virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache,
70e706ad
DK
175 pkgCache::PkgIterator const &Pkg);
176
fdba4d53
DK
177 virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str);
178
d3e8fbb3
DK
179 bool showErrors() const { return ShowError; }
180 bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }
181 GlobalError::MsgType errorType() const { return ErrorType; }
cd7bbc47
DK
182 GlobalError::MsgType errorType(GlobalError::MsgType const &newValue)
183 {
184 if (ErrorType == newValue) return ErrorType;
185 else {
186 GlobalError::MsgType const &oldValue = ErrorType;
187 ErrorType = newValue;
188 return oldValue;
189 }
d3e8fbb3 190 }
cd7bbc47 191
70e706ad
DK
192 /*}}}*/
193protected:
194 bool ShowError;
cd7bbc47 195 GlobalError::MsgType ErrorType;
fdba4d53
DK
196
197 pkgCache::VerIterator canNotGetInstCandVer(pkgCacheFile &Cache,
198 pkgCache::PkgIterator const &Pkg);
199 pkgCache::VerIterator canNotGetCandInstVer(pkgCacheFile &Cache,
200 pkgCache::PkgIterator const &Pkg);
1e064088
DK
201
202 bool PackageFromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
203 bool PackageFromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
204 bool PackageFromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
205 bool PackageFromPackageName(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
206 bool PackageFromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);
c8a4ce6c 207private:
6c55f07a 208 void * const d;
70e706ad 209}; /*}}}*/
28933259 210// Iterator templates for our Containers /*{{{*/
a0c19a21 211template<typename Interface, typename Master, typename iterator_type, typename container_iterator, typename container_value> class Container_iterator_base :
b2a893dd 212 public std::iterator<typename std::iterator_traits<container_iterator>::iterator_category, container_value>,
3707fd4f 213 public Interface::template iterator_base<iterator_type>
28933259
DK
214{
215protected:
216 container_iterator _iter;
28933259
DK
217public:
218 explicit Container_iterator_base(container_iterator i) : _iter(i) {}
3707fd4f 219 inline container_value operator*(void) const { return static_cast<iterator_type const*>(this)->getType(); };
28933259
DK
220 operator container_iterator(void) const { return _iter; }
221 inline iterator_type& operator++() { ++_iter; return static_cast<iterator_type&>(*this); }
222 inline iterator_type operator++(int) { iterator_type tmp(*this); operator++(); return tmp; }
223 inline iterator_type operator+(typename container_iterator::difference_type const &n) { return iterator_type(_iter + n); }
224 inline iterator_type operator+=(typename container_iterator::difference_type const &n) { _iter += n; return static_cast<iterator_type&>(*this); }
225 inline iterator_type& operator--() { --_iter;; return static_cast<iterator_type&>(*this); }
226 inline iterator_type operator--(int) { iterator_type tmp(*this); operator--(); return tmp; }
227 inline iterator_type operator-(typename container_iterator::difference_type const &n) { return iterator_type(_iter - n); }
2fc9d1eb 228 inline typename container_iterator::difference_type operator-(iterator_type const &b) { return (_iter - b._iter); }
28933259
DK
229 inline iterator_type operator-=(typename container_iterator::difference_type const &n) { _iter -= n; return static_cast<iterator_type&>(*this); }
230 inline bool operator!=(iterator_type const &i) const { return _iter != i._iter; }
231 inline bool operator==(iterator_type const &i) const { return _iter == i._iter; }
232 inline bool operator<(iterator_type const &i) const { return _iter < i._iter; }
233 inline bool operator>(iterator_type const &i) const { return _iter > i._iter; }
234 inline bool operator<=(iterator_type const &i) const { return _iter <= i._iter; }
235 inline bool operator>=(iterator_type const &i) const { return _iter >= i._iter; }
236 inline typename container_iterator::reference operator[](typename container_iterator::difference_type const &n) const { return _iter[n]; }
237
238 friend std::ostream& operator<<(std::ostream& out, iterator_type i) { return operator<<(out, *i); }
239 friend Master;
240};
241template<class Interface, class Container, class Master> class Container_const_iterator :
a0c19a21 242 public Container_iterator_base<Interface, Master, Container_const_iterator<Interface, Container, Master>, typename Container::const_iterator, typename Container::value_type>
28933259
DK
243{
244 typedef Container_const_iterator<Interface, Container, Master> iterator_type;
245 typedef typename Container::const_iterator container_iterator;
246public:
247 explicit Container_const_iterator(container_iterator i) :
a0c19a21
DK
248 Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}
249
3707fd4f 250 inline typename Container::value_type getType(void) const { return *this->_iter; }
28933259
DK
251};
252template<class Interface, class Container, class Master> class Container_iterator :
a0c19a21 253 public Container_iterator_base<Interface, Master, Container_iterator<Interface, Container, Master>, typename Container::iterator, typename Container::value_type>
28933259
DK
254{
255 typedef Container_iterator<Interface, Container, Master> iterator_type;
256 typedef typename Container::iterator container_iterator;
257public:
258 explicit Container_iterator(container_iterator i) :
a0c19a21 259 Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}
28933259
DK
260
261 operator typename Master::const_iterator() { return typename Master::const_iterator(this->_iter); }
262 inline iterator_type& operator=(iterator_type const &i) { this->_iter = i._iter; return static_cast<iterator_type&>(*this); }
263 inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast<iterator_type&>(*this); }
b2a893dd 264 inline typename Container::iterator::reference operator*(void) const { return *this->_iter; }
a0c19a21 265
3707fd4f 266 inline typename Container::value_type getType(void) const { return *this->_iter; }
28933259
DK
267};
268template<class Interface, class Container, class Master> class Container_const_reverse_iterator :
a0c19a21 269 public Container_iterator_base<Interface, Master, Container_const_reverse_iterator<Interface, Container, Master>, typename Container::const_reverse_iterator, typename Container::value_type>
28933259
DK
270{
271 typedef Container_const_reverse_iterator<Interface, Container, Master> iterator_type;
272 typedef typename Container::const_reverse_iterator container_iterator;
273public:
274 explicit Container_const_reverse_iterator(container_iterator i) :
a0c19a21
DK
275 Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}
276
3707fd4f 277 inline typename Container::value_type getType(void) const { return *this->_iter; }
28933259
DK
278};
279template<class Interface, class Container, class Master> class Container_reverse_iterator :
a0c19a21 280 public Container_iterator_base<Interface, Master, Container_reverse_iterator<Interface, Container, Master>, typename Container::reverse_iterator, typename Container::value_type>
28933259
DK
281{
282 typedef Container_reverse_iterator<Interface, Container, Master> iterator_type;
283 typedef typename Container::reverse_iterator container_iterator;
284public:
285 explicit Container_reverse_iterator(container_iterator i) :
a0c19a21 286 Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}
5c8c7321 287
28933259
DK
288 operator typename Master::const_iterator() { return typename Master::const_iterator(this->_iter); }
289 inline iterator_type& operator=(iterator_type const &i) { this->_iter = i._iter; return static_cast<iterator_type&>(*this); }
290 inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast<iterator_type&>(*this); }
b2a893dd 291 inline typename Container::reverse_iterator::reference operator*(void) const { return *this->_iter; }
a0c19a21 292
3707fd4f 293 inline typename Container::value_type getType(void) const { return *this->_iter; }
28933259
DK
294};
295 /*}}}*/
15fc8636
DK
296class PackageContainerInterface { /*{{{*/
297/** \class PackageContainerInterface
298
299 * Interface ensuring that all operations can be executed on the yet to
300 * define concrete PackageContainer - access to all methods is possible,
301 * but in general the wrappers provided by the PackageContainer template
302 * are nicer to use.
303
304 * This class mostly protects use from the need to write all implementation
305 * of the methods working on containers in the template */
306public:
3707fd4f
DK
307 template<class Itr> class iterator_base { /*{{{*/
308 pkgCache::PkgIterator getType() const { return static_cast<Itr const*>(this)->getType(); };
e1dbde8d 309 public:
28933259 310 operator pkgCache::PkgIterator(void) const { return getType(); }
15fc8636 311
28933259
DK
312 inline const char *Name() const {return getType().Name(); }
313 inline std::string FullName(bool const Pretty) const { return getType().FullName(Pretty); }
314 inline std::string FullName() const { return getType().FullName(); }
5dd00edb 315 APT_DEPRECATED_MSG("Use the .Section method of VerIterator instead") inline const char *Section() const {
2b4cead3 316 APT_IGNORE_DEPRECATED_PUSH
28933259 317 return getType().Section();
2b4cead3 318 APT_IGNORE_DEPRECATED_POP
7a669774 319 }
28933259
DK
320 inline bool Purge() const {return getType().Purge(); }
321 inline const char *Arch() const {return getType().Arch(); }
322 inline pkgCache::GrpIterator Group() const { return getType().Group(); }
323 inline pkgCache::VerIterator VersionList() const { return getType().VersionList(); }
324 inline pkgCache::VerIterator CurrentVer() const { return getType().CurrentVer(); }
325 inline pkgCache::DepIterator RevDependsList() const { return getType().RevDependsList(); }
326 inline pkgCache::PrvIterator ProvidesList() const { return getType().ProvidesList(); }
327 inline pkgCache::PkgIterator::OkState State() const { return getType().State(); }
328 inline const char *CandVersion() const { return getType().CandVersion(); }
329 inline const char *CurVersion() const { return getType().CurVersion(); }
330 inline pkgCache *Cache() const { return getType().Cache(); }
331 inline unsigned long Index() const {return getType().Index();}
78c32596 332 // we have only valid iterators here
d3e8fbb3 333 inline bool end() const { return false; }
e1dbde8d 334
28933259 335 inline pkgCache::Package const * operator->() const {return &*getType();}
15fc8636
DK
336 };
337 /*}}}*/
338
339 virtual bool insert(pkgCache::PkgIterator const &P) = 0;
340 virtual bool empty() const = 0;
341 virtual void clear() = 0;
28933259 342 virtual size_t size() const = 0;
15fc8636 343
5dd00edb 344 enum APT_DEPRECATED_MSG("Use CacheSetHelper::PkgSelector instead") Constructor { UNKNOWN = CacheSetHelper::UNKNOWN,
fdba4d53
DK
345 REGEX = CacheSetHelper::REGEX,
346 TASK = CacheSetHelper::TASK,
347 FNMATCH = CacheSetHelper::FNMATCH };
586d8704 348APT_IGNORE_DEPRECATED_PUSH
fdba4d53 349 void setConstructor(Constructor const by) { ConstructedBy = (CacheSetHelper::PkgSelector)by; }
586d8704 350APT_IGNORE_DEPRECATED_POP
fdba4d53
DK
351
352 void setConstructor(CacheSetHelper::PkgSelector const by) { ConstructedBy = by; }
353 CacheSetHelper::PkgSelector getConstructor() const { return ConstructedBy; }
c8a4ce6c 354 PackageContainerInterface();
e8afd168 355 explicit PackageContainerInterface(CacheSetHelper::PkgSelector const by);
6c55f07a 356 PackageContainerInterface& operator=(PackageContainerInterface const &other);
c8a4ce6c 357 virtual ~PackageContainerInterface();
15fc8636 358
5dd00edb 359 APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::TASK, …) instead") static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
1e064088 360 return helper.PackageFrom(CacheSetHelper::TASK, pci, Cache, pattern); }
5dd00edb 361 APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::REGEX, …) instead") static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
1e064088 362 return helper.PackageFrom(CacheSetHelper::REGEX, pci, Cache, pattern); }
5dd00edb 363 APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::FNMATCH, …) instead") static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
1e064088 364 return helper.PackageFrom(CacheSetHelper::FNMATCH, pci, Cache, pattern); }
5dd00edb 365 APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::PACKAGENAME, …) instead") static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
1e064088 366 return helper.PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, pattern); }
5dd00edb 367 APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::STRING, …) instead") static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
1e064088 368 return helper.PackageFrom(CacheSetHelper::STRING, pci, Cache, pattern); }
5dd00edb 369 APT_DEPRECATED_MSG("Use helper.PackageFromCommandLine instead") static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
1e064088
DK
370 return helper.PackageFromCommandLine(pci, Cache, cmdline); }
371
5dd00edb 372 APT_DEPRECATED_MSG("enum moved to CacheSetHelper::PkgModifier") typedef CacheSetHelper::PkgModifier Modifier;
15fc8636 373
586d8704 374APT_IGNORE_DEPRECATED_PUSH
5dd00edb 375 APT_DEPRECATED_MSG("Use helper.PackageFromName instead") static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
1e064088 376 return helper.PackageFromName(Cache, pattern); }
5dd00edb 377 APT_DEPRECATED_MSG("Use helper.PackageFromModifierCommandLine instead") static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
1e064088
DK
378 pkgCacheFile &Cache, const char * cmdline,
379 std::list<Modifier> const &mods, CacheSetHelper &helper) {
380 return helper.PackageFromModifierCommandLine(modID, pci, Cache, cmdline, mods); }
586d8704 381APT_IGNORE_DEPRECATED_POP
fdba4d53
DK
382
383private:
384 CacheSetHelper::PkgSelector ConstructedBy;
6c55f07a 385 void * const d;
15fc8636
DK
386};
387 /*}}}*/
388template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
389/** \class APT::PackageContainer
e1dbde8d 390
15fc8636
DK
391 Simple wrapper around a container class like std::set to provide a similar
392 interface to a set of packages as to the complete set of all packages in the
393 pkgCache. */
394 Container _cont;
395public: /*{{{*/
396 /** \brief smell like a pkgCache::PkgIterator */
28933259
DK
397 typedef Container_const_iterator<PackageContainerInterface, Container, PackageContainer> const_iterator;
398 typedef Container_iterator<PackageContainerInterface, Container, PackageContainer> iterator;
399 typedef Container_const_reverse_iterator<PackageContainerInterface, Container, PackageContainer> const_reverse_iterator;
400 typedef Container_reverse_iterator<PackageContainerInterface, Container, PackageContainer> reverse_iterator;
b2a893dd 401 typedef typename Container::value_type value_type;
2fc9d1eb
DK
402 typedef typename Container::pointer pointer;
403 typedef typename Container::const_pointer const_pointer;
b2a893dd
DK
404 typedef typename Container::reference reference;
405 typedef typename Container::const_reference const_reference;
406 typedef typename Container::difference_type difference_type;
407 typedef typename Container::size_type size_type;
2fc9d1eb 408 typedef typename Container::allocator_type allocator_type;
ffee1c2b 409
28933259 410 bool insert(pkgCache::PkgIterator const &P) APT_OVERRIDE { if (P.end() == true) return false; _cont.insert(P); return true; }
d3e8fbb3
DK
411 template<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); }
412 void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }
c4cca791 413
28933259
DK
414 bool empty() const APT_OVERRIDE { return _cont.empty(); }
415 void clear() APT_OVERRIDE { return _cont.clear(); }
416 size_t size() const APT_OVERRIDE { return _cont.size(); }
3dddcdf2 417#if __GNUC__ >= 5 || (__GNUC_MINOR__ >= 9 && __GNUC__ >= 4)
ffb081b7
DK
418 iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); }
419 iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
420#else
421 iterator erase( iterator pos ) { return iterator(_cont.erase(pos._iter)); }
422 iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
423#endif
d3e8fbb3
DK
424 const_iterator begin() const { return const_iterator(_cont.begin()); }
425 const_iterator end() const { return const_iterator(_cont.end()); }
28933259
DK
426 const_reverse_iterator rbegin() const { return const_reverse_iterator(_cont.rbegin()); }
427 const_reverse_iterator rend() const { return const_reverse_iterator(_cont.rend()); }
428#if __cplusplus >= 201103L
ffb081b7
DK
429 const_iterator cbegin() const { return const_iterator(_cont.cbegin()); }
430 const_iterator cend() const { return const_iterator(_cont.cend()); }
28933259
DK
431 const_reverse_iterator crbegin() const { return const_reverse_iterator(_cont.crbegin()); }
432 const_reverse_iterator crend() const { return const_reverse_iterator(_cont.crend()); }
433#endif
d3e8fbb3
DK
434 iterator begin() { return iterator(_cont.begin()); }
435 iterator end() { return iterator(_cont.end()); }
28933259
DK
436 reverse_iterator rbegin() { return reverse_iterator(_cont.rbegin()); }
437 reverse_iterator rend() { return reverse_iterator(_cont.rend()); }
d3e8fbb3 438 const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); }
15fc8636 439
c8a4ce6c 440 PackageContainer() : PackageContainerInterface(CacheSetHelper::UNKNOWN) {}
e8afd168 441 explicit PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {}
586d8704 442APT_IGNORE_DEPRECATED_PUSH
5dd00edb 443 APT_DEPRECATED_MSG("Construct with a CacheSetHelper::PkgSelector instead") explicit PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {}
586d8704 444APT_IGNORE_DEPRECATED_POP
2fc9d1eb
DK
445 template<typename Itr> PackageContainer(Itr first, Itr last) : PackageContainerInterface(CacheSetHelper::UNKNOWN), _cont(first, last) {}
446#if __cplusplus >= 201103L
447 PackageContainer(std::initializer_list<value_type> list) : PackageContainerInterface(CacheSetHelper::UNKNOWN), _cont(list) {}
448 void push_back(value_type&& P) { _cont.emplace_back(std::move(P)); }
449 template<typename... Args> void emplace_back(Args&&... args) { _cont.emplace_back(std::forward<Args>(args)...); }
450#endif
451 void push_back(const value_type& P) { _cont.push_back(P); }
c45f2d19 452
5c8c7321
DK
453 /** \brief sort all included versions with given comparer
454
455 Some containers are sorted by default, some are not and can't be,
456 but a few like std::vector can be sorted if need be, so this can be
457 specialized in later on. The default is that this will fail though.
458 Specifically, already sorted containers like std::set will return
459 false as well as there is no easy way to check that the given comparer
460 would sort in the same way the set is currently sorted
461
462 \return \b true if the set was sorted, \b false if not. */
463 template<class Compare> bool sort(Compare /*Comp*/) { return false; }
464
dc0f01f7
DK
465 /** \brief returns all packages in the cache who belong to the given task
466
467 A simple helper responsible for search for all members of a task
468 in the cache. Optional it prints a a notice about the
469 packages chosen cause of the given task.
470 \param Cache the packages are in
471 \param pattern name of the task
c8db3fff 472 \param helper responsible for error and message handling */
15fc8636 473 static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
fdba4d53 474 PackageContainer cont(CacheSetHelper::TASK);
1e064088 475 helper.PackageFrom(CacheSetHelper::TASK, &cont, Cache, pattern);
15fc8636
DK
476 return cont;
477 }
478 static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern) {
70e706ad 479 CacheSetHelper helper;
446bbcf4 480 return FromTask(Cache, pattern, helper);
dc0f01f7
DK
481 }
482
ffee1c2b
DK
483 /** \brief returns all packages in the cache whose name matchs a given pattern
484
485 A simple helper responsible for executing a regular expression on all
486 package names in the cache. Optional it prints a a notice about the
487 packages chosen cause of the given package.
488 \param Cache the packages are in
489 \param pattern regular expression for package names
c8db3fff 490 \param helper responsible for error and message handling */
fdba4d53
DK
491 static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
492 PackageContainer cont(CacheSetHelper::REGEX);
1e064088 493 helper.PackageFrom(CacheSetHelper::REGEX, &cont, Cache, pattern);
15fc8636
DK
494 return cont;
495 }
496
497 static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern) {
70e706ad 498 CacheSetHelper helper;
446bbcf4 499 return FromRegEx(Cache, pattern, helper);
ffee1c2b
DK
500 }
501
fdba4d53
DK
502 static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
503 PackageContainer cont(CacheSetHelper::FNMATCH);
1e064088 504 helper.PackageFrom(CacheSetHelper::FNMATCH, &cont, Cache, pattern);
b9179170
MV
505 return cont;
506 }
507 static PackageContainer FromFnMatch(pkgCacheFile &Cache, std::string const &pattern) {
508 CacheSetHelper helper;
509 return FromFnmatch(Cache, pattern, helper);
510 }
511
586d8704 512APT_IGNORE_DEPRECATED_PUSH
15fc8636 513 /** \brief returns a package specified by a string
856d3b06 514
15fc8636
DK
515 \param Cache the package is in
516 \param pattern String the package name should be extracted from
c8db3fff 517 \param helper responsible for error and message handling */
5dd00edb 518 APT_DEPRECATED_MSG("Use helper.PackageFromName instead") static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
1e064088 519 return helper.PackageFromName(Cache, pattern);
15fc8636 520 }
5dd00edb 521 APT_DEPRECATED_MSG("Use helper.PackageFromName instead") static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) {
70e706ad 522 CacheSetHelper helper;
1e064088 523 return FromName(Cache, pattern, helper);
856d3b06 524 }
586d8704 525APT_IGNORE_DEPRECATED_POP
856d3b06 526
15fc8636 527 /** \brief returns all packages specified by a string
bd631595 528
15fc8636
DK
529 \param Cache the packages are in
530 \param pattern String the package name(s) should be extracted from
c8db3fff 531 \param helper responsible for error and message handling */
15fc8636
DK
532 static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
533 PackageContainer cont;
1e064088 534 helper.PackageFrom(CacheSetHelper::PACKAGENAME, &cont, Cache, pattern);
15fc8636
DK
535 return cont;
536 }
537 static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern) {
bd631595 538 CacheSetHelper helper;
15fc8636 539 return FromString(Cache, pattern, helper);
bd631595
DK
540 }
541
78c32596
DK
542 /** \brief returns all packages specified on the commandline
543
544 Get all package names from the commandline and executes regex's if needed.
545 No special package command is supported, just plain names.
546 \param Cache the packages are in
547 \param cmdline Command line the package names should be extracted from
c8db3fff 548 \param helper responsible for error and message handling */
15fc8636
DK
549 static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
550 PackageContainer cont;
1e064088 551 helper.PackageFromCommandLine(&cont, Cache, cmdline);
15fc8636
DK
552 return cont;
553 }
554 static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
70e706ad 555 CacheSetHelper helper;
446bbcf4 556 return FromCommandLine(Cache, cmdline, helper);
78c32596 557 }
9cc83a6f 558
c8db3fff
DK
559 /** \brief group packages by a action modifiers
560
561 At some point it is needed to get from the same commandline
562 different package sets grouped by a modifier. Take
563 apt-get install apt awesome-
564 as an example.
565 \param Cache the packages are in
566 \param cmdline Command line the package names should be extracted from
567 \param mods list of modifiers the method should accept
568 \param fallback the default modifier group for a package
569 \param helper responsible for error and message handling */
15fc8636
DK
570 static std::map<unsigned short, PackageContainer> GroupedFromCommandLine(
571 pkgCacheFile &Cache,
572 const char **cmdline,
1e064088 573 std::list<CacheSetHelper::PkgModifier> const &mods,
15fc8636
DK
574 unsigned short const &fallback,
575 CacheSetHelper &helper) {
576 std::map<unsigned short, PackageContainer> pkgsets;
577 for (const char **I = cmdline; *I != 0; ++I) {
578 unsigned short modID = fallback;
579 PackageContainer pkgset;
1e064088 580 helper.PackageFromModifierCommandLine(modID, &pkgset, Cache, *I, mods);
15fc8636
DK
581 pkgsets[modID].insert(pkgset);
582 }
583 return pkgsets;
584 }
585 static std::map<unsigned short, PackageContainer> GroupedFromCommandLine(
586 pkgCacheFile &Cache,
587 const char **cmdline,
1e064088 588 std::list<CacheSetHelper::PkgModifier> const &mods,
15fc8636 589 unsigned short const &fallback) {
70e706ad 590 CacheSetHelper helper;
446bbcf4 591 return GroupedFromCommandLine(Cache, cmdline,
70e706ad 592 mods, fallback, helper);
9cc83a6f 593 }
c8db3fff 594 /*}}}*/
d4489d49 595}; /*}}}*/
28933259 596// various specialisations for PackageContainer /*{{{*/
c4cca791
DK
597template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
598 for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
599 _cont.push_back(*p);
d3e8fbb3 600}
ffb081b7
DK
601#if __cplusplus >= 201103L
602template<> template<class Cont> void PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
603 for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
604 _cont.push_front(*p);
605}
606#endif
a0c19a21
DK
607template<> template<class Cont> void PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
608 for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
609 _cont.push_back(*p);
610}
5c8c7321
DK
611template<> template<class Cont> void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
612 for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
613 _cont.push_back(*p);
614}
ffb081b7 615// these are 'inline' as otherwise the linker has problems with seeing these untemplated
c4cca791
DK
616// specializations again and again - but we need to see them, so that library users can use them
617template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
618 if (P.end() == true)
619 return false;
620 _cont.push_back(P);
621 return true;
d3e8fbb3 622}
ffb081b7
DK
623#if __cplusplus >= 201103L
624template<> inline bool PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
625 if (P.end() == true)
626 return false;
627 _cont.push_front(P);
628 return true;
629}
630#endif
a0c19a21
DK
631template<> inline bool PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
632 if (P.end() == true)
633 return false;
634 _cont.push_back(P);
635 return true;
636}
5c8c7321
DK
637template<> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
638 if (P.end() == true)
639 return false;
640 _cont.push_back(P);
641 return true;
642}
c4cca791
DK
643template<> inline void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
644 for (const_iterator p = begin; p != end; ++p)
645 _cont.push_back(*p);
d3e8fbb3 646}
ffb081b7
DK
647#if __cplusplus >= 201103L
648template<> inline void PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
649 for (const_iterator p = begin; p != end; ++p)
650 _cont.push_front(*p);
651}
652#endif
a0c19a21
DK
653template<> inline void PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
654 for (const_iterator p = begin; p != end; ++p)
655 _cont.push_back(*p);
656}
5c8c7321
DK
657template<> inline void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
658 for (const_iterator p = begin; p != end; ++p)
659 _cont.push_back(*p);
660}
2c1e4917 661#if APT_GCC_VERSION < 0x409
ffb081b7
DK
662template<> inline PackageContainer<std::set<pkgCache::PkgIterator> >::iterator PackageContainer<std::set<pkgCache::PkgIterator> >::erase(iterator i) {
663 _cont.erase(i._iter);
664 return end();
665}
666template<> inline PackageContainer<std::set<pkgCache::PkgIterator> >::iterator PackageContainer<std::set<pkgCache::PkgIterator> >::erase(iterator first, iterator last) {
667 _cont.erase(first, last);
668 return end();
669}
670#endif
5c8c7321
DK
671template<> template<class Compare> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::sort(Compare Comp) {
672 std::sort(_cont.begin(), _cont.end(), Comp);
673 return true;
674}
ffb081b7
DK
675template<> template<class Compare> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::sort(Compare Comp) {
676 _cont.sort(Comp);
677 return true;
678}
679#if __cplusplus >= 201103L
680template<> template<class Compare> inline bool PackageContainer<std::forward_list<pkgCache::PkgIterator> >::sort(Compare Comp) {
681 _cont.sort(Comp);
682 return true;
683}
684#endif
a0c19a21
DK
685template<> template<class Compare> inline bool PackageContainer<std::deque<pkgCache::PkgIterator> >::sort(Compare Comp) {
686 std::sort(_cont.begin(), _cont.end(), Comp);
687 return true;
688}
28933259 689 /*}}}*/
5c8c7321 690
840ca971
DK
691// class PackageUniverse - pkgCache as PackageContainerInterface /*{{{*/
692/** \class PackageUniverse
693
694 Wraps around our usual pkgCache, so that it can be stuffed into methods
695 expecting a PackageContainer.
696
697 The wrapping is read-only in practice modeled by making erase and co
698 private methods. */
a0c19a21 699class APT_PUBLIC PackageUniverse : public PackageContainerInterface {
840ca971 700 pkgCache * const _cont;
6c55f07a 701 void * const d;
840ca971 702public:
a0c19a21
DK
703 class const_iterator : public APT::Container_iterator_base<APT::PackageContainerInterface, PackageUniverse, PackageUniverse::const_iterator, pkgCache::PkgIterator, pkgCache::PkgIterator>
704 {
a0c19a21
DK
705 public:
706 explicit const_iterator(pkgCache::PkgIterator i):
707 Container_iterator_base<APT::PackageContainerInterface, PackageUniverse, PackageUniverse::const_iterator, pkgCache::PkgIterator, pkgCache::PkgIterator>(i) {}
708
3707fd4f 709 inline pkgCache::PkgIterator getType(void) const { return _iter; }
a0c19a21
DK
710 };
711 typedef const_iterator iterator;
b2a893dd 712 typedef pkgCache::PkgIterator value_type;
2fc9d1eb
DK
713 typedef typename pkgCache::PkgIterator* pointer;
714 typedef typename pkgCache::PkgIterator const* const_pointer;
b2a893dd
DK
715 typedef const pkgCache::PkgIterator& const_reference;
716 typedef const_reference reference;
717 typedef const_iterator::difference_type difference_type;
718 typedef std::make_unsigned<const_iterator::difference_type>::type size_type;
719
840ca971 720
3707fd4f
DK
721 bool empty() const APT_OVERRIDE { return false; }
722 size_t size() const APT_OVERRIDE { return _cont->Head().PackageCount; }
840ca971 723
3707fd4f
DK
724 const_iterator begin() const { return const_iterator(_cont->PkgBegin()); }
725 const_iterator end() const { return const_iterator(_cont->PkgEnd()); }
726 const_iterator cbegin() const { return const_iterator(_cont->PkgBegin()); }
727 const_iterator cend() const { return const_iterator(_cont->PkgEnd()); }
728 iterator begin() { return iterator(_cont->PkgBegin()); }
729 iterator end() { return iterator(_cont->PkgEnd()); }
a0c19a21 730
3707fd4f 731 pkgCache * data() const { return _cont; }
840ca971 732
3707fd4f
DK
733 explicit PackageUniverse(pkgCache * const Owner);
734 explicit PackageUniverse(pkgCacheFile * const Owner);
735 virtual ~PackageUniverse();
840ca971
DK
736
737private:
3707fd4f
DK
738 APT_HIDDEN bool insert(pkgCache::PkgIterator const &) APT_OVERRIDE { return true; }
739 template<class Cont> APT_HIDDEN void insert(PackageContainer<Cont> const &) { }
740 APT_HIDDEN void insert(const_iterator, const_iterator) { }
840ca971 741
3707fd4f
DK
742 APT_HIDDEN void clear() APT_OVERRIDE { }
743 APT_HIDDEN iterator erase( const_iterator pos );
744 APT_HIDDEN iterator erase( const_iterator first, const_iterator last );
840ca971
DK
745};
746 /*}}}*/
15fc8636 747typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
ffb081b7
DK
748#if __cplusplus >= 201103L
749typedef PackageContainer<std::unordered_set<pkgCache::PkgIterator> > PackageUnorderedSet;
750typedef PackageContainer<std::forward_list<pkgCache::PkgIterator> > PackageForwardList;
751#endif
c4cca791 752typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList;
a0c19a21 753typedef PackageContainer<std::deque<pkgCache::PkgIterator> > PackageDeque;
5c8c7321 754typedef PackageContainer<std::vector<pkgCache::PkgIterator> > PackageVector;
78c32596 755
15fc8636
DK
756class VersionContainerInterface { /*{{{*/
757/** \class APT::VersionContainerInterface
758
759 Same as APT::PackageContainerInterface, just for Versions */
760public:
d4489d49 761 /** \brief smell like a pkgCache::VerIterator */
3707fd4f
DK
762 template<class Itr> class iterator_base { /*{{{*/
763 pkgCache::VerIterator getType() const { return static_cast<Itr const*>(this)->getType(); };
d4489d49 764 public:
28933259
DK
765 operator pkgCache::VerIterator(void) { return getType(); }
766
767 inline pkgCache *Cache() const { return getType().Cache(); }
768 inline unsigned long Index() const {return getType().Index();}
769 inline int CompareVer(const pkgCache::VerIterator &B) const { return getType().CompareVer(B); }
770 inline const char *VerStr() const { return getType().VerStr(); }
771 inline const char *Section() const { return getType().Section(); }
772 inline const char *Arch() const { return getType().Arch(); }
773 inline pkgCache::PkgIterator ParentPkg() const { return getType().ParentPkg(); }
774 inline pkgCache::DescIterator DescriptionList() const { return getType().DescriptionList(); }
775 inline pkgCache::DescIterator TranslatedDescription() const { return getType().TranslatedDescription(); }
776 inline pkgCache::DepIterator DependsList() const { return getType().DependsList(); }
777 inline pkgCache::PrvIterator ProvidesList() const { return getType().ProvidesList(); }
778 inline pkgCache::VerFileIterator FileList() const { return getType().FileList(); }
779 inline bool Downloadable() const { return getType().Downloadable(); }
780 inline const char *PriorityType() const { return getType().PriorityType(); }
781 inline std::string RelStr() const { return getType().RelStr(); }
782 inline bool Automatic() const { return getType().Automatic(); }
783 inline pkgCache::VerFileIterator NewestFile() const { return getType().NewestFile(); }
d4489d49 784 // we have only valid iterators here
d3e8fbb3 785 inline bool end() const { return false; }
d4489d49 786
28933259 787 inline pkgCache::Version const * operator->() const { return &*getType(); }
d4489d49 788 };
dc0f01f7 789 /*}}}*/
78c32596 790
15fc8636
DK
791 virtual bool insert(pkgCache::VerIterator const &V) = 0;
792 virtual bool empty() const = 0;
793 virtual void clear() = 0;
28933259 794 virtual size_t size() const = 0;
c45f2d19 795
856d3b06 796 /** \brief specifies which version(s) will be returned if non is given */
5dd00edb 797 enum APT_DEPRECATED_MSG("enum moved to CacheSetHelper::VerSelector instead") Version {
fdba4d53
DK
798 ALL = CacheSetHelper::ALL,
799 CANDANDINST = CacheSetHelper::CANDANDINST,
800 CANDIDATE = CacheSetHelper::CANDIDATE,
801 INSTALLED = CacheSetHelper::INSTALLED,
802 CANDINST = CacheSetHelper::CANDINST,
803 INSTCAND = CacheSetHelper::INSTCAND,
804 NEWEST = CacheSetHelper::NEWEST
856d3b06
DK
805 };
806
15fc8636 807 struct Modifier {
fdba4d53 808 unsigned short const ID;
15fc8636 809 const char * const Alias;
fdba4d53
DK
810 enum Position { NONE, PREFIX, POSTFIX } const Pos;
811 enum CacheSetHelper::VerSelector const SelectVersion;
15fc8636 812 Modifier (unsigned short const &id, const char * const alias, Position const &pos,
fdba4d53 813 enum CacheSetHelper::VerSelector const select) : ID(id), Alias(alias), Pos(pos),
d3e8fbb3 814 SelectVersion(select) {}
586d8704 815APT_IGNORE_DEPRECATED_PUSH
5dd00edb 816 APT_DEPRECATED_MSG("Construct with a CacheSetHelper::VerSelector instead") Modifier(unsigned short const &id, const char * const alias, Position const &pos,
fdba4d53
DK
817 Version const &select) : ID(id), Alias(alias), Pos(pos),
818 SelectVersion((CacheSetHelper::VerSelector)select) {}
586d8704 819APT_IGNORE_DEPRECATED_POP
15fc8636
DK
820 };
821
822 static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
fdba4d53 823 const char **cmdline, CacheSetHelper::VerSelector const fallback,
15fc8636 824 CacheSetHelper &helper);
586d8704 825APT_IGNORE_DEPRECATED_PUSH
5dd00edb 826 APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
fdba4d53
DK
827 const char **cmdline, Version const &fallback,
828 CacheSetHelper &helper) {
829 return FromCommandLine(vci, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
830 }
586d8704 831APT_IGNORE_DEPRECATED_POP
15fc8636
DK
832
833 static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
fdba4d53 834 std::string pkg, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
15fc8636 835 bool const onlyFromName = false);
586d8704 836APT_IGNORE_DEPRECATED_PUSH
5dd00edb 837 APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
fdba4d53
DK
838 std::string pkg, Version const &fallback, CacheSetHelper &helper,
839 bool const onlyFromName = false) {
840 return FromString(vci, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper, onlyFromName);
841 }
586d8704 842APT_IGNORE_DEPRECATED_POP
15fc8636
DK
843
844 static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
fdba4d53 845 pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback,
15fc8636 846 CacheSetHelper &helper);
586d8704 847APT_IGNORE_DEPRECATED_PUSH
5dd00edb 848 APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
fdba4d53
DK
849 pkgCache::PkgIterator const &P, Version const &fallback,
850 CacheSetHelper &helper) {
851 return FromPackage(vci, Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
852 }
586d8704 853APT_IGNORE_DEPRECATED_POP
15fc8636
DK
854
855 static bool FromModifierCommandLine(unsigned short &modID,
856 VersionContainerInterface * const vci,
857 pkgCacheFile &Cache, const char * cmdline,
858 std::list<Modifier> const &mods,
859 CacheSetHelper &helper);
860
c4cca791
DK
861
862 static bool FromDependency(VersionContainerInterface * const vci,
863 pkgCacheFile &Cache,
864 pkgCache::DepIterator const &D,
fdba4d53 865 CacheSetHelper::VerSelector const selector,
c4cca791 866 CacheSetHelper &helper);
586d8704 867APT_IGNORE_DEPRECATED_PUSH
5dd00edb 868 APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromDependency(VersionContainerInterface * const vci,
fdba4d53
DK
869 pkgCacheFile &Cache,
870 pkgCache::DepIterator const &D,
871 Version const &selector,
872 CacheSetHelper &helper) {
873 return FromDependency(vci, Cache, D, (CacheSetHelper::VerSelector)selector, helper);
874 }
586d8704 875APT_IGNORE_DEPRECATED_POP
c4cca791 876
c8a4ce6c 877 VersionContainerInterface();
6c55f07a 878 VersionContainerInterface& operator=(VersionContainerInterface const &other);
c8a4ce6c
DK
879 virtual ~VersionContainerInterface();
880private:
6c55f07a 881 void * const d;
c8a4ce6c 882
15fc8636
DK
883protected: /*{{{*/
884
885 /** \brief returns the candidate version of the package
886
887 \param Cache to be used to query for information
255c9e4b
DK
888 \param Pkg we want the candidate version from this package
889 \param helper used in this container instance */
15fc8636
DK
890 static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache,
891 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
892
893 /** \brief returns the installed version of the package
894
895 \param Cache to be used to query for information
255c9e4b
DK
896 \param Pkg we want the installed version from this package
897 \param helper used in this container instance */
15fc8636
DK
898 static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache,
899 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
900 /*}}}*/
901};
902 /*}}}*/
903template<class Container> class VersionContainer : public VersionContainerInterface {/*{{{*/
c4cca791 904/** \class APT::VersionContainer
15fc8636
DK
905
906 Simple wrapper around a container class like std::set to provide a similar
907 interface to a set of versions as to the complete set of all versions in the
908 pkgCache. */
909 Container _cont;
910public: /*{{{*/
b2a893dd 911
28933259
DK
912 typedef Container_const_iterator<VersionContainerInterface, Container, VersionContainer> const_iterator;
913 typedef Container_iterator<VersionContainerInterface, Container, VersionContainer> iterator;
914 typedef Container_const_reverse_iterator<VersionContainerInterface, Container, VersionContainer> const_reverse_iterator;
915 typedef Container_reverse_iterator<VersionContainerInterface, Container, VersionContainer> reverse_iterator;
b2a893dd 916 typedef typename Container::value_type value_type;
2fc9d1eb
DK
917 typedef typename Container::pointer pointer;
918 typedef typename Container::const_pointer const_pointer;
b2a893dd
DK
919 typedef typename Container::reference reference;
920 typedef typename Container::const_reference const_reference;
921 typedef typename Container::difference_type difference_type;
922 typedef typename Container::size_type size_type;
2fc9d1eb 923 typedef typename Container::allocator_type allocator_type;
15fc8636 924
28933259 925 bool insert(pkgCache::VerIterator const &V) APT_OVERRIDE { if (V.end() == true) return false; _cont.insert(V); return true; }
d3e8fbb3
DK
926 template<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); }
927 void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }
28933259
DK
928 bool empty() const APT_OVERRIDE { return _cont.empty(); }
929 void clear() APT_OVERRIDE { return _cont.clear(); }
930 size_t size() const APT_OVERRIDE { return _cont.size(); }
2c1e4917 931#if APT_GCC_VERSION >= 0x409
ffb081b7
DK
932 iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); }
933 iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
934#else
935 iterator erase( iterator pos ) { return iterator(_cont.erase(pos._iter)); }
936 iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
937#endif
d3e8fbb3
DK
938 const_iterator begin() const { return const_iterator(_cont.begin()); }
939 const_iterator end() const { return const_iterator(_cont.end()); }
28933259
DK
940 const_reverse_iterator rbegin() const { return const_reverse_iterator(_cont.rbegin()); }
941 const_reverse_iterator rend() const { return const_reverse_iterator(_cont.rend()); }
942#if __cplusplus >= 201103L
ffb081b7
DK
943 const_iterator cbegin() const { return const_iterator(_cont.cbegin()); }
944 const_iterator cend() const { return const_iterator(_cont.cend()); }
28933259
DK
945 const_reverse_iterator crbegin() const { return const_reverse_iterator(_cont.crbegin()); }
946 const_reverse_iterator crend() const { return const_reverse_iterator(_cont.crend()); }
947#endif
d3e8fbb3
DK
948 iterator begin() { return iterator(_cont.begin()); }
949 iterator end() { return iterator(_cont.end()); }
28933259
DK
950 reverse_iterator rbegin() { return reverse_iterator(_cont.rbegin()); }
951 reverse_iterator rend() { return reverse_iterator(_cont.rend()); }
d3e8fbb3 952 const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); }
15fc8636 953
2fc9d1eb
DK
954 VersionContainer() : VersionContainerInterface() {}
955 template<typename Itr> VersionContainer(Itr first, Itr last) : VersionContainerInterface(), _cont(first, last) {}
956#if __cplusplus >= 201103L
957 VersionContainer(std::initializer_list<value_type> list) : VersionContainerInterface(), _cont(list) {}
958 void push_back(value_type&& P) { _cont.emplace_back(std::move(P)); }
959 template<typename... Args> void emplace_back(Args&&... args) { _cont.emplace_back(std::forward<Args>(args)...); }
960#endif
961 void push_back(const value_type& P) { _cont.push_back(P); }
962
5c8c7321
DK
963 /** \brief sort all included versions with given comparer
964
965 Some containers are sorted by default, some are not and can't be,
966 but a few like std::vector can be sorted if need be, so this can be
967 specialized in later on. The default is that this will fail though.
968 Specifically, already sorted containers like std::set will return
969 false as well as there is no easy way to check that the given comparer
970 would sort in the same way the set is currently sorted
971
972 \return \b true if the set was sorted, \b false if not. */
973 template<class Compare> bool sort(Compare /*Comp*/) { return false; }
974
856d3b06
DK
975 /** \brief returns all versions specified on the commandline
976
977 Get all versions from the commandline, uses given default version if
978 non specifically requested and executes regex's if needed on names.
979 \param Cache the packages and versions are in
980 \param cmdline Command line the versions should be extracted from
255c9e4b 981 \param fallback version specification
c8db3fff 982 \param helper responsible for error and message handling */
15fc8636 983 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
fdba4d53 984 CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
15fc8636
DK
985 VersionContainer vercon;
986 VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper);
987 return vercon;
988 }
989 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
fdba4d53 990 CacheSetHelper::VerSelector const fallback) {
70e706ad 991 CacheSetHelper helper;
446bbcf4 992 return FromCommandLine(Cache, cmdline, fallback, helper);
856d3b06 993 }
15fc8636 994 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
fdba4d53 995 return FromCommandLine(Cache, cmdline, CacheSetHelper::CANDINST);
856d3b06 996 }
15fc8636 997 static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
fdba4d53 998 CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
80624be7 999 bool const /*onlyFromName = false*/) {
15fc8636
DK
1000 VersionContainer vercon;
1001 VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper);
1002 return vercon;
1003 }
1004 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
fdba4d53 1005 CacheSetHelper::VerSelector const fallback) {
70e706ad 1006 CacheSetHelper helper;
446bbcf4 1007 return FromString(Cache, pkg, fallback, helper);
55c59998 1008 }
15fc8636 1009 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) {
fdba4d53
DK
1010 return FromString(Cache, pkg, CacheSetHelper::CANDINST);
1011 }
586d8704 1012APT_IGNORE_DEPRECATED_PUSH
fdba4d53
DK
1013 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
1014 Version const &fallback, CacheSetHelper &helper) {
1015 VersionContainer vercon;
1016 VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
1017 return vercon;
1018 }
1019 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
1020 Version const &fallback) {
1021 CacheSetHelper helper;
1022 return FromCommandLine(Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
55c59998 1023 }
fdba4d53
DK
1024 static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
1025 Version const &fallback, CacheSetHelper &helper,
1026 bool const /*onlyFromName = false*/) {
1027 VersionContainer vercon;
1028 VersionContainerInterface::FromString(&vercon, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper);
1029 return vercon;
1030 }
1031 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
1032 Version const &fallback) {
1033 CacheSetHelper helper;
1034 return FromString(Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper);
1035 }
586d8704 1036APT_IGNORE_DEPRECATED_POP
55c59998 1037
fb83c1d0
DK
1038 /** \brief returns all versions specified for the package
1039
1040 \param Cache the package and versions are in
1041 \param P the package in question
1042 \param fallback the version(s) you want to get
1043 \param helper the helper used for display and error handling */
15fc8636 1044 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
fdba4d53 1045 CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
15fc8636
DK
1046 VersionContainer vercon;
1047 VersionContainerInterface::FromPackage(&vercon, Cache, P, fallback, helper);
1048 return vercon;
1049 }
1050 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
fdba4d53 1051 CacheSetHelper::VerSelector const fallback) {
c8db3fff 1052 CacheSetHelper helper;
446bbcf4 1053 return FromPackage(Cache, P, fallback, helper);
c8db3fff 1054 }
586d8704 1055APT_IGNORE_DEPRECATED_PUSH
fdba4d53
DK
1056 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
1057 Version const &fallback, CacheSetHelper &helper) {
1058 VersionContainer vercon;
1059 VersionContainerInterface::FromPackage(&vercon, Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
1060 return vercon;
1061 }
1062 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
1063 Version const &fallback) {
1064 CacheSetHelper helper;
1065 return FromPackage(Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
1066 }
586d8704 1067APT_IGNORE_DEPRECATED_POP
15fc8636 1068 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
fdba4d53 1069 return FromPackage(Cache, P, CacheSetHelper::CANDIDATE);
c8db3fff 1070 }
fb83c1d0 1071
15fc8636
DK
1072 static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
1073 pkgCacheFile &Cache,
1074 const char **cmdline,
1075 std::list<Modifier> const &mods,
1076 unsigned short const fallback,
1077 CacheSetHelper &helper) {
1078 std::map<unsigned short, VersionContainer> versets;
1079 for (const char **I = cmdline; *I != 0; ++I) {
1080 unsigned short modID = fallback;
1081 VersionContainer verset;
1082 VersionContainerInterface::FromModifierCommandLine(modID, &verset, Cache, *I, mods, helper);
1083 versets[modID].insert(verset);
1084 }
1085 return versets;
55c59998 1086
15fc8636
DK
1087 }
1088 static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
55c59998 1089 pkgCacheFile &Cache, const char **cmdline,
15fc8636
DK
1090 std::list<Modifier> const &mods,
1091 unsigned short const fallback) {
70e706ad 1092 CacheSetHelper helper;
446bbcf4 1093 return GroupedFromCommandLine(Cache, cmdline,
70e706ad 1094 mods, fallback, helper);
55c59998 1095 }
c4cca791
DK
1096
1097 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
fdba4d53 1098 CacheSetHelper::VerSelector const selector, CacheSetHelper &helper) {
c4cca791
DK
1099 VersionContainer vercon;
1100 VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper);
1101 return vercon;
1102 }
1103 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
fdba4d53 1104 CacheSetHelper::VerSelector const selector) {
c4cca791 1105 CacheSetHelper helper;
9112f777 1106 return FromDependency(Cache, D, selector, helper);
c4cca791 1107 }
586d8704 1108APT_IGNORE_DEPRECATED_PUSH
fdba4d53
DK
1109 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
1110 Version const &selector, CacheSetHelper &helper) {
1111 VersionContainer vercon;
1112 VersionContainerInterface::FromDependency(&vercon, Cache, D, (CacheSetHelper::VerSelector)selector, helper);
1113 return vercon;
1114 }
1115 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
1116 Version const &selector) {
1117 CacheSetHelper helper;
9112f777 1118 return FromDependency(Cache, D, (CacheSetHelper::VerSelector)selector, helper);
fdba4d53 1119 }
586d8704 1120APT_IGNORE_DEPRECATED_POP
c4cca791 1121 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) {
9112f777 1122 return FromDependency(Cache, D, CacheSetHelper::CANDIDATE);
c4cca791 1123 }
856d3b06 1124 /*}}}*/
d4489d49 1125}; /*}}}*/
28933259 1126// various specialisations for VersionContainer /*{{{*/
c4cca791
DK
1127template<> template<class Cont> void VersionContainer<std::list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
1128 for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
1129 _cont.push_back(*v);
d3e8fbb3 1130}
ffb081b7
DK
1131#if __cplusplus >= 201103L
1132template<> template<class Cont> void VersionContainer<std::forward_list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
1133 for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
1134 _cont.push_front(*v);
1135}
1136#endif
a0c19a21
DK
1137template<> template<class Cont> void VersionContainer<std::deque<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
1138 for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
1139 _cont.push_back(*v);
1140}
5c8c7321
DK
1141template<> template<class Cont> void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
1142 for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
1143 _cont.push_back(*v);
1144}
ffb081b7 1145// these are 'inline' as otherwise the linker has problems with seeing these untemplated
c4cca791
DK
1146// specializations again and again - but we need to see them, so that library users can use them
1147template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
1148 if (V.end() == true)
1149 return false;
1150 _cont.push_back(V);
1151 return true;
d3e8fbb3 1152}
ffb081b7
DK
1153#if __cplusplus >= 201103L
1154template<> inline bool VersionContainer<std::forward_list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
1155 if (V.end() == true)
1156 return false;
1157 _cont.push_front(V);
1158 return true;
1159}
1160#endif
a0c19a21
DK
1161template<> inline bool VersionContainer<std::deque<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
1162 if (V.end() == true)
1163 return false;
1164 _cont.push_back(V);
1165 return true;
1166}
5c8c7321
DK
1167template<> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
1168 if (V.end() == true)
1169 return false;
1170 _cont.push_back(V);
1171 return true;
1172}
c4cca791
DK
1173template<> inline void VersionContainer<std::list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
1174 for (const_iterator v = begin; v != end; ++v)
1175 _cont.push_back(*v);
d3e8fbb3 1176}
ffb081b7
DK
1177#if __cplusplus >= 201103L
1178template<> inline void VersionContainer<std::forward_list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
1179 for (const_iterator v = begin; v != end; ++v)
1180 _cont.push_front(*v);
1181}
1182#endif
a0c19a21
DK
1183template<> inline void VersionContainer<std::deque<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
1184 for (const_iterator v = begin; v != end; ++v)
1185 _cont.push_back(*v);
1186}
5c8c7321
DK
1187template<> inline void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
1188 for (const_iterator v = begin; v != end; ++v)
1189 _cont.push_back(*v);
1190}
2c1e4917 1191#if APT_GCC_VERSION < 0x409
ffb081b7
DK
1192template<> inline VersionContainer<std::set<pkgCache::VerIterator> >::iterator VersionContainer<std::set<pkgCache::VerIterator> >::erase(iterator i) {
1193 _cont.erase(i._iter);
1194 return end();
c687384b 1195}
ffb081b7
DK
1196template<> inline VersionContainer<std::set<pkgCache::VerIterator> >::iterator VersionContainer<std::set<pkgCache::VerIterator> >::erase(iterator first, iterator last) {
1197 _cont.erase(first, last);
1198 return end();
c687384b 1199}
ffb081b7 1200#endif
5c8c7321
DK
1201template<> template<class Compare> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::sort(Compare Comp) {
1202 std::sort(_cont.begin(), _cont.end(), Comp);
1203 return true;
1204}
ffb081b7
DK
1205template<> template<class Compare> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::sort(Compare Comp) {
1206 _cont.sort(Comp);
1207 return true;
1208}
1209#if __cplusplus >= 201103L
1210template<> template<class Compare> inline bool VersionContainer<std::forward_list<pkgCache::VerIterator> >::sort(Compare Comp) {
1211 _cont.sort(Comp);
1212 return true;
1213}
1214#endif
a0c19a21
DK
1215template<> template<class Compare> inline bool VersionContainer<std::deque<pkgCache::VerIterator> >::sort(Compare Comp) {
1216 std::sort(_cont.begin(), _cont.end(), Comp);
1217 return true;
1218}
28933259 1219 /*}}}*/
5c8c7321 1220
15fc8636 1221typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet;
ffb081b7
DK
1222#if __cplusplus >= 201103L
1223typedef VersionContainer<std::unordered_set<pkgCache::VerIterator> > VersionUnorderedSet;
1224typedef VersionContainer<std::forward_list<pkgCache::VerIterator> > VersionForwardList;
1225#endif
c4cca791 1226typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList;
a0c19a21 1227typedef VersionContainer<std::deque<pkgCache::VerIterator> > VersionDeque;
5c8c7321 1228typedef VersionContainer<std::vector<pkgCache::VerIterator> > VersionVector;
e1dbde8d
DK
1229}
1230#endif