* apt-pkg/cacheset.cc:
[ntk/apt.git] / apt-pkg / cacheset.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /** \file cacheset.h
4 Wrappers around std::set to have set::iterators which behave
5 similar to the Iterators of the cache structures.
6
7 Provides also a few helper methods which work with these sets */
8 /*}}}*/
9 #ifndef APT_CACHESET_H
10 #define APT_CACHESET_H
11 // Include Files /*{{{*/
12 #include <iostream>
13 #include <fstream>
14 #include <list>
15 #include <map>
16 #include <set>
17 #include <string>
18 #include <iterator>
19
20 #include <apt-pkg/error.h>
21 #include <apt-pkg/pkgcache.h>
22 /*}}}*/
23
24 class pkgCacheFile;
25
26 namespace APT {
27 class PackageContainerInterface;
28 class VersionContainerInterface;
29
30 class 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 */
39 public: /*{{{*/
40 CacheSetHelper(bool const ShowError = true,
41 GlobalError::MsgType ErrorType = GlobalError::ERROR) :
42 ShowError(ShowError), ErrorType(ErrorType) {};
43 virtual ~CacheSetHelper() {};
44
45 virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
46 virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
47 virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
48 std::string const &ver, bool const verIsRel);
49
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,
56 pkgCache::PkgIterator const &Pkg);
57 virtual void canNotFindCandInstVer(VersionContainerInterface * const vci,
58 pkgCacheFile &Cache,
59 pkgCache::PkgIterator const &Pkg);
60
61 virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str);
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; };
70 bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); };
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
82 /*}}}*/
83 protected:
84 bool ShowError;
85 GlobalError::MsgType ErrorType;
86 }; /*}}}*/
87 class 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 */
97 public:
98 class const_iterator { /*{{{*/
99 public:
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();};
119 // we have only valid iterators here
120 inline bool end() const { return false; };
121
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 /*}}}*/
153 template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
154 /** \class APT::PackageContainer
155
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;
160 public: /*{{{*/
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); }
174 };
175 // we are not going to allow modify our pkgiterators (it doesn't make sense)…
176 typedef APT::PackageContainer<Container>::const_iterator iterator;
177 /*}}}*/
178
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) {};
198
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
206 \param helper responsible for error and message handling */
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) {
213 CacheSetHelper helper;
214 return FromTask(Cache, pattern, helper);
215 }
216
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
224 \param helper responsible for error and message handling */
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) {
232 CacheSetHelper helper;
233 return FromRegEx(Cache, pattern, helper);
234 }
235
236 /** \brief returns a package specified by a string
237
238 \param Cache the package is in
239 \param pattern String the package name should be extracted from
240 \param helper responsible for error and message handling */
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) {
245 CacheSetHelper helper;
246 return PackageContainerInterface::FromName(Cache, pattern, helper);
247 }
248
249 /** \brief returns all packages specified by a string
250
251 \param Cache the packages are in
252 \param pattern String the package name(s) should be extracted from
253 \param helper responsible for error and message handling */
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) {
260 CacheSetHelper helper;
261 return FromString(Cache, pattern, helper);
262 }
263
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
270 \param helper responsible for error and message handling */
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) {
277 CacheSetHelper helper;
278 return FromCommandLine(Cache, cmdline, helper);
279 }
280
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 */
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) {
312 CacheSetHelper helper;
313 return GroupedFromCommandLine(Cache, cmdline,
314 mods, fallback, helper);
315 }
316 /*}}}*/
317 private: /*{{{*/
318 Constructor ConstructedBy;
319 /*}}}*/
320 }; /*}}}*/
321 typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
322
323 class VersionContainerInterface { /*{{{*/
324 /** \class APT::VersionContainerInterface
325
326 Same as APT::PackageContainerInterface, just for Versions */
327 public:
328 /** \brief smell like a pkgCache::VerIterator */
329 class const_iterator { /*{{{*/
330 public:
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(); };
351 // we have only valid iterators here
352 inline bool end() const { return false; };
353
354 inline pkgCache::Version const * operator->() const { return &*getVer(); };
355 };
356 /*}}}*/
357
358 virtual bool insert(pkgCache::VerIterator const &V) = 0;
359 virtual bool empty() const = 0;
360 virtual void clear() = 0;
361
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
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
409 protected: /*{{{*/
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 /*}}}*/
427 template<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;
434 public: /*{{{*/
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
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
473 \param helper responsible for error and message handling */
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) {
482 CacheSetHelper helper;
483 return FromCommandLine(Cache, cmdline, fallback, helper);
484 }
485 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
486 return FromCommandLine(Cache, cmdline, CANDINST);
487 }
488
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) {
498 CacheSetHelper helper;
499 return FromString(Cache, pkg, fallback, helper);
500 }
501 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) {
502 return FromString(Cache, pkg, CANDINST);
503 }
504
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 */
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) {
519 CacheSetHelper helper;
520 return FromPackage(Cache, P, fallback, helper);
521 }
522 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
523 return FromPackage(Cache, P, CANDINST);
524 }
525
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;
540
541 }
542 static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
543 pkgCacheFile &Cache, const char **cmdline,
544 std::list<Modifier> const &mods,
545 unsigned short const fallback) {
546 CacheSetHelper helper;
547 return GroupedFromCommandLine(Cache, cmdline,
548 mods, fallback, helper);
549 }
550 /*}}}*/
551 }; /*}}}*/
552 typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet;
553 }
554 #endif