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 /*{{{*/
15 #if __cplusplus >= 201103L
16 #include <unordered_set>
17 #include <forward_list>
27 #include <apt-pkg/error.h>
28 #include <apt-pkg/pkgcache.h>
29 #include <apt-pkg/cacheiterators.h>
30 #include <apt-pkg/macros.h>
32 #ifndef APT_8_CLEANER_HEADERS
33 #include <apt-pkg/cachefile.h>
35 #ifndef APT_10_CLEANER_HEADERS
43 class PackageContainerInterface
;
44 class VersionContainerInterface
;
46 class CacheSetHelper
{ /*{{{*/
47 /** \class APT::CacheSetHelper
48 Simple base class with a lot of virtual methods which can be overridden
49 to alter the behavior or the output of the CacheSets.
51 This helper is passed around by the static methods in the CacheSets and
52 used every time they hit an error condition or something could be
56 CacheSetHelper(bool const ShowError
= true,
57 GlobalError::MsgType ErrorType
= GlobalError::ERROR
);
58 virtual ~CacheSetHelper();
60 enum PkgSelector
{ UNKNOWN
, REGEX
, TASK
, FNMATCH
, PACKAGENAME
, STRING
};
62 virtual bool PackageFrom(enum PkgSelector
const select
, PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
);
64 virtual bool PackageFromCommandLine(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, const char **cmdline
);
67 enum Position
{ NONE
, PREFIX
, POSTFIX
};
69 const char * const Alias
;
71 PkgModifier (unsigned short const &id
, const char * const alias
, Position
const &pos
) : ID(id
), Alias(alias
), Pos(pos
) {}
73 virtual bool PackageFromModifierCommandLine(unsigned short &modID
, PackageContainerInterface
* const pci
,
74 pkgCacheFile
&Cache
, const char * cmdline
,
75 std::list
<PkgModifier
> const &mods
);
77 // use PackageFrom(PACKAGENAME, …) instead
78 APT_DEPRECATED
pkgCache::PkgIterator
PackageFromName(pkgCacheFile
&Cache
, std::string
const &pattern
);
80 /** \brief be notified about the package being selected via pattern
82 * Main use is probably to show a message to the user what happened
84 * \param pkg is the package which was selected
85 * \param select is the selection method which choose the package
86 * \param pattern is the string used by the selection method to pick the package
88 virtual void showPackageSelection(pkgCache::PkgIterator
const &pkg
, PkgSelector
const select
, std::string
const &pattern
);
89 // use the method above instead, react only on the type you need and let the base handle the rest if need be
90 // this allows use to add new selection methods without breaking the ABI constantly with new virtual methods
91 APT_DEPRECATED
virtual void showTaskSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
92 APT_DEPRECATED
virtual void showRegExSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
93 APT_DEPRECATED
virtual void showFnmatchSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
95 /** \brief be notified if a package can't be found via pattern
97 * Can be used to show a message as well as to try something else to make it match
99 * \param select is the method tried for selection
100 * \param pci is the container the package should be inserted in
101 * \param Cache is the package universe available
102 * \param pattern is the string not matching anything
104 virtual void canNotFindPackage(enum PkgSelector
const select
, PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
);
105 // same as above for showPackageSelection
106 APT_DEPRECATED
virtual void canNotFindTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
107 APT_DEPRECATED
virtual void canNotFindRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
108 APT_DEPRECATED
virtual void canNotFindFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
109 APT_DEPRECATED
virtual void canNotFindPackage(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &str
);
111 /** \brief specifies which version(s) we want to refer to */
113 /** by release string */
115 /** by version number string */
119 /** Candidate and installed version */
121 /** Candidate version */
123 /** Installed version */
125 /** Candidate or if non installed version */
127 /** Installed or if non candidate version */
129 /** Newest version */
133 /** \brief be notified about the version being selected via pattern
135 * Main use is probably to show a message to the user what happened
136 * Note that at the moment this method is only called for RELEASE
137 * and VERSION selections, not for the others.
139 * \param Pkg is the package which was selected for
140 * \param Ver is the version selected
141 * \param select is the selection method which choose the version
142 * \param pattern is the string used by the selection method to pick the version
144 virtual void showVersionSelection(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const &Ver
,
145 enum VerSelector
const select
, std::string
const &pattern
);
146 // renamed to have a similar interface to showPackageSelection
147 APT_DEPRECATED
virtual void showSelectedVersion(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const Ver
,
148 std::string
const &ver
, bool const verIsRel
);
150 /** \brief be notified if a version can't be found for a package
152 * Main use is probably to show a message to the user what happened
154 * \param select is the method tried for selection
155 * \param vci is the container the version should be inserted in
156 * \param Cache is the package universe available
157 * \param Pkg is the package we wanted a version from
159 virtual void canNotFindVersion(enum VerSelector
const select
, VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
);
160 // same as above for showPackageSelection
161 APT_DEPRECATED
virtual void canNotFindAllVer(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
);
162 APT_DEPRECATED
virtual void canNotFindInstCandVer(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
163 pkgCache::PkgIterator
const &Pkg
);
164 APT_DEPRECATED
virtual void canNotFindCandInstVer(VersionContainerInterface
* const vci
,
166 pkgCache::PkgIterator
const &Pkg
);
168 // the difference between canNotFind and canNotGet is that the later is more low-level
169 // and called from other places: In this case looking into the code is the only real answer…
170 virtual pkgCache::VerIterator
canNotGetVersion(enum VerSelector
const select
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
);
171 // same as above for showPackageSelection
172 APT_DEPRECATED
virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
,
173 pkgCache::PkgIterator
const &Pkg
);
174 APT_DEPRECATED
virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
,
175 pkgCache::PkgIterator
const &Pkg
);
176 APT_DEPRECATED
virtual pkgCache::VerIterator
canNotFindInstalledVer(pkgCacheFile
&Cache
,
177 pkgCache::PkgIterator
const &Pkg
);
179 virtual pkgCache::PkgIterator
canNotFindPkgName(pkgCacheFile
&Cache
, std::string
const &str
);
181 bool showErrors() const { return ShowError
; }
182 bool showErrors(bool const newValue
) { if (ShowError
== newValue
) return ShowError
; else return ((ShowError
= newValue
) == false); }
183 GlobalError::MsgType
errorType() const { return ErrorType
; }
184 GlobalError::MsgType
errorType(GlobalError::MsgType
const &newValue
)
186 if (ErrorType
== newValue
) return ErrorType
;
188 GlobalError::MsgType
const &oldValue
= ErrorType
;
189 ErrorType
= newValue
;
197 GlobalError::MsgType ErrorType
;
199 pkgCache::VerIterator
canNotGetInstCandVer(pkgCacheFile
&Cache
,
200 pkgCache::PkgIterator
const &Pkg
);
201 pkgCache::VerIterator
canNotGetCandInstVer(pkgCacheFile
&Cache
,
202 pkgCache::PkgIterator
const &Pkg
);
204 bool PackageFromTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
205 bool PackageFromRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
206 bool PackageFromFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
207 bool PackageFromPackageName(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
208 bool PackageFromString(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
);
213 class PackageContainerInterface
{ /*{{{*/
214 /** \class PackageContainerInterface
216 * Interface ensuring that all operations can be executed on the yet to
217 * define concrete PackageContainer - access to all methods is possible,
218 * but in general the wrappers provided by the PackageContainer template
221 * This class mostly protects use from the need to write all implementation
222 * of the methods working on containers in the template */
224 class const_iterator
{ /*{{{*/
226 virtual pkgCache::PkgIterator
getPkg() const = 0;
227 operator pkgCache::PkgIterator(void) const { return getPkg(); }
229 inline const char *Name() const {return getPkg().Name(); }
230 inline std::string
FullName(bool const Pretty
) const { return getPkg().FullName(Pretty
); }
231 inline std::string
FullName() const { return getPkg().FullName(); }
232 APT_DEPRECATED
inline const char *Section() const {
233 APT_IGNORE_DEPRECATED_PUSH
234 return getPkg().Section();
235 APT_IGNORE_DEPRECATED_POP
237 inline bool Purge() const {return getPkg().Purge(); }
238 inline const char *Arch() const {return getPkg().Arch(); }
239 inline pkgCache::GrpIterator
Group() const { return getPkg().Group(); }
240 inline pkgCache::VerIterator
VersionList() const { return getPkg().VersionList(); }
241 inline pkgCache::VerIterator
CurrentVer() const { return getPkg().CurrentVer(); }
242 inline pkgCache::DepIterator
RevDependsList() const { return getPkg().RevDependsList(); }
243 inline pkgCache::PrvIterator
ProvidesList() const { return getPkg().ProvidesList(); }
244 inline pkgCache::PkgIterator::OkState
State() const { return getPkg().State(); }
245 inline const char *CandVersion() const { return getPkg().CandVersion(); }
246 inline const char *CurVersion() const { return getPkg().CurVersion(); }
247 inline pkgCache
*Cache() const { return getPkg().Cache(); }
248 inline unsigned long Index() const {return getPkg().Index();}
249 // we have only valid iterators here
250 inline bool end() const { return false; }
252 inline pkgCache::Package
const * operator->() const {return &*getPkg();}
256 virtual bool insert(pkgCache::PkgIterator
const &P
) = 0;
257 virtual bool empty() const = 0;
258 virtual void clear() = 0;
260 // FIXME: This is a bloody hack removed soon. Use CacheSetHelper::PkgSelector !
261 enum APT_DEPRECATED Constructor
{ UNKNOWN
= CacheSetHelper::UNKNOWN
,
262 REGEX
= CacheSetHelper::REGEX
,
263 TASK
= CacheSetHelper::TASK
,
264 FNMATCH
= CacheSetHelper::FNMATCH
};
265 APT_IGNORE_DEPRECATED_PUSH
266 void setConstructor(Constructor
const by
) { ConstructedBy
= (CacheSetHelper::PkgSelector
)by
; }
267 APT_IGNORE_DEPRECATED_POP
269 void setConstructor(CacheSetHelper::PkgSelector
const by
) { ConstructedBy
= by
; }
270 CacheSetHelper::PkgSelector
getConstructor() const { return ConstructedBy
; }
271 PackageContainerInterface();
272 explicit PackageContainerInterface(CacheSetHelper::PkgSelector
const by
);
273 PackageContainerInterface
& operator=(PackageContainerInterface
const &other
);
274 virtual ~PackageContainerInterface();
276 APT_DEPRECATED
static bool FromTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
277 return helper
.PackageFrom(CacheSetHelper::TASK
, pci
, Cache
, pattern
); }
278 APT_DEPRECATED
static bool FromRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
279 return helper
.PackageFrom(CacheSetHelper::REGEX
, pci
, Cache
, pattern
); }
280 APT_DEPRECATED
static bool FromFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
281 return helper
.PackageFrom(CacheSetHelper::FNMATCH
, pci
, Cache
, pattern
); }
282 APT_DEPRECATED
static bool FromGroup(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
283 return helper
.PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, pattern
); }
284 APT_DEPRECATED
static bool FromString(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
285 return helper
.PackageFrom(CacheSetHelper::STRING
, pci
, Cache
, pattern
); }
286 APT_DEPRECATED
static bool FromCommandLine(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
) {
287 return helper
.PackageFromCommandLine(pci
, Cache
, cmdline
); }
289 APT_DEPRECATED
typedef CacheSetHelper::PkgModifier Modifier
;
291 APT_IGNORE_DEPRECATED_PUSH
292 APT_DEPRECATED
static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
293 return helper
.PackageFromName(Cache
, pattern
); }
294 APT_DEPRECATED
static bool FromModifierCommandLine(unsigned short &modID
, PackageContainerInterface
* const pci
,
295 pkgCacheFile
&Cache
, const char * cmdline
,
296 std::list
<Modifier
> const &mods
, CacheSetHelper
&helper
) {
297 return helper
.PackageFromModifierCommandLine(modID
, pci
, Cache
, cmdline
, mods
); }
298 APT_IGNORE_DEPRECATED_POP
301 CacheSetHelper::PkgSelector ConstructedBy
;
305 template<class Container
> class PackageContainer
: public PackageContainerInterface
{/*{{{*/
306 /** \class APT::PackageContainer
308 Simple wrapper around a container class like std::set to provide a similar
309 interface to a set of packages as to the complete set of all packages in the
313 /** \brief smell like a pkgCache::PkgIterator */
314 class const_iterator
: public PackageContainerInterface::const_iterator
,/*{{{*/
315 public std::iterator
<typename
std::iterator_traits
<typename
Container::const_iterator
>::iterator_category
, typename
Container::const_iterator
> {
316 typedef typename
Container::const_iterator container_iterator
;
317 container_iterator _iter
;
318 typedef const_iterator iterator_type
;
320 explicit const_iterator(container_iterator i
) : _iter(i
) {}
321 inline pkgCache::PkgIterator
getPkg(void) const { return *_iter
; }
322 inline pkgCache::PkgIterator
operator*(void) const { return *_iter
; }
323 operator container_iterator(void) const { return _iter
; }
324 inline iterator_type
& operator++() { ++_iter
; return *this; }
325 inline iterator_type
operator++(int) { iterator_type
tmp(*this); operator++(); return tmp
; }
326 inline iterator_type
operator+(typename
iterator_type::difference_type
const &n
) { return iterator_type(_iter
+ n
); }
327 inline iterator_type
operator+=(typename
iterator_type::difference_type
const &n
) { _iter
+= n
; return *this; }
328 inline iterator_type
& operator--() { --_iter
; return *this; }
329 inline iterator_type
operator--(int) { iterator_type
tmp(*this); operator--(); return tmp
; }
330 inline iterator_type
operator-(typename
iterator_type::difference_type
const &n
) { return iterator_type(_iter
- n
); }
331 inline iterator_type
operator-=(typename
iterator_type::difference_type
const &n
) { _iter
-= n
; return *this; }
332 inline bool operator!=(iterator_type
const &i
) const { return _iter
!= i
._iter
; }
333 inline bool operator==(iterator_type
const &i
) const { return _iter
== i
._iter
; }
334 inline bool operator<(iterator_type
const &i
) const { return _iter
< i
._iter
; }
335 inline bool operator>(iterator_type
const &i
) const { return _iter
> i
._iter
; }
336 inline bool operator<=(iterator_type
const &i
) const { return _iter
<= i
._iter
; }
337 inline bool operator>=(iterator_type
const &i
) const { return _iter
>= i
._iter
; }
338 inline typename
iterator_type::reference
operator[](typename
iterator_type::difference_type
const &n
) const { return _iter
[n
]; }
340 friend std::ostream
& operator<<(std::ostream
& out
, iterator_type i
) { return operator<<(out
, *i
); }
341 friend class PackageContainer
<Container
>;
343 class iterator
: public PackageContainerInterface::const_iterator
,
344 public std::iterator
<typename
std::iterator_traits
<typename
Container::iterator
>::iterator_category
, typename
Container::iterator
> {
345 typedef typename
Container::iterator container_iterator
;
346 container_iterator _iter
;
347 typedef iterator iterator_type
;
349 explicit iterator(container_iterator i
) : _iter(i
) {}
350 inline pkgCache::PkgIterator
getPkg(void) const { return *_iter
; }
351 inline pkgCache::PkgIterator
operator*(void) const { return *_iter
; }
352 operator container_iterator(void) const { return _iter
; }
353 inline iterator_type
& operator++() { ++_iter
; return *this; }
354 inline iterator_type
operator++(int) { iterator_type
tmp(*this); operator++(); return tmp
; }
355 inline iterator_type
operator+(typename
iterator_type::difference_type
const &n
) { return iterator_type(_iter
+ n
); }
356 inline iterator_type
operator+=(typename
iterator_type::difference_type
const &n
) { _iter
+= n
; return *this; }
357 inline iterator_type
& operator--() { --_iter
; return *this; }
358 inline iterator_type
operator--(int) { iterator_type
tmp(*this); operator--(); return tmp
; }
359 inline iterator_type
operator-(typename
iterator_type::difference_type
const &n
) { return iterator_type(_iter
- n
); }
360 inline iterator_type
operator-=(typename
iterator_type::difference_type
const &n
) { _iter
-= n
; return *this; }
361 inline bool operator!=(iterator_type
const &i
) const { return _iter
!= i
._iter
; }
362 inline bool operator==(iterator_type
const &i
) const { return _iter
== i
._iter
; }
363 inline bool operator<(iterator_type
const &i
) const { return _iter
< i
._iter
; }
364 inline bool operator>(iterator_type
const &i
) const { return _iter
> i
._iter
; }
365 inline bool operator<=(iterator_type
const &i
) const { return _iter
<= i
._iter
; }
366 inline bool operator>=(iterator_type
const &i
) const { return _iter
>= i
._iter
; }
367 inline typename
iterator_type::reference
operator[](typename
iterator_type::difference_type
const &n
) const { return _iter
[n
]; }
369 operator typename PackageContainer
<Container
>::const_iterator() { return typename PackageContainer
<Container
>::const_iterator(_iter
); }
370 inline iterator
& operator=(iterator_type
const &i
) { _iter
= i
._iter
; return *this; }
371 inline iterator
& operator=(container_iterator
const &i
) { _iter
= i
; return *this; }
373 friend std::ostream
& operator<<(std::ostream
& out
, iterator_type i
) { return operator<<(out
, *i
); }
374 friend class PackageContainer
<Container
>;
378 bool insert(pkgCache::PkgIterator
const &P
) { if (P
.end() == true) return false; _cont
.insert(P
); return true; }
379 template<class Cont
> void insert(PackageContainer
<Cont
> const &pkgcont
) { _cont
.insert((typename
Cont::const_iterator
)pkgcont
.begin(), (typename
Cont::const_iterator
)pkgcont
.end()); }
380 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); }
382 bool empty() const { return _cont
.empty(); }
383 void clear() { return _cont
.clear(); }
384 size_t size() const { return _cont
.size(); }
385 #if __cplusplus >= 201103L
386 iterator
erase( const_iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
387 iterator
erase( const_iterator first
, const_iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
389 iterator
erase( iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
390 iterator
erase( iterator first
, iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
392 const_iterator
begin() const { return const_iterator(_cont
.begin()); }
393 const_iterator
end() const { return const_iterator(_cont
.end()); }
394 const_iterator
cbegin() const { return const_iterator(_cont
.cbegin()); }
395 const_iterator
cend() const { return const_iterator(_cont
.cend()); }
396 iterator
begin() { return iterator(_cont
.begin()); }
397 iterator
end() { return iterator(_cont
.end()); }
398 const_iterator
find(pkgCache::PkgIterator
const &P
) const { return const_iterator(_cont
.find(P
)); }
400 PackageContainer() : PackageContainerInterface(CacheSetHelper::UNKNOWN
) {}
401 explicit PackageContainer(CacheSetHelper::PkgSelector
const &by
) : PackageContainerInterface(by
) {}
402 APT_IGNORE_DEPRECATED_PUSH
403 APT_DEPRECATED
PackageContainer(Constructor
const &by
) : PackageContainerInterface((CacheSetHelper::PkgSelector
)by
) {}
404 APT_IGNORE_DEPRECATED_POP
406 /** \brief sort all included versions with given comparer
408 Some containers are sorted by default, some are not and can't be,
409 but a few like std::vector can be sorted if need be, so this can be
410 specialized in later on. The default is that this will fail though.
411 Specifically, already sorted containers like std::set will return
412 false as well as there is no easy way to check that the given comparer
413 would sort in the same way the set is currently sorted
415 \return \b true if the set was sorted, \b false if not. */
416 template<class Compare
> bool sort(Compare
/*Comp*/) { return false; }
418 /** \brief returns all packages in the cache who belong to the given task
420 A simple helper responsible for search for all members of a task
421 in the cache. Optional it prints a a notice about the
422 packages chosen cause of the given task.
423 \param Cache the packages are in
424 \param pattern name of the task
425 \param helper responsible for error and message handling */
426 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
427 PackageContainer
cont(CacheSetHelper::TASK
);
428 helper
.PackageFrom(CacheSetHelper::TASK
, &cont
, Cache
, pattern
);
431 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
) {
432 CacheSetHelper helper
;
433 return FromTask(Cache
, pattern
, helper
);
436 /** \brief returns all packages in the cache whose name matchs a given pattern
438 A simple helper responsible for executing a regular expression on all
439 package names in the cache. Optional it prints a a notice about the
440 packages chosen cause of the given package.
441 \param Cache the packages are in
442 \param pattern regular expression for package names
443 \param helper responsible for error and message handling */
444 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
445 PackageContainer
cont(CacheSetHelper::REGEX
);
446 helper
.PackageFrom(CacheSetHelper::REGEX
, &cont
, Cache
, pattern
);
450 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
451 CacheSetHelper helper
;
452 return FromRegEx(Cache
, pattern
, helper
);
455 static PackageContainer
FromFnmatch(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
456 PackageContainer
cont(CacheSetHelper::FNMATCH
);
457 helper
.PackageFrom(CacheSetHelper::FNMATCH
, &cont
, Cache
, pattern
);
460 static PackageContainer
FromFnMatch(pkgCacheFile
&Cache
, std::string
const &pattern
) {
461 CacheSetHelper helper
;
462 return FromFnmatch(Cache
, pattern
, helper
);
465 APT_IGNORE_DEPRECATED_PUSH
466 /** \brief returns a package specified by a string
468 \param Cache the package is in
469 \param pattern String the package name should be extracted from
470 \param helper responsible for error and message handling */
471 APT_DEPRECATED
static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
472 return helper
.PackageFromName(Cache
, pattern
);
474 APT_DEPRECATED
static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
) {
475 CacheSetHelper helper
;
476 return FromName(Cache
, pattern
, helper
);
478 APT_IGNORE_DEPRECATED_POP
480 /** \brief returns all packages specified by a string
482 \param Cache the packages are in
483 \param pattern String the package name(s) should be extracted from
484 \param helper responsible for error and message handling */
485 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
486 PackageContainer cont
;
487 helper
.PackageFrom(CacheSetHelper::PACKAGENAME
, &cont
, Cache
, pattern
);
490 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
) {
491 CacheSetHelper helper
;
492 return FromString(Cache
, pattern
, helper
);
495 /** \brief returns all packages specified on the commandline
497 Get all package names from the commandline and executes regex's if needed.
498 No special package command is supported, just plain names.
499 \param Cache the packages are in
500 \param cmdline Command line the package names should be extracted from
501 \param helper responsible for error and message handling */
502 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
) {
503 PackageContainer cont
;
504 helper
.PackageFromCommandLine(&cont
, Cache
, cmdline
);
507 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
508 CacheSetHelper helper
;
509 return FromCommandLine(Cache
, cmdline
, helper
);
512 /** \brief group packages by a action modifiers
514 At some point it is needed to get from the same commandline
515 different package sets grouped by a modifier. Take
516 apt-get install apt awesome-
518 \param Cache the packages are in
519 \param cmdline Command line the package names should be extracted from
520 \param mods list of modifiers the method should accept
521 \param fallback the default modifier group for a package
522 \param helper responsible for error and message handling */
523 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
525 const char **cmdline
,
526 std::list
<CacheSetHelper::PkgModifier
> const &mods
,
527 unsigned short const &fallback
,
528 CacheSetHelper
&helper
) {
529 std::map
<unsigned short, PackageContainer
> pkgsets
;
530 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
531 unsigned short modID
= fallback
;
532 PackageContainer pkgset
;
533 helper
.PackageFromModifierCommandLine(modID
, &pkgset
, Cache
, *I
, mods
);
534 pkgsets
[modID
].insert(pkgset
);
538 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
540 const char **cmdline
,
541 std::list
<CacheSetHelper::PkgModifier
> const &mods
,
542 unsigned short const &fallback
) {
543 CacheSetHelper helper
;
544 return GroupedFromCommandLine(Cache
, cmdline
,
545 mods
, fallback
, helper
);
549 // specialisations for push_back containers: std::list & std::vector /*{{{*/
550 template<> template<class Cont
> void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
551 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
554 #if __cplusplus >= 201103L
555 template<> template<class Cont
> void PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
556 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
557 _cont
.push_front(*p
);
560 template<> template<class Cont
> void PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
561 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
564 // these are 'inline' as otherwise the linker has problems with seeing these untemplated
565 // specializations again and again - but we need to see them, so that library users can use them
566 template<> inline bool PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
572 #if __cplusplus >= 201103L
573 template<> inline bool PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
580 template<> inline bool PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
586 template<> inline void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
587 for (const_iterator p
= begin
; p
!= end
; ++p
)
590 #if __cplusplus >= 201103L
591 template<> inline void PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
592 for (const_iterator p
= begin
; p
!= end
; ++p
)
593 _cont
.push_front(*p
);
596 template<> inline void PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
597 for (const_iterator p
= begin
; p
!= end
; ++p
)
600 #if __cplusplus < 201103L
601 template<> inline PackageContainer
<std::set
<pkgCache::PkgIterator
> >::iterator PackageContainer
<std::set
<pkgCache::PkgIterator
> >::erase(iterator i
) {
602 _cont
.erase(i
._iter
);
605 template<> inline PackageContainer
<std::set
<pkgCache::PkgIterator
> >::iterator PackageContainer
<std::set
<pkgCache::PkgIterator
> >::erase(iterator first
, iterator last
) {
606 _cont
.erase(first
, last
);
612 template<> template<class Compare
> inline bool PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::sort(Compare Comp
) {
613 std::sort(_cont
.begin(), _cont
.end(), Comp
);
616 template<> template<class Compare
> inline bool PackageContainer
<std::list
<pkgCache::PkgIterator
> >::sort(Compare Comp
) {
620 #if __cplusplus >= 201103L
621 template<> template<class Compare
> inline bool PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::sort(Compare Comp
) {
627 // class PackageUniverse - pkgCache as PackageContainerInterface /*{{{*/
628 /** \class PackageUniverse
630 Wraps around our usual pkgCache, so that it can be stuffed into methods
631 expecting a PackageContainer.
633 The wrapping is read-only in practice modeled by making erase and co
635 class APT_HIDDEN PackageUniverse
: public PackageContainerInterface
{
636 pkgCache
* const _cont
;
639 typedef pkgCache::PkgIterator iterator
;
640 typedef pkgCache::PkgIterator const_iterator
;
642 APT_PUBLIC
bool empty() const { return false; }
643 APT_PUBLIC
size_t size() const { return _cont
->Head().PackageCount
; }
645 APT_PUBLIC const_iterator
begin() const { return _cont
->PkgBegin(); }
646 APT_PUBLIC const_iterator
end() const { return _cont
->PkgEnd(); }
647 APT_PUBLIC const_iterator
cbegin() const { return _cont
->PkgBegin(); }
648 APT_PUBLIC const_iterator
cend() const { return _cont
->PkgEnd(); }
649 APT_PUBLIC iterator
begin() { return _cont
->PkgBegin(); }
650 APT_PUBLIC iterator
end() { return _cont
->PkgEnd(); }
652 explicit APT_PUBLIC
PackageUniverse(pkgCache
* const Owner
);
653 APT_PUBLIC
virtual ~PackageUniverse();
656 bool insert(pkgCache::PkgIterator
const &) { return true; }
657 template<class Cont
> void insert(PackageContainer
<Cont
> const &) { }
658 void insert(const_iterator
, const_iterator
) { }
661 iterator
erase( const_iterator pos
);
662 iterator
erase( const_iterator first
, const_iterator last
);
665 typedef PackageContainer
<std::set
<pkgCache::PkgIterator
> > PackageSet
;
666 #if __cplusplus >= 201103L
667 typedef PackageContainer
<std::unordered_set
<pkgCache::PkgIterator
> > PackageUnorderedSet
;
668 typedef PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> > PackageForwardList
;
670 typedef PackageContainer
<std::list
<pkgCache::PkgIterator
> > PackageList
;
671 typedef PackageContainer
<std::vector
<pkgCache::PkgIterator
> > PackageVector
;
673 class VersionContainerInterface
{ /*{{{*/
674 /** \class APT::VersionContainerInterface
676 Same as APT::PackageContainerInterface, just for Versions */
678 /** \brief smell like a pkgCache::VerIterator */
679 class const_iterator
{ /*{{{*/
681 virtual pkgCache::VerIterator
getVer() const = 0;
682 operator pkgCache::VerIterator(void) { return getVer(); }
684 inline pkgCache
*Cache() const { return getVer().Cache(); }
685 inline unsigned long Index() const {return getVer().Index();}
686 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return getVer().CompareVer(B
); }
687 inline const char *VerStr() const { return getVer().VerStr(); }
688 inline const char *Section() const { return getVer().Section(); }
689 inline const char *Arch() const { return getVer().Arch(); }
690 inline pkgCache::PkgIterator
ParentPkg() const { return getVer().ParentPkg(); }
691 inline pkgCache::DescIterator
DescriptionList() const { return getVer().DescriptionList(); }
692 inline pkgCache::DescIterator
TranslatedDescription() const { return getVer().TranslatedDescription(); }
693 inline pkgCache::DepIterator
DependsList() const { return getVer().DependsList(); }
694 inline pkgCache::PrvIterator
ProvidesList() const { return getVer().ProvidesList(); }
695 inline pkgCache::VerFileIterator
FileList() const { return getVer().FileList(); }
696 inline bool Downloadable() const { return getVer().Downloadable(); }
697 inline const char *PriorityType() const { return getVer().PriorityType(); }
698 inline std::string
RelStr() const { return getVer().RelStr(); }
699 inline bool Automatic() const { return getVer().Automatic(); }
700 inline pkgCache::VerFileIterator
NewestFile() const { return getVer().NewestFile(); }
701 // we have only valid iterators here
702 inline bool end() const { return false; }
704 inline pkgCache::Version
const * operator->() const { return &*getVer(); }
708 virtual bool insert(pkgCache::VerIterator
const &V
) = 0;
709 virtual bool empty() const = 0;
710 virtual void clear() = 0;
712 /** \brief specifies which version(s) will be returned if non is given */
713 enum APT_DEPRECATED Version
{
714 ALL
= CacheSetHelper::ALL
,
715 CANDANDINST
= CacheSetHelper::CANDANDINST
,
716 CANDIDATE
= CacheSetHelper::CANDIDATE
,
717 INSTALLED
= CacheSetHelper::INSTALLED
,
718 CANDINST
= CacheSetHelper::CANDINST
,
719 INSTCAND
= CacheSetHelper::INSTCAND
,
720 NEWEST
= CacheSetHelper::NEWEST
724 unsigned short const ID
;
725 const char * const Alias
;
726 enum Position
{ NONE
, PREFIX
, POSTFIX
} const Pos
;
727 enum CacheSetHelper::VerSelector
const SelectVersion
;
728 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
,
729 enum CacheSetHelper::VerSelector
const select
) : ID(id
), Alias(alias
), Pos(pos
),
730 SelectVersion(select
) {}
731 APT_IGNORE_DEPRECATED_PUSH
732 APT_DEPRECATED
Modifier(unsigned short const &id
, const char * const alias
, Position
const &pos
,
733 Version
const &select
) : ID(id
), Alias(alias
), Pos(pos
),
734 SelectVersion((CacheSetHelper::VerSelector
)select
) {}
735 APT_IGNORE_DEPRECATED_POP
738 static bool FromCommandLine(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
739 const char **cmdline
, CacheSetHelper::VerSelector
const fallback
,
740 CacheSetHelper
&helper
);
741 APT_IGNORE_DEPRECATED_PUSH
742 APT_DEPRECATED
static bool FromCommandLine(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
743 const char **cmdline
, Version
const &fallback
,
744 CacheSetHelper
&helper
) {
745 return FromCommandLine(vci
, Cache
, cmdline
, (CacheSetHelper::VerSelector
)fallback
, helper
);
747 APT_IGNORE_DEPRECATED_POP
749 static bool FromString(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
750 std::string pkg
, CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
,
751 bool const onlyFromName
= false);
752 APT_IGNORE_DEPRECATED_PUSH
753 APT_DEPRECATED
static bool FromString(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
754 std::string pkg
, Version
const &fallback
, CacheSetHelper
&helper
,
755 bool const onlyFromName
= false) {
756 return FromString(vci
, Cache
, pkg
, (CacheSetHelper::VerSelector
)fallback
, helper
, onlyFromName
);
758 APT_IGNORE_DEPRECATED_POP
760 static bool FromPackage(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
761 pkgCache::PkgIterator
const &P
, CacheSetHelper::VerSelector
const fallback
,
762 CacheSetHelper
&helper
);
763 APT_IGNORE_DEPRECATED_PUSH
764 APT_DEPRECATED
static bool FromPackage(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
765 pkgCache::PkgIterator
const &P
, Version
const &fallback
,
766 CacheSetHelper
&helper
) {
767 return FromPackage(vci
, Cache
, P
, (CacheSetHelper::VerSelector
)fallback
, helper
);
769 APT_IGNORE_DEPRECATED_POP
771 static bool FromModifierCommandLine(unsigned short &modID
,
772 VersionContainerInterface
* const vci
,
773 pkgCacheFile
&Cache
, const char * cmdline
,
774 std::list
<Modifier
> const &mods
,
775 CacheSetHelper
&helper
);
778 static bool FromDependency(VersionContainerInterface
* const vci
,
780 pkgCache::DepIterator
const &D
,
781 CacheSetHelper::VerSelector
const selector
,
782 CacheSetHelper
&helper
);
783 APT_IGNORE_DEPRECATED_PUSH
784 APT_DEPRECATED
static bool FromDependency(VersionContainerInterface
* const vci
,
786 pkgCache::DepIterator
const &D
,
787 Version
const &selector
,
788 CacheSetHelper
&helper
) {
789 return FromDependency(vci
, Cache
, D
, (CacheSetHelper::VerSelector
)selector
, helper
);
791 APT_IGNORE_DEPRECATED_POP
793 VersionContainerInterface();
794 VersionContainerInterface
& operator=(VersionContainerInterface
const &other
);
795 virtual ~VersionContainerInterface();
801 /** \brief returns the candidate version of the package
803 \param Cache to be used to query for information
804 \param Pkg we want the candidate version from this package
805 \param helper used in this container instance */
806 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
807 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
809 /** \brief returns the installed version of the package
811 \param Cache to be used to query for information
812 \param Pkg we want the installed version from this package
813 \param helper used in this container instance */
814 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
815 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
819 template<class Container
> class VersionContainer
: public VersionContainerInterface
{/*{{{*/
820 /** \class APT::VersionContainer
822 Simple wrapper around a container class like std::set to provide a similar
823 interface to a set of versions as to the complete set of all versions in the
827 /** \brief smell like a pkgCache::VerIterator */
828 class const_iterator
: public VersionContainerInterface::const_iterator
,/*{{{*/
829 public std::iterator
<typename
std::iterator_traits
<typename
Container::const_iterator
>::iterator_category
, typename
Container::const_iterator
> {
830 typedef typename
Container::const_iterator container_iterator
;
831 container_iterator _iter
;
832 typedef const_iterator iterator_type
;
834 explicit const_iterator(container_iterator i
) : _iter(i
) {}
835 inline pkgCache::VerIterator
getVer(void) const { return *_iter
; }
836 inline pkgCache::VerIterator
operator*(void) const { return *_iter
; }
837 operator container_iterator(void) const { return _iter
; }
838 inline iterator_type
& operator++() { ++_iter
; return *this; }
839 inline iterator_type
operator++(int) { iterator_type
tmp(*this); operator++(); return tmp
; }
840 inline iterator_type
operator+(typename
iterator_type::difference_type
const &n
) { return iterator_type(_iter
+ n
); }
841 inline iterator_type
operator+=(typename
iterator_type::difference_type
const &n
) { _iter
+= n
; return *this; }
842 inline iterator_type
& operator--() { --_iter
; return *this; }
843 inline iterator_type
operator--(int) { iterator_type
tmp(*this); operator--(); return tmp
; }
844 inline iterator_type
operator-(typename
iterator_type::difference_type
const &n
) { return iterator_type(_iter
- n
); }
845 inline iterator_type
operator-=(typename
iterator_type::difference_type
const &n
) { _iter
-= n
; return *this; }
846 inline bool operator!=(iterator_type
const &i
) const { return _iter
!= i
._iter
; }
847 inline bool operator==(iterator_type
const &i
) const { return _iter
== i
._iter
; }
848 inline bool operator<(iterator_type
const &i
) const { return _iter
< i
._iter
; }
849 inline bool operator>(iterator_type
const &i
) const { return _iter
> i
._iter
; }
850 inline bool operator<=(iterator_type
const &i
) const { return _iter
<= i
._iter
; }
851 inline bool operator>=(iterator_type
const &i
) const { return _iter
>= i
._iter
; }
852 inline typename
iterator_type::reference
operator[](typename
iterator_type::difference_type
const &n
) const { return _iter
[n
]; }
854 friend std::ostream
& operator<<(std::ostream
& out
, iterator_type i
) { return operator<<(out
, *i
); }
855 friend class VersionContainer
<Container
>;
857 class iterator
: public VersionContainerInterface::const_iterator
,
858 public std::iterator
<typename
std::iterator_traits
<typename
Container::iterator
>::iterator_category
, typename
Container::iterator
> {
859 typedef typename
Container::iterator container_iterator
;
860 container_iterator _iter
;
861 typedef iterator iterator_type
;
863 explicit iterator(container_iterator i
) : _iter(i
) {}
864 inline pkgCache::VerIterator
getVer(void) const { return *_iter
; }
865 inline pkgCache::VerIterator
operator*(void) const { return *_iter
; }
866 operator container_iterator(void) const { return _iter
; }
867 inline iterator_type
& operator++() { ++_iter
; return *this; }
868 inline iterator_type
operator++(int) { iterator_type
tmp(*this); operator++(); return tmp
; }
869 inline iterator_type
operator+(typename
iterator_type::difference_type
const &n
) { return iterator_type(_iter
+ n
); }
870 inline iterator_type
operator+=(typename
iterator_type::difference_type
const &n
) { _iter
+= n
; return *this; }
871 inline iterator_type
& operator--() { --_iter
; return *this; }
872 inline iterator_type
operator--(int) { iterator_type
tmp(*this); operator--(); return tmp
; }
873 inline iterator_type
operator-(typename
iterator_type::difference_type
const &n
) { return iterator_type(_iter
- n
); }
874 inline iterator_type
operator-=(typename
iterator_type::difference_type
const &n
) { _iter
-= n
; return *this; }
875 inline bool operator!=(iterator_type
const &i
) const { return _iter
!= i
._iter
; }
876 inline bool operator==(iterator_type
const &i
) const { return _iter
== i
._iter
; }
877 inline bool operator<(iterator_type
const &i
) const { return _iter
< i
._iter
; }
878 inline bool operator>(iterator_type
const &i
) const { return _iter
> i
._iter
; }
879 inline bool operator<=(iterator_type
const &i
) const { return _iter
<= i
._iter
; }
880 inline bool operator>=(iterator_type
const &i
) const { return _iter
>= i
._iter
; }
881 inline typename
iterator_type::reference
operator[](typename
iterator_type::difference_type
const &n
) const { return _iter
[n
]; }
883 operator typename VersionContainer
<Container
>::const_iterator() { return typename VersionContainer
<Container
>::const_iterator(_iter
); }
884 inline iterator
& operator=(iterator_type
const &i
) { _iter
= i
._iter
; return *this; }
885 inline iterator
& operator=(container_iterator
const &i
) { _iter
= i
; return *this; }
887 friend std::ostream
& operator<<(std::ostream
& out
, iterator_type i
) { return operator<<(out
, *i
); }
888 friend class VersionContainer
<Container
>;
892 bool insert(pkgCache::VerIterator
const &V
) { if (V
.end() == true) return false; _cont
.insert(V
); return true; }
893 template<class Cont
> void insert(VersionContainer
<Cont
> const &vercont
) { _cont
.insert((typename
Cont::const_iterator
)vercont
.begin(), (typename
Cont::const_iterator
)vercont
.end()); }
894 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); }
895 bool empty() const { return _cont
.empty(); }
896 void clear() { return _cont
.clear(); }
897 size_t size() const { return _cont
.size(); }
898 #if __cplusplus >= 201103L
899 iterator
erase( const_iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
900 iterator
erase( const_iterator first
, const_iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
902 iterator
erase( iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
903 iterator
erase( iterator first
, iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
906 const_iterator
begin() const { return const_iterator(_cont
.begin()); }
907 const_iterator
end() const { return const_iterator(_cont
.end()); }
908 const_iterator
cbegin() const { return const_iterator(_cont
.cbegin()); }
909 const_iterator
cend() const { return const_iterator(_cont
.cend()); }
910 iterator
begin() { return iterator(_cont
.begin()); }
911 iterator
end() { return iterator(_cont
.end()); }
912 const_iterator
find(pkgCache::VerIterator
const &V
) const { return const_iterator(_cont
.find(V
)); }
914 /** \brief sort all included versions with given comparer
916 Some containers are sorted by default, some are not and can't be,
917 but a few like std::vector can be sorted if need be, so this can be
918 specialized in later on. The default is that this will fail though.
919 Specifically, already sorted containers like std::set will return
920 false as well as there is no easy way to check that the given comparer
921 would sort in the same way the set is currently sorted
923 \return \b true if the set was sorted, \b false if not. */
924 template<class Compare
> bool sort(Compare
/*Comp*/) { return false; }
926 /** \brief returns all versions specified on the commandline
928 Get all versions from the commandline, uses given default version if
929 non specifically requested and executes regex's if needed on names.
930 \param Cache the packages and versions are in
931 \param cmdline Command line the versions should be extracted from
932 \param fallback version specification
933 \param helper responsible for error and message handling */
934 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
935 CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
) {
936 VersionContainer vercon
;
937 VersionContainerInterface::FromCommandLine(&vercon
, Cache
, cmdline
, fallback
, helper
);
940 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
941 CacheSetHelper::VerSelector
const fallback
) {
942 CacheSetHelper helper
;
943 return FromCommandLine(Cache
, cmdline
, fallback
, helper
);
945 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
946 return FromCommandLine(Cache
, cmdline
, CacheSetHelper::CANDINST
);
948 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pkg
,
949 CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
,
950 bool const /*onlyFromName = false*/) {
951 VersionContainer vercon
;
952 VersionContainerInterface::FromString(&vercon
, Cache
, pkg
, fallback
, helper
);
955 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
,
956 CacheSetHelper::VerSelector
const fallback
) {
957 CacheSetHelper helper
;
958 return FromString(Cache
, pkg
, fallback
, helper
);
960 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
) {
961 return FromString(Cache
, pkg
, CacheSetHelper::CANDINST
);
963 APT_IGNORE_DEPRECATED_PUSH
964 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
965 Version
const &fallback
, CacheSetHelper
&helper
) {
966 VersionContainer vercon
;
967 VersionContainerInterface::FromCommandLine(&vercon
, Cache
, cmdline
, (CacheSetHelper::VerSelector
)fallback
, helper
);
970 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
971 Version
const &fallback
) {
972 CacheSetHelper helper
;
973 return FromCommandLine(Cache
, cmdline
, (CacheSetHelper::VerSelector
)fallback
, helper
);
975 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pkg
,
976 Version
const &fallback
, CacheSetHelper
&helper
,
977 bool const /*onlyFromName = false*/) {
978 VersionContainer vercon
;
979 VersionContainerInterface::FromString(&vercon
, Cache
, pkg
, (CacheSetHelper::VerSelector
)fallback
, helper
);
982 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
,
983 Version
const &fallback
) {
984 CacheSetHelper helper
;
985 return FromString(Cache
, pkg
, (CacheSetHelper::VerSelector
)fallback
, helper
);
987 APT_IGNORE_DEPRECATED_POP
989 /** \brief returns all versions specified for the package
991 \param Cache the package and versions are in
992 \param P the package in question
993 \param fallback the version(s) you want to get
994 \param helper the helper used for display and error handling */
995 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
996 CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
) {
997 VersionContainer vercon
;
998 VersionContainerInterface::FromPackage(&vercon
, Cache
, P
, fallback
, helper
);
1001 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
1002 CacheSetHelper::VerSelector
const fallback
) {
1003 CacheSetHelper helper
;
1004 return FromPackage(Cache
, P
, fallback
, helper
);
1006 APT_IGNORE_DEPRECATED_PUSH
1007 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
1008 Version
const &fallback
, CacheSetHelper
&helper
) {
1009 VersionContainer vercon
;
1010 VersionContainerInterface::FromPackage(&vercon
, Cache
, P
, (CacheSetHelper::VerSelector
)fallback
, helper
);
1013 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
1014 Version
const &fallback
) {
1015 CacheSetHelper helper
;
1016 return FromPackage(Cache
, P
, (CacheSetHelper::VerSelector
)fallback
, helper
);
1018 APT_IGNORE_DEPRECATED_POP
1019 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
) {
1020 return FromPackage(Cache
, P
, CacheSetHelper::CANDIDATE
);
1023 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
1024 pkgCacheFile
&Cache
,
1025 const char **cmdline
,
1026 std::list
<Modifier
> const &mods
,
1027 unsigned short const fallback
,
1028 CacheSetHelper
&helper
) {
1029 std::map
<unsigned short, VersionContainer
> versets
;
1030 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
1031 unsigned short modID
= fallback
;
1032 VersionContainer verset
;
1033 VersionContainerInterface::FromModifierCommandLine(modID
, &verset
, Cache
, *I
, mods
, helper
);
1034 versets
[modID
].insert(verset
);
1039 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
1040 pkgCacheFile
&Cache
, const char **cmdline
,
1041 std::list
<Modifier
> const &mods
,
1042 unsigned short const fallback
) {
1043 CacheSetHelper helper
;
1044 return GroupedFromCommandLine(Cache
, cmdline
,
1045 mods
, fallback
, helper
);
1048 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1049 CacheSetHelper::VerSelector
const selector
, CacheSetHelper
&helper
) {
1050 VersionContainer vercon
;
1051 VersionContainerInterface::FromDependency(&vercon
, Cache
, D
, selector
, helper
);
1054 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1055 CacheSetHelper::VerSelector
const selector
) {
1056 CacheSetHelper helper
;
1057 return FromPackage(Cache
, D
, selector
, helper
);
1059 APT_IGNORE_DEPRECATED_PUSH
1060 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1061 Version
const &selector
, CacheSetHelper
&helper
) {
1062 VersionContainer vercon
;
1063 VersionContainerInterface::FromDependency(&vercon
, Cache
, D
, (CacheSetHelper::VerSelector
)selector
, helper
);
1066 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1067 Version
const &selector
) {
1068 CacheSetHelper helper
;
1069 return FromPackage(Cache
, D
, (CacheSetHelper::VerSelector
)selector
, helper
);
1071 APT_IGNORE_DEPRECATED_POP
1072 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
) {
1073 return FromPackage(Cache
, D
, CacheSetHelper::CANDIDATE
);
1077 // specialisations for push_back containers: std::list & std::vector /*{{{*/
1078 template<> template<class Cont
> void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
1079 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
1080 _cont
.push_back(*v
);
1082 #if __cplusplus >= 201103L
1083 template<> template<class Cont
> void VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
1084 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
1085 _cont
.push_front(*v
);
1088 template<> template<class Cont
> void VersionContainer
<std::vector
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
1089 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
1090 _cont
.push_back(*v
);
1092 // these are 'inline' as otherwise the linker has problems with seeing these untemplated
1093 // specializations again and again - but we need to see them, so that library users can use them
1094 template<> inline bool VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
1095 if (V
.end() == true)
1100 #if __cplusplus >= 201103L
1101 template<> inline bool VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
1102 if (V
.end() == true)
1104 _cont
.push_front(V
);
1108 template<> inline bool VersionContainer
<std::vector
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
1109 if (V
.end() == true)
1114 template<> inline void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
1115 for (const_iterator v
= begin
; v
!= end
; ++v
)
1116 _cont
.push_back(*v
);
1118 #if __cplusplus >= 201103L
1119 template<> inline void VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
1120 for (const_iterator v
= begin
; v
!= end
; ++v
)
1121 _cont
.push_front(*v
);
1124 template<> inline void VersionContainer
<std::vector
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
1125 for (const_iterator v
= begin
; v
!= end
; ++v
)
1126 _cont
.push_back(*v
);
1128 #if __cplusplus < 201103L
1129 template<> inline VersionContainer
<std::set
<pkgCache::VerIterator
> >::iterator VersionContainer
<std::set
<pkgCache::VerIterator
> >::erase(iterator i
) {
1130 _cont
.erase(i
._iter
);
1133 template<> inline VersionContainer
<std::set
<pkgCache::VerIterator
> >::iterator VersionContainer
<std::set
<pkgCache::VerIterator
> >::erase(iterator first
, iterator last
) {
1134 _cont
.erase(first
, last
);
1140 template<> template<class Compare
> inline bool VersionContainer
<std::vector
<pkgCache::VerIterator
> >::sort(Compare Comp
) {
1141 std::sort(_cont
.begin(), _cont
.end(), Comp
);
1144 template<> template<class Compare
> inline bool VersionContainer
<std::list
<pkgCache::VerIterator
> >::sort(Compare Comp
) {
1148 #if __cplusplus >= 201103L
1149 template<> template<class Compare
> inline bool VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::sort(Compare Comp
) {
1155 typedef VersionContainer
<std::set
<pkgCache::VerIterator
> > VersionSet
;
1156 #if __cplusplus >= 201103L
1157 typedef VersionContainer
<std::unordered_set
<pkgCache::VerIterator
> > VersionUnorderedSet
;
1158 typedef VersionContainer
<std::forward_list
<pkgCache::VerIterator
> > VersionForwardList
;
1160 typedef VersionContainer
<std::list
<pkgCache::VerIterator
> > VersionList
;
1161 typedef VersionContainer
<std::vector
<pkgCache::VerIterator
> > VersionVector
;