// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
/** \file cacheset.h
Wrappers around std : : set to have set : : iterators which behave
similar to the Iterators of the cache structures .
Provides also a few helper methods which work with these sets */
/*}}}*/
# ifndef APT_CACHESET_H
# define APT_CACHESET_H
// Include Files /*{{{*/
# include <fstream>
# include <map>
# include <set>
# if __cplusplus >= 201103L
# include <forward_list>
# include <initializer_list>
# include <unordered_set>
# endif
# include <algorithm>
# include <deque>
# include <iterator>
# include <list>
# include <string>
# include <vector>
# include <stddef.h>
# include <apt-pkg/error.h>
# include <apt-pkg/macros.h>
# include <apt-pkg/pkgcache.h>
# ifndef APT_8_CLEANER_HEADERS
# include <apt-pkg/cachefile.h>
# endif
# ifndef APT_10_CLEANER_HEADERS
# include <iostream>
# endif
/*}}}*/
class pkgCacheFile ;
namespace APT {
class PackageContainerInterface ;
class VersionContainerInterface ;
class CacheSetHelper { /*{{{*/
/** \class APT::CacheSetHelper
Simple base class with a lot of virtual methods which can be overridden
to alter the behavior or the output of the CacheSets .
This helper is passed around by the static methods in the CacheSets and
used every time they hit an error condition or something could be
printed out .
*/
public : /*{{{*/
CacheSetHelper ( bool const ShowError = true ,
GlobalError : : MsgType ErrorType = GlobalError : : ERROR ) ;
virtual ~ CacheSetHelper ( ) ;
enum PkgSelector { UNKNOWN , REGEX , TASK , FNMATCH , PACKAGENAME , STRING } ;
virtual bool PackageFrom ( enum PkgSelector const select , PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string const & pattern ) ;
virtual bool PackageFromCommandLine ( PackageContainerInterface * const pci , pkgCacheFile & Cache , const char * * cmdline ) ;
struct PkgModifier {
enum Position { NONE , PREFIX , POSTFIX } ;
unsigned short ID ;
const char * const Alias ;
Position Pos ;
PkgModifier ( unsigned short const & id , const char * const alias , Position const & pos ) : ID ( id ) , Alias ( alias ) , Pos ( pos ) { }
} ;
virtual bool PackageFromModifierCommandLine ( unsigned short & modID , PackageContainerInterface * const pci ,
pkgCacheFile & Cache , const char * cmdline ,
std : : list < PkgModifier > const & mods ) ;
APT_DEPRECATED_MSG ( " use .PackageFrom(PACKAGENAME, …) instead " ) pkgCache : : PkgIterator PackageFromName ( pkgCacheFile & Cache , std : : string const & pattern ) ;
/** \brief be notified about the package being selected via pattern
*
* Main use is probably to show a message to the user what happened
*
* \ param pkg is the package which was selected
* \ param select is the selection method which choose the package
* \ param pattern is the string used by the selection method to pick the package
*/
virtual void showPackageSelection ( pkgCache : : PkgIterator const & pkg , PkgSelector const select , std : : string const & pattern ) ;
// use the method above instead, react only on the type you need and let the base handle the rest if need be
// this allows us to add new selection methods without breaking the ABI constantly with new virtual methods
APT_DEPRECATED_MSG ( " override .showPackageSelection and select with switch " ) virtual void showTaskSelection ( pkgCache : : PkgIterator const & pkg , std : : string const & pattern ) ;
APT_DEPRECATED_MSG ( " override .showPackageSelection and select with switch " ) virtual void showRegExSelection ( pkgCache : : PkgIterator const & pkg , std : : string const & pattern ) ;
APT_DEPRECATED_MSG ( " override .showPackageSelection and select with switch " ) virtual void showFnmatchSelection ( pkgCache : : PkgIterator const & pkg , std : : string const & pattern ) ;
/** \brief be notified if a package can't be found via pattern
*
* Can be used to show a message as well as to try something else to make it match
*
* \ param select is the method tried for selection
* \ param pci is the container the package should be inserted in
* \ param Cache is the package universe available
* \ param pattern is the string not matching anything
*/
virtual void canNotFindPackage ( enum PkgSelector const select , PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string const & pattern ) ;
// same as above for showPackageSelection
APT_DEPRECATED_MSG ( " override .canNotFindPackage and select with switch " ) virtual void canNotFindTask ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string pattern ) ;
APT_DEPRECATED_MSG ( " override .canNotFindPackage and select with switch " ) virtual void canNotFindRegEx ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string pattern ) ;
APT_DEPRECATED_MSG ( " override .canNotFindPackage and select with switch " ) virtual void canNotFindFnmatch ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string pattern ) ;
APT_DEPRECATED_MSG ( " override .canNotFindPackage and select with switch " ) virtual void canNotFindPackage ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string const & str ) ;
/** \brief specifies which version(s) we want to refer to */
enum VerSelector {
/** by release string */
RELEASE ,
/** by version number string */
VERSIONNUMBER ,
/** All versions */
ALL ,
/** Candidate and installed version */
CANDANDINST ,
/** Candidate version */
CANDIDATE ,
/** Installed version */
INSTALLED ,
/** Candidate or if non installed version */
CANDINST ,
/** Installed or if non candidate version */
INSTCAND ,
/** Newest version */
NEWEST
} ;
/** \brief be notified about the version being selected via pattern
*
* Main use is probably to show a message to the user what happened
* Note that at the moment this method is only called for RELEASE
* and VERSION selections , not for the others .
*
* \ param Pkg is the package which was selected for
* \ param Ver is the version selected
* \ param select is the selection method which choose the version
* \ param pattern is the string used by the selection method to pick the version
*/
virtual void showVersionSelection ( pkgCache : : PkgIterator const & Pkg , pkgCache : : VerIterator const & Ver ,
enum VerSelector const select , std : : string const & pattern ) ;
APT_DEPRECATED_MSG ( " use .showVersionSelection instead, similar to .showPackageSelection " ) virtual void showSelectedVersion ( pkgCache : : PkgIterator const & Pkg , pkgCache : : VerIterator const Ver ,
std : : string const & ver , bool const verIsRel ) ;
/** \brief be notified if a version can't be found for a package
*
* Main use is probably to show a message to the user what happened
*
* \ param select is the method tried for selection
* \ param vci is the container the version should be inserted in
* \ param Cache is the package universe available
* \ param Pkg is the package we wanted a version from
*/
virtual void canNotFindVersion ( enum VerSelector const select , VersionContainerInterface * const vci , pkgCacheFile & Cache , pkgCache : : PkgIterator const & Pkg ) ;
APT_DEPRECATED_MSG ( " override .canNotFindVersion and select via switch " ) virtual void canNotFindAllVer ( VersionContainerInterface * const vci , pkgCacheFile & Cache , pkgCache : : PkgIterator const & Pkg ) ;
APT_DEPRECATED_MSG ( " override .canNotFindVersion and select via switch " ) virtual void canNotFindInstCandVer ( VersionContainerInterface * const vci , pkgCacheFile & Cache ,
pkgCache : : PkgIterator const & Pkg ) ;
APT_DEPRECATED_MSG ( " override .canNotFindVersion and select via switch " ) virtual void canNotFindCandInstVer ( VersionContainerInterface * const vci ,
pkgCacheFile & Cache ,
pkgCache : : PkgIterator const & Pkg ) ;
// the difference between canNotFind and canNotGet is that the later is more low-level
// and called from other places: In this case looking into the code is the only real answer…
virtual pkgCache : : VerIterator canNotGetVersion ( enum VerSelector const select , pkgCacheFile & Cache , pkgCache : : PkgIterator const & Pkg ) ;
APT_DEPRECATED_MSG ( " override .canNotGetVersion and select via switch " ) virtual pkgCache : : VerIterator canNotFindNewestVer ( pkgCacheFile & Cache ,
pkgCache : : PkgIterator const & Pkg ) ;
APT_DEPRECATED_MSG ( " override .canNotGetVersion and select via switch " ) virtual pkgCache : : VerIterator canNotFindCandidateVer ( pkgCacheFile & Cache ,
pkgCache : : PkgIterator const & Pkg ) ;
APT_DEPRECATED_MSG ( " override .canNotGetVersion and select via switch " ) virtual pkgCache : : VerIterator canNotFindInstalledVer ( pkgCacheFile & Cache ,
pkgCache : : PkgIterator const & Pkg ) ;
virtual pkgCache : : PkgIterator canNotFindPkgName ( pkgCacheFile & Cache , std : : string const & str ) ;
bool showErrors ( ) const { return ShowError ; }
bool showErrors ( bool const newValue ) { if ( ShowError = = newValue ) return ShowError ; else return ( ( ShowError = newValue ) = = false ) ; }
GlobalError : : MsgType errorType ( ) const { return ErrorType ; }
GlobalError : : MsgType errorType ( GlobalError : : MsgType const & newValue )
{
if ( ErrorType = = newValue ) return ErrorType ;
else {
GlobalError : : MsgType const & oldValue = ErrorType ;
ErrorType = newValue ;
return oldValue ;
}
}
/*}}}*/
protected :
bool ShowError ;
GlobalError : : MsgType ErrorType ;
pkgCache : : VerIterator canNotGetInstCandVer ( pkgCacheFile & Cache ,
pkgCache : : PkgIterator const & Pkg ) ;
pkgCache : : VerIterator canNotGetCandInstVer ( pkgCacheFile & Cache ,
pkgCache : : PkgIterator const & Pkg ) ;
bool PackageFromTask ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string pattern ) ;
bool PackageFromRegEx ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string pattern ) ;
bool PackageFromFnmatch ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string pattern ) ;
bool PackageFromPackageName ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string pattern ) ;
bool PackageFromString ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string const & pattern ) ;
private :
void * const d ;
} ; /*}}}*/
// Iterator templates for our Containers /*{{{*/
template < typename Interface , typename Master , typename iterator_type , typename container_iterator , typename container_value > class Container_iterator_base :
public std : : iterator < typename std : : iterator_traits < container_iterator > : : iterator_category , container_value > ,
public Interface : : template iterator_base < iterator_type >
{
protected :
container_iterator _iter ;
public :
explicit Container_iterator_base ( container_iterator i ) : _iter ( i ) { }
inline container_value operator * ( void ) const { return static_cast < iterator_type const * > ( this ) - > getType ( ) ; } ;
operator container_iterator ( void ) const { return _iter ; }
inline iterator_type & operator + + ( ) { + + _iter ; return static_cast < iterator_type & > ( * this ) ; }
inline iterator_type operator + + ( int ) { iterator_type tmp ( * this ) ; operator + + ( ) ; return tmp ; }
inline iterator_type operator + ( typename container_iterator : : difference_type const & n ) { return iterator_type ( _iter + n ) ; }
inline iterator_type operator + = ( typename container_iterator : : difference_type const & n ) { _iter + = n ; return static_cast < iterator_type & > ( * this ) ; }
inline iterator_type & operator - - ( ) { - - _iter ; ; return static_cast < iterator_type & > ( * this ) ; }
inline iterator_type operator - - ( int ) { iterator_type tmp ( * this ) ; operator - - ( ) ; return tmp ; }
inline iterator_type operator - ( typename container_iterator : : difference_type const & n ) { return iterator_type ( _iter - n ) ; }
inline typename container_iterator : : difference_type operator - ( iterator_type const & b ) { return ( _iter - b . _iter ) ; }
inline iterator_type operator - = ( typename container_iterator : : difference_type const & n ) { _iter - = n ; return static_cast < iterator_type & > ( * this ) ; }
inline bool operator ! = ( iterator_type const & i ) const { return _iter ! = i . _iter ; }
inline bool operator = = ( iterator_type const & i ) const { return _iter = = i . _iter ; }
inline bool operator < ( iterator_type const & i ) const { return _iter < i . _iter ; }
inline bool operator > ( iterator_type const & i ) const { return _iter > i . _iter ; }
inline bool operator < = ( iterator_type const & i ) const { return _iter < = i . _iter ; }
inline bool operator > = ( iterator_type const & i ) const { return _iter > = i . _iter ; }
inline typename container_iterator : : reference operator [ ] ( typename container_iterator : : difference_type const & n ) const { return _iter [ n ] ; }
friend std : : ostream & operator < < ( std : : ostream & out , iterator_type i ) { return operator < < ( out , * i ) ; }
friend Master ;
} ;
template < class Interface , class Container , class Master > class Container_const_iterator :
public Container_iterator_base < Interface , Master , Container_const_iterator < Interface , Container , Master > , typename Container : : const_iterator , typename Container : : value_type >
{
typedef Container_const_iterator < Interface , Container , Master > iterator_type ;
typedef typename Container : : const_iterator container_iterator ;
public :
explicit Container_const_iterator ( container_iterator i ) :
Container_iterator_base < Interface , Master , iterator_type , container_iterator , typename Container : : value_type > ( i ) { }
inline typename Container : : value_type getType ( void ) const { return * this - > _iter ; }
} ;
template < class Interface , class Container , class Master > class Container_iterator :
public Container_iterator_base < Interface , Master , Container_iterator < Interface , Container , Master > , typename Container : : iterator , typename Container : : value_type >
{
typedef Container_iterator < Interface , Container , Master > iterator_type ;
typedef typename Container : : iterator container_iterator ;
public :
explicit Container_iterator ( container_iterator i ) :
Container_iterator_base < Interface , Master , iterator_type , container_iterator , typename Container : : value_type > ( i ) { }
operator typename Master : : const_iterator ( ) { return typename Master : : const_iterator ( this - > _iter ) ; }
inline iterator_type & operator = ( iterator_type const & i ) { this - > _iter = i . _iter ; return static_cast < iterator_type & > ( * this ) ; }
inline iterator_type & operator = ( container_iterator const & i ) { this - > _iter = i ; return static_cast < iterator_type & > ( * this ) ; }
inline typename Container : : iterator : : reference operator * ( void ) const { return * this - > _iter ; }
inline typename Container : : value_type getType ( void ) const { return * this - > _iter ; }
} ;
template < class Interface , class Container , class Master > class Container_const_reverse_iterator :
public Container_iterator_base < Interface , Master , Container_const_reverse_iterator < Interface , Container , Master > , typename Container : : const_reverse_iterator , typename Container : : value_type >
{
typedef Container_const_reverse_iterator < Interface , Container , Master > iterator_type ;
typedef typename Container : : const_reverse_iterator container_iterator ;
public :
explicit Container_const_reverse_iterator ( container_iterator i ) :
Container_iterator_base < Interface , Master , iterator_type , container_iterator , typename Container : : value_type > ( i ) { }
inline typename Container : : value_type getType ( void ) const { return * this - > _iter ; }
} ;
template < class Interface , class Container , class Master > class Container_reverse_iterator :
public Container_iterator_base < Interface , Master , Container_reverse_iterator < Interface , Container , Master > , typename Container : : reverse_iterator , typename Container : : value_type >
{
typedef Container_reverse_iterator < Interface , Container , Master > iterator_type ;
typedef typename Container : : reverse_iterator container_iterator ;
public :
explicit Container_reverse_iterator ( container_iterator i ) :
Container_iterator_base < Interface , Master , iterator_type , container_iterator , typename Container : : value_type > ( i ) { }
operator typename Master : : const_iterator ( ) { return typename Master : : const_iterator ( this - > _iter ) ; }
inline iterator_type & operator = ( iterator_type const & i ) { this - > _iter = i . _iter ; return static_cast < iterator_type & > ( * this ) ; }
inline iterator_type & operator = ( container_iterator const & i ) { this - > _iter = i ; return static_cast < iterator_type & > ( * this ) ; }
inline typename Container : : reverse_iterator : : reference operator * ( void ) const { return * this - > _iter ; }
inline typename Container : : value_type getType ( void ) const { return * this - > _iter ; }
} ;
/*}}}*/
class PackageContainerInterface { /*{{{*/
/** \class PackageContainerInterface
* Interface ensuring that all operations can be executed on the yet to
* define concrete PackageContainer - access to all methods is possible ,
* but in general the wrappers provided by the PackageContainer template
* are nicer to use .
* This class mostly protects use from the need to write all implementation
* of the methods working on containers in the template */
public :
template < class Itr > class iterator_base { /*{{{*/
pkgCache : : PkgIterator getType ( ) const { return static_cast < Itr const * > ( this ) - > getType ( ) ; } ;
public :
operator pkgCache : : PkgIterator ( void ) const { return getType ( ) ; }
inline const char * Name ( ) const { return getType ( ) . Name ( ) ; }
inline std : : string FullName ( bool const Pretty ) const { return getType ( ) . FullName ( Pretty ) ; }
inline std : : string FullName ( ) const { return getType ( ) . FullName ( ) ; }
APT_DEPRECATED_MSG ( " Use the .Section method of VerIterator instead " ) inline const char * Section ( ) const {
APT_IGNORE_DEPRECATED_PUSH
return getType ( ) . Section ( ) ;
APT_IGNORE_DEPRECATED_POP
}
inline bool Purge ( ) const { return getType ( ) . Purge ( ) ; }
inline const char * Arch ( ) const { return getType ( ) . Arch ( ) ; }
inline pkgCache : : GrpIterator Group ( ) const { return getType ( ) . Group ( ) ; }
inline pkgCache : : VerIterator VersionList ( ) const { return getType ( ) . VersionList ( ) ; }
inline pkgCache : : VerIterator CurrentVer ( ) const { return getType ( ) . CurrentVer ( ) ; }
inline pkgCache : : DepIterator RevDependsList ( ) const { return getType ( ) . RevDependsList ( ) ; }
inline pkgCache : : PrvIterator ProvidesList ( ) const { return getType ( ) . ProvidesList ( ) ; }
inline pkgCache : : PkgIterator : : OkState State ( ) const { return getType ( ) . State ( ) ; }
APT_DEPRECATED_MSG ( " This method does not respect apt_preferences! Use pkgDepCache::GetCandidateVersion(Pkg) " ) inline const char * CandVersion ( ) const { return getType ( ) . CandVersion ( ) ; }
inline const char * CurVersion ( ) const { return getType ( ) . CurVersion ( ) ; }
inline pkgCache * Cache ( ) const { return getType ( ) . Cache ( ) ; }
inline unsigned long Index ( ) const { return getType ( ) . Index ( ) ; }
// we have only valid iterators here
inline bool end ( ) const { return false ; }
inline pkgCache : : Package const * operator - > ( ) const { return & * getType ( ) ; }
} ;
/*}}}*/
virtual bool insert ( pkgCache : : PkgIterator const & P ) = 0 ;
virtual bool empty ( ) const = 0 ;
virtual void clear ( ) = 0 ;
virtual size_t size ( ) const = 0 ;
enum APT_DEPRECATED_MSG ( " Use CacheSetHelper::PkgSelector instead " ) Constructor { UNKNOWN = CacheSetHelper : : UNKNOWN ,
REGEX = CacheSetHelper : : REGEX ,
TASK = CacheSetHelper : : TASK ,
FNMATCH = CacheSetHelper : : FNMATCH } ;
APT_IGNORE_DEPRECATED_PUSH
void setConstructor ( Constructor const by ) { ConstructedBy = ( CacheSetHelper : : PkgSelector ) by ; }
APT_IGNORE_DEPRECATED_POP
void setConstructor ( CacheSetHelper : : PkgSelector const by ) { ConstructedBy = by ; }
CacheSetHelper : : PkgSelector getConstructor ( ) const { return ConstructedBy ; }
PackageContainerInterface ( ) ;
explicit PackageContainerInterface ( CacheSetHelper : : PkgSelector const by ) ;
PackageContainerInterface & operator = ( PackageContainerInterface const & other ) ;
virtual ~ PackageContainerInterface ( ) ;
APT_DEPRECATED_MSG ( " Use helper.PackageFrom(CacheSetHelper::TASK, …) instead " ) static bool FromTask ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string pattern , CacheSetHelper & helper ) {
return helper . PackageFrom ( CacheSetHelper : : TASK , pci , Cache , pattern ) ; }
APT_DEPRECATED_MSG ( " Use helper.PackageFrom(CacheSetHelper::REGEX, …) instead " ) static bool FromRegEx ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string pattern , CacheSetHelper & helper ) {
return helper . PackageFrom ( CacheSetHelper : : REGEX , pci , Cache , pattern ) ; }
APT_DEPRECATED_MSG ( " Use helper.PackageFrom(CacheSetHelper::FNMATCH, …) instead " ) static bool FromFnmatch ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string pattern , CacheSetHelper & helper ) {
return helper . PackageFrom ( CacheSetHelper : : FNMATCH , pci , Cache , pattern ) ; }
APT_DEPRECATED_MSG ( " Use helper.PackageFrom(CacheSetHelper::PACKAGENAME, …) instead " ) static bool FromGroup ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string pattern , CacheSetHelper & helper ) {
return helper . PackageFrom ( CacheSetHelper : : PACKAGENAME , pci , Cache , pattern ) ; }
APT_DEPRECATED_MSG ( " Use helper.PackageFrom(CacheSetHelper::STRING, …) instead " ) static bool FromString ( PackageContainerInterface * const pci , pkgCacheFile & Cache , std : : string const & pattern , CacheSetHelper & helper ) {
return helper . PackageFrom ( CacheSetHelper : : STRING , pci , Cache , pattern ) ; }
APT_DEPRECATED_MSG ( " Use helper.PackageFromCommandLine instead " ) static bool FromCommandLine ( PackageContainerInterface * const pci , pkgCacheFile & Cache , const char * * cmdline , CacheSetHelper & helper ) {
return helper . PackageFromCommandLine ( pci , Cache , cmdline ) ; }
APT_DEPRECATED_MSG ( " enum moved to CacheSetHelper::PkgModifier " ) typedef CacheSetHelper : : PkgModifier Modifier ;
APT_IGNORE_DEPRECATED_PUSH
APT_DEPRECATED_MSG ( " Use helper.PackageFromName instead " ) static pkgCache : : PkgIterator FromName ( pkgCacheFile & Cache , std : : string const & pattern , CacheSetHelper & helper ) {
return helper . PackageFromName ( Cache , pattern ) ; }
APT_DEPRECATED_MSG ( " Use helper.PackageFromModifierCommandLine instead " ) static bool FromModifierCommandLine ( unsigned short & modID , PackageContainerInterface * const pci ,
pkgCacheFile & Cache , const char * cmdline ,
std : : list < Modifier > const & mods , CacheSetHelper & helper ) {
return helper . PackageFromModifierCommandLine ( modID , pci , Cache , cmdline , mods ) ; }
APT_IGNORE_DEPRECATED_POP
private :
CacheSetHelper : : PkgSelector ConstructedBy ;
void * const d ;
} ;
/*}}}*/
template < class Container > class PackageContainer : public PackageContainerInterface { /*{{{*/
/** \class APT::PackageContainer
Simple wrapper around a container class like std : : set to provide a similar
interface to a set of packages as to the complete set of all packages in the
pkgCache . */
Container _cont ;
public : /*{{{*/
/** \brief smell like a pkgCache::PkgIterator */
typedef Container_const_iterator < PackageContainerInterface , Container , PackageContainer > const_iterator ;
typedef Container_iterator < PackageContainerInterface , Container , PackageContainer > iterator ;
typedef Container_const_reverse_iterator < PackageContainerInterface , Container , PackageContainer > const_reverse_iterator ;
typedef Container_reverse_iterator < PackageContainerInterface , Container , PackageContainer > reverse_iterator ;
typedef typename Container : : value_type value_type ;
typedef typename Container : : pointer pointer ;
typedef typename Container : : const_pointer const_pointer ;
typedef typename Container : : reference reference ;
typedef typename Container : : const_reference const_reference ;
typedef typename Container : : difference_type difference_type ;
typedef typename Container : : size_type size_type ;
typedef typename Container : : allocator_type allocator_type ;
bool insert ( pkgCache : : PkgIterator const & P ) APT_OVERRIDE { if ( P . end ( ) = = true ) return false ; _cont . insert ( P ) ; return true ; }
template < class Cont > void insert ( PackageContainer < Cont > const & pkgcont ) { _cont . insert ( ( typename Cont : : const_iterator ) pkgcont . begin ( ) , ( typename Cont : : const_iterator ) pkgcont . end ( ) ) ; }
void insert ( const_iterator begin , const_iterator end ) { _cont . insert ( begin , end ) ; }
bool empty ( ) const APT_OVERRIDE { return _cont . empty ( ) ; }
void clear ( ) APT_OVERRIDE { return _cont . clear ( ) ; }
size_t size ( ) const APT_OVERRIDE { return _cont . size ( ) ; }
# if __GNUC__ >= 5 || (__GNUC_MINOR__ >= 9 && __GNUC__ >= 4)
iterator erase ( const_iterator pos ) { return iterator ( _cont . erase ( pos . _iter ) ) ; }
iterator erase ( const_iterator first , const_iterator last ) { return iterator ( _cont . erase ( first . _iter , last . _iter ) ) ; }
# else
iterator erase ( iterator pos ) { return iterator ( _cont . erase ( pos . _iter ) ) ; }
iterator erase ( iterator first , iterator last ) { return iterator ( _cont . erase ( first . _iter , last . _iter ) ) ; }
# endif
const_iterator begin ( ) const { return const_iterator ( _cont . begin ( ) ) ; }
const_iterator end ( ) const { return const_iterator ( _cont . end ( ) ) ; }
const_reverse_iterator rbegin ( ) const { return const_reverse_iterator ( _cont . rbegin ( ) ) ; }
const_reverse_iterator rend ( ) const { return const_reverse_iterator ( _cont . rend ( ) ) ; }
# if __cplusplus >= 201103L
const_iterator cbegin ( ) const { return const_iterator ( _cont . cbegin ( ) ) ; }
const_iterator cend ( ) const { return const_iterator ( _cont . cend ( ) ) ; }
const_reverse_iterator crbegin ( ) const { return const_reverse_iterator ( _cont . crbegin ( ) ) ; }
const_reverse_iterator crend ( ) const { return const_reverse_iterator ( _cont . crend ( ) ) ; }
# endif
iterator begin ( ) { return iterator ( _cont . begin ( ) ) ; }
iterator end ( ) { return iterator ( _cont . end ( ) ) ; }
reverse_iterator rbegin ( ) { return reverse_iterator ( _cont . rbegin ( ) ) ; }
reverse_iterator rend ( ) { return reverse_iterator ( _cont . rend ( ) ) ; }
const_iterator find ( pkgCache : : PkgIterator const & P ) const { return const_iterator ( _cont . find ( P ) ) ; }
PackageContainer ( ) : PackageContainerInterface ( CacheSetHelper : : UNKNOWN ) { }
explicit PackageContainer ( CacheSetHelper : : PkgSelector const & by ) : PackageContainerInterface ( by ) { }
APT_IGNORE_DEPRECATED_PUSH
APT_DEPRECATED_MSG ( " Construct with a CacheSetHelper::PkgSelector instead " ) explicit PackageContainer ( Constructor const & by ) : PackageContainerInterface ( ( CacheSetHelper : : PkgSelector ) by ) { }
APT_IGNORE_DEPRECATED_POP
template < typename Itr > PackageContainer ( Itr first , Itr last ) : PackageContainerInterface ( CacheSetHelper : : UNKNOWN ) , _cont ( first , last ) { }
# if __cplusplus >= 201103L
PackageContainer ( std : : initializer_list < value_type > list ) : PackageContainerInterface ( CacheSetHelper : : UNKNOWN ) , _cont ( list ) { }
void push_back ( value_type & & P ) { _cont . emplace_back ( std : : move ( P ) ) ; }
template < typename . . . Args > void emplace_back ( Args & & . . . args ) { _cont . emplace_back ( std : : forward < Args > ( args ) . . . ) ; }
# endif
void push_back ( const value_type & P ) { _cont . push_back ( P ) ; }
/** \brief sort all included versions with given comparer
Some containers are sorted by default , some are not and can ' t be ,
but a few like std : : vector can be sorted if need be , so this can be
specialized in later on . The default is that this will fail though .
Specifically , already sorted containers like std : : set will return
false as well as there is no easy way to check that the given comparer
would sort in the same way the set is currently sorted
\ return \ b true if the set was sorted , \ b false if not . */
template < class Compare > bool sort ( Compare /*Comp*/ ) { return false ; }
/** \brief returns all packages in the cache who belong to the given task
A simple helper responsible for search for all members of a task
in the cache . Optional it prints a notice about the
packages chosen cause of the given task .
\ param Cache the packages are in
\ param pattern name of the task
\ param helper responsible for error and message handling */
static PackageContainer FromTask ( pkgCacheFile & Cache , std : : string const & pattern , CacheSetHelper & helper ) {
PackageContainer cont ( CacheSetHelper : : TASK ) ;
helper . PackageFrom ( CacheSetHelper : : TASK , & cont , Cache , pattern ) ;
return cont ;
}
static PackageContainer FromTask ( pkgCacheFile & Cache , std : : string const & pattern ) {
CacheSetHelper helper ;
return FromTask ( Cache , pattern , helper ) ;
}
/** \brief returns all packages in the cache whose name matchs a given pattern
A simple helper responsible for executing a regular expression on all
package names in the cache . Optional it prints a notice about the
packages chosen cause of the given package .
\ param Cache the packages are in
\ param pattern regular expression for package names
\ param helper responsible for error and message handling */
static PackageContainer FromRegEx ( pkgCacheFile & Cache , std : : string const & pattern , CacheSetHelper & helper ) {
PackageContainer cont ( CacheSetHelper : : REGEX ) ;
helper . PackageFrom ( CacheSetHelper : : REGEX , & cont , Cache , pattern ) ;
return cont ;
}
static PackageContainer FromRegEx ( pkgCacheFile & Cache , std : : string const & pattern ) {
CacheSetHelper helper ;
return FromRegEx ( Cache , pattern , helper ) ;
}
static PackageContainer FromFnmatch ( pkgCacheFile & Cache , std : : string const & pattern , CacheSetHelper & helper ) {
PackageContainer cont ( CacheSetHelper : : FNMATCH ) ;
helper . PackageFrom ( CacheSetHelper : : FNMATCH , & cont , Cache , pattern ) ;
return cont ;
}
static PackageContainer FromFnMatch ( pkgCacheFile & Cache , std : : string const & pattern ) {
CacheSetHelper helper ;
return FromFnmatch ( Cache , pattern , helper ) ;
}
APT_IGNORE_DEPRECATED_PUSH
/** \brief returns a package specified by a string
\ param Cache the package is in
\ param pattern String the package name should be extracted from
\ param helper responsible for error and message handling */
APT_DEPRECATED_MSG ( " Use helper.PackageFromName instead " ) static pkgCache : : PkgIterator FromName ( pkgCacheFile & Cache , std : : string const & pattern , CacheSetHelper & helper ) {
return helper . PackageFromName ( Cache , pattern ) ;
}
APT_DEPRECATED_MSG ( " Use helper.PackageFromName instead " ) static pkgCache : : PkgIterator FromName ( pkgCacheFile & Cache , std : : string const & pattern ) {
CacheSetHelper helper ;
return FromName ( Cache , pattern , helper ) ;
}
APT_IGNORE_DEPRECATED_POP
/** \brief returns all packages specified by a string
\ param Cache the packages are in
\ param pattern String the package name ( s ) should be extracted from
\ param helper responsible for error and message handling */
static PackageContainer FromString ( pkgCacheFile & Cache , std : : string const & pattern , CacheSetHelper & helper ) {
PackageContainer cont ;
helper . PackageFrom ( CacheSetHelper : : PACKAGENAME , & cont , Cache , pattern ) ;
return cont ;
}
static PackageContainer FromString ( pkgCacheFile & Cache , std : : string const & pattern ) {
CacheSetHelper helper ;
return FromString ( Cache , pattern , helper ) ;
}
/** \brief returns all packages specified on the commandline
Get all package names from the commandline and executes regex ' s if needed .
No special package command is supported , just plain names .
\ param Cache the packages are in
\ param cmdline Command line the package names should be extracted from
\ param helper responsible for error and message handling */
static PackageContainer FromCommandLine ( pkgCacheFile & Cache , const char * * cmdline , CacheSetHelper & helper ) {
PackageContainer cont ;
helper . PackageFromCommandLine ( & cont , Cache , cmdline ) ;
return cont ;
}
static PackageContainer FromCommandLine ( pkgCacheFile & Cache , const char * * cmdline ) {
CacheSetHelper helper ;
return FromCommandLine ( Cache , cmdline , helper ) ;