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>
28 #include <apt-pkg/error.h>
29 #include <apt-pkg/pkgcache.h>
30 #include <apt-pkg/cacheiterators.h>
31 #include <apt-pkg/macros.h>
33 #ifndef APT_8_CLEANER_HEADERS
34 #include <apt-pkg/cachefile.h>
36 #ifndef APT_10_CLEANER_HEADERS
44 class PackageContainerInterface
;
45 class VersionContainerInterface
;
47 class CacheSetHelper
{ /*{{{*/
48 /** \class APT::CacheSetHelper
49 Simple base class with a lot of virtual methods which can be overridden
50 to alter the behavior or the output of the CacheSets.
52 This helper is passed around by the static methods in the CacheSets and
53 used every time they hit an error condition or something could be
57 CacheSetHelper(bool const ShowError
= true,
58 GlobalError::MsgType ErrorType
= GlobalError::ERROR
);
59 virtual ~CacheSetHelper();
61 enum PkgSelector
{ UNKNOWN
, REGEX
, TASK
, FNMATCH
, PACKAGENAME
, STRING
};
63 virtual bool PackageFrom(enum PkgSelector
const select
, PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
);
65 virtual bool PackageFromCommandLine(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, const char **cmdline
);
68 enum Position
{ NONE
, PREFIX
, POSTFIX
};
70 const char * const Alias
;
72 PkgModifier (unsigned short const &id
, const char * const alias
, Position
const &pos
) : ID(id
), Alias(alias
), Pos(pos
) {}
74 virtual bool PackageFromModifierCommandLine(unsigned short &modID
, PackageContainerInterface
* const pci
,
75 pkgCacheFile
&Cache
, const char * cmdline
,
76 std::list
<PkgModifier
> const &mods
);
78 // use PackageFrom(PACKAGENAME, …) instead
79 APT_DEPRECATED
pkgCache::PkgIterator
PackageFromName(pkgCacheFile
&Cache
, std::string
const &pattern
);
81 /** \brief be notified about the package being selected via pattern
83 * Main use is probably to show a message to the user what happened
85 * \param pkg is the package which was selected
86 * \param select is the selection method which choose the package
87 * \param pattern is the string used by the selection method to pick the package
89 virtual void showPackageSelection(pkgCache::PkgIterator
const &pkg
, PkgSelector
const select
, std::string
const &pattern
);
90 // use the method above instead, react only on the type you need and let the base handle the rest if need be
91 // this allows use to add new selection methods without breaking the ABI constantly with new virtual methods
92 APT_DEPRECATED
virtual void showTaskSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
93 APT_DEPRECATED
virtual void showRegExSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
94 APT_DEPRECATED
virtual void showFnmatchSelection(pkgCache::PkgIterator
const &pkg
, std::string
const &pattern
);
96 /** \brief be notified if a package can't be found via pattern
98 * Can be used to show a message as well as to try something else to make it match
100 * \param select is the method tried for selection
101 * \param pci is the container the package should be inserted in
102 * \param Cache is the package universe available
103 * \param pattern is the string not matching anything
105 virtual void canNotFindPackage(enum PkgSelector
const select
, PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
);
106 // same as above for showPackageSelection
107 APT_DEPRECATED
virtual void canNotFindTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
108 APT_DEPRECATED
virtual void canNotFindRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
109 APT_DEPRECATED
virtual void canNotFindFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
110 APT_DEPRECATED
virtual void canNotFindPackage(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &str
);
112 /** \brief specifies which version(s) we want to refer to */
114 /** by release string */
116 /** by version number string */
120 /** Candidate and installed version */
122 /** Candidate version */
124 /** Installed version */
126 /** Candidate or if non installed version */
128 /** Installed or if non candidate version */
130 /** Newest version */
134 /** \brief be notified about the version being selected via pattern
136 * Main use is probably to show a message to the user what happened
137 * Note that at the moment this method is only called for RELEASE
138 * and VERSION selections, not for the others.
140 * \param Pkg is the package which was selected for
141 * \param Ver is the version selected
142 * \param select is the selection method which choose the version
143 * \param pattern is the string used by the selection method to pick the version
145 virtual void showVersionSelection(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const &Ver
,
146 enum VerSelector
const select
, std::string
const &pattern
);
147 // renamed to have a similar interface to showPackageSelection
148 APT_DEPRECATED
virtual void showSelectedVersion(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const Ver
,
149 std::string
const &ver
, bool const verIsRel
);
151 /** \brief be notified if a version can't be found for a package
153 * Main use is probably to show a message to the user what happened
155 * \param select is the method tried for selection
156 * \param vci is the container the version should be inserted in
157 * \param Cache is the package universe available
158 * \param Pkg is the package we wanted a version from
160 virtual void canNotFindVersion(enum VerSelector
const select
, VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
);
161 // same as above for showPackageSelection
162 APT_DEPRECATED
virtual void canNotFindAllVer(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
);
163 APT_DEPRECATED
virtual void canNotFindInstCandVer(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
164 pkgCache::PkgIterator
const &Pkg
);
165 APT_DEPRECATED
virtual void canNotFindCandInstVer(VersionContainerInterface
* const vci
,
167 pkgCache::PkgIterator
const &Pkg
);
169 // the difference between canNotFind and canNotGet is that the later is more low-level
170 // and called from other places: In this case looking into the code is the only real answer…
171 virtual pkgCache::VerIterator
canNotGetVersion(enum VerSelector
const select
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
);
172 // same as above for showPackageSelection
173 APT_DEPRECATED
virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
,
174 pkgCache::PkgIterator
const &Pkg
);
175 APT_DEPRECATED
virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
,
176 pkgCache::PkgIterator
const &Pkg
);
177 APT_DEPRECATED
virtual pkgCache::VerIterator
canNotFindInstalledVer(pkgCacheFile
&Cache
,
178 pkgCache::PkgIterator
const &Pkg
);
180 virtual pkgCache::PkgIterator
canNotFindPkgName(pkgCacheFile
&Cache
, std::string
const &str
);
182 bool showErrors() const { return ShowError
; }
183 bool showErrors(bool const newValue
) { if (ShowError
== newValue
) return ShowError
; else return ((ShowError
= newValue
) == false); }
184 GlobalError::MsgType
errorType() const { return ErrorType
; }
185 GlobalError::MsgType
errorType(GlobalError::MsgType
const &newValue
)
187 if (ErrorType
== newValue
) return ErrorType
;
189 GlobalError::MsgType
const &oldValue
= ErrorType
;
190 ErrorType
= newValue
;
198 GlobalError::MsgType ErrorType
;
200 pkgCache::VerIterator
canNotGetInstCandVer(pkgCacheFile
&Cache
,
201 pkgCache::PkgIterator
const &Pkg
);
202 pkgCache::VerIterator
canNotGetCandInstVer(pkgCacheFile
&Cache
,
203 pkgCache::PkgIterator
const &Pkg
);
205 bool PackageFromTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
206 bool PackageFromRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
207 bool PackageFromFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
208 bool PackageFromPackageName(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
);
209 bool PackageFromString(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
);
213 // Iterator templates for our Containers /*{{{*/
214 template<typename Interface
, typename Master
, typename iterator_type
, typename container_iterator
, typename container_value
> class Container_iterator_base
:
215 public std::iterator
<typename
std::iterator_traits
<container_iterator
>::iterator_category
, container_iterator
>,
216 public Interface::template iterator_base
<iterator_type
>
219 container_iterator _iter
;
221 explicit Container_iterator_base(container_iterator i
) : _iter(i
) {}
222 inline container_value
operator*(void) const { return static_cast<iterator_type
const*>(this)->getType(); };
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
, Master
, Container_const_iterator
<Interface
, Container
, Master
>, typename
Container::const_iterator
, typename
Container::value_type
>
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
, Master
, iterator_type
, container_iterator
, typename
Container::value_type
>(i
) {}
252 inline typename
Container::value_type
getType(void) const { return *this->_iter
; }
254 template<class Interface
, class Container
, class Master
> class Container_iterator
:
255 public Container_iterator_base
<Interface
, Master
, Container_iterator
<Interface
, Container
, Master
>, typename
Container::iterator
, typename
Container::value_type
>
257 typedef Container_iterator
<Interface
, Container
, Master
> iterator_type
;
258 typedef typename
Container::iterator container_iterator
;
260 explicit Container_iterator(container_iterator i
) :
261 Container_iterator_base
<Interface
, Master
, iterator_type
, container_iterator
, typename
Container::value_type
>(i
) {}
263 operator typename
Master::const_iterator() { return typename
Master::const_iterator(this->_iter
); }
264 inline iterator_type
& operator=(iterator_type
const &i
) { this->_iter
= i
._iter
; return static_cast<iterator_type
&>(*this); }
265 inline iterator_type
& operator=(container_iterator
const &i
) { this->_iter
= i
; return static_cast<iterator_type
&>(*this); }
267 inline typename
Container::value_type
getType(void) const { return *this->_iter
; }
269 template<class Interface
, class Container
, class Master
> class Container_const_reverse_iterator
:
270 public Container_iterator_base
<Interface
, Master
, Container_const_reverse_iterator
<Interface
, Container
, Master
>, typename
Container::const_reverse_iterator
, typename
Container::value_type
>
272 typedef Container_const_reverse_iterator
<Interface
, Container
, Master
> iterator_type
;
273 typedef typename
Container::const_reverse_iterator container_iterator
;
275 explicit Container_const_reverse_iterator(container_iterator i
) :
276 Container_iterator_base
<Interface
, Master
, iterator_type
, container_iterator
, typename
Container::value_type
>(i
) {}
278 inline typename
Container::value_type
getType(void) const { return *this->_iter
; }
280 template<class Interface
, class Container
, class Master
> class Container_reverse_iterator
:
281 public Container_iterator_base
<Interface
, Master
, Container_reverse_iterator
<Interface
, Container
, Master
>, typename
Container::reverse_iterator
, typename
Container::value_type
>
283 typedef Container_reverse_iterator
<Interface
, Container
, Master
> iterator_type
;
284 typedef typename
Container::reverse_iterator container_iterator
;
286 explicit Container_reverse_iterator(container_iterator i
) :
287 Container_iterator_base
<Interface
, Master
, iterator_type
, container_iterator
, typename
Container::value_type
>(i
) {}
289 operator typename
Master::const_iterator() { return typename
Master::const_iterator(this->_iter
); }
290 inline iterator_type
& operator=(iterator_type
const &i
) { this->_iter
= i
._iter
; return static_cast<iterator_type
&>(*this); }
291 inline iterator_type
& operator=(container_iterator
const &i
) { this->_iter
= i
; return static_cast<iterator_type
&>(*this); }
293 inline typename
Container::value_type
getType(void) const { return *this->_iter
; }
296 class PackageContainerInterface
{ /*{{{*/
297 /** \class PackageContainerInterface
299 * Interface ensuring that all operations can be executed on the yet to
300 * define concrete PackageContainer - access to all methods is possible,
301 * but in general the wrappers provided by the PackageContainer template
304 * This class mostly protects use from the need to write all implementation
305 * of the methods working on containers in the template */
307 template<class Itr
> class iterator_base
{ /*{{{*/
308 pkgCache::PkgIterator
getType() const { return static_cast<Itr
const*>(this)->getType(); };
310 operator pkgCache::PkgIterator(void) const { return getType(); }
312 inline const char *Name() const {return getType().Name(); }
313 inline std::string
FullName(bool const Pretty
) const { return getType().FullName(Pretty
); }
314 inline std::string
FullName() const { return getType().FullName(); }
315 APT_DEPRECATED
inline const char *Section() const {
316 APT_IGNORE_DEPRECATED_PUSH
317 return getType().Section();
318 APT_IGNORE_DEPRECATED_POP
320 inline bool Purge() const {return getType().Purge(); }
321 inline const char *Arch() const {return getType().Arch(); }
322 inline pkgCache::GrpIterator
Group() const { return getType().Group(); }
323 inline pkgCache::VerIterator
VersionList() const { return getType().VersionList(); }
324 inline pkgCache::VerIterator
CurrentVer() const { return getType().CurrentVer(); }
325 inline pkgCache::DepIterator
RevDependsList() const { return getType().RevDependsList(); }
326 inline pkgCache::PrvIterator
ProvidesList() const { return getType().ProvidesList(); }
327 inline pkgCache::PkgIterator::OkState
State() const { return getType().State(); }
328 inline const char *CandVersion() const { return getType().CandVersion(); }
329 inline const char *CurVersion() const { return getType().CurVersion(); }
330 inline pkgCache
*Cache() const { return getType().Cache(); }
331 inline unsigned long Index() const {return getType().Index();}
332 // we have only valid iterators here
333 inline bool end() const { return false; }
335 inline pkgCache::Package
const * operator->() const {return &*getType();}
339 virtual bool insert(pkgCache::PkgIterator
const &P
) = 0;
340 virtual bool empty() const = 0;
341 virtual void clear() = 0;
342 virtual size_t size() const = 0;
344 // FIXME: This is a bloody hack removed soon. Use CacheSetHelper::PkgSelector !
345 enum APT_DEPRECATED Constructor
{ UNKNOWN
= CacheSetHelper::UNKNOWN
,
346 REGEX
= CacheSetHelper::REGEX
,
347 TASK
= CacheSetHelper::TASK
,
348 FNMATCH
= CacheSetHelper::FNMATCH
};
349 APT_IGNORE_DEPRECATED_PUSH
350 void setConstructor(Constructor
const by
) { ConstructedBy
= (CacheSetHelper::PkgSelector
)by
; }
351 APT_IGNORE_DEPRECATED_POP
353 void setConstructor(CacheSetHelper::PkgSelector
const by
) { ConstructedBy
= by
; }
354 CacheSetHelper::PkgSelector
getConstructor() const { return ConstructedBy
; }
355 PackageContainerInterface();
356 explicit PackageContainerInterface(CacheSetHelper::PkgSelector
const by
);
357 PackageContainerInterface
& operator=(PackageContainerInterface
const &other
);
358 virtual ~PackageContainerInterface();
360 APT_DEPRECATED
static bool FromTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
361 return helper
.PackageFrom(CacheSetHelper::TASK
, pci
, Cache
, pattern
); }
362 APT_DEPRECATED
static bool FromRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
363 return helper
.PackageFrom(CacheSetHelper::REGEX
, pci
, Cache
, pattern
); }
364 APT_DEPRECATED
static bool FromFnmatch(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
365 return helper
.PackageFrom(CacheSetHelper::FNMATCH
, pci
, Cache
, pattern
); }
366 APT_DEPRECATED
static bool FromGroup(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
) {
367 return helper
.PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, pattern
); }
368 APT_DEPRECATED
static bool FromString(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
369 return helper
.PackageFrom(CacheSetHelper::STRING
, pci
, Cache
, pattern
); }
370 APT_DEPRECATED
static bool FromCommandLine(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
) {
371 return helper
.PackageFromCommandLine(pci
, Cache
, cmdline
); }
373 APT_DEPRECATED
typedef CacheSetHelper::PkgModifier Modifier
;
375 APT_IGNORE_DEPRECATED_PUSH
376 APT_DEPRECATED
static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
377 return helper
.PackageFromName(Cache
, pattern
); }
378 APT_DEPRECATED
static bool FromModifierCommandLine(unsigned short &modID
, PackageContainerInterface
* const pci
,
379 pkgCacheFile
&Cache
, const char * cmdline
,
380 std::list
<Modifier
> const &mods
, CacheSetHelper
&helper
) {
381 return helper
.PackageFromModifierCommandLine(modID
, pci
, Cache
, cmdline
, mods
); }
382 APT_IGNORE_DEPRECATED_POP
385 CacheSetHelper::PkgSelector ConstructedBy
;
389 template<class Container
> class PackageContainer
: public PackageContainerInterface
{/*{{{*/
390 /** \class APT::PackageContainer
392 Simple wrapper around a container class like std::set to provide a similar
393 interface to a set of packages as to the complete set of all packages in the
397 /** \brief smell like a pkgCache::PkgIterator */
398 typedef Container_const_iterator
<PackageContainerInterface
, Container
, PackageContainer
> const_iterator
;
399 typedef Container_iterator
<PackageContainerInterface
, Container
, PackageContainer
> iterator
;
400 typedef Container_const_reverse_iterator
<PackageContainerInterface
, Container
, PackageContainer
> const_reverse_iterator
;
401 typedef Container_reverse_iterator
<PackageContainerInterface
, Container
, PackageContainer
> reverse_iterator
;
403 bool insert(pkgCache::PkgIterator
const &P
) APT_OVERRIDE
{ if (P
.end() == true) return false; _cont
.insert(P
); return true; }
404 template<class Cont
> void insert(PackageContainer
<Cont
> const &pkgcont
) { _cont
.insert((typename
Cont::const_iterator
)pkgcont
.begin(), (typename
Cont::const_iterator
)pkgcont
.end()); }
405 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); }
407 bool empty() const APT_OVERRIDE
{ return _cont
.empty(); }
408 void clear() APT_OVERRIDE
{ return _cont
.clear(); }
409 size_t size() const APT_OVERRIDE
{ return _cont
.size(); }
410 #if __GNUC__ >= 5 || (__GNUC_MINOR__ >= 9 && __GNUC__ >= 4)
411 iterator
erase( const_iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
412 iterator
erase( const_iterator first
, const_iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
414 iterator
erase( iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
415 iterator
erase( iterator first
, iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
417 const_iterator
begin() const { return const_iterator(_cont
.begin()); }
418 const_iterator
end() const { return const_iterator(_cont
.end()); }
419 const_reverse_iterator
rbegin() const { return const_reverse_iterator(_cont
.rbegin()); }
420 const_reverse_iterator
rend() const { return const_reverse_iterator(_cont
.rend()); }
421 #if __cplusplus >= 201103L
422 const_iterator
cbegin() const { return const_iterator(_cont
.cbegin()); }
423 const_iterator
cend() const { return const_iterator(_cont
.cend()); }
424 const_reverse_iterator
crbegin() const { return const_reverse_iterator(_cont
.crbegin()); }
425 const_reverse_iterator
crend() const { return const_reverse_iterator(_cont
.crend()); }
427 iterator
begin() { return iterator(_cont
.begin()); }
428 iterator
end() { return iterator(_cont
.end()); }
429 reverse_iterator
rbegin() { return reverse_iterator(_cont
.rbegin()); }
430 reverse_iterator
rend() { return reverse_iterator(_cont
.rend()); }
431 const_iterator
find(pkgCache::PkgIterator
const &P
) const { return const_iterator(_cont
.find(P
)); }
433 PackageContainer() : PackageContainerInterface(CacheSetHelper::UNKNOWN
) {}
434 explicit PackageContainer(CacheSetHelper::PkgSelector
const &by
) : PackageContainerInterface(by
) {}
435 APT_IGNORE_DEPRECATED_PUSH
436 APT_DEPRECATED
PackageContainer(Constructor
const &by
) : PackageContainerInterface((CacheSetHelper::PkgSelector
)by
) {}
437 APT_IGNORE_DEPRECATED_POP
439 /** \brief sort all included versions with given comparer
441 Some containers are sorted by default, some are not and can't be,
442 but a few like std::vector can be sorted if need be, so this can be
443 specialized in later on. The default is that this will fail though.
444 Specifically, already sorted containers like std::set will return
445 false as well as there is no easy way to check that the given comparer
446 would sort in the same way the set is currently sorted
448 \return \b true if the set was sorted, \b false if not. */
449 template<class Compare
> bool sort(Compare
/*Comp*/) { return false; }
451 /** \brief returns all packages in the cache who belong to the given task
453 A simple helper responsible for search for all members of a task
454 in the cache. Optional it prints a a notice about the
455 packages chosen cause of the given task.
456 \param Cache the packages are in
457 \param pattern name of the task
458 \param helper responsible for error and message handling */
459 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
460 PackageContainer
cont(CacheSetHelper::TASK
);
461 helper
.PackageFrom(CacheSetHelper::TASK
, &cont
, Cache
, pattern
);
464 static PackageContainer
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
) {
465 CacheSetHelper helper
;
466 return FromTask(Cache
, pattern
, helper
);
469 /** \brief returns all packages in the cache whose name matchs a given pattern
471 A simple helper responsible for executing a regular expression on all
472 package names in the cache. Optional it prints a a notice about the
473 packages chosen cause of the given package.
474 \param Cache the packages are in
475 \param pattern regular expression for package names
476 \param helper responsible for error and message handling */
477 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
478 PackageContainer
cont(CacheSetHelper::REGEX
);
479 helper
.PackageFrom(CacheSetHelper::REGEX
, &cont
, Cache
, pattern
);
483 static PackageContainer
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
484 CacheSetHelper helper
;
485 return FromRegEx(Cache
, pattern
, helper
);
488 static PackageContainer
FromFnmatch(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
489 PackageContainer
cont(CacheSetHelper::FNMATCH
);
490 helper
.PackageFrom(CacheSetHelper::FNMATCH
, &cont
, Cache
, pattern
);
493 static PackageContainer
FromFnMatch(pkgCacheFile
&Cache
, std::string
const &pattern
) {
494 CacheSetHelper helper
;
495 return FromFnmatch(Cache
, pattern
, helper
);
498 APT_IGNORE_DEPRECATED_PUSH
499 /** \brief returns a package specified by a string
501 \param Cache the package is in
502 \param pattern String the package name should be extracted from
503 \param helper responsible for error and message handling */
504 APT_DEPRECATED
static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
505 return helper
.PackageFromName(Cache
, pattern
);
507 APT_DEPRECATED
static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &pattern
) {
508 CacheSetHelper helper
;
509 return FromName(Cache
, pattern
, helper
);
511 APT_IGNORE_DEPRECATED_POP
513 /** \brief returns all packages specified by a string
515 \param Cache the packages are in
516 \param pattern String the package name(s) should be extracted from
517 \param helper responsible for error and message handling */
518 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
, CacheSetHelper
&helper
) {
519 PackageContainer cont
;
520 helper
.PackageFrom(CacheSetHelper::PACKAGENAME
, &cont
, Cache
, pattern
);
523 static PackageContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pattern
) {
524 CacheSetHelper helper
;
525 return FromString(Cache
, pattern
, helper
);
528 /** \brief returns all packages specified on the commandline
530 Get all package names from the commandline and executes regex's if needed.
531 No special package command is supported, just plain names.
532 \param Cache the packages are in
533 \param cmdline Command line the package names should be extracted from
534 \param helper responsible for error and message handling */
535 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
) {
536 PackageContainer cont
;
537 helper
.PackageFromCommandLine(&cont
, Cache
, cmdline
);
540 static PackageContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
541 CacheSetHelper helper
;
542 return FromCommandLine(Cache
, cmdline
, helper
);
545 /** \brief group packages by a action modifiers
547 At some point it is needed to get from the same commandline
548 different package sets grouped by a modifier. Take
549 apt-get install apt awesome-
551 \param Cache the packages are in
552 \param cmdline Command line the package names should be extracted from
553 \param mods list of modifiers the method should accept
554 \param fallback the default modifier group for a package
555 \param helper responsible for error and message handling */
556 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
558 const char **cmdline
,
559 std::list
<CacheSetHelper::PkgModifier
> const &mods
,
560 unsigned short const &fallback
,
561 CacheSetHelper
&helper
) {
562 std::map
<unsigned short, PackageContainer
> pkgsets
;
563 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
564 unsigned short modID
= fallback
;
565 PackageContainer pkgset
;
566 helper
.PackageFromModifierCommandLine(modID
, &pkgset
, Cache
, *I
, mods
);
567 pkgsets
[modID
].insert(pkgset
);
571 static std::map
<unsigned short, PackageContainer
> GroupedFromCommandLine(
573 const char **cmdline
,
574 std::list
<CacheSetHelper::PkgModifier
> const &mods
,
575 unsigned short const &fallback
) {
576 CacheSetHelper helper
;
577 return GroupedFromCommandLine(Cache
, cmdline
,
578 mods
, fallback
, helper
);
582 // various specialisations for PackageContainer /*{{{*/
583 template<> template<class Cont
> void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
584 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
587 #if __cplusplus >= 201103L
588 template<> template<class Cont
> void PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
589 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
590 _cont
.push_front(*p
);
593 template<> template<class Cont
> void PackageContainer
<std::deque
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
594 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
597 template<> template<class Cont
> void PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::insert(PackageContainer
<Cont
> const &pkgcont
) {
598 for (typename PackageContainer
<Cont
>::const_iterator p
= pkgcont
.begin(); p
!= pkgcont
.end(); ++p
)
601 // these are 'inline' as otherwise the linker has problems with seeing these untemplated
602 // specializations again and again - but we need to see them, so that library users can use them
603 template<> inline bool PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
609 #if __cplusplus >= 201103L
610 template<> inline bool PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
617 template<> inline bool PackageContainer
<std::deque
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
623 template<> inline bool PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::insert(pkgCache::PkgIterator
const &P
) {
629 template<> inline void PackageContainer
<std::list
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
630 for (const_iterator p
= begin
; p
!= end
; ++p
)
633 #if __cplusplus >= 201103L
634 template<> inline void PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
635 for (const_iterator p
= begin
; p
!= end
; ++p
)
636 _cont
.push_front(*p
);
639 template<> inline void PackageContainer
<std::deque
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
640 for (const_iterator p
= begin
; p
!= end
; ++p
)
643 template<> inline void PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::insert(const_iterator begin
, const_iterator end
) {
644 for (const_iterator p
= begin
; p
!= end
; ++p
)
647 #if __cplusplus < 201103L
648 template<> inline PackageContainer
<std::set
<pkgCache::PkgIterator
> >::iterator PackageContainer
<std::set
<pkgCache::PkgIterator
> >::erase(iterator i
) {
649 _cont
.erase(i
._iter
);
652 template<> inline PackageContainer
<std::set
<pkgCache::PkgIterator
> >::iterator PackageContainer
<std::set
<pkgCache::PkgIterator
> >::erase(iterator first
, iterator last
) {
653 _cont
.erase(first
, last
);
657 template<> template<class Compare
> inline bool PackageContainer
<std::vector
<pkgCache::PkgIterator
> >::sort(Compare Comp
) {
658 std::sort(_cont
.begin(), _cont
.end(), Comp
);
661 template<> template<class Compare
> inline bool PackageContainer
<std::list
<pkgCache::PkgIterator
> >::sort(Compare Comp
) {
665 #if __cplusplus >= 201103L
666 template<> template<class Compare
> inline bool PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> >::sort(Compare Comp
) {
671 template<> template<class Compare
> inline bool PackageContainer
<std::deque
<pkgCache::PkgIterator
> >::sort(Compare Comp
) {
672 std::sort(_cont
.begin(), _cont
.end(), Comp
);
677 // class PackageUniverse - pkgCache as PackageContainerInterface /*{{{*/
678 /** \class PackageUniverse
680 Wraps around our usual pkgCache, so that it can be stuffed into methods
681 expecting a PackageContainer.
683 The wrapping is read-only in practice modeled by making erase and co
685 class APT_PUBLIC PackageUniverse
: public PackageContainerInterface
{
686 pkgCache
* const _cont
;
689 class const_iterator
: public APT::Container_iterator_base
<APT::PackageContainerInterface
, PackageUniverse
, PackageUniverse::const_iterator
, pkgCache::PkgIterator
, pkgCache::PkgIterator
>
692 explicit const_iterator(pkgCache::PkgIterator i
):
693 Container_iterator_base
<APT::PackageContainerInterface
, PackageUniverse
, PackageUniverse::const_iterator
, pkgCache::PkgIterator
, pkgCache::PkgIterator
>(i
) {}
695 inline pkgCache::PkgIterator
getType(void) const { return _iter
; }
697 typedef const_iterator iterator
;
699 bool empty() const APT_OVERRIDE
{ return false; }
700 size_t size() const APT_OVERRIDE
{ return _cont
->Head().PackageCount
; }
702 const_iterator
begin() const { return const_iterator(_cont
->PkgBegin()); }
703 const_iterator
end() const { return const_iterator(_cont
->PkgEnd()); }
704 const_iterator
cbegin() const { return const_iterator(_cont
->PkgBegin()); }
705 const_iterator
cend() const { return const_iterator(_cont
->PkgEnd()); }
706 iterator
begin() { return iterator(_cont
->PkgBegin()); }
707 iterator
end() { return iterator(_cont
->PkgEnd()); }
709 pkgCache
* data() const { return _cont
; }
711 explicit PackageUniverse(pkgCache
* const Owner
);
712 explicit PackageUniverse(pkgCacheFile
* const Owner
);
713 virtual ~PackageUniverse();
716 APT_HIDDEN
bool insert(pkgCache::PkgIterator
const &) APT_OVERRIDE
{ return true; }
717 template<class Cont
> APT_HIDDEN
void insert(PackageContainer
<Cont
> const &) { }
718 APT_HIDDEN
void insert(const_iterator
, const_iterator
) { }
720 APT_HIDDEN
void clear() APT_OVERRIDE
{ }
721 APT_HIDDEN iterator
erase( const_iterator pos
);
722 APT_HIDDEN iterator
erase( const_iterator first
, const_iterator last
);
725 typedef PackageContainer
<std::set
<pkgCache::PkgIterator
> > PackageSet
;
726 #if __cplusplus >= 201103L
727 typedef PackageContainer
<std::unordered_set
<pkgCache::PkgIterator
> > PackageUnorderedSet
;
728 typedef PackageContainer
<std::forward_list
<pkgCache::PkgIterator
> > PackageForwardList
;
730 typedef PackageContainer
<std::list
<pkgCache::PkgIterator
> > PackageList
;
731 typedef PackageContainer
<std::deque
<pkgCache::PkgIterator
> > PackageDeque
;
732 typedef PackageContainer
<std::vector
<pkgCache::PkgIterator
> > PackageVector
;
734 class VersionContainerInterface
{ /*{{{*/
735 /** \class APT::VersionContainerInterface
737 Same as APT::PackageContainerInterface, just for Versions */
739 /** \brief smell like a pkgCache::VerIterator */
740 template<class Itr
> class iterator_base
{ /*{{{*/
741 pkgCache::VerIterator
getType() const { return static_cast<Itr
const*>(this)->getType(); };
743 operator pkgCache::VerIterator(void) { return getType(); }
745 inline pkgCache
*Cache() const { return getType().Cache(); }
746 inline unsigned long Index() const {return getType().Index();}
747 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return getType().CompareVer(B
); }
748 inline const char *VerStr() const { return getType().VerStr(); }
749 inline const char *Section() const { return getType().Section(); }
750 inline const char *Arch() const { return getType().Arch(); }
751 inline pkgCache::PkgIterator
ParentPkg() const { return getType().ParentPkg(); }
752 inline pkgCache::DescIterator
DescriptionList() const { return getType().DescriptionList(); }
753 inline pkgCache::DescIterator
TranslatedDescription() const { return getType().TranslatedDescription(); }
754 inline pkgCache::DepIterator
DependsList() const { return getType().DependsList(); }
755 inline pkgCache::PrvIterator
ProvidesList() const { return getType().ProvidesList(); }
756 inline pkgCache::VerFileIterator
FileList() const { return getType().FileList(); }
757 inline bool Downloadable() const { return getType().Downloadable(); }
758 inline const char *PriorityType() const { return getType().PriorityType(); }
759 inline std::string
RelStr() const { return getType().RelStr(); }
760 inline bool Automatic() const { return getType().Automatic(); }
761 inline pkgCache::VerFileIterator
NewestFile() const { return getType().NewestFile(); }
762 // we have only valid iterators here
763 inline bool end() const { return false; }
765 inline pkgCache::Version
const * operator->() const { return &*getType(); }
769 virtual bool insert(pkgCache::VerIterator
const &V
) = 0;
770 virtual bool empty() const = 0;
771 virtual void clear() = 0;
772 virtual size_t size() const = 0;
774 /** \brief specifies which version(s) will be returned if non is given */
775 enum APT_DEPRECATED Version
{
776 ALL
= CacheSetHelper::ALL
,
777 CANDANDINST
= CacheSetHelper::CANDANDINST
,
778 CANDIDATE
= CacheSetHelper::CANDIDATE
,
779 INSTALLED
= CacheSetHelper::INSTALLED
,
780 CANDINST
= CacheSetHelper::CANDINST
,
781 INSTCAND
= CacheSetHelper::INSTCAND
,
782 NEWEST
= CacheSetHelper::NEWEST
786 unsigned short const ID
;
787 const char * const Alias
;
788 enum Position
{ NONE
, PREFIX
, POSTFIX
} const Pos
;
789 enum CacheSetHelper::VerSelector
const SelectVersion
;
790 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
,
791 enum CacheSetHelper::VerSelector
const select
) : ID(id
), Alias(alias
), Pos(pos
),
792 SelectVersion(select
) {}
793 APT_IGNORE_DEPRECATED_PUSH
794 APT_DEPRECATED
Modifier(unsigned short const &id
, const char * const alias
, Position
const &pos
,
795 Version
const &select
) : ID(id
), Alias(alias
), Pos(pos
),
796 SelectVersion((CacheSetHelper::VerSelector
)select
) {}
797 APT_IGNORE_DEPRECATED_POP
800 static bool FromCommandLine(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
801 const char **cmdline
, CacheSetHelper::VerSelector
const fallback
,
802 CacheSetHelper
&helper
);
803 APT_IGNORE_DEPRECATED_PUSH
804 APT_DEPRECATED
static bool FromCommandLine(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
805 const char **cmdline
, Version
const &fallback
,
806 CacheSetHelper
&helper
) {
807 return FromCommandLine(vci
, Cache
, cmdline
, (CacheSetHelper::VerSelector
)fallback
, helper
);
809 APT_IGNORE_DEPRECATED_POP
811 static bool FromString(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
812 std::string pkg
, CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
,
813 bool const onlyFromName
= false);
814 APT_IGNORE_DEPRECATED_PUSH
815 APT_DEPRECATED
static bool FromString(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
816 std::string pkg
, Version
const &fallback
, CacheSetHelper
&helper
,
817 bool const onlyFromName
= false) {
818 return FromString(vci
, Cache
, pkg
, (CacheSetHelper::VerSelector
)fallback
, helper
, onlyFromName
);
820 APT_IGNORE_DEPRECATED_POP
822 static bool FromPackage(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
823 pkgCache::PkgIterator
const &P
, CacheSetHelper::VerSelector
const fallback
,
824 CacheSetHelper
&helper
);
825 APT_IGNORE_DEPRECATED_PUSH
826 APT_DEPRECATED
static bool FromPackage(VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
,
827 pkgCache::PkgIterator
const &P
, Version
const &fallback
,
828 CacheSetHelper
&helper
) {
829 return FromPackage(vci
, Cache
, P
, (CacheSetHelper::VerSelector
)fallback
, helper
);
831 APT_IGNORE_DEPRECATED_POP
833 static bool FromModifierCommandLine(unsigned short &modID
,
834 VersionContainerInterface
* const vci
,
835 pkgCacheFile
&Cache
, const char * cmdline
,
836 std::list
<Modifier
> const &mods
,
837 CacheSetHelper
&helper
);
840 static bool FromDependency(VersionContainerInterface
* const vci
,
842 pkgCache::DepIterator
const &D
,
843 CacheSetHelper::VerSelector
const selector
,
844 CacheSetHelper
&helper
);
845 APT_IGNORE_DEPRECATED_PUSH
846 APT_DEPRECATED
static bool FromDependency(VersionContainerInterface
* const vci
,
848 pkgCache::DepIterator
const &D
,
849 Version
const &selector
,
850 CacheSetHelper
&helper
) {
851 return FromDependency(vci
, Cache
, D
, (CacheSetHelper::VerSelector
)selector
, helper
);
853 APT_IGNORE_DEPRECATED_POP
855 VersionContainerInterface();
856 VersionContainerInterface
& operator=(VersionContainerInterface
const &other
);
857 virtual ~VersionContainerInterface();
863 /** \brief returns the candidate version of the package
865 \param Cache to be used to query for information
866 \param Pkg we want the candidate version from this package
867 \param helper used in this container instance */
868 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
869 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
871 /** \brief returns the installed version of the package
873 \param Cache to be used to query for information
874 \param Pkg we want the installed version from this package
875 \param helper used in this container instance */
876 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
877 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
881 template<class Container
> class VersionContainer
: public VersionContainerInterface
{/*{{{*/
882 /** \class APT::VersionContainer
884 Simple wrapper around a container class like std::set to provide a similar
885 interface to a set of versions as to the complete set of all versions in the
889 typedef Container_const_iterator
<VersionContainerInterface
, Container
, VersionContainer
> const_iterator
;
890 typedef Container_iterator
<VersionContainerInterface
, Container
, VersionContainer
> iterator
;
891 typedef Container_const_reverse_iterator
<VersionContainerInterface
, Container
, VersionContainer
> const_reverse_iterator
;
892 typedef Container_reverse_iterator
<VersionContainerInterface
, Container
, VersionContainer
> reverse_iterator
;
894 bool insert(pkgCache::VerIterator
const &V
) APT_OVERRIDE
{ if (V
.end() == true) return false; _cont
.insert(V
); return true; }
895 template<class Cont
> void insert(VersionContainer
<Cont
> const &vercont
) { _cont
.insert((typename
Cont::const_iterator
)vercont
.begin(), (typename
Cont::const_iterator
)vercont
.end()); }
896 void insert(const_iterator begin
, const_iterator end
) { _cont
.insert(begin
, end
); }
897 bool empty() const APT_OVERRIDE
{ return _cont
.empty(); }
898 void clear() APT_OVERRIDE
{ return _cont
.clear(); }
899 size_t size() const APT_OVERRIDE
{ return _cont
.size(); }
900 #if __GNUC__ >= 5 || (__GNUC_MINOR__ >= 9 && __GNUC__ >= 4)
901 iterator
erase( const_iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
902 iterator
erase( const_iterator first
, const_iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
904 iterator
erase( iterator pos
) { return iterator(_cont
.erase(pos
._iter
)); }
905 iterator
erase( iterator first
, iterator last
) { return iterator(_cont
.erase(first
._iter
, last
._iter
)); }
907 const_iterator
begin() const { return const_iterator(_cont
.begin()); }
908 const_iterator
end() const { return const_iterator(_cont
.end()); }
909 const_reverse_iterator
rbegin() const { return const_reverse_iterator(_cont
.rbegin()); }
910 const_reverse_iterator
rend() const { return const_reverse_iterator(_cont
.rend()); }
911 #if __cplusplus >= 201103L
912 const_iterator
cbegin() const { return const_iterator(_cont
.cbegin()); }
913 const_iterator
cend() const { return const_iterator(_cont
.cend()); }
914 const_reverse_iterator
crbegin() const { return const_reverse_iterator(_cont
.crbegin()); }
915 const_reverse_iterator
crend() const { return const_reverse_iterator(_cont
.crend()); }
917 iterator
begin() { return iterator(_cont
.begin()); }
918 iterator
end() { return iterator(_cont
.end()); }
919 reverse_iterator
rbegin() { return reverse_iterator(_cont
.rbegin()); }
920 reverse_iterator
rend() { return reverse_iterator(_cont
.rend()); }
921 const_iterator
find(pkgCache::VerIterator
const &V
) const { return const_iterator(_cont
.find(V
)); }
923 /** \brief sort all included versions with given comparer
925 Some containers are sorted by default, some are not and can't be,
926 but a few like std::vector can be sorted if need be, so this can be
927 specialized in later on. The default is that this will fail though.
928 Specifically, already sorted containers like std::set will return
929 false as well as there is no easy way to check that the given comparer
930 would sort in the same way the set is currently sorted
932 \return \b true if the set was sorted, \b false if not. */
933 template<class Compare
> bool sort(Compare
/*Comp*/) { return false; }
935 /** \brief returns all versions specified on the commandline
937 Get all versions from the commandline, uses given default version if
938 non specifically requested and executes regex's if needed on names.
939 \param Cache the packages and versions are in
940 \param cmdline Command line the versions should be extracted from
941 \param fallback version specification
942 \param helper responsible for error and message handling */
943 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
944 CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
) {
945 VersionContainer vercon
;
946 VersionContainerInterface::FromCommandLine(&vercon
, Cache
, cmdline
, fallback
, helper
);
949 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
950 CacheSetHelper::VerSelector
const fallback
) {
951 CacheSetHelper helper
;
952 return FromCommandLine(Cache
, cmdline
, fallback
, helper
);
954 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
955 return FromCommandLine(Cache
, cmdline
, CacheSetHelper::CANDINST
);
957 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pkg
,
958 CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
,
959 bool const /*onlyFromName = false*/) {
960 VersionContainer vercon
;
961 VersionContainerInterface::FromString(&vercon
, Cache
, pkg
, fallback
, helper
);
964 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
,
965 CacheSetHelper::VerSelector
const fallback
) {
966 CacheSetHelper helper
;
967 return FromString(Cache
, pkg
, fallback
, helper
);
969 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
) {
970 return FromString(Cache
, pkg
, CacheSetHelper::CANDINST
);
972 APT_IGNORE_DEPRECATED_PUSH
973 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
974 Version
const &fallback
, CacheSetHelper
&helper
) {
975 VersionContainer vercon
;
976 VersionContainerInterface::FromCommandLine(&vercon
, Cache
, cmdline
, (CacheSetHelper::VerSelector
)fallback
, helper
);
979 static VersionContainer
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
980 Version
const &fallback
) {
981 CacheSetHelper helper
;
982 return FromCommandLine(Cache
, cmdline
, (CacheSetHelper::VerSelector
)fallback
, helper
);
984 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string
const &pkg
,
985 Version
const &fallback
, CacheSetHelper
&helper
,
986 bool const /*onlyFromName = false*/) {
987 VersionContainer vercon
;
988 VersionContainerInterface::FromString(&vercon
, Cache
, pkg
, (CacheSetHelper::VerSelector
)fallback
, helper
);
991 static VersionContainer
FromString(pkgCacheFile
&Cache
, std::string pkg
,
992 Version
const &fallback
) {
993 CacheSetHelper helper
;
994 return FromString(Cache
, pkg
, (CacheSetHelper::VerSelector
)fallback
, helper
);
996 APT_IGNORE_DEPRECATED_POP
998 /** \brief returns all versions specified for the package
1000 \param Cache the package and versions are in
1001 \param P the package in question
1002 \param fallback the version(s) you want to get
1003 \param helper the helper used for display and error handling */
1004 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
1005 CacheSetHelper::VerSelector
const fallback
, CacheSetHelper
&helper
) {
1006 VersionContainer vercon
;
1007 VersionContainerInterface::FromPackage(&vercon
, Cache
, P
, fallback
, helper
);
1010 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
1011 CacheSetHelper::VerSelector
const fallback
) {
1012 CacheSetHelper helper
;
1013 return FromPackage(Cache
, P
, fallback
, helper
);
1015 APT_IGNORE_DEPRECATED_PUSH
1016 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
1017 Version
const &fallback
, CacheSetHelper
&helper
) {
1018 VersionContainer vercon
;
1019 VersionContainerInterface::FromPackage(&vercon
, Cache
, P
, (CacheSetHelper::VerSelector
)fallback
, helper
);
1022 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
,
1023 Version
const &fallback
) {
1024 CacheSetHelper helper
;
1025 return FromPackage(Cache
, P
, (CacheSetHelper::VerSelector
)fallback
, helper
);
1027 APT_IGNORE_DEPRECATED_POP
1028 static VersionContainer
FromPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &P
) {
1029 return FromPackage(Cache
, P
, CacheSetHelper::CANDIDATE
);
1032 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
1033 pkgCacheFile
&Cache
,
1034 const char **cmdline
,
1035 std::list
<Modifier
> const &mods
,
1036 unsigned short const fallback
,
1037 CacheSetHelper
&helper
) {
1038 std::map
<unsigned short, VersionContainer
> versets
;
1039 for (const char **I
= cmdline
; *I
!= 0; ++I
) {
1040 unsigned short modID
= fallback
;
1041 VersionContainer verset
;
1042 VersionContainerInterface::FromModifierCommandLine(modID
, &verset
, Cache
, *I
, mods
, helper
);
1043 versets
[modID
].insert(verset
);
1048 static std::map
<unsigned short, VersionContainer
> GroupedFromCommandLine(
1049 pkgCacheFile
&Cache
, const char **cmdline
,
1050 std::list
<Modifier
> const &mods
,
1051 unsigned short const fallback
) {
1052 CacheSetHelper helper
;
1053 return GroupedFromCommandLine(Cache
, cmdline
,
1054 mods
, fallback
, helper
);
1057 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1058 CacheSetHelper::VerSelector
const selector
, CacheSetHelper
&helper
) {
1059 VersionContainer vercon
;
1060 VersionContainerInterface::FromDependency(&vercon
, Cache
, D
, selector
, helper
);
1063 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1064 CacheSetHelper::VerSelector
const selector
) {
1065 CacheSetHelper helper
;
1066 return FromDependency(Cache
, D
, selector
, helper
);
1068 APT_IGNORE_DEPRECATED_PUSH
1069 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1070 Version
const &selector
, CacheSetHelper
&helper
) {
1071 VersionContainer vercon
;
1072 VersionContainerInterface::FromDependency(&vercon
, Cache
, D
, (CacheSetHelper::VerSelector
)selector
, helper
);
1075 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
,
1076 Version
const &selector
) {
1077 CacheSetHelper helper
;
1078 return FromDependency(Cache
, D
, (CacheSetHelper::VerSelector
)selector
, helper
);
1080 APT_IGNORE_DEPRECATED_POP
1081 static VersionContainer
FromDependency(pkgCacheFile
&Cache
, pkgCache::DepIterator
const &D
) {
1082 return FromDependency(Cache
, D
, CacheSetHelper::CANDIDATE
);
1086 // various specialisations for VersionContainer /*{{{*/
1087 template<> template<class Cont
> void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
1088 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
1089 _cont
.push_back(*v
);
1091 #if __cplusplus >= 201103L
1092 template<> template<class Cont
> void VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
1093 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
1094 _cont
.push_front(*v
);
1097 template<> template<class Cont
> void VersionContainer
<std::deque
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
1098 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
1099 _cont
.push_back(*v
);
1101 template<> template<class Cont
> void VersionContainer
<std::vector
<pkgCache::VerIterator
> >::insert(VersionContainer
<Cont
> const &vercont
) {
1102 for (typename VersionContainer
<Cont
>::const_iterator v
= vercont
.begin(); v
!= vercont
.end(); ++v
)
1103 _cont
.push_back(*v
);
1105 // these are 'inline' as otherwise the linker has problems with seeing these untemplated
1106 // specializations again and again - but we need to see them, so that library users can use them
1107 template<> inline bool VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
1108 if (V
.end() == true)
1113 #if __cplusplus >= 201103L
1114 template<> inline bool VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
1115 if (V
.end() == true)
1117 _cont
.push_front(V
);
1121 template<> inline bool VersionContainer
<std::deque
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
1122 if (V
.end() == true)
1127 template<> inline bool VersionContainer
<std::vector
<pkgCache::VerIterator
> >::insert(pkgCache::VerIterator
const &V
) {
1128 if (V
.end() == true)
1133 template<> inline void VersionContainer
<std::list
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
1134 for (const_iterator v
= begin
; v
!= end
; ++v
)
1135 _cont
.push_back(*v
);
1137 #if __cplusplus >= 201103L
1138 template<> inline void VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
1139 for (const_iterator v
= begin
; v
!= end
; ++v
)
1140 _cont
.push_front(*v
);
1143 template<> inline void VersionContainer
<std::deque
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
1144 for (const_iterator v
= begin
; v
!= end
; ++v
)
1145 _cont
.push_back(*v
);
1147 template<> inline void VersionContainer
<std::vector
<pkgCache::VerIterator
> >::insert(const_iterator begin
, const_iterator end
) {
1148 for (const_iterator v
= begin
; v
!= end
; ++v
)
1149 _cont
.push_back(*v
);
1151 #if __cplusplus < 201103L
1152 template<> inline VersionContainer
<std::set
<pkgCache::VerIterator
> >::iterator VersionContainer
<std::set
<pkgCache::VerIterator
> >::erase(iterator i
) {
1153 _cont
.erase(i
._iter
);
1156 template<> inline VersionContainer
<std::set
<pkgCache::VerIterator
> >::iterator VersionContainer
<std::set
<pkgCache::VerIterator
> >::erase(iterator first
, iterator last
) {
1157 _cont
.erase(first
, last
);
1161 template<> template<class Compare
> inline bool VersionContainer
<std::vector
<pkgCache::VerIterator
> >::sort(Compare Comp
) {
1162 std::sort(_cont
.begin(), _cont
.end(), Comp
);
1165 template<> template<class Compare
> inline bool VersionContainer
<std::list
<pkgCache::VerIterator
> >::sort(Compare Comp
) {
1169 #if __cplusplus >= 201103L
1170 template<> template<class Compare
> inline bool VersionContainer
<std::forward_list
<pkgCache::VerIterator
> >::sort(Compare Comp
) {
1175 template<> template<class Compare
> inline bool VersionContainer
<std::deque
<pkgCache::VerIterator
> >::sort(Compare Comp
) {
1176 std::sort(_cont
.begin(), _cont
.end(), Comp
);
1181 typedef VersionContainer
<std::set
<pkgCache::VerIterator
> > VersionSet
;
1182 #if __cplusplus >= 201103L
1183 typedef VersionContainer
<std::unordered_set
<pkgCache::VerIterator
> > VersionUnorderedSet
;
1184 typedef VersionContainer
<std::forward_list
<pkgCache::VerIterator
> > VersionForwardList
;
1186 typedef VersionContainer
<std::list
<pkgCache::VerIterator
> > VersionList
;
1187 typedef VersionContainer
<std::deque
<pkgCache::VerIterator
> > VersionDeque
;
1188 typedef VersionContainer
<std::vector
<pkgCache::VerIterator
> > VersionVector
;