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