* apt-pkg/cacheset.cc:
[ntk/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
DK
12#include <iostream>
13#include <fstream>
9cc83a6f
DK
14#include <list>
15#include <map>
ffee1c2b 16#include <set>
e1dbde8d 17#include <string>
15fc8636 18#include <iterator>
ffee1c2b 19
472ff00e 20#include <apt-pkg/error.h>
e1dbde8d
DK
21#include <apt-pkg/pkgcache.h>
22 /*}}}*/
472ff00e
DK
23
24class pkgCacheFile;
25
e1dbde8d 26namespace APT {
15fc8636
DK
27class PackageContainerInterface;
28class VersionContainerInterface;
29
70e706ad
DK
30class CacheSetHelper { /*{{{*/
31/** \class APT::CacheSetHelper
32 Simple base class with a lot of virtual methods which can be overridden
33 to alter the behavior or the output of the CacheSets.
34
35 This helper is passed around by the static methods in the CacheSets and
36 used every time they hit an error condition or something could be
37 printed out.
38*/
39public: /*{{{*/
15fc8636 40 CacheSetHelper(bool const ShowError = true,
cd7bbc47
DK
41 GlobalError::MsgType ErrorType = GlobalError::ERROR) :
42 ShowError(ShowError), ErrorType(ErrorType) {};
70e706ad
DK
43 virtual ~CacheSetHelper() {};
44
15fc8636
DK
45 virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
46 virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
70e706ad 47 virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
15fc8636 48 std::string const &ver, bool const verIsRel);
70e706ad 49
15fc8636
DK
50 virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
51 virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
52 virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str);
53
54 virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
55 virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
70e706ad 56 pkgCache::PkgIterator const &Pkg);
15fc8636
DK
57 virtual void canNotFindCandInstVer(VersionContainerInterface * const vci,
58 pkgCacheFile &Cache,
cf28bcad 59 pkgCache::PkgIterator const &Pkg);
15fc8636
DK
60
61 virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str);
70e706ad
DK
62 virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache,
63 pkgCache::PkgIterator const &Pkg);
64 virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache,
65 pkgCache::PkgIterator const &Pkg);
66 virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache,
67 pkgCache::PkgIterator const &Pkg);
68
69 bool showErrors() const { return ShowError; };
15fc8636 70 bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); };
cd7bbc47
DK
71 GlobalError::MsgType errorType() const { return ErrorType; };
72 GlobalError::MsgType errorType(GlobalError::MsgType const &newValue)
73 {
74 if (ErrorType == newValue) return ErrorType;
75 else {
76 GlobalError::MsgType const &oldValue = ErrorType;
77 ErrorType = newValue;
78 return oldValue;
79 }
80 };
81
70e706ad
DK
82 /*}}}*/
83protected:
84 bool ShowError;
cd7bbc47 85 GlobalError::MsgType ErrorType;
70e706ad 86}; /*}}}*/
15fc8636
DK
87class PackageContainerInterface { /*{{{*/
88/** \class PackageContainerInterface
89
90 * Interface ensuring that all operations can be executed on the yet to
91 * define concrete PackageContainer - access to all methods is possible,
92 * but in general the wrappers provided by the PackageContainer template
93 * are nicer to use.
94
95 * This class mostly protects use from the need to write all implementation
96 * of the methods working on containers in the template */
97public:
98 class const_iterator { /*{{{*/
e1dbde8d 99 public:
15fc8636
DK
100 virtual pkgCache::PkgIterator getPkg() const = 0;
101 operator pkgCache::PkgIterator(void) const { return getPkg(); }
102
103 inline const char *Name() const {return getPkg().Name(); }
104 inline std::string FullName(bool const Pretty) const { return getPkg().FullName(Pretty); }
105 inline std::string FullName() const { return getPkg().FullName(); }
106 inline const char *Section() const {return getPkg().Section(); }
107 inline bool Purge() const {return getPkg().Purge(); }
108 inline const char *Arch() const {return getPkg().Arch(); }
109 inline pkgCache::GrpIterator Group() const { return getPkg().Group(); }
110 inline pkgCache::VerIterator VersionList() const { return getPkg().VersionList(); }
111 inline pkgCache::VerIterator CurrentVer() const { return getPkg().CurrentVer(); }
112 inline pkgCache::DepIterator RevDependsList() const { return getPkg().RevDependsList(); }
113 inline pkgCache::PrvIterator ProvidesList() const { return getPkg().ProvidesList(); }
114 inline pkgCache::PkgIterator::OkState State() const { return getPkg().State(); }
115 inline const char *CandVersion() const { return getPkg().CandVersion(); }
116 inline const char *CurVersion() const { return getPkg().CurVersion(); }
117 inline pkgCache *Cache() const { return getPkg().Cache(); };
118 inline unsigned long Index() const {return getPkg().Index();};
78c32596
DK
119 // we have only valid iterators here
120 inline bool end() const { return false; };
e1dbde8d 121
15fc8636
DK
122 inline pkgCache::Package const * operator->() const {return &*getPkg();};
123 };
124 /*}}}*/
125
126 virtual bool insert(pkgCache::PkgIterator const &P) = 0;
127 virtual bool empty() const = 0;
128 virtual void clear() = 0;
129
130 enum Constructor { UNKNOWN, REGEX, TASK };
131 virtual void setConstructor(Constructor const &con) = 0;
132 virtual Constructor getConstructor() const = 0;
133
134 static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
135 static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
136 static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper);
137 static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper);
138 static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper);
139
140 struct Modifier {
141 enum Position { NONE, PREFIX, POSTFIX };
142 unsigned short ID;
143 const char * const Alias;
144 Position Pos;
145 Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {};
146 };
147
148 static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
149 pkgCacheFile &Cache, const char * cmdline,
150 std::list<Modifier> const &mods, CacheSetHelper &helper);
151};
152 /*}}}*/
153template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
154/** \class APT::PackageContainer
e1dbde8d 155
15fc8636
DK
156 Simple wrapper around a container class like std::set to provide a similar
157 interface to a set of packages as to the complete set of all packages in the
158 pkgCache. */
159 Container _cont;
160public: /*{{{*/
161 /** \brief smell like a pkgCache::PkgIterator */
162 class const_iterator : public PackageContainerInterface::const_iterator,
163 public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {/*{{{*/
164 typename Container::const_iterator _iter;
165 public:
166 const_iterator(typename Container::const_iterator i) : _iter(i) {}
167 pkgCache::PkgIterator getPkg(void) const { return *_iter; }
168 inline pkgCache::PkgIterator operator*(void) const { return *_iter; };
169 operator typename Container::const_iterator(void) const { return _iter; }
170 inline void operator++(void) { ++_iter; };
171 inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; };
172 inline bool operator==(const_iterator const &i) const { return _iter == i._iter; };
173 friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
e1dbde8d 174 };
15fc8636
DK
175 // we are not going to allow modify our pkgiterators (it doesn't make sense)…
176 typedef APT::PackageContainer<Container>::const_iterator iterator;
dc0f01f7 177 /*}}}*/
ffee1c2b 178
15fc8636
DK
179 bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; };
180 template<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); };
181 void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); };
182 bool empty() const { return _cont.empty(); };
183 void clear() { return _cont.clear(); };
184 void erase(iterator position) { _cont.erase((typename Container::const_iterator)position); };
185 size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); };
186 void erase(iterator first, iterator last) { _cont.erase(first, last); };
187 size_t size() const { return _cont.size(); };
188
189 const_iterator begin() const { return const_iterator(_cont.begin()); };
190 const_iterator end() const { return const_iterator(_cont.end()); };
191 const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); };
192
193 void setConstructor(Constructor const &by) { ConstructedBy = by; };
194 Constructor getConstructor() const { return ConstructedBy; };
195
196 PackageContainer() : ConstructedBy(UNKNOWN) {};
197 PackageContainer(Constructor const &by) : ConstructedBy(by) {};
c45f2d19 198
dc0f01f7
DK
199 /** \brief returns all packages in the cache who belong to the given task
200
201 A simple helper responsible for search for all members of a task
202 in the cache. Optional it prints a a notice about the
203 packages chosen cause of the given task.
204 \param Cache the packages are in
205 \param pattern name of the task
c8db3fff 206 \param helper responsible for error and message handling */
15fc8636
DK
207 static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
208 PackageContainer cont(TASK);
209 PackageContainerInterface::FromTask(&cont, Cache, pattern, helper);
210 return cont;
211 }
212 static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern) {
70e706ad 213 CacheSetHelper helper;
446bbcf4 214 return FromTask(Cache, pattern, helper);
dc0f01f7
DK
215 }
216
ffee1c2b
DK
217 /** \brief returns all packages in the cache whose name matchs a given pattern
218
219 A simple helper responsible for executing a regular expression on all
220 package names in the cache. Optional it prints a a notice about the
221 packages chosen cause of the given package.
222 \param Cache the packages are in
223 \param pattern regular expression for package names
c8db3fff 224 \param helper responsible for error and message handling */
15fc8636
DK
225 static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
226 PackageContainer cont(REGEX);
227 PackageContainerInterface::FromRegEx(&cont, Cache, pattern, helper);
228 return cont;
229 }
230
231 static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern) {
70e706ad 232 CacheSetHelper helper;
446bbcf4 233 return FromRegEx(Cache, pattern, helper);
ffee1c2b
DK
234 }
235
15fc8636 236 /** \brief returns a package specified by a string
856d3b06 237
15fc8636
DK
238 \param Cache the package is in
239 \param pattern String the package name should be extracted from
c8db3fff 240 \param helper responsible for error and message handling */
15fc8636
DK
241 static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
242 return PackageContainerInterface::FromName(Cache, pattern, helper);
243 }
244 static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) {
70e706ad 245 CacheSetHelper helper;
15fc8636 246 return PackageContainerInterface::FromName(Cache, pattern, helper);
856d3b06
DK
247 }
248
15fc8636 249 /** \brief returns all packages specified by a string
bd631595 250
15fc8636
DK
251 \param Cache the packages are in
252 \param pattern String the package name(s) should be extracted from
c8db3fff 253 \param helper responsible for error and message handling */
15fc8636
DK
254 static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
255 PackageContainer cont;
256 PackageContainerInterface::FromString(&cont, Cache, pattern, helper);
257 return cont;
258 }
259 static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern) {
bd631595 260 CacheSetHelper helper;
15fc8636 261 return FromString(Cache, pattern, helper);
bd631595
DK
262 }
263
78c32596
DK
264 /** \brief returns all packages specified on the commandline
265
266 Get all package names from the commandline and executes regex's if needed.
267 No special package command is supported, just plain names.
268 \param Cache the packages are in
269 \param cmdline Command line the package names should be extracted from
c8db3fff 270 \param helper responsible for error and message handling */
15fc8636
DK
271 static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
272 PackageContainer cont;
273 PackageContainerInterface::FromCommandLine(&cont, Cache, cmdline, helper);
274 return cont;
275 }
276 static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
70e706ad 277 CacheSetHelper helper;
446bbcf4 278 return FromCommandLine(Cache, cmdline, helper);
78c32596 279 }
9cc83a6f 280
c8db3fff
DK
281 /** \brief group packages by a action modifiers
282
283 At some point it is needed to get from the same commandline
284 different package sets grouped by a modifier. Take
285 apt-get install apt awesome-
286 as an example.
287 \param Cache the packages are in
288 \param cmdline Command line the package names should be extracted from
289 \param mods list of modifiers the method should accept
290 \param fallback the default modifier group for a package
291 \param helper responsible for error and message handling */
15fc8636
DK
292 static std::map<unsigned short, PackageContainer> GroupedFromCommandLine(
293 pkgCacheFile &Cache,
294 const char **cmdline,
295 std::list<Modifier> const &mods,
296 unsigned short const &fallback,
297 CacheSetHelper &helper) {
298 std::map<unsigned short, PackageContainer> pkgsets;
299 for (const char **I = cmdline; *I != 0; ++I) {
300 unsigned short modID = fallback;
301 PackageContainer pkgset;
302 PackageContainerInterface::FromModifierCommandLine(modID, &pkgset, Cache, *I, mods, helper);
303 pkgsets[modID].insert(pkgset);
304 }
305 return pkgsets;
306 }
307 static std::map<unsigned short, PackageContainer> GroupedFromCommandLine(
308 pkgCacheFile &Cache,
309 const char **cmdline,
310 std::list<Modifier> const &mods,
311 unsigned short const &fallback) {
70e706ad 312 CacheSetHelper helper;
446bbcf4 313 return GroupedFromCommandLine(Cache, cmdline,
70e706ad 314 mods, fallback, helper);
9cc83a6f 315 }
c8db3fff
DK
316 /*}}}*/
317private: /*{{{*/
318 Constructor ConstructedBy;
d4489d49
DK
319 /*}}}*/
320}; /*}}}*/
15fc8636 321typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
78c32596 322
15fc8636
DK
323class VersionContainerInterface { /*{{{*/
324/** \class APT::VersionContainerInterface
325
326 Same as APT::PackageContainerInterface, just for Versions */
327public:
d4489d49 328 /** \brief smell like a pkgCache::VerIterator */
15fc8636 329 class const_iterator { /*{{{*/
d4489d49 330 public:
15fc8636
DK
331 virtual pkgCache::VerIterator getVer() const = 0;
332 operator pkgCache::VerIterator(void) { return getVer(); }
333
334 inline pkgCache *Cache() const { return getVer().Cache(); };
335 inline unsigned long Index() const {return getVer().Index();};
336 inline int CompareVer(const pkgCache::VerIterator &B) const { return getVer().CompareVer(B); };
337 inline const char *VerStr() const { return getVer().VerStr(); };
338 inline const char *Section() const { return getVer().Section(); };
339 inline const char *Arch() const { return getVer().Arch(); };
340 inline pkgCache::PkgIterator ParentPkg() const { return getVer().ParentPkg(); };
341 inline pkgCache::DescIterator DescriptionList() const { return getVer().DescriptionList(); };
342 inline pkgCache::DescIterator TranslatedDescription() const { return getVer().TranslatedDescription(); };
343 inline pkgCache::DepIterator DependsList() const { return getVer().DependsList(); };
344 inline pkgCache::PrvIterator ProvidesList() const { return getVer().ProvidesList(); };
345 inline pkgCache::VerFileIterator FileList() const { return getVer().FileList(); };
346 inline bool Downloadable() const { return getVer().Downloadable(); };
347 inline const char *PriorityType() const { return getVer().PriorityType(); };
348 inline std::string RelStr() const { return getVer().RelStr(); };
349 inline bool Automatic() const { return getVer().Automatic(); };
350 inline pkgCache::VerFileIterator NewestFile() const { return getVer().NewestFile(); };
d4489d49
DK
351 // we have only valid iterators here
352 inline bool end() const { return false; };
353
15fc8636 354 inline pkgCache::Version const * operator->() const { return &*getVer(); };
d4489d49 355 };
dc0f01f7 356 /*}}}*/
78c32596 357
15fc8636
DK
358 virtual bool insert(pkgCache::VerIterator const &V) = 0;
359 virtual bool empty() const = 0;
360 virtual void clear() = 0;
c45f2d19 361
856d3b06
DK
362 /** \brief specifies which version(s) will be returned if non is given */
363 enum Version {
364 /** All versions */
365 ALL,
366 /** Candidate and installed version */
367 CANDANDINST,
368 /** Candidate version */
369 CANDIDATE,
370 /** Installed version */
371 INSTALLED,
372 /** Candidate or if non installed version */
373 CANDINST,
374 /** Installed or if non candidate version */
375 INSTCAND,
376 /** Newest version */
377 NEWEST
378 };
379
15fc8636
DK
380 struct Modifier {
381 enum Position { NONE, PREFIX, POSTFIX };
382 unsigned short ID;
383 const char * const Alias;
384 Position Pos;
385 Version SelectVersion;
386 Modifier (unsigned short const &id, const char * const alias, Position const &pos,
387 Version const &select) : ID(id), Alias(alias), Pos(pos),
388 SelectVersion(select) {};
389 };
390
391 static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
392 const char **cmdline, Version const &fallback,
393 CacheSetHelper &helper);
394
395 static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
396 std::string pkg, Version const &fallback, CacheSetHelper &helper,
397 bool const onlyFromName = false);
398
399 static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
400 pkgCache::PkgIterator const &P, Version const &fallback,
401 CacheSetHelper &helper);
402
403 static bool FromModifierCommandLine(unsigned short &modID,
404 VersionContainerInterface * const vci,
405 pkgCacheFile &Cache, const char * cmdline,
406 std::list<Modifier> const &mods,
407 CacheSetHelper &helper);
408
409protected: /*{{{*/
410
411 /** \brief returns the candidate version of the package
412
413 \param Cache to be used to query for information
414 \param Pkg we want the candidate version from this package */
415 static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache,
416 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
417
418 /** \brief returns the installed version of the package
419
420 \param Cache to be used to query for information
421 \param Pkg we want the installed version from this package */
422 static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache,
423 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
424 /*}}}*/
425};
426 /*}}}*/
427template<class Container> class VersionContainer : public VersionContainerInterface {/*{{{*/
428/** \class APT::PackageContainer
429
430 Simple wrapper around a container class like std::set to provide a similar
431 interface to a set of versions as to the complete set of all versions in the
432 pkgCache. */
433 Container _cont;
434public: /*{{{*/
435 /** \brief smell like a pkgCache::VerIterator */
436 class const_iterator : public VersionContainerInterface::const_iterator,
437 public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {/*{{{*/
438 typename Container::const_iterator _iter;
439 public:
440 const_iterator(typename Container::const_iterator i) : _iter(i) {}
441 pkgCache::VerIterator getVer(void) const { return *_iter; }
442 inline pkgCache::VerIterator operator*(void) const { return *_iter; };
443 operator typename Container::const_iterator(void) const { return _iter; }
444 inline void operator++(void) { ++_iter; };
445 inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; };
446 inline bool operator==(const_iterator const &i) const { return _iter == i._iter; };
447 friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
448 };
449 // we are not going to allow modify our veriterators (it doesn't make sense)…
450 typedef APT::VersionContainer<Container>::const_iterator iterator;
451 /*}}}*/
452
453 bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; };
454 template<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); };
455 void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); };
456 bool empty() const { return _cont.empty(); };
457 void clear() { return _cont.clear(); };
458 void erase(iterator position) { _cont.erase((typename Container::const_iterator)position); };
459 size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); };
460 void erase(iterator first, iterator last) { _cont.erase(first, last); };
461 size_t size() const { return _cont.size(); };
462
463 const_iterator begin() const { return const_iterator(_cont.begin()); };
464 const_iterator end() const { return const_iterator(_cont.end()); };
465 const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); };
466
856d3b06
DK
467 /** \brief returns all versions specified on the commandline
468
469 Get all versions from the commandline, uses given default version if
470 non specifically requested and executes regex's if needed on names.
471 \param Cache the packages and versions are in
472 \param cmdline Command line the versions should be extracted from
c8db3fff 473 \param helper responsible for error and message handling */
15fc8636
DK
474 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
475 Version const &fallback, CacheSetHelper &helper) {
476 VersionContainer vercon;
477 VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper);
478 return vercon;
479 }
480 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
481 Version const &fallback) {
70e706ad 482 CacheSetHelper helper;
446bbcf4 483 return FromCommandLine(Cache, cmdline, fallback, helper);
856d3b06 484 }
15fc8636 485 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
446bbcf4 486 return FromCommandLine(Cache, cmdline, CANDINST);
856d3b06 487 }
55c59998 488
15fc8636
DK
489 static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
490 Version const &fallback, CacheSetHelper &helper,
491 bool const onlyFromName = false) {
492 VersionContainer vercon;
493 VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper);
494 return vercon;
495 }
496 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
497 Version const &fallback) {
70e706ad 498 CacheSetHelper helper;
446bbcf4 499 return FromString(Cache, pkg, fallback, helper);
55c59998 500 }
15fc8636 501 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) {
446bbcf4 502 return FromString(Cache, pkg, CANDINST);
55c59998
DK
503 }
504
fb83c1d0
DK
505 /** \brief returns all versions specified for the package
506
507 \param Cache the package and versions are in
508 \param P the package in question
509 \param fallback the version(s) you want to get
510 \param helper the helper used for display and error handling */
15fc8636
DK
511 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
512 Version const &fallback, CacheSetHelper &helper) {
513 VersionContainer vercon;
514 VersionContainerInterface::FromPackage(&vercon, Cache, P, fallback, helper);
515 return vercon;
516 }
517 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
518 Version const &fallback) {
c8db3fff 519 CacheSetHelper helper;
446bbcf4 520 return FromPackage(Cache, P, fallback, helper);
c8db3fff 521 }
15fc8636 522 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
446bbcf4 523 return FromPackage(Cache, P, CANDINST);
c8db3fff 524 }
fb83c1d0 525
15fc8636
DK
526 static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
527 pkgCacheFile &Cache,
528 const char **cmdline,
529 std::list<Modifier> const &mods,
530 unsigned short const fallback,
531 CacheSetHelper &helper) {
532 std::map<unsigned short, VersionContainer> versets;
533 for (const char **I = cmdline; *I != 0; ++I) {
534 unsigned short modID = fallback;
535 VersionContainer verset;
536 VersionContainerInterface::FromModifierCommandLine(modID, &verset, Cache, *I, mods, helper);
537 versets[modID].insert(verset);
538 }
539 return versets;
55c59998 540
15fc8636
DK
541 }
542 static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
55c59998 543 pkgCacheFile &Cache, const char **cmdline,
15fc8636
DK
544 std::list<Modifier> const &mods,
545 unsigned short const fallback) {
70e706ad 546 CacheSetHelper helper;
446bbcf4 547 return GroupedFromCommandLine(Cache, cmdline,
70e706ad 548 mods, fallback, helper);
55c59998 549 }
856d3b06 550 /*}}}*/
d4489d49 551}; /*}}}*/
15fc8636 552typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet;
e1dbde8d
DK
553}
554#endif