]> git.saurik.com Git - apt.git/blob - apt-pkg/cacheset.h
Add GetPriority(VerIterator) to pkgDepCache::Policy
[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::template iterator_base<iterator_type>
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 static_cast<iterator_type const*>(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 typename Container::value_type getType(void) const { 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 typename Container::value_type getType(void) const { 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 typename Container::value_type getType(void) const { 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 typename Container::value_type getType(void) const { 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 template<class Itr> class iterator_base { /*{{{*/
308 pkgCache::PkgIterator getType() const { return static_cast<Itr const*>(this)->getType(); };
309 public:
310 operator pkgCache::PkgIterator(void) const { return getType(); }
311
312 inline const char *Name() const {return getType().Name(); }
313 inline std::string FullName(bool const Pretty) const { return getType().FullName(Pretty); }
314 inline std::string FullName() const { return getType().FullName(); }
315 APT_DEPRECATED inline const char *Section() const {
316 APT_IGNORE_DEPRECATED_PUSH
317 return getType().Section();
318 APT_IGNORE_DEPRECATED_POP
319 }
320 inline bool Purge() const {return getType().Purge(); }
321 inline const char *Arch() const {return getType().Arch(); }
322 inline pkgCache::GrpIterator Group() const { return getType().Group(); }
323 inline pkgCache::VerIterator VersionList() const { return getType().VersionList(); }
324 inline pkgCache::VerIterator CurrentVer() const { return getType().CurrentVer(); }
325 inline pkgCache::DepIterator RevDependsList() const { return getType().RevDependsList(); }
326 inline pkgCache::PrvIterator ProvidesList() const { return getType().ProvidesList(); }
327 inline pkgCache::PkgIterator::OkState State() const { return getType().State(); }
328 inline const char *CandVersion() const { return getType().CandVersion(); }
329 inline const char *CurVersion() const { return getType().CurVersion(); }
330 inline pkgCache *Cache() const { return getType().Cache(); }
331 inline unsigned long Index() const {return getType().Index();}
332 // we have only valid iterators here
333 inline bool end() const { return false; }
334
335 inline pkgCache::Package const * operator->() const {return &*getType();}
336 };
337 /*}}}*/
338
339 virtual bool insert(pkgCache::PkgIterator const &P) = 0;
340 virtual bool empty() const = 0;
341 virtual void clear() = 0;
342 virtual size_t size() const = 0;
343
344 // FIXME: This is a bloody hack removed soon. Use CacheSetHelper::PkgSelector !
345 enum APT_DEPRECATED Constructor { UNKNOWN = CacheSetHelper::UNKNOWN,
346 REGEX = CacheSetHelper::REGEX,
347 TASK = CacheSetHelper::TASK,
348 FNMATCH = CacheSetHelper::FNMATCH };
349 APT_IGNORE_DEPRECATED_PUSH
350 void setConstructor(Constructor const by) { ConstructedBy = (CacheSetHelper::PkgSelector)by; }
351 APT_IGNORE_DEPRECATED_POP
352
353 void setConstructor(CacheSetHelper::PkgSelector const by) { ConstructedBy = by; }
354 CacheSetHelper::PkgSelector getConstructor() const { return ConstructedBy; }
355 PackageContainerInterface();
356 explicit PackageContainerInterface(CacheSetHelper::PkgSelector const by);
357 PackageContainerInterface& operator=(PackageContainerInterface const &other);
358 virtual ~PackageContainerInterface();
359
360 APT_DEPRECATED static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
361 return helper.PackageFrom(CacheSetHelper::TASK, pci, Cache, pattern); }
362 APT_DEPRECATED static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
363 return helper.PackageFrom(CacheSetHelper::REGEX, pci, Cache, pattern); }
364 APT_DEPRECATED static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
365 return helper.PackageFrom(CacheSetHelper::FNMATCH, pci, Cache, pattern); }
366 APT_DEPRECATED static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
367 return helper.PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, pattern); }
368 APT_DEPRECATED static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
369 return helper.PackageFrom(CacheSetHelper::STRING, pci, Cache, pattern); }
370 APT_DEPRECATED static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
371 return helper.PackageFromCommandLine(pci, Cache, cmdline); }
372
373 APT_DEPRECATED typedef CacheSetHelper::PkgModifier Modifier;
374
375 APT_IGNORE_DEPRECATED_PUSH
376 APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
377 return helper.PackageFromName(Cache, pattern); }
378 APT_DEPRECATED static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
379 pkgCacheFile &Cache, const char * cmdline,
380 std::list<Modifier> const &mods, CacheSetHelper &helper) {
381 return helper.PackageFromModifierCommandLine(modID, pci, Cache, cmdline, mods); }
382 APT_IGNORE_DEPRECATED_POP
383
384 private:
385 CacheSetHelper::PkgSelector ConstructedBy;
386 void * const d;
387 };
388 /*}}}*/
389 template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
390 /** \class APT::PackageContainer
391
392 Simple wrapper around a container class like std::set to provide a similar
393 interface to a set of packages as to the complete set of all packages in the
394 pkgCache. */
395 Container _cont;
396 public: /*{{{*/
397 /** \brief smell like a pkgCache::PkgIterator */
398 typedef Container_const_iterator<PackageContainerInterface, Container, PackageContainer> const_iterator;
399 typedef Container_iterator<PackageContainerInterface, Container, PackageContainer> iterator;
400 typedef Container_const_reverse_iterator<PackageContainerInterface, Container, PackageContainer> const_reverse_iterator;
401 typedef Container_reverse_iterator<PackageContainerInterface, Container, PackageContainer> reverse_iterator;
402
403 bool insert(pkgCache::PkgIterator const &P) APT_OVERRIDE { if (P.end() == true) return false; _cont.insert(P); return true; }
404 template<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); }
405 void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }
406
407 bool empty() const APT_OVERRIDE { return _cont.empty(); }
408 void clear() APT_OVERRIDE { return _cont.clear(); }
409 size_t size() const APT_OVERRIDE { return _cont.size(); }
410 #if __cplusplus >= 201103L
411 iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); }
412 iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
413 #else
414 iterator erase( iterator pos ) { return iterator(_cont.erase(pos._iter)); }
415 iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
416 #endif
417 const_iterator begin() const { return const_iterator(_cont.begin()); }
418 const_iterator end() const { return const_iterator(_cont.end()); }
419 const_reverse_iterator rbegin() const { return const_reverse_iterator(_cont.rbegin()); }
420 const_reverse_iterator rend() const { return const_reverse_iterator(_cont.rend()); }
421 #if __cplusplus >= 201103L
422 const_iterator cbegin() const { return const_iterator(_cont.cbegin()); }
423 const_iterator cend() const { return const_iterator(_cont.cend()); }
424 const_reverse_iterator crbegin() const { return const_reverse_iterator(_cont.crbegin()); }
425 const_reverse_iterator crend() const { return const_reverse_iterator(_cont.crend()); }
426 #endif
427 iterator begin() { return iterator(_cont.begin()); }
428 iterator end() { return iterator(_cont.end()); }
429 reverse_iterator rbegin() { return reverse_iterator(_cont.rbegin()); }
430 reverse_iterator rend() { return reverse_iterator(_cont.rend()); }
431 const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); }
432
433 PackageContainer() : PackageContainerInterface(CacheSetHelper::UNKNOWN) {}
434 explicit PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {}
435 APT_IGNORE_DEPRECATED_PUSH
436 APT_DEPRECATED PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {}
437 APT_IGNORE_DEPRECATED_POP
438
439 /** \brief sort all included versions with given comparer
440
441 Some containers are sorted by default, some are not and can't be,
442 but a few like std::vector can be sorted if need be, so this can be
443 specialized in later on. The default is that this will fail though.
444 Specifically, already sorted containers like std::set will return
445 false as well as there is no easy way to check that the given comparer
446 would sort in the same way the set is currently sorted
447
448 \return \b true if the set was sorted, \b false if not. */
449 template<class Compare> bool sort(Compare /*Comp*/) { return false; }
450
451 /** \brief returns all packages in the cache who belong to the given task
452
453 A simple helper responsible for search for all members of a task
454 in the cache. Optional it prints a a notice about the
455 packages chosen cause of the given task.
456 \param Cache the packages are in
457 \param pattern name of the task
458 \param helper responsible for error and message handling */
459 static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
460 PackageContainer cont(CacheSetHelper::TASK);
461 helper.PackageFrom(CacheSetHelper::TASK, &cont, Cache, pattern);
462 return cont;
463 }
464 static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern) {
465 CacheSetHelper helper;
466 return FromTask(Cache, pattern, helper);
467 }
468
469 /** \brief returns all packages in the cache whose name matchs a given pattern
470
471 A simple helper responsible for executing a regular expression on all
472 package names in the cache. Optional it prints a a notice about the
473 packages chosen cause of the given package.
474 \param Cache the packages are in
475 \param pattern regular expression for package names
476 \param helper responsible for error and message handling */
477 static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
478 PackageContainer cont(CacheSetHelper::REGEX);
479 helper.PackageFrom(CacheSetHelper::REGEX, &cont, Cache, pattern);
480 return cont;
481 }
482
483 static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern) {
484 CacheSetHelper helper;
485 return FromRegEx(Cache, pattern, helper);
486 }
487
488 static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
489 PackageContainer cont(CacheSetHelper::FNMATCH);
490 helper.PackageFrom(CacheSetHelper::FNMATCH, &cont, Cache, pattern);
491 return cont;
492 }
493 static PackageContainer FromFnMatch(pkgCacheFile &Cache, std::string const &pattern) {
494 CacheSetHelper helper;
495 return FromFnmatch(Cache, pattern, helper);
496 }
497
498 APT_IGNORE_DEPRECATED_PUSH
499 /** \brief returns a package specified by a string
500
501 \param Cache the package is in
502 \param pattern String the package name should be extracted from
503 \param helper responsible for error and message handling */
504 APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
505 return helper.PackageFromName(Cache, pattern);
506 }
507 APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) {
508 CacheSetHelper helper;
509 return FromName(Cache, pattern, helper);
510 }
511 APT_IGNORE_DEPRECATED_POP
512
513 /** \brief returns all packages specified by a string
514
515 \param Cache the packages are in
516 \param pattern String the package name(s) should be extracted from
517 \param helper responsible for error and message handling */
518 static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
519 PackageContainer cont;
520 helper.PackageFrom(CacheSetHelper::PACKAGENAME, &cont, Cache, pattern);
521 return cont;
522 }
523 static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern) {
524 CacheSetHelper helper;
525 return FromString(Cache, pattern, helper);
526 }
527
528 /** \brief returns all packages specified on the commandline
529
530 Get all package names from the commandline and executes regex's if needed.
531 No special package command is supported, just plain names.
532 \param Cache the packages are in
533 \param cmdline Command line the package names should be extracted from
534 \param helper responsible for error and message handling */
535 static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
536 PackageContainer cont;
537 helper.PackageFromCommandLine(&cont, Cache, cmdline);
538 return cont;
539 }
540 static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
541 CacheSetHelper helper;
542 return FromCommandLine(Cache, cmdline, helper);
543 }
544
545 /** \brief group packages by a action modifiers
546
547 At some point it is needed to get from the same commandline
548 different package sets grouped by a modifier. Take
549 apt-get install apt awesome-
550 as an example.
551 \param Cache the packages are in
552 \param cmdline Command line the package names should be extracted from
553 \param mods list of modifiers the method should accept
554 \param fallback the default modifier group for a package
555 \param helper responsible for error and message handling */
556 static std::map<unsigned short, PackageContainer> GroupedFromCommandLine(
557 pkgCacheFile &Cache,
558 const char **cmdline,
559 std::list<CacheSetHelper::PkgModifier> const &mods,
560 unsigned short const &fallback,
561 CacheSetHelper &helper) {
562 std::map<unsigned short, PackageContainer> pkgsets;
563 for (const char **I = cmdline; *I != 0; ++I) {
564 unsigned short modID = fallback;
565 PackageContainer pkgset;
566 helper.PackageFromModifierCommandLine(modID, &pkgset, Cache, *I, mods);
567 pkgsets[modID].insert(pkgset);
568 }
569 return pkgsets;
570 }
571 static std::map<unsigned short, PackageContainer> GroupedFromCommandLine(
572 pkgCacheFile &Cache,
573 const char **cmdline,
574 std::list<CacheSetHelper::PkgModifier> const &mods,
575 unsigned short const &fallback) {
576 CacheSetHelper helper;
577 return GroupedFromCommandLine(Cache, cmdline,
578 mods, fallback, helper);
579 }
580 /*}}}*/
581 }; /*}}}*/
582 // various specialisations for PackageContainer /*{{{*/
583 template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
584 for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
585 _cont.push_back(*p);
586 }
587 #if __cplusplus >= 201103L
588 template<> template<class Cont> void PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
589 for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
590 _cont.push_front(*p);
591 }
592 #endif
593 template<> template<class Cont> void PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
594 for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
595 _cont.push_back(*p);
596 }
597 template<> template<class Cont> void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
598 for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
599 _cont.push_back(*p);
600 }
601 // these are 'inline' as otherwise the linker has problems with seeing these untemplated
602 // specializations again and again - but we need to see them, so that library users can use them
603 template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
604 if (P.end() == true)
605 return false;
606 _cont.push_back(P);
607 return true;
608 }
609 #if __cplusplus >= 201103L
610 template<> inline bool PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
611 if (P.end() == true)
612 return false;
613 _cont.push_front(P);
614 return true;
615 }
616 #endif
617 template<> inline bool PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
618 if (P.end() == true)
619 return false;
620 _cont.push_back(P);
621 return true;
622 }
623 template<> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
624 if (P.end() == true)
625 return false;
626 _cont.push_back(P);
627 return true;
628 }
629 template<> inline void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
630 for (const_iterator p = begin; p != end; ++p)
631 _cont.push_back(*p);
632 }
633 #if __cplusplus >= 201103L
634 template<> inline void PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
635 for (const_iterator p = begin; p != end; ++p)
636 _cont.push_front(*p);
637 }
638 #endif
639 template<> inline void PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
640 for (const_iterator p = begin; p != end; ++p)
641 _cont.push_back(*p);
642 }
643 template<> inline void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
644 for (const_iterator p = begin; p != end; ++p)
645 _cont.push_back(*p);
646 }
647 #if __cplusplus < 201103L
648 template<> inline PackageContainer<std::set<pkgCache::PkgIterator> >::iterator PackageContainer<std::set<pkgCache::PkgIterator> >::erase(iterator i) {
649 _cont.erase(i._iter);
650 return end();
651 }
652 template<> inline PackageContainer<std::set<pkgCache::PkgIterator> >::iterator PackageContainer<std::set<pkgCache::PkgIterator> >::erase(iterator first, iterator last) {
653 _cont.erase(first, last);
654 return end();
655 }
656 #endif
657 template<> template<class Compare> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::sort(Compare Comp) {
658 std::sort(_cont.begin(), _cont.end(), Comp);
659 return true;
660 }
661 template<> template<class Compare> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::sort(Compare Comp) {
662 _cont.sort(Comp);
663 return true;
664 }
665 #if __cplusplus >= 201103L
666 template<> template<class Compare> inline bool PackageContainer<std::forward_list<pkgCache::PkgIterator> >::sort(Compare Comp) {
667 _cont.sort(Comp);
668 return true;
669 }
670 #endif
671 template<> template<class Compare> inline bool PackageContainer<std::deque<pkgCache::PkgIterator> >::sort(Compare Comp) {
672 std::sort(_cont.begin(), _cont.end(), Comp);
673 return true;
674 }
675 /*}}}*/
676
677 // class PackageUniverse - pkgCache as PackageContainerInterface /*{{{*/
678 /** \class PackageUniverse
679
680 Wraps around our usual pkgCache, so that it can be stuffed into methods
681 expecting a PackageContainer.
682
683 The wrapping is read-only in practice modeled by making erase and co
684 private methods. */
685 class APT_PUBLIC PackageUniverse : public PackageContainerInterface {
686 pkgCache * const _cont;
687 void * const d;
688 public:
689 class const_iterator : public APT::Container_iterator_base<APT::PackageContainerInterface, PackageUniverse, PackageUniverse::const_iterator, pkgCache::PkgIterator, pkgCache::PkgIterator>
690 {
691 public:
692 explicit const_iterator(pkgCache::PkgIterator i):
693 Container_iterator_base<APT::PackageContainerInterface, PackageUniverse, PackageUniverse::const_iterator, pkgCache::PkgIterator, pkgCache::PkgIterator>(i) {}
694
695 inline pkgCache::PkgIterator getType(void) const { return _iter; }
696 };
697 typedef const_iterator iterator;
698
699 bool empty() const APT_OVERRIDE { return false; }
700 size_t size() const APT_OVERRIDE { return _cont->Head().PackageCount; }
701
702 const_iterator begin() const { return const_iterator(_cont->PkgBegin()); }
703 const_iterator end() const { return const_iterator(_cont->PkgEnd()); }
704 const_iterator cbegin() const { return const_iterator(_cont->PkgBegin()); }
705 const_iterator cend() const { return const_iterator(_cont->PkgEnd()); }
706 iterator begin() { return iterator(_cont->PkgBegin()); }
707 iterator end() { return iterator(_cont->PkgEnd()); }
708
709 pkgCache * data() const { return _cont; }
710
711 explicit PackageUniverse(pkgCache * const Owner);
712 explicit PackageUniverse(pkgCacheFile * const Owner);
713 virtual ~PackageUniverse();
714
715 private:
716 APT_HIDDEN bool insert(pkgCache::PkgIterator const &) APT_OVERRIDE { return true; }
717 template<class Cont> APT_HIDDEN void insert(PackageContainer<Cont> const &) { }
718 APT_HIDDEN void insert(const_iterator, const_iterator) { }
719
720 APT_HIDDEN void clear() APT_OVERRIDE { }
721 APT_HIDDEN iterator erase( const_iterator pos );
722 APT_HIDDEN iterator erase( const_iterator first, const_iterator last );
723 };
724 /*}}}*/
725 typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
726 #if __cplusplus >= 201103L
727 typedef PackageContainer<std::unordered_set<pkgCache::PkgIterator> > PackageUnorderedSet;
728 typedef PackageContainer<std::forward_list<pkgCache::PkgIterator> > PackageForwardList;
729 #endif
730 typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList;
731 typedef PackageContainer<std::deque<pkgCache::PkgIterator> > PackageDeque;
732 typedef PackageContainer<std::vector<pkgCache::PkgIterator> > PackageVector;
733
734 class VersionContainerInterface { /*{{{*/
735 /** \class APT::VersionContainerInterface
736
737 Same as APT::PackageContainerInterface, just for Versions */
738 public:
739 /** \brief smell like a pkgCache::VerIterator */
740 template<class Itr> class iterator_base { /*{{{*/
741 pkgCache::VerIterator getType() const { return static_cast<Itr const*>(this)->getType(); };
742 public:
743 operator pkgCache::VerIterator(void) { return getType(); }
744
745 inline pkgCache *Cache() const { return getType().Cache(); }
746 inline unsigned long Index() const {return getType().Index();}
747 inline int CompareVer(const pkgCache::VerIterator &B) const { return getType().CompareVer(B); }
748 inline const char *VerStr() const { return getType().VerStr(); }
749 inline const char *Section() const { return getType().Section(); }
750 inline const char *Arch() const { return getType().Arch(); }
751 inline pkgCache::PkgIterator ParentPkg() const { return getType().ParentPkg(); }
752 inline pkgCache::DescIterator DescriptionList() const { return getType().DescriptionList(); }
753 inline pkgCache::DescIterator TranslatedDescription() const { return getType().TranslatedDescription(); }
754 inline pkgCache::DepIterator DependsList() const { return getType().DependsList(); }
755 inline pkgCache::PrvIterator ProvidesList() const { return getType().ProvidesList(); }
756 inline pkgCache::VerFileIterator FileList() const { return getType().FileList(); }
757 inline bool Downloadable() const { return getType().Downloadable(); }
758 inline const char *PriorityType() const { return getType().PriorityType(); }
759 inline std::string RelStr() const { return getType().RelStr(); }
760 inline bool Automatic() const { return getType().Automatic(); }
761 inline pkgCache::VerFileIterator NewestFile() const { return getType().NewestFile(); }
762 // we have only valid iterators here
763 inline bool end() const { return false; }
764
765 inline pkgCache::Version const * operator->() const { return &*getType(); }
766 };
767 /*}}}*/
768
769 virtual bool insert(pkgCache::VerIterator const &V) = 0;
770 virtual bool empty() const = 0;
771 virtual void clear() = 0;
772 virtual size_t size() const = 0;
773
774 /** \brief specifies which version(s) will be returned if non is given */
775 enum APT_DEPRECATED Version {
776 ALL = CacheSetHelper::ALL,
777 CANDANDINST = CacheSetHelper::CANDANDINST,
778 CANDIDATE = CacheSetHelper::CANDIDATE,
779 INSTALLED = CacheSetHelper::INSTALLED,
780 CANDINST = CacheSetHelper::CANDINST,
781 INSTCAND = CacheSetHelper::INSTCAND,
782 NEWEST = CacheSetHelper::NEWEST
783 };
784
785 struct Modifier {
786 unsigned short const ID;
787 const char * const Alias;
788 enum Position { NONE, PREFIX, POSTFIX } const Pos;
789 enum CacheSetHelper::VerSelector const SelectVersion;
790 Modifier (unsigned short const &id, const char * const alias, Position const &pos,
791 enum CacheSetHelper::VerSelector const select) : ID(id), Alias(alias), Pos(pos),
792 SelectVersion(select) {}
793 APT_IGNORE_DEPRECATED_PUSH
794 APT_DEPRECATED Modifier(unsigned short const &id, const char * const alias, Position const &pos,
795 Version const &select) : ID(id), Alias(alias), Pos(pos),
796 SelectVersion((CacheSetHelper::VerSelector)select) {}
797 APT_IGNORE_DEPRECATED_POP
798 };
799
800 static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
801 const char **cmdline, CacheSetHelper::VerSelector const fallback,
802 CacheSetHelper &helper);
803 APT_IGNORE_DEPRECATED_PUSH
804 APT_DEPRECATED static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
805 const char **cmdline, Version const &fallback,
806 CacheSetHelper &helper) {
807 return FromCommandLine(vci, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
808 }
809 APT_IGNORE_DEPRECATED_POP
810
811 static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
812 std::string pkg, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
813 bool const onlyFromName = false);
814 APT_IGNORE_DEPRECATED_PUSH
815 APT_DEPRECATED static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
816 std::string pkg, Version const &fallback, CacheSetHelper &helper,
817 bool const onlyFromName = false) {
818 return FromString(vci, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper, onlyFromName);
819 }
820 APT_IGNORE_DEPRECATED_POP
821
822 static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
823 pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback,
824 CacheSetHelper &helper);
825 APT_IGNORE_DEPRECATED_PUSH
826 APT_DEPRECATED static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
827 pkgCache::PkgIterator const &P, Version const &fallback,
828 CacheSetHelper &helper) {
829 return FromPackage(vci, Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
830 }
831 APT_IGNORE_DEPRECATED_POP
832
833 static bool FromModifierCommandLine(unsigned short &modID,
834 VersionContainerInterface * const vci,
835 pkgCacheFile &Cache, const char * cmdline,
836 std::list<Modifier> const &mods,
837 CacheSetHelper &helper);
838
839
840 static bool FromDependency(VersionContainerInterface * const vci,
841 pkgCacheFile &Cache,
842 pkgCache::DepIterator const &D,
843 CacheSetHelper::VerSelector const selector,
844 CacheSetHelper &helper);
845 APT_IGNORE_DEPRECATED_PUSH
846 APT_DEPRECATED static bool FromDependency(VersionContainerInterface * const vci,
847 pkgCacheFile &Cache,
848 pkgCache::DepIterator const &D,
849 Version const &selector,
850 CacheSetHelper &helper) {
851 return FromDependency(vci, Cache, D, (CacheSetHelper::VerSelector)selector, helper);
852 }
853 APT_IGNORE_DEPRECATED_POP
854
855 VersionContainerInterface();
856 VersionContainerInterface& operator=(VersionContainerInterface const &other);
857 virtual ~VersionContainerInterface();
858 private:
859 void * const d;
860
861 protected: /*{{{*/
862
863 /** \brief returns the candidate version of the package
864
865 \param Cache to be used to query for information
866 \param Pkg we want the candidate version from this package
867 \param helper used in this container instance */
868 static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache,
869 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
870
871 /** \brief returns the installed version of the package
872
873 \param Cache to be used to query for information
874 \param Pkg we want the installed version from this package
875 \param helper used in this container instance */
876 static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache,
877 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
878 /*}}}*/
879 };
880 /*}}}*/
881 template<class Container> class VersionContainer : public VersionContainerInterface {/*{{{*/
882 /** \class APT::VersionContainer
883
884 Simple wrapper around a container class like std::set to provide a similar
885 interface to a set of versions as to the complete set of all versions in the
886 pkgCache. */
887 Container _cont;
888 public: /*{{{*/
889 typedef Container_const_iterator<VersionContainerInterface, Container, VersionContainer> const_iterator;
890 typedef Container_iterator<VersionContainerInterface, Container, VersionContainer> iterator;
891 typedef Container_const_reverse_iterator<VersionContainerInterface, Container, VersionContainer> const_reverse_iterator;
892 typedef Container_reverse_iterator<VersionContainerInterface, Container, VersionContainer> reverse_iterator;
893
894 bool insert(pkgCache::VerIterator const &V) APT_OVERRIDE { if (V.end() == true) return false; _cont.insert(V); return true; }
895 template<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); }
896 void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }
897 bool empty() const APT_OVERRIDE { return _cont.empty(); }
898 void clear() APT_OVERRIDE { return _cont.clear(); }
899 size_t size() const APT_OVERRIDE { return _cont.size(); }
900 #if __cplusplus >= 201103L
901 iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); }
902 iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
903 #else
904 iterator erase( iterator pos ) { return iterator(_cont.erase(pos._iter)); }
905 iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
906 #endif
907 const_iterator begin() const { return const_iterator(_cont.begin()); }
908 const_iterator end() const { return const_iterator(_cont.end()); }
909 const_reverse_iterator rbegin() const { return const_reverse_iterator(_cont.rbegin()); }
910 const_reverse_iterator rend() const { return const_reverse_iterator(_cont.rend()); }
911 #if __cplusplus >= 201103L
912 const_iterator cbegin() const { return const_iterator(_cont.cbegin()); }
913 const_iterator cend() const { return const_iterator(_cont.cend()); }
914 const_reverse_iterator crbegin() const { return const_reverse_iterator(_cont.crbegin()); }
915 const_reverse_iterator crend() const { return const_reverse_iterator(_cont.crend()); }
916 #endif
917 iterator begin() { return iterator(_cont.begin()); }
918 iterator end() { return iterator(_cont.end()); }
919 reverse_iterator rbegin() { return reverse_iterator(_cont.rbegin()); }
920 reverse_iterator rend() { return reverse_iterator(_cont.rend()); }
921 const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); }
922
923 /** \brief sort all included versions with given comparer
924
925 Some containers are sorted by default, some are not and can't be,
926 but a few like std::vector can be sorted if need be, so this can be
927 specialized in later on. The default is that this will fail though.
928 Specifically, already sorted containers like std::set will return
929 false as well as there is no easy way to check that the given comparer
930 would sort in the same way the set is currently sorted
931
932 \return \b true if the set was sorted, \b false if not. */
933 template<class Compare> bool sort(Compare /*Comp*/) { return false; }
934
935 /** \brief returns all versions specified on the commandline
936
937 Get all versions from the commandline, uses given default version if
938 non specifically requested and executes regex's if needed on names.
939 \param Cache the packages and versions are in
940 \param cmdline Command line the versions should be extracted from
941 \param fallback version specification
942 \param helper responsible for error and message handling */
943 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
944 CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
945 VersionContainer vercon;
946 VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper);
947 return vercon;
948 }
949 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
950 CacheSetHelper::VerSelector const fallback) {
951 CacheSetHelper helper;
952 return FromCommandLine(Cache, cmdline, fallback, helper);
953 }
954 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
955 return FromCommandLine(Cache, cmdline, CacheSetHelper::CANDINST);
956 }
957 static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
958 CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
959 bool const /*onlyFromName = false*/) {
960 VersionContainer vercon;
961 VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper);
962 return vercon;
963 }
964 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
965 CacheSetHelper::VerSelector const fallback) {
966 CacheSetHelper helper;
967 return FromString(Cache, pkg, fallback, helper);
968 }
969 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) {
970 return FromString(Cache, pkg, CacheSetHelper::CANDINST);
971 }
972 APT_IGNORE_DEPRECATED_PUSH
973 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
974 Version const &fallback, CacheSetHelper &helper) {
975 VersionContainer vercon;
976 VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
977 return vercon;
978 }
979 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
980 Version const &fallback) {
981 CacheSetHelper helper;
982 return FromCommandLine(Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
983 }
984 static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
985 Version const &fallback, CacheSetHelper &helper,
986 bool const /*onlyFromName = false*/) {
987 VersionContainer vercon;
988 VersionContainerInterface::FromString(&vercon, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper);
989 return vercon;
990 }
991 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
992 Version const &fallback) {
993 CacheSetHelper helper;
994 return FromString(Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper);
995 }
996 APT_IGNORE_DEPRECATED_POP
997
998 /** \brief returns all versions specified for the package
999
1000 \param Cache the package and versions are in
1001 \param P the package in question
1002 \param fallback the version(s) you want to get
1003 \param helper the helper used for display and error handling */
1004 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
1005 CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
1006 VersionContainer vercon;
1007 VersionContainerInterface::FromPackage(&vercon, Cache, P, fallback, helper);
1008 return vercon;
1009 }
1010 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
1011 CacheSetHelper::VerSelector const fallback) {
1012 CacheSetHelper helper;
1013 return FromPackage(Cache, P, fallback, helper);
1014 }
1015 APT_IGNORE_DEPRECATED_PUSH
1016 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
1017 Version const &fallback, CacheSetHelper &helper) {
1018 VersionContainer vercon;
1019 VersionContainerInterface::FromPackage(&vercon, Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
1020 return vercon;
1021 }
1022 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
1023 Version const &fallback) {
1024 CacheSetHelper helper;
1025 return FromPackage(Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
1026 }
1027 APT_IGNORE_DEPRECATED_POP
1028 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
1029 return FromPackage(Cache, P, CacheSetHelper::CANDIDATE);
1030 }
1031
1032 static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
1033 pkgCacheFile &Cache,
1034 const char **cmdline,
1035 std::list<Modifier> const &mods,
1036 unsigned short const fallback,
1037 CacheSetHelper &helper) {
1038 std::map<unsigned short, VersionContainer> versets;
1039 for (const char **I = cmdline; *I != 0; ++I) {
1040 unsigned short modID = fallback;
1041 VersionContainer verset;
1042 VersionContainerInterface::FromModifierCommandLine(modID, &verset, Cache, *I, mods, helper);
1043 versets[modID].insert(verset);
1044 }
1045 return versets;
1046
1047 }
1048 static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
1049 pkgCacheFile &Cache, const char **cmdline,
1050 std::list<Modifier> const &mods,
1051 unsigned short const fallback) {
1052 CacheSetHelper helper;
1053 return GroupedFromCommandLine(Cache, cmdline,
1054 mods, fallback, helper);
1055 }
1056
1057 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
1058 CacheSetHelper::VerSelector const selector, CacheSetHelper &helper) {
1059 VersionContainer vercon;
1060 VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper);
1061 return vercon;
1062 }
1063 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
1064 CacheSetHelper::VerSelector const selector) {
1065 CacheSetHelper helper;
1066 return FromDependency(Cache, D, selector, helper);
1067 }
1068 APT_IGNORE_DEPRECATED_PUSH
1069 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
1070 Version const &selector, CacheSetHelper &helper) {
1071 VersionContainer vercon;
1072 VersionContainerInterface::FromDependency(&vercon, Cache, D, (CacheSetHelper::VerSelector)selector, helper);
1073 return vercon;
1074 }
1075 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
1076 Version const &selector) {
1077 CacheSetHelper helper;
1078 return FromDependency(Cache, D, (CacheSetHelper::VerSelector)selector, helper);
1079 }
1080 APT_IGNORE_DEPRECATED_POP
1081 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) {
1082 return FromDependency(Cache, D, CacheSetHelper::CANDIDATE);
1083 }
1084 /*}}}*/
1085 }; /*}}}*/
1086 // various specialisations for VersionContainer /*{{{*/
1087 template<> template<class Cont> void VersionContainer<std::list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
1088 for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
1089 _cont.push_back(*v);
1090 }
1091 #if __cplusplus >= 201103L
1092 template<> template<class Cont> void VersionContainer<std::forward_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_front(*v);
1095 }
1096 #endif
1097 template<> template<class Cont> void VersionContainer<std::deque<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
1098 for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
1099 _cont.push_back(*v);
1100 }
1101 template<> template<class Cont> void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
1102 for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
1103 _cont.push_back(*v);
1104 }
1105 // these are 'inline' as otherwise the linker has problems with seeing these untemplated
1106 // specializations again and again - but we need to see them, so that library users can use them
1107 template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
1108 if (V.end() == true)
1109 return false;
1110 _cont.push_back(V);
1111 return true;
1112 }
1113 #if __cplusplus >= 201103L
1114 template<> inline bool VersionContainer<std::forward_list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
1115 if (V.end() == true)
1116 return false;
1117 _cont.push_front(V);
1118 return true;
1119 }
1120 #endif
1121 template<> inline bool VersionContainer<std::deque<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
1122 if (V.end() == true)
1123 return false;
1124 _cont.push_back(V);
1125 return true;
1126 }
1127 template<> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
1128 if (V.end() == true)
1129 return false;
1130 _cont.push_back(V);
1131 return true;
1132 }
1133 template<> inline void VersionContainer<std::list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
1134 for (const_iterator v = begin; v != end; ++v)
1135 _cont.push_back(*v);
1136 }
1137 #if __cplusplus >= 201103L
1138 template<> inline void VersionContainer<std::forward_list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
1139 for (const_iterator v = begin; v != end; ++v)
1140 _cont.push_front(*v);
1141 }
1142 #endif
1143 template<> inline void VersionContainer<std::deque<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
1144 for (const_iterator v = begin; v != end; ++v)
1145 _cont.push_back(*v);
1146 }
1147 template<> inline void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
1148 for (const_iterator v = begin; v != end; ++v)
1149 _cont.push_back(*v);
1150 }
1151 #if __cplusplus < 201103L
1152 template<> inline VersionContainer<std::set<pkgCache::VerIterator> >::iterator VersionContainer<std::set<pkgCache::VerIterator> >::erase(iterator i) {
1153 _cont.erase(i._iter);
1154 return end();
1155 }
1156 template<> inline VersionContainer<std::set<pkgCache::VerIterator> >::iterator VersionContainer<std::set<pkgCache::VerIterator> >::erase(iterator first, iterator last) {
1157 _cont.erase(first, last);
1158 return end();
1159 }
1160 #endif
1161 template<> template<class Compare> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::sort(Compare Comp) {
1162 std::sort(_cont.begin(), _cont.end(), Comp);
1163 return true;
1164 }
1165 template<> template<class Compare> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::sort(Compare Comp) {
1166 _cont.sort(Comp);
1167 return true;
1168 }
1169 #if __cplusplus >= 201103L
1170 template<> template<class Compare> inline bool VersionContainer<std::forward_list<pkgCache::VerIterator> >::sort(Compare Comp) {
1171 _cont.sort(Comp);
1172 return true;
1173 }
1174 #endif
1175 template<> template<class Compare> inline bool VersionContainer<std::deque<pkgCache::VerIterator> >::sort(Compare Comp) {
1176 std::sort(_cont.begin(), _cont.end(), Comp);
1177 return true;
1178 }
1179 /*}}}*/
1180
1181 typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet;
1182 #if __cplusplus >= 201103L
1183 typedef VersionContainer<std::unordered_set<pkgCache::VerIterator> > VersionUnorderedSet;
1184 typedef VersionContainer<std::forward_list<pkgCache::VerIterator> > VersionForwardList;
1185 #endif
1186 typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList;
1187 typedef VersionContainer<std::deque<pkgCache::VerIterator> > VersionDeque;
1188 typedef VersionContainer<std::vector<pkgCache::VerIterator> > VersionVector;
1189 }
1190 #endif