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