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