1 // -*- mode: cpp; mode: fold -*-
4 Wrappers around std::set to have set::iterators which behave
5 similar to the Iterators of the cache structures.
7 Provides also a few helper methods which work with these sets */
10 #define APT_CACHESET_H
11 // Include Files /*{{{*/
21 #include <apt-pkg/error.h>
22 #include <apt-pkg/pkgcache.h>
23 #include <apt-pkg/cacheiterators.h>
25 #ifndef APT_8_CLEANER_HEADERS
26 #include <apt-pkg/cachefile.h>
28 #ifndef APT_10_CLEANER_HEADERS
36 class PackageContainerInterface
;
37 class VersionContainerInterface
;
39 class CacheSetHelper
{ /*{{{*/
40 /** \class APT::CacheSetHelper
41 Simple base class with a lot of virtual methods which can be overridden
42 to alter the behavior or the output of the CacheSets.
44 This helper is passed around by the static methods in the CacheSets and
45 used every time they hit an error condition or something could be
49 CacheSetHelper(bool const ShowError
= true,
50 GlobalError::MsgType ErrorType
= GlobalError::ERROR
) :
51 ShowError(ShowError
), ErrorType(ErrorType
) {}
52 virtual ~CacheSetHelper() {}
54 virtual void showTaskSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
55 virtual void showRegExSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
56 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
57 virtual void showFnmatchSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
59 virtual void showSelectedVersion(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const Ver
,
60 std::string
const &ver
, bool const verIsRel
);
62 virtual void canNotFindTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
63 virtual void canNotFindRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
64 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
65 virtual void canNotFindFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
67 virtual void canNotFindPackage(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &str
);
69 virtual void canNotFindAllVer(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
);
70 virtual void canNotFindInstCandVer(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
71 pkgCache::PkgIterator
const &Pkg
);
72 virtual void canNotFindCandInstVer(VersionContainerInterface
* const vci
,
74 pkgCache::PkgIterator
const &Pkg
);
76 virtual pkgCache::PkgIterator
canNotFindPkgName(pkgCacheFile
&Cache
, std::string
const &str
);
77 virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
,
78 pkgCache::PkgIterator
const &Pkg
);
79 virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
,
80 pkgCache::PkgIterator
const &Pkg
);
81 virtual pkgCache::VerIterator
canNotFindInstalledVer(pkgCacheFile
&Cache
,
82 pkgCache::PkgIterator
const &Pkg
);
84 bool showErrors() const { return ShowError
; }
85 bool showErrors(bool const newValue
) { if (ShowError
== newValue
) return ShowError
; else return ((ShowError
= newValue
) == false); }
86 GlobalError::MsgType
errorType() const { return ErrorType
; }
87 GlobalError::MsgType
errorType(GlobalError::MsgType
const &newValue
)
89 if (ErrorType
== newValue
) return ErrorType
;
91 GlobalError::MsgType
const &oldValue
= ErrorType
;
100 GlobalError::MsgType ErrorType
;
102 class PackageContainerInterface
{ /*{{{*/
103 /** \class PackageContainerInterface
105 * Interface ensuring that all operations can be executed on the yet to
106 * define concrete PackageContainer - access to all methods is possible,
107 * but in general the wrappers provided by the PackageContainer template
110 * This class mostly protects use from the need to write all implementation
111 * of the methods working on containers in the template */
113 class const_iterator
{ /*{{{*/
115 virtual pkgCache::PkgIterator
getPkg() const = 0;
116 operator pkgCache::PkgIterator(void) const { return getPkg(); }
118 inline const char *Name() const {return getPkg().Name(); }
119 inline std::string
FullName(bool const Pretty
) const { return getPkg().FullName(Pretty
); }
120 inline std::string
FullName() const { return getPkg().FullName(); }
121 inline const char *Section() const {return getPkg().Section(); }
122 inline bool Purge() const {return getPkg().Purge(); }
123 inline const char *Arch() const {return getPkg().Arch(); }
124 inline pkgCache::GrpIterator
Group() const { return getPkg().Group(); }
125 inline pkgCache::VerIterator
VersionList() const { return getPkg().VersionList(); }
126 inline pkgCache::VerIterator
CurrentVer() const { return getPkg().CurrentVer(); }
127 inline pkgCache::DepIterator
RevDependsList() const { return getPkg().RevDependsList(); }
128 inline pkgCache::PrvIterator
ProvidesList() const { return getPkg().ProvidesList(); }
129 inline pkgCache::PkgIterator::OkState
State() const { return getPkg().State(); }
130 inline const char *CandVersion() const { return getPkg().CandVersion(); }
131 inline const char *CurVersion() const { return getPkg().CurVersion(); }
132 inline pkgCache
*Cache() const { return getPkg().Cache(); }
133 inline unsigned long Index() const {return getPkg().Index();}
134 // we have only valid iterators here
135 inline bool end() const { return false; }
137 inline pkgCache::Package
const * operator->() const {return &*getPkg();}
141 virtual bool insert(pkgCache::PkgIterator
const &P
) = 0;
142 virtual bool empty() const = 0;
143 virtual void clear() = 0;
145 enum Constructor
{ UNKNOWN
, REGEX
, TASK
, FNMATCH
};
146 virtual void setConstructor(Constructor
const &con
) = 0;
147 virtual Constructor
getConstructor() const = 0;
149 static bool FromTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
150 static bool FromRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
151 static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
);
152 static bool FromFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
153 static bool FromGroup(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
154 static bool FromString(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
);
155 static bool FromCommandLine(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
);
158 enum Position
{ NONE
, PREFIX
, POSTFIX
};
160 const char * const Alias
;
162 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
) : ID(id
), Alias(alias
), Pos(pos
) {}
165 static bool FromModifierCommandLine(unsigned short &modID
, PackageContainerInterface
* const pci
,
166 pkgCacheFile
&Cache
, const char * cmdline
,
167 std::list
<Modifier
> const &mods
, CacheSetHelper
&helper
);
170 template<class Container
> class PackageContainer
: public PackageContainerInterface
{/*{{{*/
171 /** \class APT::PackageContainer
173 Simple wrapper around a container class like std::set to provide a similar
174 interface to a set of packages as to the complete set of all packages in the
178 /** \brief smell like a pkgCache::PkgIterator */
179 class const_iterator
: public PackageContainerInterface::const_iterator
,/*{{{*/
180 public std::iterator
<std::forward_iterator_tag
, typename
Container::const_iterator
> {
181 typename
Container::const_iterator _iter
;
183 const_iterator(typename
Container::const_iterator i
) : _iter(i
) {}
184 pkgCache::PkgIterator
getPkg(void) const { return *_iter
; }
185 inline pkgCache::PkgIterator
operator*(void) const { return *_iter
; }
186 operator typename
Container::const_iterator(void) const { return _iter
; }
187 inline const_iterator
& operator++() { ++_iter
; return *this; }
188 inline const_iterator
operator++(int) { const_iterator
tmp(*this); operator++(); return tmp
; }
189 inline bool operator!=(const_iterator
const &i
) const { return _iter
!= i
._iter
; }
190 inline bool operator==(const_iterator
const &i
) const { return _iter
== i
._iter
; }
191 friend std::ostream
& operator<<(std::ostream
& out
, const_iterator i
) { return operator<<(out
, *i
); }
193 class iterator
: public PackageContainerInterface::const_iterator
,
194 public std::iterator
<std::forward_iterator_tag
, typename
Container::iterator
> {
195 typename
Container::iterator _iter
;
197 iterator(typename
Container::iterator i
) : _iter(i
) {}
198 pkgCache::PkgIterator
getPkg(void) const { return *_iter
; }
199 inline pkgCache::PkgIterator
operator*(void) const { return *_iter
; }
200 operator typename
Container::iterator(void) const { return _iter
; }
201 operator typename PackageContainer
<Container
>::const_iterator() { return typename PackageContainer
<Container
>::const_iterator(_iter
); }
202 inline iterator
& operator++() { ++_iter
; return *this; }
203 inline iterator
operator++(int) { iterator
tmp(*this); operator++(); return tmp
; }
204 inline bool operator!=(iterator
const &i
) const { return _iter
!= i
._iter
; }
205 inline bool operator==(iterator
const &i
) const { return _iter
== i
._iter
; }
206 inline iterator
& operator=(iterator
const &i
) { _iter
= i
._iter
; return *this; }
207 inline iterator
& operator=(typename
Container::iterator
const &i
) { _iter
= i
; return *this; }
208 friend std::ostream
& operator<<(std::ostream
& out
, iterator i
) { return operator<<(out
, *i
); }
212 bool insert(pkgCache::PkgIterator
const &P
) { if (P
.end() == true) return false; _cont
.insert(P
); return true; }
213 template<class Cont
> void insert(PackageContainer
<Cont
> const &pkgcont
) { _cont
.insert((typename
Cont::const_iterator
)pkgcont
.begin(), (typename
Cont::const_iterator
)pkgcont
.end()); }
214 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); }
216 bool empty() const { return _cont
.empty(); }
217 void clear() { return _cont
.clear(); }
218 //FIXME: on ABI break, replace the first with the second without bool
219 void erase(iterator position
) { _cont
.erase((typename
Container::iterator
)position
); }
220 iterator
& erase(iterator
&position
, bool) { return position
= _cont
.erase((typename
Container::iterator
)position
); }
221 size_t erase(const pkgCache::PkgIterator x
) { return _cont
.erase(x
); }
222 void erase(iterator first
, iterator last
) { _cont
.erase(first
, last
); }
223 size_t size() const { return _cont
.size(); }
225 const_iterator
begin() const { return const_iterator(_cont
.begin()); }
226 const_iterator
end() const { return const_iterator(_cont
.end()); }
227 iterator
begin() { return iterator(_cont
.begin()); }
228 iterator
end() { return iterator(_cont
.end()); }
229 const_iterator
find(pkgCache::PkgIterator
const &P
) const { return const_iterator(_cont
.find(P
)); }
231 void setConstructor(Constructor
const &by
) { ConstructedBy
= by
; }
232 Constructor
getConstructor() const { return ConstructedBy
; }
234 PackageContainer() : ConstructedBy(UNKNOWN
) {}
235 PackageContainer(Constructor
const &by
) : ConstructedBy(by
) {}
237 /** \brief returns all packages in the cache who belong to the given task
239 A simple helper responsible for search for all members of a task
240 in the cache. Optional it prints a a notice about the
241 packages chosen cause of the given task.
242 \param Cache the packages are in
243 \param pattern name of the task
244 \param helper responsible for error and message handling */
245 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
246 PackageContainer
cont(TASK
);
247 PackageContainerInterface::FromTask(&cont
, Cache
, pattern
, helper
);
250 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
) {
251 CacheSetHelper helper
;
252 return FromTask(Cache
, pattern
, helper
);
255 /** \brief returns all packages in the cache whose name matchs a given pattern
257 A simple helper responsible for executing a regular expression on all
258 package names in the cache. Optional it prints a a notice about the
259 packages chosen cause of the given package.
260 \param Cache the packages are in
261 \param pattern regular expression for package names
262 \param helper responsible for error and message handling */
263 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
264 PackageContainer
cont(REGEX
);
265 PackageContainerInterface::FromRegEx(&cont
, Cache
, pattern
, helper
);
269 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
270 CacheSetHelper helper
;
271 return FromRegEx(Cache
, pattern
, helper
);
274 static PackageContainer
FromFnmatch(pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
275 PackageContainer
cont(FNMATCH
);
276 PackageContainerInterface::FromFnmatch(&cont
, Cache
, pattern
, helper
);
279 static PackageContainer
FromFnMatch(pkgCacheFile
&Cache
, std::string
const &pattern
) {
280 CacheSetHelper helper
;
281 return FromFnmatch(Cache
, pattern
, helper
);
284 /** \brief returns a package specified by a string
286 \param Cache the package is in
287 \param pattern String the package name should be extracted from
288 \param helper responsible for error and message handling */
289 static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
290 return PackageContainerInterface::FromName(Cache
, pattern
, helper
);
292 static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
) {
293 CacheSetHelper helper
;
294 return PackageContainerInterface::FromName(Cache
, pattern
, helper
);
297 /** \brief returns all packages specified by a string
299 \param Cache the packages are in
300 \param pattern String the package name(s) should be extracted from
301 \param helper responsible for error and message handling */
302 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
303 PackageContainer cont
;
304 PackageContainerInterface::FromString(&cont
, Cache
, pattern
, helper
);
307 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
) {
308 CacheSetHelper helper
;
309 return FromString(Cache
, pattern
, helper
);
312 /** \brief returns all packages specified on the commandline
314 Get all package names from the commandline and executes regex's if needed.
315 No special package command is supported, just plain names.
316 \param Cache the packages are in
317 \param cmdline Command line the package names should be extracted from
318 \param helper responsible for error and message handling */
319 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
) {
320 PackageContainer cont
;
321 PackageContainerInterface::FromCommandLine(&cont
, Cache
, cmdline
, helper
);
324 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
325 CacheSetHelper helper
;
326 return FromCommandLine(Cache
, cmdline
, helper
);
329 /** \brief group packages by a action modifiers
331 At some point it is needed to get from the same commandline
332 different package sets grouped by a modifier. Take
333 apt-get install apt awesome-
335 \param Cache the packages are in
336 \param cmdline Command line the package names should be extracted from
337 \param mods list of modifiers the method should accept
338 \param fallback the default modifier group for a package
339 \param helper responsible for error and message handling */
340 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
342 const char **cmdline
,
343 std::list
<Modifier
> const &mods
,
344 unsigned short const &fallback
,
345 CacheSetHelper
&helper
) {
346 std::map
<unsigned short, PackageContainer
> pkgsets
;
347 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
348 unsigned short modID
= fallback
;
349 PackageContainer pkgset
;
350 PackageContainerInterface::FromModifierCommandLine(modID
, &pkgset
, Cache
, *I
, mods
, helper
);
351 pkgsets
[modID
].insert(pkgset
);
355 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
357 const char **cmdline
,
358 std::list
<Modifier
> const &mods
,
359 unsigned short const &fallback
) {
360 CacheSetHelper helper
;
361 return GroupedFromCommandLine(Cache
, cmdline
,
362 mods
, fallback
, helper
);
366 Constructor ConstructedBy
;
370 template<> template<class Cont
> void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
371 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
374 // these two are 'inline' as otherwise the linker has problems with seeing these untemplated
375 // specializations again and again - but we need to see them, so that library users can use them
376 template<> inline bool PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
382 template<> inline void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
383 for (const_iterator p
= begin
; p
!= end
; ++p
)
386 typedef PackageContainer
<std::set
<pkgCache::PkgIterator
> > PackageSet
;
387 typedef PackageContainer
<std::list
<pkgCache::PkgIterator
> > PackageList
;
389 class VersionContainerInterface
{ /*{{{*/
390 /** \class APT::VersionContainerInterface
392 Same as APT::PackageContainerInterface, just for Versions */
394 /** \brief smell like a pkgCache::VerIterator */
395 class const_iterator
{ /*{{{*/
397 virtual pkgCache::VerIterator
getVer() const = 0;
398 operator pkgCache::VerIterator(void) { return getVer(); }
400 inline pkgCache
*Cache() const { return getVer().Cache(); }
401 inline unsigned long Index() const {return getVer().Index();}
402 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return getVer().CompareVer(B
); }
403 inline const char *VerStr() const { return getVer().VerStr(); }
404 inline const char *Section() const { return getVer().Section(); }
405 inline const char *Arch() const { return getVer().Arch(); }
406 inline pkgCache::PkgIterator
ParentPkg() const { return getVer().ParentPkg(); }
407 inline pkgCache::DescIterator
DescriptionList() const { return getVer().DescriptionList(); }
408 inline pkgCache::DescIterator
TranslatedDescription() const { return getVer().TranslatedDescription(); }
409 inline pkgCache::DepIterator
DependsList() const { return getVer().DependsList(); }
410 inline pkgCache::PrvIterator
ProvidesList() const { return getVer().ProvidesList(); }
411 inline pkgCache::VerFileIterator
FileList() const { return getVer().FileList(); }
412 inline bool Downloadable() const { return getVer().Downloadable(); }
413 inline const char *PriorityType() const { return getVer().PriorityType(); }
414 inline std::string
RelStr() const { return getVer().RelStr(); }
415 inline bool Automatic() const { return getVer().Automatic(); }
416 inline pkgCache::VerFileIterator
NewestFile() const { return getVer().NewestFile(); }
417 // we have only valid iterators here
418 inline bool end() const { return false; }
420 inline pkgCache::Version
const * operator->() const { return &*getVer(); }
424 virtual bool insert(pkgCache::VerIterator
const &V
) = 0;
425 virtual bool empty() const = 0;
426 virtual void clear() = 0;
428 /** \brief specifies which version(s) will be returned if non is given */
432 /** Candidate and installed version */
434 /** Candidate version */
436 /** Installed version */
438 /** Candidate or if non installed version */
440 /** Installed or if non candidate version */
442 /** Newest version */
447 enum Position
{ NONE
, PREFIX
, POSTFIX
};
449 const char * const Alias
;
451 Version SelectVersion
;
452 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
,
453 Version
const &select
) : ID(id
), Alias(alias
), Pos(pos
),
454 SelectVersion(select
) {}
457 static bool FromCommandLine(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
458 const char **cmdline
, Version
const &fallback
,
459 CacheSetHelper
&helper
);
461 static bool FromString(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
462 std::string pkg
, Version
const &fallback
, CacheSetHelper
&helper
,
463 bool const onlyFromName
= false);
465 static bool FromPackage(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
466 pkgCache::PkgIterator
const &P
, Version
const &fallback
,
467 CacheSetHelper
&helper
);
469 static bool FromModifierCommandLine(unsigned short &modID
,
470 VersionContainerInterface
* const vci
,
471 pkgCacheFile
&Cache
, const char * cmdline
,
472 std::list
<Modifier
> const &mods
,
473 CacheSetHelper
&helper
);
476 static bool FromDependency(VersionContainerInterface
* const vci
,
478 pkgCache::DepIterator
const &D
,
479 Version
const &selector
,
480 CacheSetHelper
&helper
);
484 /** \brief returns the candidate version of the package
486 \param Cache to be used to query for information
487 \param Pkg we want the candidate version from this package
488 \param helper used in this container instance */
489 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
490 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
492 /** \brief returns the installed version of the package
494 \param Cache to be used to query for information
495 \param Pkg we want the installed version from this package
496 \param helper used in this container instance */
497 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
498 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
502 template<class Container
> class VersionContainer
: public VersionContainerInterface
{/*{{{*/
503 /** \class APT::VersionContainer
505 Simple wrapper around a container class like std::set to provide a similar
506 interface to a set of versions as to the complete set of all versions in the
510 /** \brief smell like a pkgCache::VerIterator */
511 class const_iterator
: public VersionContainerInterface::const_iterator
,
512 public std::iterator
<std::forward_iterator_tag
, typename
Container::const_iterator
> {/*{{{*/
513 typename
Container::const_iterator _iter
;
515 const_iterator(typename
Container::const_iterator i
) : _iter(i
) {}
516 pkgCache::VerIterator
getVer(void) const { return *_iter
; }
517 inline pkgCache::VerIterator
operator*(void) const { return *_iter
; }
518 operator typename
Container::const_iterator(void) const { return _iter
; }
519 inline const_iterator
& operator++() { ++_iter
; return *this; }
520 inline const_iterator
operator++(int) { const_iterator
tmp(*this); operator++(); return tmp
; }
521 inline bool operator!=(const_iterator
const &i
) const { return _iter
!= i
._iter
; }
522 inline bool operator==(const_iterator
const &i
) const { return _iter
== i
._iter
; }
523 friend std::ostream
& operator<<(std::ostream
& out
, const_iterator i
) { return operator<<(out
, *i
); }
525 class iterator
: public VersionContainerInterface::const_iterator
,
526 public std::iterator
<std::forward_iterator_tag
, typename
Container::iterator
> {
527 typename
Container::iterator _iter
;
529 iterator(typename
Container::iterator i
) : _iter(i
) {}
530 pkgCache::VerIterator
getVer(void) const { return *_iter
; }
531 inline pkgCache::VerIterator
operator*(void) const { return *_iter
; }
532 operator typename
Container::iterator(void) const { return _iter
; }
533 operator typename VersionContainer
<Container
>::const_iterator() { return typename VersionContainer
<Container
>::const_iterator(_iter
); }
534 inline iterator
& operator++() { ++_iter
; return *this; }
535 inline iterator
operator++(int) { iterator
tmp(*this); operator++(); return tmp
; }
536 inline bool operator!=(iterator
const &i
) const { return _iter
!= i
._iter
; }
537 inline bool operator==(iterator
const &i
) const { return _iter
== i
._iter
; }
538 inline iterator
& operator=(iterator
const &i
) { _iter
= i
._iter
; return *this; }
539 inline iterator
& operator=(typename
Container::iterator
const &i
) { _iter
= i
; return *this; }
540 friend std::ostream
& operator<<(std::ostream
& out
, iterator i
) { return operator<<(out
, *i
); }
544 bool insert(pkgCache::VerIterator
const &V
) { if (V
.end() == true) return false; _cont
.insert(V
); return true; }
545 template<class Cont
> void insert(VersionContainer
<Cont
> const &vercont
) { _cont
.insert((typename
Cont::const_iterator
)vercont
.begin(), (typename
Cont::const_iterator
)vercont
.end()); }
546 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); }
547 bool empty() const { return _cont
.empty(); }
548 void clear() { return _cont
.clear(); }
549 //FIXME: on ABI break, replace the first with the second without bool
550 void erase(iterator position
) { _cont
.erase((typename
Container::iterator
)position
); }
551 iterator
& erase(iterator
&position
, bool) { return position
= _cont
.erase((typename
Container::iterator
)position
); }
552 size_t erase(const pkgCache::VerIterator x
) { return _cont
.erase(x
); }
553 void erase(iterator first
, iterator last
) { _cont
.erase(first
, last
); }
554 size_t size() const { return _cont
.size(); }
556 const_iterator
begin() const { return const_iterator(_cont
.begin()); }
557 const_iterator
end() const { return const_iterator(_cont
.end()); }
558 iterator
begin() { return iterator(_cont
.begin()); }
559 iterator
end() { return iterator(_cont
.end()); }
560 const_iterator
find(pkgCache::VerIterator
const &V
) const { return const_iterator(_cont
.find(V
)); }
562 /** \brief returns all versions specified on the commandline
564 Get all versions from the commandline, uses given default version if
565 non specifically requested and executes regex's if needed on names.
566 \param Cache the packages and versions are in
567 \param cmdline Command line the versions should be extracted from
568 \param fallback version specification
569 \param helper responsible for error and message handling */
570 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
571 Version
const &fallback
, CacheSetHelper
&helper
) {
572 VersionContainer vercon
;
573 VersionContainerInterface::FromCommandLine(&vercon
, Cache
, cmdline
, fallback
, helper
);
576 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
577 Version
const &fallback
) {
578 CacheSetHelper helper
;
579 return FromCommandLine(Cache
, cmdline
, fallback
, helper
);
581 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
582 return FromCommandLine(Cache
, cmdline
, CANDINST
);
585 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pkg
,
586 Version
const &fallback
, CacheSetHelper
&helper
,
587 bool const onlyFromName
= false) {
588 VersionContainer vercon
;
589 VersionContainerInterface::FromString(&vercon
, Cache
, pkg
, fallback
, helper
);
592 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
,
593 Version
const &fallback
) {
594 CacheSetHelper helper
;
595 return FromString(Cache
, pkg
, fallback
, helper
);
597 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
) {
598 return FromString(Cache
, pkg
, CANDINST
);
601 /** \brief returns all versions specified for the package
603 \param Cache the package and versions are in
604 \param P the package in question
605 \param fallback the version(s) you want to get
606 \param helper the helper used for display and error handling */
607 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
608 Version
const &fallback
, CacheSetHelper
&helper
) {
609 VersionContainer vercon
;
610 VersionContainerInterface::FromPackage(&vercon
, Cache
, P
, fallback
, helper
);
613 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
614 Version
const &fallback
) {
615 CacheSetHelper helper
;
616 return FromPackage(Cache
, P
, fallback
, helper
);
618 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
) {
619 return FromPackage(Cache
, P
, CANDIDATE
);
622 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
624 const char **cmdline
,
625 std::list
<Modifier
> const &mods
,
626 unsigned short const fallback
,
627 CacheSetHelper
&helper
) {
628 std::map
<unsigned short, VersionContainer
> versets
;
629 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
630 unsigned short modID
= fallback
;
631 VersionContainer verset
;
632 VersionContainerInterface::FromModifierCommandLine(modID
, &verset
, Cache
, *I
, mods
, helper
);
633 versets
[modID
].insert(verset
);
638 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
639 pkgCacheFile
&Cache
, const char **cmdline
,
640 std::list
<Modifier
> const &mods
,
641 unsigned short const fallback
) {
642 CacheSetHelper helper
;
643 return GroupedFromCommandLine(Cache
, cmdline
,
644 mods
, fallback
, helper
);
647 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
648 Version
const &selector
, CacheSetHelper
&helper
) {
649 VersionContainer vercon
;
650 VersionContainerInterface::FromDependency(&vercon
, Cache
, D
, selector
, helper
);
653 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
654 Version
const &selector
) {
655 CacheSetHelper helper
;
656 return FromPackage(Cache
, D
, selector
, helper
);
658 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
) {
659 return FromPackage(Cache
, D
, CANDIDATE
);
664 template<> template<class Cont
> void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
665 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
668 // these two are 'inline' as otherwise the linker has problems with seeing these untemplated
669 // specializations again and again - but we need to see them, so that library users can use them
670 template<> inline bool VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
676 template<> inline void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
677 for (const_iterator v
= begin
; v
!= end
; ++v
)
680 typedef VersionContainer
<std::set
<pkgCache::VerIterator
> > VersionSet
;
681 typedef VersionContainer
<std::list
<pkgCache::VerIterator
> > VersionList
;