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 APT_DEPRECATED
inline const char *Section() const {
123 #pragma GCC diagnostic push
124 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
126 return getPkg().Section();
128 #pragma GCC diagnostic pop
131 inline bool Purge() const {return getPkg().Purge(); }
132 inline const char *Arch() const {return getPkg().Arch(); }
133 inline pkgCache::GrpIterator
Group() const { return getPkg().Group(); }
134 inline pkgCache::VerIterator
VersionList() const { return getPkg().VersionList(); }
135 inline pkgCache::VerIterator
CurrentVer() const { return getPkg().CurrentVer(); }
136 inline pkgCache::DepIterator
RevDependsList() const { return getPkg().RevDependsList(); }
137 inline pkgCache::PrvIterator
ProvidesList() const { return getPkg().ProvidesList(); }
138 inline pkgCache::PkgIterator::OkState
State() const { return getPkg().State(); }
139 inline const char *CandVersion() const { return getPkg().CandVersion(); }
140 inline const char *CurVersion() const { return getPkg().CurVersion(); }
141 inline pkgCache
*Cache() const { return getPkg().Cache(); }
142 inline unsigned long Index() const {return getPkg().Index();}
143 // we have only valid iterators here
144 inline bool end() const { return false; }
146 inline pkgCache::Package
const * operator->() const {return &*getPkg();}
150 virtual bool insert(pkgCache::PkgIterator
const &P
) = 0;
151 virtual bool empty() const = 0;
152 virtual void clear() = 0;
154 enum Constructor
{ UNKNOWN
, REGEX
, TASK
, FNMATCH
};
155 virtual void setConstructor(Constructor
const &con
) = 0;
156 virtual Constructor
getConstructor() const = 0;
158 static bool FromTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
159 static bool FromRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
160 static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
);
161 static bool FromFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
162 static bool FromGroup(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
163 static bool FromString(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
);
164 static bool FromCommandLine(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
);
167 enum Position
{ NONE
, PREFIX
, POSTFIX
};
169 const char * const Alias
;
171 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
) : ID(id
), Alias(alias
), Pos(pos
) {}
174 static bool FromModifierCommandLine(unsigned short &modID
, PackageContainerInterface
* const pci
,
175 pkgCacheFile
&Cache
, const char * cmdline
,
176 std::list
<Modifier
> const &mods
, CacheSetHelper
&helper
);
179 template<class Container
> class PackageContainer
: public PackageContainerInterface
{/*{{{*/
180 /** \class APT::PackageContainer
182 Simple wrapper around a container class like std::set to provide a similar
183 interface to a set of packages as to the complete set of all packages in the
187 /** \brief smell like a pkgCache::PkgIterator */
188 class const_iterator
: public PackageContainerInterface::const_iterator
,/*{{{*/
189 public std::iterator
<std::forward_iterator_tag
, typename
Container::const_iterator
> {
190 typename
Container::const_iterator _iter
;
192 const_iterator(typename
Container::const_iterator i
) : _iter(i
) {}
193 pkgCache::PkgIterator
getPkg(void) const { return *_iter
; }
194 inline pkgCache::PkgIterator
operator*(void) const { return *_iter
; }
195 operator typename
Container::const_iterator(void) const { return _iter
; }
196 inline const_iterator
& operator++() { ++_iter
; return *this; }
197 inline const_iterator
operator++(int) { const_iterator
tmp(*this); operator++(); return tmp
; }
198 inline bool operator!=(const_iterator
const &i
) const { return _iter
!= i
._iter
; }
199 inline bool operator==(const_iterator
const &i
) const { return _iter
== i
._iter
; }
200 friend std::ostream
& operator<<(std::ostream
& out
, const_iterator i
) { return operator<<(out
, *i
); }
202 class iterator
: public PackageContainerInterface::const_iterator
,
203 public std::iterator
<std::forward_iterator_tag
, typename
Container::iterator
> {
204 typename
Container::iterator _iter
;
206 iterator(typename
Container::iterator i
) : _iter(i
) {}
207 pkgCache::PkgIterator
getPkg(void) const { return *_iter
; }
208 inline pkgCache::PkgIterator
operator*(void) const { return *_iter
; }
209 operator typename
Container::iterator(void) const { return _iter
; }
210 operator typename PackageContainer
<Container
>::const_iterator() { return typename PackageContainer
<Container
>::const_iterator(_iter
); }
211 inline iterator
& operator++() { ++_iter
; return *this; }
212 inline iterator
operator++(int) { iterator
tmp(*this); operator++(); return tmp
; }
213 inline bool operator!=(iterator
const &i
) const { return _iter
!= i
._iter
; }
214 inline bool operator==(iterator
const &i
) const { return _iter
== i
._iter
; }
215 inline iterator
& operator=(iterator
const &i
) { _iter
= i
._iter
; return *this; }
216 inline iterator
& operator=(typename
Container::iterator
const &i
) { _iter
= i
; return *this; }
217 friend std::ostream
& operator<<(std::ostream
& out
, iterator i
) { return operator<<(out
, *i
); }
221 bool insert(pkgCache::PkgIterator
const &P
) { if (P
.end() == true) return false; _cont
.insert(P
); return true; }
222 template<class Cont
> void insert(PackageContainer
<Cont
> const &pkgcont
) { _cont
.insert((typename
Cont::const_iterator
)pkgcont
.begin(), (typename
Cont::const_iterator
)pkgcont
.end()); }
223 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); }
225 bool empty() const { return _cont
.empty(); }
226 void clear() { return _cont
.clear(); }
227 //FIXME: on ABI break, replace the first with the second without bool
228 void erase(iterator position
) { _cont
.erase((typename
Container::iterator
)position
); }
229 iterator
& erase(iterator
&position
, bool) { return position
= _cont
.erase((typename
Container::iterator
)position
); }
230 size_t erase(const pkgCache::PkgIterator x
) { return _cont
.erase(x
); }
231 void erase(iterator first
, iterator last
) { _cont
.erase(first
, last
); }
232 size_t size() const { return _cont
.size(); }
234 const_iterator
begin() const { return const_iterator(_cont
.begin()); }
235 const_iterator
end() const { return const_iterator(_cont
.end()); }
236 iterator
begin() { return iterator(_cont
.begin()); }
237 iterator
end() { return iterator(_cont
.end()); }
238 const_iterator
find(pkgCache::PkgIterator
const &P
) const { return const_iterator(_cont
.find(P
)); }
240 void setConstructor(Constructor
const &by
) { ConstructedBy
= by
; }
241 Constructor
getConstructor() const { return ConstructedBy
; }
243 PackageContainer() : ConstructedBy(UNKNOWN
) {}
244 PackageContainer(Constructor
const &by
) : ConstructedBy(by
) {}
246 /** \brief returns all packages in the cache who belong to the given task
248 A simple helper responsible for search for all members of a task
249 in the cache. Optional it prints a a notice about the
250 packages chosen cause of the given task.
251 \param Cache the packages are in
252 \param pattern name of the task
253 \param helper responsible for error and message handling */
254 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
255 PackageContainer
cont(TASK
);
256 PackageContainerInterface::FromTask(&cont
, Cache
, pattern
, helper
);
259 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
) {
260 CacheSetHelper helper
;
261 return FromTask(Cache
, pattern
, helper
);
264 /** \brief returns all packages in the cache whose name matchs a given pattern
266 A simple helper responsible for executing a regular expression on all
267 package names in the cache. Optional it prints a a notice about the
268 packages chosen cause of the given package.
269 \param Cache the packages are in
270 \param pattern regular expression for package names
271 \param helper responsible for error and message handling */
272 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
273 PackageContainer
cont(REGEX
);
274 PackageContainerInterface::FromRegEx(&cont
, Cache
, pattern
, helper
);
278 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
279 CacheSetHelper helper
;
280 return FromRegEx(Cache
, pattern
, helper
);
283 static PackageContainer
FromFnmatch(pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
284 PackageContainer
cont(FNMATCH
);
285 PackageContainerInterface::FromFnmatch(&cont
, Cache
, pattern
, helper
);
288 static PackageContainer
FromFnMatch(pkgCacheFile
&Cache
, std::string
const &pattern
) {
289 CacheSetHelper helper
;
290 return FromFnmatch(Cache
, pattern
, helper
);
293 /** \brief returns a package specified by a string
295 \param Cache the package is in
296 \param pattern String the package name should be extracted from
297 \param helper responsible for error and message handling */
298 static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
299 return PackageContainerInterface::FromName(Cache
, pattern
, helper
);
301 static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
) {
302 CacheSetHelper helper
;
303 return PackageContainerInterface::FromName(Cache
, pattern
, helper
);
306 /** \brief returns all packages specified by a string
308 \param Cache the packages are in
309 \param pattern String the package name(s) should be extracted from
310 \param helper responsible for error and message handling */
311 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
312 PackageContainer cont
;
313 PackageContainerInterface::FromString(&cont
, Cache
, pattern
, helper
);
316 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
) {
317 CacheSetHelper helper
;
318 return FromString(Cache
, pattern
, helper
);
321 /** \brief returns all packages specified on the commandline
323 Get all package names from the commandline and executes regex's if needed.
324 No special package command is supported, just plain names.
325 \param Cache the packages are in
326 \param cmdline Command line the package names should be extracted from
327 \param helper responsible for error and message handling */
328 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
) {
329 PackageContainer cont
;
330 PackageContainerInterface::FromCommandLine(&cont
, Cache
, cmdline
, helper
);
333 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
334 CacheSetHelper helper
;
335 return FromCommandLine(Cache
, cmdline
, helper
);
338 /** \brief group packages by a action modifiers
340 At some point it is needed to get from the same commandline
341 different package sets grouped by a modifier. Take
342 apt-get install apt awesome-
344 \param Cache the packages are in
345 \param cmdline Command line the package names should be extracted from
346 \param mods list of modifiers the method should accept
347 \param fallback the default modifier group for a package
348 \param helper responsible for error and message handling */
349 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
351 const char **cmdline
,
352 std::list
<Modifier
> const &mods
,
353 unsigned short const &fallback
,
354 CacheSetHelper
&helper
) {
355 std::map
<unsigned short, PackageContainer
> pkgsets
;
356 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
357 unsigned short modID
= fallback
;
358 PackageContainer pkgset
;
359 PackageContainerInterface::FromModifierCommandLine(modID
, &pkgset
, Cache
, *I
, mods
, helper
);
360 pkgsets
[modID
].insert(pkgset
);
364 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
366 const char **cmdline
,
367 std::list
<Modifier
> const &mods
,
368 unsigned short const &fallback
) {
369 CacheSetHelper helper
;
370 return GroupedFromCommandLine(Cache
, cmdline
,
371 mods
, fallback
, helper
);
375 Constructor ConstructedBy
;
379 template<> template<class Cont
> void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
380 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
383 // these two are 'inline' as otherwise the linker has problems with seeing these untemplated
384 // specializations again and again - but we need to see them, so that library users can use them
385 template<> inline bool PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
391 template<> inline void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
392 for (const_iterator p
= begin
; p
!= end
; ++p
)
395 typedef PackageContainer
<std::set
<pkgCache::PkgIterator
> > PackageSet
;
396 typedef PackageContainer
<std::list
<pkgCache::PkgIterator
> > PackageList
;
398 class VersionContainerInterface
{ /*{{{*/
399 /** \class APT::VersionContainerInterface
401 Same as APT::PackageContainerInterface, just for Versions */
403 /** \brief smell like a pkgCache::VerIterator */
404 class const_iterator
{ /*{{{*/
406 virtual pkgCache::VerIterator
getVer() const = 0;
407 operator pkgCache::VerIterator(void) { return getVer(); }
409 inline pkgCache
*Cache() const { return getVer().Cache(); }
410 inline unsigned long Index() const {return getVer().Index();}
411 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return getVer().CompareVer(B
); }
412 inline const char *VerStr() const { return getVer().VerStr(); }
413 inline const char *Section() const { return getVer().Section(); }
414 inline const char *Arch() const { return getVer().Arch(); }
415 inline pkgCache::PkgIterator
ParentPkg() const { return getVer().ParentPkg(); }
416 inline pkgCache::DescIterator
DescriptionList() const { return getVer().DescriptionList(); }
417 inline pkgCache::DescIterator
TranslatedDescription() const { return getVer().TranslatedDescription(); }
418 inline pkgCache::DepIterator
DependsList() const { return getVer().DependsList(); }
419 inline pkgCache::PrvIterator
ProvidesList() const { return getVer().ProvidesList(); }
420 inline pkgCache::VerFileIterator
FileList() const { return getVer().FileList(); }
421 inline bool Downloadable() const { return getVer().Downloadable(); }
422 inline const char *PriorityType() const { return getVer().PriorityType(); }
423 inline std::string
RelStr() const { return getVer().RelStr(); }
424 inline bool Automatic() const { return getVer().Automatic(); }
425 inline pkgCache::VerFileIterator
NewestFile() const { return getVer().NewestFile(); }
426 // we have only valid iterators here
427 inline bool end() const { return false; }
429 inline pkgCache::Version
const * operator->() const { return &*getVer(); }
433 virtual bool insert(pkgCache::VerIterator
const &V
) = 0;
434 virtual bool empty() const = 0;
435 virtual void clear() = 0;
437 /** \brief specifies which version(s) will be returned if non is given */
441 /** Candidate and installed version */
443 /** Candidate version */
445 /** Installed version */
447 /** Candidate or if non installed version */
449 /** Installed or if non candidate version */
451 /** Newest version */
456 enum Position
{ NONE
, PREFIX
, POSTFIX
};
458 const char * const Alias
;
460 Version SelectVersion
;
461 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
,
462 Version
const &select
) : ID(id
), Alias(alias
), Pos(pos
),
463 SelectVersion(select
) {}
466 static bool FromCommandLine(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
467 const char **cmdline
, Version
const &fallback
,
468 CacheSetHelper
&helper
);
470 static bool FromString(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
471 std::string pkg
, Version
const &fallback
, CacheSetHelper
&helper
,
472 bool const onlyFromName
= false);
474 static bool FromPackage(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
475 pkgCache::PkgIterator
const &P
, Version
const &fallback
,
476 CacheSetHelper
&helper
);
478 static bool FromModifierCommandLine(unsigned short &modID
,
479 VersionContainerInterface
* const vci
,
480 pkgCacheFile
&Cache
, const char * cmdline
,
481 std::list
<Modifier
> const &mods
,
482 CacheSetHelper
&helper
);
485 static bool FromDependency(VersionContainerInterface
* const vci
,
487 pkgCache::DepIterator
const &D
,
488 Version
const &selector
,
489 CacheSetHelper
&helper
);
493 /** \brief returns the candidate version of the package
495 \param Cache to be used to query for information
496 \param Pkg we want the candidate version from this package
497 \param helper used in this container instance */
498 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
499 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
501 /** \brief returns the installed version of the package
503 \param Cache to be used to query for information
504 \param Pkg we want the installed version from this package
505 \param helper used in this container instance */
506 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
507 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
511 template<class Container
> class VersionContainer
: public VersionContainerInterface
{/*{{{*/
512 /** \class APT::VersionContainer
514 Simple wrapper around a container class like std::set to provide a similar
515 interface to a set of versions as to the complete set of all versions in the
519 /** \brief smell like a pkgCache::VerIterator */
520 class const_iterator
: public VersionContainerInterface::const_iterator
,
521 public std::iterator
<std::forward_iterator_tag
, typename
Container::const_iterator
> {/*{{{*/
522 typename
Container::const_iterator _iter
;
524 const_iterator(typename
Container::const_iterator i
) : _iter(i
) {}
525 pkgCache::VerIterator
getVer(void) const { return *_iter
; }
526 inline pkgCache::VerIterator
operator*(void) const { return *_iter
; }
527 operator typename
Container::const_iterator(void) const { return _iter
; }
528 inline const_iterator
& operator++() { ++_iter
; return *this; }
529 inline const_iterator
operator++(int) { const_iterator
tmp(*this); operator++(); return tmp
; }
530 inline bool operator!=(const_iterator
const &i
) const { return _iter
!= i
._iter
; }
531 inline bool operator==(const_iterator
const &i
) const { return _iter
== i
._iter
; }
532 friend std::ostream
& operator<<(std::ostream
& out
, const_iterator i
) { return operator<<(out
, *i
); }
534 class iterator
: public VersionContainerInterface::const_iterator
,
535 public std::iterator
<std::forward_iterator_tag
, typename
Container::iterator
> {
536 typename
Container::iterator _iter
;
538 iterator(typename
Container::iterator i
) : _iter(i
) {}
539 pkgCache::VerIterator
getVer(void) const { return *_iter
; }
540 inline pkgCache::VerIterator
operator*(void) const { return *_iter
; }
541 operator typename
Container::iterator(void) const { return _iter
; }
542 operator typename VersionContainer
<Container
>::const_iterator() { return typename VersionContainer
<Container
>::const_iterator(_iter
); }
543 inline iterator
& operator++() { ++_iter
; return *this; }
544 inline iterator
operator++(int) { iterator
tmp(*this); operator++(); return tmp
; }
545 inline bool operator!=(iterator
const &i
) const { return _iter
!= i
._iter
; }
546 inline bool operator==(iterator
const &i
) const { return _iter
== i
._iter
; }
547 inline iterator
& operator=(iterator
const &i
) { _iter
= i
._iter
; return *this; }
548 inline iterator
& operator=(typename
Container::iterator
const &i
) { _iter
= i
; return *this; }
549 friend std::ostream
& operator<<(std::ostream
& out
, iterator i
) { return operator<<(out
, *i
); }
553 bool insert(pkgCache::VerIterator
const &V
) { if (V
.end() == true) return false; _cont
.insert(V
); return true; }
554 template<class Cont
> void insert(VersionContainer
<Cont
> const &vercont
) { _cont
.insert((typename
Cont::const_iterator
)vercont
.begin(), (typename
Cont::const_iterator
)vercont
.end()); }
555 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); }
556 bool empty() const { return _cont
.empty(); }
557 void clear() { return _cont
.clear(); }
558 //FIXME: on ABI break, replace the first with the second without bool
559 void erase(iterator position
) { _cont
.erase((typename
Container::iterator
)position
); }
560 iterator
& erase(iterator
&position
, bool) { return position
= _cont
.erase((typename
Container::iterator
)position
); }
561 size_t erase(const pkgCache::VerIterator x
) { return _cont
.erase(x
); }
562 void erase(iterator first
, iterator last
) { _cont
.erase(first
, last
); }
563 size_t size() const { return _cont
.size(); }
565 const_iterator
begin() const { return const_iterator(_cont
.begin()); }
566 const_iterator
end() const { return const_iterator(_cont
.end()); }
567 iterator
begin() { return iterator(_cont
.begin()); }
568 iterator
end() { return iterator(_cont
.end()); }
569 const_iterator
find(pkgCache::VerIterator
const &V
) const { return const_iterator(_cont
.find(V
)); }
571 /** \brief returns all versions specified on the commandline
573 Get all versions from the commandline, uses given default version if
574 non specifically requested and executes regex's if needed on names.
575 \param Cache the packages and versions are in
576 \param cmdline Command line the versions should be extracted from
577 \param fallback version specification
578 \param helper responsible for error and message handling */
579 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
580 Version
const &fallback
, CacheSetHelper
&helper
) {
581 VersionContainer vercon
;
582 VersionContainerInterface::FromCommandLine(&vercon
, Cache
, cmdline
, fallback
, helper
);
585 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
586 Version
const &fallback
) {
587 CacheSetHelper helper
;
588 return FromCommandLine(Cache
, cmdline
, fallback
, helper
);
590 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
591 return FromCommandLine(Cache
, cmdline
, CANDINST
);
594 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pkg
,
595 Version
const &fallback
, CacheSetHelper
&helper
,
596 bool const /*onlyFromName = false*/) {
597 VersionContainer vercon
;
598 VersionContainerInterface::FromString(&vercon
, Cache
, pkg
, fallback
, helper
);
601 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
,
602 Version
const &fallback
) {
603 CacheSetHelper helper
;
604 return FromString(Cache
, pkg
, fallback
, helper
);
606 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
) {
607 return FromString(Cache
, pkg
, CANDINST
);
610 /** \brief returns all versions specified for the package
612 \param Cache the package and versions are in
613 \param P the package in question
614 \param fallback the version(s) you want to get
615 \param helper the helper used for display and error handling */
616 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
617 Version
const &fallback
, CacheSetHelper
&helper
) {
618 VersionContainer vercon
;
619 VersionContainerInterface::FromPackage(&vercon
, Cache
, P
, fallback
, helper
);
622 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
623 Version
const &fallback
) {
624 CacheSetHelper helper
;
625 return FromPackage(Cache
, P
, fallback
, helper
);
627 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
) {
628 return FromPackage(Cache
, P
, CANDIDATE
);
631 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
633 const char **cmdline
,
634 std::list
<Modifier
> const &mods
,
635 unsigned short const fallback
,
636 CacheSetHelper
&helper
) {
637 std::map
<unsigned short, VersionContainer
> versets
;
638 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
639 unsigned short modID
= fallback
;
640 VersionContainer verset
;
641 VersionContainerInterface::FromModifierCommandLine(modID
, &verset
, Cache
, *I
, mods
, helper
);
642 versets
[modID
].insert(verset
);
647 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
648 pkgCacheFile
&Cache
, const char **cmdline
,
649 std::list
<Modifier
> const &mods
,
650 unsigned short const fallback
) {
651 CacheSetHelper helper
;
652 return GroupedFromCommandLine(Cache
, cmdline
,
653 mods
, fallback
, helper
);
656 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
657 Version
const &selector
, CacheSetHelper
&helper
) {
658 VersionContainer vercon
;
659 VersionContainerInterface::FromDependency(&vercon
, Cache
, D
, selector
, helper
);
662 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
663 Version
const &selector
) {
664 CacheSetHelper helper
;
665 return FromPackage(Cache
, D
, selector
, helper
);
667 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
) {
668 return FromPackage(Cache
, D
, CANDIDATE
);
673 template<> template<class Cont
> void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
674 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
677 // these two are 'inline' as otherwise the linker has problems with seeing these untemplated
678 // specializations again and again - but we need to see them, so that library users can use them
679 template<> inline bool VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
685 template<> inline void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
686 for (const_iterator v
= begin
; v
!= end
; ++v
)
689 typedef VersionContainer
<std::set
<pkgCache::VerIterator
> > VersionSet
;
690 typedef VersionContainer
<std::list
<pkgCache::VerIterator
> > VersionList
;