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