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
);
212 // Iterator templates for our Containers /*{{{*/
213 template<typename Interface
, typename Container
, typename Master
, typename iterator_type
, typename container_iterator
> class Container_iterator_base
:
214 public std::iterator
<typename
std::iterator_traits
<container_iterator
>::iterator_category
, container_iterator
>,
215 public Interface::iterator_base
218 container_iterator _iter
;
219 inline virtual typename
Container::value_type
getType(void) const APT_OVERRIDE
{ return *_iter
; }
221 explicit Container_iterator_base(container_iterator i
) : _iter(i
) {}
222 inline typename
Container::value_type
operator*(void) const { return *_iter
; }
223 operator container_iterator(void) const { return _iter
; }
224 inline iterator_type
& operator++() { ++_iter
; return static_cast<iterator_type
&>(*this); }
225 inline iterator_type
operator++(int) { iterator_type
tmp(*this); operator++(); return tmp
; }
226 inline iterator_type
operator+(typename
container_iterator::difference_type
const &n
) { return iterator_type(_iter
+ n
); }
227 inline iterator_type
operator+=(typename
container_iterator::difference_type
const &n
) { _iter
+= n
; return static_cast<iterator_type
&>(*this); }
228 inline iterator_type
& operator--() { --_iter
;; return static_cast<iterator_type
&>(*this); }
229 inline iterator_type
operator--(int) { iterator_type
tmp(*this); operator--(); return tmp
; }
230 inline iterator_type
operator-(typename
container_iterator::difference_type
const &n
) { return iterator_type(_iter
- n
); }
231 inline iterator_type
operator-=(typename
container_iterator::difference_type
const &n
) { _iter
-= n
; return static_cast<iterator_type
&>(*this); }
232 inline bool operator!=(iterator_type
const &i
) const { return _iter
!= i
._iter
; }
233 inline bool operator==(iterator_type
const &i
) const { return _iter
== i
._iter
; }
234 inline bool operator<(iterator_type
const &i
) const { return _iter
< i
._iter
; }
235 inline bool operator>(iterator_type
const &i
) const { return _iter
> i
._iter
; }
236 inline bool operator<=(iterator_type
const &i
) const { return _iter
<= i
._iter
; }
237 inline bool operator>=(iterator_type
const &i
) const { return _iter
>= i
._iter
; }
238 inline typename
container_iterator::reference
operator[](typename
container_iterator::difference_type
const &n
) const { return _iter
[n
]; }
240 friend std::ostream
& operator<<(std::ostream
& out
, iterator_type i
) { return operator<<(out
, *i
); }
243 template<class Interface
, class Container
, class Master
> class Container_const_iterator
:
244 public Container_iterator_base
<Interface
, Container
, Master
, Container_const_iterator
<Interface
, Container
, Master
>, typename
Container::const_iterator
>
246 typedef Container_const_iterator
<Interface
, Container
, Master
> iterator_type
;
247 typedef typename
Container::const_iterator container_iterator
;
249 explicit Container_const_iterator(container_iterator i
) :
250 Container_iterator_base
<Interface
, Container
, Master
, iterator_type
, container_iterator
>(i
) {}
252 template<class Interface
, class Container
, class Master
> class Container_iterator
:
253 public Container_iterator_base
<Interface
, Container
, Master
, Container_iterator
<Interface
, Container
, Master
>, typename
Container::iterator
>
255 typedef Container_iterator
<Interface
, Container
, Master
> iterator_type
;
256 typedef typename
Container::iterator container_iterator
;
258 explicit Container_iterator(container_iterator i
) :
259 Container_iterator_base
<Interface
, Container
, Master
, iterator_type
, container_iterator
>(i
) {}
261 operator typename
Master::const_iterator() { return typename
Master::const_iterator(this->_iter
); }
262 inline iterator_type
& operator=(iterator_type
const &i
) { this->_iter
= i
._iter
; return static_cast<iterator_type
&>(*this); }
263 inline iterator_type
& operator=(container_iterator
const &i
) { this->_iter
= i
; return static_cast<iterator_type
&>(*this); }
265 template<class Interface
, class Container
, class Master
> class Container_const_reverse_iterator
:
266 public Container_iterator_base
<Interface
, Container
, Master
, Container_const_reverse_iterator
<Interface
, Container
, Master
>, typename
Container::const_reverse_iterator
>
268 typedef Container_const_reverse_iterator
<Interface
, Container
, Master
> iterator_type
;
269 typedef typename
Container::const_reverse_iterator container_iterator
;
271 explicit Container_const_reverse_iterator(container_iterator i
) :
272 Container_iterator_base
<Interface
, Container
, Master
, iterator_type
, container_iterator
>(i
) {}
274 template<class Interface
, class Container
, class Master
> class Container_reverse_iterator
:
275 public Container_iterator_base
<Interface
, Container
, Master
, Container_reverse_iterator
<Interface
, Container
, Master
>, typename
Container::reverse_iterator
>
277 typedef Container_reverse_iterator
<Interface
, Container
, Master
> iterator_type
;
278 typedef typename
Container::reverse_iterator container_iterator
;
280 explicit Container_reverse_iterator(container_iterator i
) :
281 Container_iterator_base
<Interface
, Container
, Master
, iterator_type
, container_iterator
>(i
) {}
283 operator typename
Master::const_iterator() { return typename
Master::const_iterator(this->_iter
); }
284 inline iterator_type
& operator=(iterator_type
const &i
) { this->_iter
= i
._iter
; return static_cast<iterator_type
&>(*this); }
285 inline iterator_type
& operator=(container_iterator
const &i
) { this->_iter
= i
; return static_cast<iterator_type
&>(*this); }
288 class PackageContainerInterface
{ /*{{{*/
289 /** \class PackageContainerInterface
291 * Interface ensuring that all operations can be executed on the yet to
292 * define concrete PackageContainer - access to all methods is possible,
293 * but in general the wrappers provided by the PackageContainer template
296 * This class mostly protects use from the need to write all implementation
297 * of the methods working on containers in the template */
299 class iterator_base
{ /*{{{*/
301 virtual pkgCache::PkgIterator
getType() const = 0;
303 operator pkgCache::PkgIterator(void) const { return getType(); }
305 inline const char *Name() const {return getType().Name(); }
306 inline std::string
FullName(bool const Pretty
) const { return getType().FullName(Pretty
); }
307 inline std::string
FullName() const { return getType().FullName(); }
308 APT_DEPRECATED
inline const char *Section() const {
309 APT_IGNORE_DEPRECATED_PUSH
310 return getType().Section();
311 APT_IGNORE_DEPRECATED_POP
313 inline bool Purge() const {return getType().Purge(); }
314 inline const char *Arch() const {return getType().Arch(); }
315 inline pkgCache::GrpIterator
Group() const { return getType().Group(); }
316 inline pkgCache::VerIterator
VersionList() const { return getType().VersionList(); }
317 inline pkgCache::VerIterator
CurrentVer() const { return getType().CurrentVer(); }
318 inline pkgCache::DepIterator
RevDependsList() const { return getType().RevDependsList(); }
319 inline pkgCache::PrvIterator
ProvidesList() const { return getType().ProvidesList(); }
320 inline pkgCache::PkgIterator::OkState
State() const { return getType().State(); }
321 inline const char *CandVersion() const { return getType().CandVersion(); }
322 inline const char *CurVersion() const { return getType().CurVersion(); }
323 inline pkgCache
*Cache() const { return getType().Cache(); }
324 inline unsigned long Index() const {return getType().Index();}
325 // we have only valid iterators here
326 inline bool end() const { return false; }
328 inline pkgCache::Package
const * operator->() const {return &*getType();}
332 virtual bool insert(pkgCache::PkgIterator
const &P
) = 0;
333 virtual bool empty() const = 0;
334 virtual void clear() = 0;
335 virtual size_t size() const = 0;
337 // FIXME: This is a bloody hack removed soon. Use CacheSetHelper::PkgSelector !
338 enum APT_DEPRECATED Constructor
{ UNKNOWN
= CacheSetHelper::UNKNOWN
,
339 REGEX
= CacheSetHelper::REGEX
,
340 TASK
= CacheSetHelper::TASK
,
341 FNMATCH
= CacheSetHelper::FNMATCH
};
342 APT_IGNORE_DEPRECATED_PUSH
343 void setConstructor(Constructor
const by
) { ConstructedBy
= (CacheSetHelper::PkgSelector
)by
; }
344 APT_IGNORE_DEPRECATED_POP
346 void setConstructor(CacheSetHelper::PkgSelector
const by
) { ConstructedBy
= by
; }
347 CacheSetHelper::PkgSelector
getConstructor() const { return ConstructedBy
; }
348 PackageContainerInterface();
349 explicit PackageContainerInterface(CacheSetHelper::PkgSelector
const by
);
350 PackageContainerInterface
& operator=(PackageContainerInterface
const &other
);
351 virtual ~PackageContainerInterface();
353 APT_DEPRECATED
static bool FromTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
354 return helper
.PackageFrom(CacheSetHelper::TASK
, pci
, Cache
, pattern
); }
355 APT_DEPRECATED
static bool FromRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
356 return helper
.PackageFrom(CacheSetHelper::REGEX
, pci
, Cache
, pattern
); }
357 APT_DEPRECATED
static bool FromFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
358 return helper
.PackageFrom(CacheSetHelper::FNMATCH
, pci
, Cache
, pattern
); }
359 APT_DEPRECATED
static bool FromGroup(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
360 return helper
.PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, pattern
); }
361 APT_DEPRECATED
static bool FromString(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
362 return helper
.PackageFrom(CacheSetHelper::STRING
, pci
, Cache
, pattern
); }
363 APT_DEPRECATED
static bool FromCommandLine(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
) {
364 return helper
.PackageFromCommandLine(pci
, Cache
, cmdline
); }
366 APT_DEPRECATED
typedef CacheSetHelper::PkgModifier Modifier
;
368 APT_IGNORE_DEPRECATED_PUSH
369 APT_DEPRECATED
static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
370 return helper
.PackageFromName(Cache
, pattern
); }
371 APT_DEPRECATED
static bool FromModifierCommandLine(unsigned short &modID
, PackageContainerInterface
* const pci
,
372 pkgCacheFile
&Cache
, const char * cmdline
,
373 std::list
<Modifier
> const &mods
, CacheSetHelper
&helper
) {
374 return helper
.PackageFromModifierCommandLine(modID
, pci
, Cache
, cmdline
, mods
); }
375 APT_IGNORE_DEPRECATED_POP
378 CacheSetHelper::PkgSelector ConstructedBy
;
382 template<class Container
> class PackageContainer
: public PackageContainerInterface
{/*{{{*/
383 /** \class APT::PackageContainer
385 Simple wrapper around a container class like std::set to provide a similar
386 interface to a set of packages as to the complete set of all packages in the
390 /** \brief smell like a pkgCache::PkgIterator */
391 typedef Container_const_iterator
<PackageContainerInterface
, Container
, PackageContainer
> const_iterator
;
392 typedef Container_iterator
<PackageContainerInterface
, Container
, PackageContainer
> iterator
;
393 typedef Container_const_reverse_iterator
<PackageContainerInterface
, Container
, PackageContainer
> const_reverse_iterator
;
394 typedef Container_reverse_iterator
<PackageContainerInterface
, Container
, PackageContainer
> reverse_iterator
;
396 bool insert(pkgCache::PkgIterator
const &P
) APT_OVERRIDE
{ if (P
.end() == true) return false; _cont
.insert(P
); return true; }
397 template<class Cont
> void insert(PackageContainer
<Cont
> const &pkgcont
) { _cont
.insert((typename
Cont::const_iterator
)pkgcont
.begin(), (typename
Cont::const_iterator
)pkgcont
.end()); }
398 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); }
400 bool empty() const APT_OVERRIDE
{ return _cont
.empty(); }
401 void clear() APT_OVERRIDE
{ return _cont
.clear(); }
402 size_t size() const APT_OVERRIDE
{ return _cont
.size(); }
403 #if __cplusplus >= 201103L
404 iterator
erase( const_iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
405 iterator
erase( const_iterator first
, const_iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
407 iterator
erase( iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
408 iterator
erase( iterator first
, iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
410 const_iterator
begin() const { return const_iterator(_cont
.begin()); }
411 const_iterator
end() const { return const_iterator(_cont
.end()); }
412 const_reverse_iterator
rbegin() const { return const_reverse_iterator(_cont
.rbegin()); }
413 const_reverse_iterator
rend() const { return const_reverse_iterator(_cont
.rend()); }
414 #if __cplusplus >= 201103L
415 const_iterator
cbegin() const { return const_iterator(_cont
.cbegin()); }
416 const_iterator
cend() const { return const_iterator(_cont
.cend()); }
417 const_reverse_iterator
crbegin() const { return const_reverse_iterator(_cont
.crbegin()); }
418 const_reverse_iterator
crend() const { return const_reverse_iterator(_cont
.crend()); }
420 iterator
begin() { return iterator(_cont
.begin()); }
421 iterator
end() { return iterator(_cont
.end()); }
422 reverse_iterator
rbegin() { return reverse_iterator(_cont
.rbegin()); }
423 reverse_iterator
rend() { return reverse_iterator(_cont
.rend()); }
424 const_iterator
find(pkgCache::PkgIterator
const &P
) const { return const_iterator(_cont
.find(P
)); }
426 PackageContainer() : PackageContainerInterface(CacheSetHelper::UNKNOWN
) {}
427 explicit PackageContainer(CacheSetHelper::PkgSelector
const &by
) : PackageContainerInterface(by
) {}
428 APT_IGNORE_DEPRECATED_PUSH
429 APT_DEPRECATED
PackageContainer(Constructor
const &by
) : PackageContainerInterface((CacheSetHelper::PkgSelector
)by
) {}
430 APT_IGNORE_DEPRECATED_POP
432 /** \brief sort all included versions with given comparer
434 Some containers are sorted by default, some are not and can't be,
435 but a few like std::vector can be sorted if need be, so this can be
436 specialized in later on. The default is that this will fail though.
437 Specifically, already sorted containers like std::set will return
438 false as well as there is no easy way to check that the given comparer
439 would sort in the same way the set is currently sorted
441 \return \b true if the set was sorted, \b false if not. */
442 template<class Compare
> bool sort(Compare
/*Comp*/) { return false; }
444 /** \brief returns all packages in the cache who belong to the given task
446 A simple helper responsible for search for all members of a task
447 in the cache. Optional it prints a a notice about the
448 packages chosen cause of the given task.
449 \param Cache the packages are in
450 \param pattern name of the task
451 \param helper responsible for error and message handling */
452 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
453 PackageContainer
cont(CacheSetHelper::TASK
);
454 helper
.PackageFrom(CacheSetHelper::TASK
, &cont
, Cache
, pattern
);
457 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
) {
458 CacheSetHelper helper
;
459 return FromTask(Cache
, pattern
, helper
);
462 /** \brief returns all packages in the cache whose name matchs a given pattern
464 A simple helper responsible for executing a regular expression on all
465 package names in the cache. Optional it prints a a notice about the
466 packages chosen cause of the given package.
467 \param Cache the packages are in
468 \param pattern regular expression for package names
469 \param helper responsible for error and message handling */
470 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
471 PackageContainer
cont(CacheSetHelper::REGEX
);
472 helper
.PackageFrom(CacheSetHelper::REGEX
, &cont
, Cache
, pattern
);
476 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
477 CacheSetHelper helper
;
478 return FromRegEx(Cache
, pattern
, helper
);
481 static PackageContainer
FromFnmatch(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
482 PackageContainer
cont(CacheSetHelper::FNMATCH
);
483 helper
.PackageFrom(CacheSetHelper::FNMATCH
, &cont
, Cache
, pattern
);
486 static PackageContainer
FromFnMatch(pkgCacheFile
&Cache
, std::string
const &pattern
) {
487 CacheSetHelper helper
;
488 return FromFnmatch(Cache
, pattern
, helper
);
491 APT_IGNORE_DEPRECATED_PUSH
492 /** \brief returns a package specified by a string
494 \param Cache the package is in
495 \param pattern String the package name should be extracted from
496 \param helper responsible for error and message handling */
497 APT_DEPRECATED
static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
498 return helper
.PackageFromName(Cache
, pattern
);
500 APT_DEPRECATED
static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
) {
501 CacheSetHelper helper
;
502 return FromName(Cache
, pattern
, helper
);
504 APT_IGNORE_DEPRECATED_POP
506 /** \brief returns all packages specified by a string
508 \param Cache the packages are in
509 \param pattern String the package name(s) should be extracted from
510 \param helper responsible for error and message handling */
511 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
512 PackageContainer cont
;
513 helper
.PackageFrom(CacheSetHelper::PACKAGENAME
, &cont
, Cache
, pattern
);
516 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
) {
517 CacheSetHelper helper
;
518 return FromString(Cache
, pattern
, helper
);
521 /** \brief returns all packages specified on the commandline
523 Get all package names from the commandline and executes regex's if needed.
524 No special package command is supported, just plain names.
525 \param Cache the packages are in
526 \param cmdline Command line the package names should be extracted from
527 \param helper responsible for error and message handling */
528 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
) {
529 PackageContainer cont
;
530 helper
.PackageFromCommandLine(&cont
, Cache
, cmdline
);
533 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
534 CacheSetHelper helper
;
535 return FromCommandLine(Cache
, cmdline
, helper
);
538 /** \brief group packages by a action modifiers
540 At some point it is needed to get from the same commandline
541 different package sets grouped by a modifier. Take
542 apt-get install apt awesome-
544 \param Cache the packages are in
545 \param cmdline Command line the package names should be extracted from
546 \param mods list of modifiers the method should accept
547 \param fallback the default modifier group for a package
548 \param helper responsible for error and message handling */
549 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
551 const char **cmdline
,
552 std::list
<CacheSetHelper::PkgModifier
> const &mods
,
553 unsigned short const &fallback
,
554 CacheSetHelper
&helper
) {
555 std::map
<unsigned short, PackageContainer
> pkgsets
;
556 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
557 unsigned short modID
= fallback
;
558 PackageContainer pkgset
;
559 helper
.PackageFromModifierCommandLine(modID
, &pkgset
, Cache
, *I
, mods
);
560 pkgsets
[modID
].insert(pkgset
);
564 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
566 const char **cmdline
,
567 std::list
<CacheSetHelper::PkgModifier
> const &mods
,
568 unsigned short const &fallback
) {
569 CacheSetHelper helper
;
570 return GroupedFromCommandLine(Cache
, cmdline
,
571 mods
, fallback
, helper
);
575 // various specialisations for PackageContainer /*{{{*/
576 template<> template<class Cont
> void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
577 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
580 #if __cplusplus >= 201103L
581 template<> template<class Cont
> void PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
582 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
583 _cont
.push_front(*p
);
586 template<> template<class Cont
> void PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
587 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
590 // these are 'inline' as otherwise the linker has problems with seeing these untemplated
591 // specializations again and again - but we need to see them, so that library users can use them
592 template<> inline bool PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
598 #if __cplusplus >= 201103L
599 template<> inline bool PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
606 template<> inline bool PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
612 template<> inline void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
613 for (const_iterator p
= begin
; p
!= end
; ++p
)
616 #if __cplusplus >= 201103L
617 template<> inline void PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
618 for (const_iterator p
= begin
; p
!= end
; ++p
)
619 _cont
.push_front(*p
);
622 template<> inline void PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
623 for (const_iterator p
= begin
; p
!= end
; ++p
)
626 #if __cplusplus < 201103L
627 template<> inline PackageContainer
<std::set
<pkgCache::PkgIterator
> >::iterator PackageContainer
<std::set
<pkgCache::PkgIterator
> >::erase(iterator i
) {
628 _cont
.erase(i
._iter
);
631 template<> inline PackageContainer
<std::set
<pkgCache::PkgIterator
> >::iterator PackageContainer
<std::set
<pkgCache::PkgIterator
> >::erase(iterator first
, iterator last
) {
632 _cont
.erase(first
, last
);
636 template<> template<class Compare
> inline bool PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::sort(Compare Comp
) {
637 std::sort(_cont
.begin(), _cont
.end(), Comp
);
640 template<> template<class Compare
> inline bool PackageContainer
<std::list
<pkgCache::PkgIterator
> >::sort(Compare Comp
) {
644 #if __cplusplus >= 201103L
645 template<> template<class Compare
> inline bool PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::sort(Compare Comp
) {
652 // class PackageUniverse - pkgCache as PackageContainerInterface /*{{{*/
653 /** \class PackageUniverse
655 Wraps around our usual pkgCache, so that it can be stuffed into methods
656 expecting a PackageContainer.
658 The wrapping is read-only in practice modeled by making erase and co
660 class APT_HIDDEN PackageUniverse
: public PackageContainerInterface
{
661 pkgCache
* const _cont
;
664 typedef pkgCache::PkgIterator iterator
;
665 typedef pkgCache::PkgIterator const_iterator
;
667 APT_PUBLIC
bool empty() const APT_OVERRIDE
{ return false; }
668 APT_PUBLIC
size_t size() const APT_OVERRIDE
{ return _cont
->Head().PackageCount
; }
670 APT_PUBLIC const_iterator
begin() const { return _cont
->PkgBegin(); }
671 APT_PUBLIC const_iterator
end() const { return _cont
->PkgEnd(); }
672 APT_PUBLIC const_iterator
cbegin() const { return _cont
->PkgBegin(); }
673 APT_PUBLIC const_iterator
cend() const { return _cont
->PkgEnd(); }
674 APT_PUBLIC iterator
begin() { return _cont
->PkgBegin(); }
675 APT_PUBLIC iterator
end() { return _cont
->PkgEnd(); }
677 explicit APT_PUBLIC
PackageUniverse(pkgCache
* const Owner
);
678 APT_PUBLIC
virtual ~PackageUniverse();
681 bool insert(pkgCache::PkgIterator
const &) APT_OVERRIDE
{ return true; }
682 template<class Cont
> void insert(PackageContainer
<Cont
> const &) { }
683 void insert(const_iterator
, const_iterator
) { }
685 void clear() APT_OVERRIDE
{ }
686 iterator
erase( const_iterator pos
);
687 iterator
erase( const_iterator first
, const_iterator last
);
690 typedef PackageContainer
<std::set
<pkgCache::PkgIterator
> > PackageSet
;
691 #if __cplusplus >= 201103L
692 typedef PackageContainer
<std::unordered_set
<pkgCache::PkgIterator
> > PackageUnorderedSet
;
693 typedef PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> > PackageForwardList
;
695 typedef PackageContainer
<std::list
<pkgCache::PkgIterator
> > PackageList
;
696 typedef PackageContainer
<std::vector
<pkgCache::PkgIterator
> > PackageVector
;
698 class VersionContainerInterface
{ /*{{{*/
699 /** \class APT::VersionContainerInterface
701 Same as APT::PackageContainerInterface, just for Versions */
703 /** \brief smell like a pkgCache::VerIterator */
704 class iterator_base
{ /*{{{*/
706 virtual pkgCache::VerIterator
getType() const = 0;
708 operator pkgCache::VerIterator(void) { return getType(); }
710 inline pkgCache
*Cache() const { return getType().Cache(); }
711 inline unsigned long Index() const {return getType().Index();}
712 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return getType().CompareVer(B
); }
713 inline const char *VerStr() const { return getType().VerStr(); }
714 inline const char *Section() const { return getType().Section(); }
715 inline const char *Arch() const { return getType().Arch(); }
716 inline pkgCache::PkgIterator
ParentPkg() const { return getType().ParentPkg(); }
717 inline pkgCache::DescIterator
DescriptionList() const { return getType().DescriptionList(); }
718 inline pkgCache::DescIterator
TranslatedDescription() const { return getType().TranslatedDescription(); }
719 inline pkgCache::DepIterator
DependsList() const { return getType().DependsList(); }
720 inline pkgCache::PrvIterator
ProvidesList() const { return getType().ProvidesList(); }
721 inline pkgCache::VerFileIterator
FileList() const { return getType().FileList(); }
722 inline bool Downloadable() const { return getType().Downloadable(); }
723 inline const char *PriorityType() const { return getType().PriorityType(); }
724 inline std::string
RelStr() const { return getType().RelStr(); }
725 inline bool Automatic() const { return getType().Automatic(); }
726 inline pkgCache::VerFileIterator
NewestFile() const { return getType().NewestFile(); }
727 // we have only valid iterators here
728 inline bool end() const { return false; }
730 inline pkgCache::Version
const * operator->() const { return &*getType(); }
734 virtual bool insert(pkgCache::VerIterator
const &V
) = 0;
735 virtual bool empty() const = 0;
736 virtual void clear() = 0;
737 virtual size_t size() const = 0;
739 /** \brief specifies which version(s) will be returned if non is given */
740 enum APT_DEPRECATED Version
{
741 ALL
= CacheSetHelper::ALL
,
742 CANDANDINST
= CacheSetHelper::CANDANDINST
,
743 CANDIDATE
= CacheSetHelper::CANDIDATE
,
744 INSTALLED
= CacheSetHelper::INSTALLED
,
745 CANDINST
= CacheSetHelper::CANDINST
,
746 INSTCAND
= CacheSetHelper::INSTCAND
,
747 NEWEST
= CacheSetHelper::NEWEST
751 unsigned short const ID
;
752 const char * const Alias
;
753 enum Position
{ NONE
, PREFIX
, POSTFIX
} const Pos
;
754 enum CacheSetHelper::VerSelector
const SelectVersion
;
755 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
,
756 enum CacheSetHelper::VerSelector
const select
) : ID(id
), Alias(alias
), Pos(pos
),
757 SelectVersion(select
) {}
758 APT_IGNORE_DEPRECATED_PUSH
759 APT_DEPRECATED
Modifier(unsigned short const &id
, const char * const alias
, Position
const &pos
,
760 Version
const &select
) : ID(id
), Alias(alias
), Pos(pos
),
761 SelectVersion((CacheSetHelper::VerSelector
)select
) {}
762 APT_IGNORE_DEPRECATED_POP
765 static bool FromCommandLine(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
766 const char **cmdline
, CacheSetHelper::VerSelector
const fallback
,
767 CacheSetHelper
&helper
);
768 APT_IGNORE_DEPRECATED_PUSH
769 APT_DEPRECATED
static bool FromCommandLine(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
770 const char **cmdline
, Version
const &fallback
,
771 CacheSetHelper
&helper
) {
772 return FromCommandLine(vci
, Cache
, cmdline
, (CacheSetHelper::VerSelector
)fallback
, helper
);
774 APT_IGNORE_DEPRECATED_POP
776 static bool FromString(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
777 std::string pkg
, CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
,
778 bool const onlyFromName
= false);
779 APT_IGNORE_DEPRECATED_PUSH
780 APT_DEPRECATED
static bool FromString(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
781 std::string pkg
, Version
const &fallback
, CacheSetHelper
&helper
,
782 bool const onlyFromName
= false) {
783 return FromString(vci
, Cache
, pkg
, (CacheSetHelper::VerSelector
)fallback
, helper
, onlyFromName
);
785 APT_IGNORE_DEPRECATED_POP
787 static bool FromPackage(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
788 pkgCache::PkgIterator
const &P
, CacheSetHelper::VerSelector
const fallback
,
789 CacheSetHelper
&helper
);
790 APT_IGNORE_DEPRECATED_PUSH
791 APT_DEPRECATED
static bool FromPackage(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
792 pkgCache::PkgIterator
const &P
, Version
const &fallback
,
793 CacheSetHelper
&helper
) {
794 return FromPackage(vci
, Cache
, P
, (CacheSetHelper::VerSelector
)fallback
, helper
);
796 APT_IGNORE_DEPRECATED_POP
798 static bool FromModifierCommandLine(unsigned short &modID
,
799 VersionContainerInterface
* const vci
,
800 pkgCacheFile
&Cache
, const char * cmdline
,
801 std::list
<Modifier
> const &mods
,
802 CacheSetHelper
&helper
);
805 static bool FromDependency(VersionContainerInterface
* const vci
,
807 pkgCache::DepIterator
const &D
,
808 CacheSetHelper::VerSelector
const selector
,
809 CacheSetHelper
&helper
);
810 APT_IGNORE_DEPRECATED_PUSH
811 APT_DEPRECATED
static bool FromDependency(VersionContainerInterface
* const vci
,
813 pkgCache::DepIterator
const &D
,
814 Version
const &selector
,
815 CacheSetHelper
&helper
) {
816 return FromDependency(vci
, Cache
, D
, (CacheSetHelper::VerSelector
)selector
, helper
);
818 APT_IGNORE_DEPRECATED_POP
820 VersionContainerInterface();
821 VersionContainerInterface
& operator=(VersionContainerInterface
const &other
);
822 virtual ~VersionContainerInterface();
828 /** \brief returns the candidate version of the package
830 \param Cache to be used to query for information
831 \param Pkg we want the candidate version from this package
832 \param helper used in this container instance */
833 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
834 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
836 /** \brief returns the installed version of the package
838 \param Cache to be used to query for information
839 \param Pkg we want the installed version from this package
840 \param helper used in this container instance */
841 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
842 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
846 template<class Container
> class VersionContainer
: public VersionContainerInterface
{/*{{{*/
847 /** \class APT::VersionContainer
849 Simple wrapper around a container class like std::set to provide a similar
850 interface to a set of versions as to the complete set of all versions in the
854 typedef Container_const_iterator
<VersionContainerInterface
, Container
, VersionContainer
> const_iterator
;
855 typedef Container_iterator
<VersionContainerInterface
, Container
, VersionContainer
> iterator
;
856 typedef Container_const_reverse_iterator
<VersionContainerInterface
, Container
, VersionContainer
> const_reverse_iterator
;
857 typedef Container_reverse_iterator
<VersionContainerInterface
, Container
, VersionContainer
> reverse_iterator
;
859 bool insert(pkgCache::VerIterator
const &V
) APT_OVERRIDE
{ if (V
.end() == true) return false; _cont
.insert(V
); return true; }
860 template<class Cont
> void insert(VersionContainer
<Cont
> const &vercont
) { _cont
.insert((typename
Cont::const_iterator
)vercont
.begin(), (typename
Cont::const_iterator
)vercont
.end()); }
861 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); }
862 bool empty() const APT_OVERRIDE
{ return _cont
.empty(); }
863 void clear() APT_OVERRIDE
{ return _cont
.clear(); }
864 size_t size() const APT_OVERRIDE
{ return _cont
.size(); }
865 #if __cplusplus >= 201103L
866 iterator
erase( const_iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
867 iterator
erase( const_iterator first
, const_iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
869 iterator
erase( iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
870 iterator
erase( iterator first
, iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
872 const_iterator
begin() const { return const_iterator(_cont
.begin()); }
873 const_iterator
end() const { return const_iterator(_cont
.end()); }
874 const_reverse_iterator
rbegin() const { return const_reverse_iterator(_cont
.rbegin()); }
875 const_reverse_iterator
rend() const { return const_reverse_iterator(_cont
.rend()); }
876 #if __cplusplus >= 201103L
877 const_iterator
cbegin() const { return const_iterator(_cont
.cbegin()); }
878 const_iterator
cend() const { return const_iterator(_cont
.cend()); }
879 const_reverse_iterator
crbegin() const { return const_reverse_iterator(_cont
.crbegin()); }
880 const_reverse_iterator
crend() const { return const_reverse_iterator(_cont
.crend()); }
882 iterator
begin() { return iterator(_cont
.begin()); }
883 iterator
end() { return iterator(_cont
.end()); }
884 reverse_iterator
rbegin() { return reverse_iterator(_cont
.rbegin()); }
885 reverse_iterator
rend() { return reverse_iterator(_cont
.rend()); }
886 const_iterator
find(pkgCache::VerIterator
const &V
) const { return const_iterator(_cont
.find(V
)); }
888 /** \brief sort all included versions with given comparer
890 Some containers are sorted by default, some are not and can't be,
891 but a few like std::vector can be sorted if need be, so this can be
892 specialized in later on. The default is that this will fail though.
893 Specifically, already sorted containers like std::set will return
894 false as well as there is no easy way to check that the given comparer
895 would sort in the same way the set is currently sorted
897 \return \b true if the set was sorted, \b false if not. */
898 template<class Compare
> bool sort(Compare
/*Comp*/) { return false; }
900 /** \brief returns all versions specified on the commandline
902 Get all versions from the commandline, uses given default version if
903 non specifically requested and executes regex's if needed on names.
904 \param Cache the packages and versions are in
905 \param cmdline Command line the versions should be extracted from
906 \param fallback version specification
907 \param helper responsible for error and message handling */
908 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
909 CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
) {
910 VersionContainer vercon
;
911 VersionContainerInterface::FromCommandLine(&vercon
, Cache
, cmdline
, fallback
, helper
);
914 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
915 CacheSetHelper::VerSelector
const fallback
) {
916 CacheSetHelper helper
;
917 return FromCommandLine(Cache
, cmdline
, fallback
, helper
);
919 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
920 return FromCommandLine(Cache
, cmdline
, CacheSetHelper::CANDINST
);
922 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pkg
,
923 CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
,
924 bool const /*onlyFromName = false*/) {
925 VersionContainer vercon
;
926 VersionContainerInterface::FromString(&vercon
, Cache
, pkg
, fallback
, helper
);
929 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
,
930 CacheSetHelper::VerSelector
const fallback
) {
931 CacheSetHelper helper
;
932 return FromString(Cache
, pkg
, fallback
, helper
);
934 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
) {
935 return FromString(Cache
, pkg
, CacheSetHelper::CANDINST
);
937 APT_IGNORE_DEPRECATED_PUSH
938 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
939 Version
const &fallback
, CacheSetHelper
&helper
) {
940 VersionContainer vercon
;
941 VersionContainerInterface::FromCommandLine(&vercon
, Cache
, cmdline
, (CacheSetHelper::VerSelector
)fallback
, helper
);
944 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
945 Version
const &fallback
) {
946 CacheSetHelper helper
;
947 return FromCommandLine(Cache
, cmdline
, (CacheSetHelper::VerSelector
)fallback
, helper
);
949 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pkg
,
950 Version
const &fallback
, CacheSetHelper
&helper
,
951 bool const /*onlyFromName = false*/) {
952 VersionContainer vercon
;
953 VersionContainerInterface::FromString(&vercon
, Cache
, pkg
, (CacheSetHelper::VerSelector
)fallback
, helper
);
956 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
,
957 Version
const &fallback
) {
958 CacheSetHelper helper
;
959 return FromString(Cache
, pkg
, (CacheSetHelper::VerSelector
)fallback
, helper
);
961 APT_IGNORE_DEPRECATED_POP
963 /** \brief returns all versions specified for the package
965 \param Cache the package and versions are in
966 \param P the package in question
967 \param fallback the version(s) you want to get
968 \param helper the helper used for display and error handling */
969 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
970 CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
) {
971 VersionContainer vercon
;
972 VersionContainerInterface::FromPackage(&vercon
, Cache
, P
, fallback
, helper
);
975 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
976 CacheSetHelper::VerSelector
const fallback
) {
977 CacheSetHelper helper
;
978 return FromPackage(Cache
, P
, fallback
, helper
);
980 APT_IGNORE_DEPRECATED_PUSH
981 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
982 Version
const &fallback
, CacheSetHelper
&helper
) {
983 VersionContainer vercon
;
984 VersionContainerInterface::FromPackage(&vercon
, Cache
, P
, (CacheSetHelper::VerSelector
)fallback
, helper
);
987 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
988 Version
const &fallback
) {
989 CacheSetHelper helper
;
990 return FromPackage(Cache
, P
, (CacheSetHelper::VerSelector
)fallback
, helper
);
992 APT_IGNORE_DEPRECATED_POP
993 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
) {
994 return FromPackage(Cache
, P
, CacheSetHelper::CANDIDATE
);
997 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
999 const char **cmdline
,
1000 std::list
<Modifier
> const &mods
,
1001 unsigned short const fallback
,
1002 CacheSetHelper
&helper
) {
1003 std::map
<unsigned short, VersionContainer
> versets
;
1004 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
1005 unsigned short modID
= fallback
;
1006 VersionContainer verset
;
1007 VersionContainerInterface::FromModifierCommandLine(modID
, &verset
, Cache
, *I
, mods
, helper
);
1008 versets
[modID
].insert(verset
);
1013 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
1014 pkgCacheFile
&Cache
, const char **cmdline
,
1015 std::list
<Modifier
> const &mods
,
1016 unsigned short const fallback
) {
1017 CacheSetHelper helper
;
1018 return GroupedFromCommandLine(Cache
, cmdline
,
1019 mods
, fallback
, helper
);
1022 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1023 CacheSetHelper::VerSelector
const selector
, CacheSetHelper
&helper
) {
1024 VersionContainer vercon
;
1025 VersionContainerInterface::FromDependency(&vercon
, Cache
, D
, selector
, helper
);
1028 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1029 CacheSetHelper::VerSelector
const selector
) {
1030 CacheSetHelper helper
;
1031 return FromPackage(Cache
, D
, selector
, helper
);
1033 APT_IGNORE_DEPRECATED_PUSH
1034 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1035 Version
const &selector
, CacheSetHelper
&helper
) {
1036 VersionContainer vercon
;
1037 VersionContainerInterface::FromDependency(&vercon
, Cache
, D
, (CacheSetHelper::VerSelector
)selector
, helper
);
1040 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1041 Version
const &selector
) {
1042 CacheSetHelper helper
;
1043 return FromPackage(Cache
, D
, (CacheSetHelper::VerSelector
)selector
, helper
);
1045 APT_IGNORE_DEPRECATED_POP
1046 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
) {
1047 return FromPackage(Cache
, D
, CacheSetHelper::CANDIDATE
);
1051 // various specialisations for VersionContainer /*{{{*/
1052 template<> template<class Cont
> void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
1053 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
1054 _cont
.push_back(*v
);
1056 #if __cplusplus >= 201103L
1057 template<> template<class Cont
> void VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
1058 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
1059 _cont
.push_front(*v
);
1062 template<> template<class Cont
> void VersionContainer
<std::vector
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
1063 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
1064 _cont
.push_back(*v
);
1066 // these are 'inline' as otherwise the linker has problems with seeing these untemplated
1067 // specializations again and again - but we need to see them, so that library users can use them
1068 template<> inline bool VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
1069 if (V
.end() == true)
1074 #if __cplusplus >= 201103L
1075 template<> inline bool VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
1076 if (V
.end() == true)
1078 _cont
.push_front(V
);
1082 template<> inline bool VersionContainer
<std::vector
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
1083 if (V
.end() == true)
1088 template<> inline void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
1089 for (const_iterator v
= begin
; v
!= end
; ++v
)
1090 _cont
.push_back(*v
);
1092 #if __cplusplus >= 201103L
1093 template<> inline void VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
1094 for (const_iterator v
= begin
; v
!= end
; ++v
)
1095 _cont
.push_front(*v
);
1098 template<> inline void VersionContainer
<std::vector
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
1099 for (const_iterator v
= begin
; v
!= end
; ++v
)
1100 _cont
.push_back(*v
);
1102 #if __cplusplus < 201103L
1103 template<> inline VersionContainer
<std::set
<pkgCache::VerIterator
> >::iterator VersionContainer
<std::set
<pkgCache::VerIterator
> >::erase(iterator i
) {
1104 _cont
.erase(i
._iter
);
1107 template<> inline VersionContainer
<std::set
<pkgCache::VerIterator
> >::iterator VersionContainer
<std::set
<pkgCache::VerIterator
> >::erase(iterator first
, iterator last
) {
1108 _cont
.erase(first
, last
);
1112 template<> template<class Compare
> inline bool VersionContainer
<std::vector
<pkgCache::VerIterator
> >::sort(Compare Comp
) {
1113 std::sort(_cont
.begin(), _cont
.end(), Comp
);
1116 template<> template<class Compare
> inline bool VersionContainer
<std::list
<pkgCache::VerIterator
> >::sort(Compare Comp
) {
1120 #if __cplusplus >= 201103L
1121 template<> template<class Compare
> inline bool VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::sort(Compare Comp
) {
1128 typedef VersionContainer
<std::set
<pkgCache::VerIterator
> > VersionSet
;
1129 #if __cplusplus >= 201103L
1130 typedef VersionContainer
<std::unordered_set
<pkgCache::VerIterator
> > VersionUnorderedSet
;
1131 typedef VersionContainer
<std::forward_list
<pkgCache::VerIterator
> > VersionForwardList
;
1133 typedef VersionContainer
<std::list
<pkgCache::VerIterator
> > VersionList
;
1134 typedef VersionContainer
<std::vector
<pkgCache::VerIterator
> > VersionVector
;