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 /*{{{*/
20 #include <apt-pkg/error.h>
21 #include <apt-pkg/pkgcache.h>
23 #ifndef APT_8_CLEANER_HEADERS
24 #include <apt-pkg/cachefile.h>
31 class PackageContainerInterface
;
32 class VersionContainerInterface
;
34 class CacheSetHelper
{ /*{{{*/
35 /** \class APT::CacheSetHelper
36 Simple base class with a lot of virtual methods which can be overridden
37 to alter the behavior or the output of the CacheSets.
39 This helper is passed around by the static methods in the CacheSets and
40 used every time they hit an error condition or something could be
44 CacheSetHelper(bool const ShowError
= true,
45 GlobalError::MsgType ErrorType
= GlobalError::ERROR
) :
46 ShowError(ShowError
), ErrorType(ErrorType
) {};
47 virtual ~CacheSetHelper() {};
49 virtual void showTaskSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
50 virtual void showRegExSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
51 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
52 virtual void showFnmatchSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
54 virtual void showSelectedVersion(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const Ver
,
55 std::string
const &ver
, bool const verIsRel
);
57 virtual void canNotFindTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
58 virtual void canNotFindRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
59 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
60 virtual void canNotFindFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
62 virtual void canNotFindPackage(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &str
);
64 virtual void canNotFindAllVer(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
);
65 virtual void canNotFindInstCandVer(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
66 pkgCache::PkgIterator
const &Pkg
);
67 virtual void canNotFindCandInstVer(VersionContainerInterface
* const vci
,
69 pkgCache::PkgIterator
const &Pkg
);
71 virtual pkgCache::PkgIterator
canNotFindPkgName(pkgCacheFile
&Cache
, std::string
const &str
);
72 virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
,
73 pkgCache::PkgIterator
const &Pkg
);
74 virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
,
75 pkgCache::PkgIterator
const &Pkg
);
76 virtual pkgCache::VerIterator
canNotFindInstalledVer(pkgCacheFile
&Cache
,
77 pkgCache::PkgIterator
const &Pkg
);
79 bool showErrors() const { return ShowError
; };
80 bool showErrors(bool const newValue
) { if (ShowError
== newValue
) return ShowError
; else return ((ShowError
= newValue
) == false); };
81 GlobalError::MsgType
errorType() const { return ErrorType
; };
82 GlobalError::MsgType
errorType(GlobalError::MsgType
const &newValue
)
84 if (ErrorType
== newValue
) return ErrorType
;
86 GlobalError::MsgType
const &oldValue
= ErrorType
;
95 GlobalError::MsgType ErrorType
;
97 class PackageContainerInterface
{ /*{{{*/
98 /** \class PackageContainerInterface
100 * Interface ensuring that all operations can be executed on the yet to
101 * define concrete PackageContainer - access to all methods is possible,
102 * but in general the wrappers provided by the PackageContainer template
105 * This class mostly protects use from the need to write all implementation
106 * of the methods working on containers in the template */
108 class const_iterator
{ /*{{{*/
110 virtual pkgCache::PkgIterator
getPkg() const = 0;
111 operator pkgCache::PkgIterator(void) const { return getPkg(); }
113 inline const char *Name() const {return getPkg().Name(); }
114 inline std::string
FullName(bool const Pretty
) const { return getPkg().FullName(Pretty
); }
115 inline std::string
FullName() const { return getPkg().FullName(); }
116 inline const char *Section() const {return getPkg().Section(); }
117 inline bool Purge() const {return getPkg().Purge(); }
118 inline const char *Arch() const {return getPkg().Arch(); }
119 inline pkgCache::GrpIterator
Group() const { return getPkg().Group(); }
120 inline pkgCache::VerIterator
VersionList() const { return getPkg().VersionList(); }
121 inline pkgCache::VerIterator
CurrentVer() const { return getPkg().CurrentVer(); }
122 inline pkgCache::DepIterator
RevDependsList() const { return getPkg().RevDependsList(); }
123 inline pkgCache::PrvIterator
ProvidesList() const { return getPkg().ProvidesList(); }
124 inline pkgCache::PkgIterator::OkState
State() const { return getPkg().State(); }
125 inline const char *CandVersion() const { return getPkg().CandVersion(); }
126 inline const char *CurVersion() const { return getPkg().CurVersion(); }
127 inline pkgCache
*Cache() const { return getPkg().Cache(); };
128 inline unsigned long Index() const {return getPkg().Index();};
129 // we have only valid iterators here
130 inline bool end() const { return false; };
132 inline pkgCache::Package
const * operator->() const {return &*getPkg();};
136 virtual bool insert(pkgCache::PkgIterator
const &P
) = 0;
137 virtual bool empty() const = 0;
138 virtual void clear() = 0;
140 enum Constructor
{ UNKNOWN
, REGEX
, TASK
, FNMATCH
};
141 virtual void setConstructor(Constructor
const &con
) = 0;
142 virtual Constructor
getConstructor() const = 0;
144 static bool FromTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
145 static bool FromRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
146 static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
);
147 static bool FromFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
148 static bool FromGroup(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
149 static bool FromString(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
);
150 static bool FromCommandLine(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
);
153 enum Position
{ NONE
, PREFIX
, POSTFIX
};
155 const char * const Alias
;
157 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
) : ID(id
), Alias(alias
), Pos(pos
) {};
160 static bool FromModifierCommandLine(unsigned short &modID
, PackageContainerInterface
* const pci
,
161 pkgCacheFile
&Cache
, const char * cmdline
,
162 std::list
<Modifier
> const &mods
, CacheSetHelper
&helper
);
165 template<class Container
> class PackageContainer
: public PackageContainerInterface
{/*{{{*/
166 /** \class APT::PackageContainer
168 Simple wrapper around a container class like std::set to provide a similar
169 interface to a set of packages as to the complete set of all packages in the
173 /** \brief smell like a pkgCache::PkgIterator */
174 class const_iterator
: public PackageContainerInterface::const_iterator
,/*{{{*/
175 public std::iterator
<std::forward_iterator_tag
, typename
Container::const_iterator
> {
176 typename
Container::const_iterator _iter
;
178 const_iterator(typename
Container::const_iterator i
) : _iter(i
) {}
179 pkgCache::PkgIterator
getPkg(void) const { return *_iter
; }
180 inline pkgCache::PkgIterator
operator*(void) const { return *_iter
; };
181 operator typename
Container::const_iterator(void) const { return _iter
; }
182 inline const_iterator
& operator++() { ++_iter
; return *this; }
183 inline const_iterator
operator++(int) { const_iterator
tmp(*this); operator++(); return tmp
; }
184 inline bool operator!=(const_iterator
const &i
) const { return _iter
!= i
._iter
; };
185 inline bool operator==(const_iterator
const &i
) const { return _iter
== i
._iter
; };
186 friend std::ostream
& operator<<(std::ostream
& out
, const_iterator i
) { return operator<<(out
, *i
); }
188 class iterator
: public PackageContainerInterface::const_iterator
,
189 public std::iterator
<std::forward_iterator_tag
, typename
Container::iterator
> {
190 typename
Container::iterator _iter
;
192 iterator(typename
Container::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::iterator(void) const { return _iter
; }
196 operator typename PackageContainer
<Container
>::const_iterator() { return typename PackageContainer
<Container
>::const_iterator(_iter
); }
197 inline iterator
& operator++() { ++_iter
; return *this; }
198 inline iterator
operator++(int) { iterator
tmp(*this); operator++(); return tmp
; }
199 inline bool operator!=(iterator
const &i
) const { return _iter
!= i
._iter
; };
200 inline bool operator==(iterator
const &i
) const { return _iter
== i
._iter
; };
201 inline iterator
& operator=(iterator
const &i
) { _iter
= i
._iter
; return *this; };
202 inline iterator
& operator=(typename
Container::iterator
const &i
) { _iter
= i
; return *this; };
203 friend std::ostream
& operator<<(std::ostream
& out
, iterator i
) { return operator<<(out
, *i
); }
207 bool insert(pkgCache::PkgIterator
const &P
) { if (P
.end() == true) return false; _cont
.insert(P
); return true; };
208 template<class Cont
> void insert(PackageContainer
<Cont
> const &pkgcont
) { _cont
.insert((typename
Cont::const_iterator
)pkgcont
.begin(), (typename
Cont::const_iterator
)pkgcont
.end()); };
209 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); };
211 bool empty() const { return _cont
.empty(); };
212 void clear() { return _cont
.clear(); };
213 //FIXME: on ABI break, replace the first with the second without bool
214 void erase(iterator position
) { _cont
.erase((typename
Container::iterator
)position
); };
215 iterator
& erase(iterator
&position
, bool) { return position
= _cont
.erase((typename
Container::iterator
)position
); };
216 size_t erase(const pkgCache::PkgIterator x
) { return _cont
.erase(x
); };
217 void erase(iterator first
, iterator last
) { _cont
.erase(first
, last
); };
218 size_t size() const { return _cont
.size(); };
220 const_iterator
begin() const { return const_iterator(_cont
.begin()); };
221 const_iterator
end() const { return const_iterator(_cont
.end()); };
222 iterator
begin() { return iterator(_cont
.begin()); };
223 iterator
end() { return iterator(_cont
.end()); };
224 const_iterator
find(pkgCache::PkgIterator
const &P
) const { return const_iterator(_cont
.find(P
)); };
226 void setConstructor(Constructor
const &by
) { ConstructedBy
= by
; };
227 Constructor
getConstructor() const { return ConstructedBy
; };
229 PackageContainer() : ConstructedBy(UNKNOWN
) {};
230 PackageContainer(Constructor
const &by
) : ConstructedBy(by
) {};
232 /** \brief returns all packages in the cache who belong to the given task
234 A simple helper responsible for search for all members of a task
235 in the cache. Optional it prints a a notice about the
236 packages chosen cause of the given task.
237 \param Cache the packages are in
238 \param pattern name of the task
239 \param helper responsible for error and message handling */
240 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
241 PackageContainer
cont(TASK
);
242 PackageContainerInterface::FromTask(&cont
, Cache
, pattern
, helper
);
245 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
) {
246 CacheSetHelper helper
;
247 return FromTask(Cache
, pattern
, helper
);
250 /** \brief returns all packages in the cache whose name matchs a given pattern
252 A simple helper responsible for executing a regular expression on all
253 package names in the cache. Optional it prints a a notice about the
254 packages chosen cause of the given package.
255 \param Cache the packages are in
256 \param pattern regular expression for package names
257 \param helper responsible for error and message handling */
258 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
259 PackageContainer
cont(REGEX
);
260 PackageContainerInterface::FromRegEx(&cont
, Cache
, pattern
, helper
);
264 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
265 CacheSetHelper helper
;
266 return FromRegEx(Cache
, pattern
, helper
);
269 static PackageContainer
FromFnmatch(pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
270 PackageContainer
cont(FNMATCH
);
271 PackageContainerInterface::FromFnmatch(&cont
, Cache
, pattern
, helper
);
274 static PackageContainer
FromFnMatch(pkgCacheFile
&Cache
, std::string
const &pattern
) {
275 CacheSetHelper helper
;
276 return FromFnmatch(Cache
, pattern
, helper
);
279 /** \brief returns a package specified by a string
281 \param Cache the package is in
282 \param pattern String the package name should be extracted from
283 \param helper responsible for error and message handling */
284 static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
285 return PackageContainerInterface::FromName(Cache
, pattern
, helper
);
287 static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
) {
288 CacheSetHelper helper
;
289 return PackageContainerInterface::FromName(Cache
, pattern
, helper
);
292 /** \brief returns all packages specified by a string
294 \param Cache the packages are in
295 \param pattern String the package name(s) should be extracted from
296 \param helper responsible for error and message handling */
297 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
298 PackageContainer cont
;
299 PackageContainerInterface::FromString(&cont
, Cache
, pattern
, helper
);
302 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
) {
303 CacheSetHelper helper
;
304 return FromString(Cache
, pattern
, helper
);
307 /** \brief returns all packages specified on the commandline
309 Get all package names from the commandline and executes regex's if needed.
310 No special package command is supported, just plain names.
311 \param Cache the packages are in
312 \param cmdline Command line the package names should be extracted from
313 \param helper responsible for error and message handling */
314 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
) {
315 PackageContainer cont
;
316 PackageContainerInterface::FromCommandLine(&cont
, Cache
, cmdline
, helper
);
319 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
320 CacheSetHelper helper
;
321 return FromCommandLine(Cache
, cmdline
, helper
);
324 /** \brief group packages by a action modifiers
326 At some point it is needed to get from the same commandline
327 different package sets grouped by a modifier. Take
328 apt-get install apt awesome-
330 \param Cache the packages are in
331 \param cmdline Command line the package names should be extracted from
332 \param mods list of modifiers the method should accept
333 \param fallback the default modifier group for a package
334 \param helper responsible for error and message handling */
335 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
337 const char **cmdline
,
338 std::list
<Modifier
> const &mods
,
339 unsigned short const &fallback
,
340 CacheSetHelper
&helper
) {
341 std::map
<unsigned short, PackageContainer
> pkgsets
;
342 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
343 unsigned short modID
= fallback
;
344 PackageContainer pkgset
;
345 PackageContainerInterface::FromModifierCommandLine(modID
, &pkgset
, Cache
, *I
, mods
, helper
);
346 pkgsets
[modID
].insert(pkgset
);
350 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
352 const char **cmdline
,
353 std::list
<Modifier
> const &mods
,
354 unsigned short const &fallback
) {
355 CacheSetHelper helper
;
356 return GroupedFromCommandLine(Cache
, cmdline
,
357 mods
, fallback
, helper
);
361 Constructor ConstructedBy
;
365 template<> template<class Cont
> void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
366 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
369 // these two are 'inline' as otherwise the linker has problems with seeing these untemplated
370 // specializations again and again - but we need to see them, so that library users can use them
371 template<> inline bool PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
377 template<> inline void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
378 for (const_iterator p
= begin
; p
!= end
; ++p
)
381 typedef PackageContainer
<std::set
<pkgCache::PkgIterator
> > PackageSet
;
382 typedef PackageContainer
<std::list
<pkgCache::PkgIterator
> > PackageList
;
384 class VersionContainerInterface
{ /*{{{*/
385 /** \class APT::VersionContainerInterface
387 Same as APT::PackageContainerInterface, just for Versions */
389 /** \brief smell like a pkgCache::VerIterator */
390 class const_iterator
{ /*{{{*/
392 virtual pkgCache::VerIterator
getVer() const = 0;
393 operator pkgCache::VerIterator(void) { return getVer(); }
395 inline pkgCache
*Cache() const { return getVer().Cache(); };
396 inline unsigned long Index() const {return getVer().Index();};
397 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return getVer().CompareVer(B
); };
398 inline const char *VerStr() const { return getVer().VerStr(); };
399 inline const char *Section() const { return getVer().Section(); };
400 inline const char *Arch() const { return getVer().Arch(); };
401 inline pkgCache::PkgIterator
ParentPkg() const { return getVer().ParentPkg(); };
402 inline pkgCache::DescIterator
DescriptionList() const { return getVer().DescriptionList(); };
403 inline pkgCache::DescIterator
TranslatedDescription() const { return getVer().TranslatedDescription(); };
404 inline pkgCache::DepIterator
DependsList() const { return getVer().DependsList(); };
405 inline pkgCache::PrvIterator
ProvidesList() const { return getVer().ProvidesList(); };
406 inline pkgCache::VerFileIterator
FileList() const { return getVer().FileList(); };
407 inline bool Downloadable() const { return getVer().Downloadable(); };
408 inline const char *PriorityType() const { return getVer().PriorityType(); };
409 inline std::string
RelStr() const { return getVer().RelStr(); };
410 inline bool Automatic() const { return getVer().Automatic(); };
411 inline pkgCache::VerFileIterator
NewestFile() const { return getVer().NewestFile(); };
412 // we have only valid iterators here
413 inline bool end() const { return false; };
415 inline pkgCache::Version
const * operator->() const { return &*getVer(); };
419 virtual bool insert(pkgCache::VerIterator
const &V
) = 0;
420 virtual bool empty() const = 0;
421 virtual void clear() = 0;
423 /** \brief specifies which version(s) will be returned if non is given */
427 /** Candidate and installed version */
429 /** Candidate version */
431 /** Installed version */
433 /** Candidate or if non installed version */
435 /** Installed or if non candidate version */
437 /** Newest version */
442 enum Position
{ NONE
, PREFIX
, POSTFIX
};
444 const char * const Alias
;
446 Version SelectVersion
;
447 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
,
448 Version
const &select
) : ID(id
), Alias(alias
), Pos(pos
),
449 SelectVersion(select
) {};
452 static bool FromCommandLine(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
453 const char **cmdline
, Version
const &fallback
,
454 CacheSetHelper
&helper
);
456 static bool FromString(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
457 std::string pkg
, Version
const &fallback
, CacheSetHelper
&helper
,
458 bool const onlyFromName
= false);
460 static bool FromPackage(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
461 pkgCache::PkgIterator
const &P
, Version
const &fallback
,
462 CacheSetHelper
&helper
);
464 static bool FromModifierCommandLine(unsigned short &modID
,
465 VersionContainerInterface
* const vci
,
466 pkgCacheFile
&Cache
, const char * cmdline
,
467 std::list
<Modifier
> const &mods
,
468 CacheSetHelper
&helper
);
471 static bool FromDependency(VersionContainerInterface
* const vci
,
473 pkgCache::DepIterator
const &D
,
474 Version
const &selector
,
475 CacheSetHelper
&helper
);
479 /** \brief returns the candidate version of the package
481 \param Cache to be used to query for information
482 \param Pkg we want the candidate version from this package
483 \param helper used in this container instance */
484 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
485 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
487 /** \brief returns the installed version of the package
489 \param Cache to be used to query for information
490 \param Pkg we want the installed version from this package
491 \param helper used in this container instance */
492 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
493 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
497 template<class Container
> class VersionContainer
: public VersionContainerInterface
{/*{{{*/
498 /** \class APT::VersionContainer
500 Simple wrapper around a container class like std::set to provide a similar
501 interface to a set of versions as to the complete set of all versions in the
505 /** \brief smell like a pkgCache::VerIterator */
506 class const_iterator
: public VersionContainerInterface::const_iterator
,
507 public std::iterator
<std::forward_iterator_tag
, typename
Container::const_iterator
> {/*{{{*/
508 typename
Container::const_iterator _iter
;
510 const_iterator(typename
Container::const_iterator i
) : _iter(i
) {}
511 pkgCache::VerIterator
getVer(void) const { return *_iter
; }
512 inline pkgCache::VerIterator
operator*(void) const { return *_iter
; };
513 operator typename
Container::const_iterator(void) const { return _iter
; }
514 inline const_iterator
& operator++() { ++_iter
; return *this; }
515 inline const_iterator
operator++(int) { const_iterator
tmp(*this); operator++(); return tmp
; }
516 inline bool operator!=(const_iterator
const &i
) const { return _iter
!= i
._iter
; };
517 inline bool operator==(const_iterator
const &i
) const { return _iter
== i
._iter
; };
518 friend std::ostream
& operator<<(std::ostream
& out
, const_iterator i
) { return operator<<(out
, *i
); }
520 class iterator
: public VersionContainerInterface::const_iterator
,
521 public std::iterator
<std::forward_iterator_tag
, typename
Container::iterator
> {
522 typename
Container::iterator _iter
;
524 iterator(typename
Container::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::iterator(void) const { return _iter
; }
528 operator typename VersionContainer
<Container
>::const_iterator() { return typename VersionContainer
<Container
>::const_iterator(_iter
); }
529 inline iterator
& operator++() { ++_iter
; return *this; }
530 inline iterator
operator++(int) { iterator
tmp(*this); operator++(); return tmp
; }
531 inline bool operator!=(iterator
const &i
) const { return _iter
!= i
._iter
; };
532 inline bool operator==(iterator
const &i
) const { return _iter
== i
._iter
; };
533 inline iterator
& operator=(iterator
const &i
) { _iter
= i
._iter
; return *this; };
534 inline iterator
& operator=(typename
Container::iterator
const &i
) { _iter
= i
; return *this; };
535 friend std::ostream
& operator<<(std::ostream
& out
, iterator i
) { return operator<<(out
, *i
); }
539 bool insert(pkgCache::VerIterator
const &V
) { if (V
.end() == true) return false; _cont
.insert(V
); return true; };
540 template<class Cont
> void insert(VersionContainer
<Cont
> const &vercont
) { _cont
.insert((typename
Cont::const_iterator
)vercont
.begin(), (typename
Cont::const_iterator
)vercont
.end()); };
541 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); };
542 bool empty() const { return _cont
.empty(); };
543 void clear() { return _cont
.clear(); };
544 //FIXME: on ABI break, replace the first with the second without bool
545 void erase(iterator position
) { _cont
.erase((typename
Container::iterator
)position
); };
546 iterator
& erase(iterator
&position
, bool) { return position
= _cont
.erase((typename
Container::iterator
)position
); };
547 size_t erase(const pkgCache::VerIterator x
) { return _cont
.erase(x
); };
548 void erase(iterator first
, iterator last
) { _cont
.erase(first
, last
); };
549 size_t size() const { return _cont
.size(); };
551 const_iterator
begin() const { return const_iterator(_cont
.begin()); };
552 const_iterator
end() const { return const_iterator(_cont
.end()); };
553 iterator
begin() { return iterator(_cont
.begin()); };
554 iterator
end() { return iterator(_cont
.end()); };
555 const_iterator
find(pkgCache::VerIterator
const &V
) const { return const_iterator(_cont
.find(V
)); };
557 /** \brief returns all versions specified on the commandline
559 Get all versions from the commandline, uses given default version if
560 non specifically requested and executes regex's if needed on names.
561 \param Cache the packages and versions are in
562 \param cmdline Command line the versions should be extracted from
563 \param fallback version specification
564 \param helper responsible for error and message handling */
565 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
566 Version
const &fallback
, CacheSetHelper
&helper
) {
567 VersionContainer vercon
;
568 VersionContainerInterface::FromCommandLine(&vercon
, Cache
, cmdline
, fallback
, helper
);
571 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
572 Version
const &fallback
) {
573 CacheSetHelper helper
;
574 return FromCommandLine(Cache
, cmdline
, fallback
, helper
);
576 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
577 return FromCommandLine(Cache
, cmdline
, CANDINST
);
580 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pkg
,
581 Version
const &fallback
, CacheSetHelper
&helper
,
582 bool const onlyFromName
= false) {
583 VersionContainer vercon
;
584 VersionContainerInterface::FromString(&vercon
, Cache
, pkg
, fallback
, helper
);
587 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
,
588 Version
const &fallback
) {
589 CacheSetHelper helper
;
590 return FromString(Cache
, pkg
, fallback
, helper
);
592 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
) {
593 return FromString(Cache
, pkg
, CANDINST
);
596 /** \brief returns all versions specified for the package
598 \param Cache the package and versions are in
599 \param P the package in question
600 \param fallback the version(s) you want to get
601 \param helper the helper used for display and error handling */
602 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
603 Version
const &fallback
, CacheSetHelper
&helper
) {
604 VersionContainer vercon
;
605 VersionContainerInterface::FromPackage(&vercon
, Cache
, P
, fallback
, helper
);
608 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
609 Version
const &fallback
) {
610 CacheSetHelper helper
;
611 return FromPackage(Cache
, P
, fallback
, helper
);
613 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
) {
614 return FromPackage(Cache
, P
, CANDIDATE
);
617 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
619 const char **cmdline
,
620 std::list
<Modifier
> const &mods
,
621 unsigned short const fallback
,
622 CacheSetHelper
&helper
) {
623 std::map
<unsigned short, VersionContainer
> versets
;
624 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
625 unsigned short modID
= fallback
;
626 VersionContainer verset
;
627 VersionContainerInterface::FromModifierCommandLine(modID
, &verset
, Cache
, *I
, mods
, helper
);
628 versets
[modID
].insert(verset
);
633 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
634 pkgCacheFile
&Cache
, const char **cmdline
,
635 std::list
<Modifier
> const &mods
,
636 unsigned short const fallback
) {
637 CacheSetHelper helper
;
638 return GroupedFromCommandLine(Cache
, cmdline
,
639 mods
, fallback
, helper
);
642 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
643 Version
const &selector
, CacheSetHelper
&helper
) {
644 VersionContainer vercon
;
645 VersionContainerInterface::FromDependency(&vercon
, Cache
, D
, selector
, helper
);
648 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
649 Version
const &selector
) {
650 CacheSetHelper helper
;
651 return FromPackage(Cache
, D
, selector
, helper
);
653 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
) {
654 return FromPackage(Cache
, D
, CANDIDATE
);
659 template<> template<class Cont
> void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
660 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
663 // these two are 'inline' as otherwise the linker has problems with seeing these untemplated
664 // specializations again and again - but we need to see them, so that library users can use them
665 template<> inline bool VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
671 template<> inline void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
672 for (const_iterator v
= begin
; v
!= end
; ++v
)
675 typedef VersionContainer
<std::set
<pkgCache::VerIterator
> > VersionSet
;
676 typedef VersionContainer
<std::list
<pkgCache::VerIterator
> > VersionList
;