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