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