]>
git.saurik.com Git - apt.git/blob - cmdline/cacheset.h
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 /*{{{*/
19 #include <apt-pkg/cachefile.h>
20 #include <apt-pkg/pkgcache.h>
25 class CacheSetHelper
{ /*{{{*/
26 /** \class APT::CacheSetHelper
27 Simple base class with a lot of virtual methods which can be overridden
28 to alter the behavior or the output of the CacheSets.
30 This helper is passed around by the static methods in the CacheSets and
31 used every time they hit an error condition or something could be
35 CacheSetHelper(bool const &ShowError
= true) : ShowError(ShowError
) {};
36 virtual ~CacheSetHelper() {};
38 virtual void showTaskSelection(PackageSet
const &pkgset
, string
const &pattern
) {};
39 virtual void showRegExSelection(PackageSet
const &pkgset
, string
const &pattern
) {};
40 virtual void showSelectedVersion(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const Ver
,
41 string
const &ver
, bool const &verIsRel
) {};
43 virtual PackageSet
canNotFindTask(pkgCacheFile
&Cache
, std::string pattern
);
44 virtual PackageSet
canNotFindRegEx(pkgCacheFile
&Cache
, std::string pattern
);
45 virtual PackageSet
canNotFindPackage(pkgCacheFile
&Cache
, std::string
const &str
);
46 virtual VersionSet
canNotFindAllVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
);
47 virtual VersionSet
canNotFindInstCandVer(pkgCacheFile
&Cache
,
48 pkgCache::PkgIterator
const &Pkg
);
49 virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
,
50 pkgCache::PkgIterator
const &Pkg
);
51 virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
,
52 pkgCache::PkgIterator
const &Pkg
);
53 virtual pkgCache::VerIterator
canNotFindInstalledVer(pkgCacheFile
&Cache
,
54 pkgCache::PkgIterator
const &Pkg
);
56 bool showErrors() const { return ShowError
; };
57 bool showErrors(bool const &newValue
) { if (ShowError
== newValue
) return ShowError
; else return ((ShowError
= newValue
) == false); };
62 class PackageSet
: public std::set
<pkgCache::PkgIterator
> { /*{{{*/
63 /** \class APT::PackageSet
65 Simple wrapper around a std::set to provide a similar interface to
66 a set of packages as to the complete set of all packages in the
69 /** \brief smell like a pkgCache::PkgIterator */
70 class const_iterator
: public std::set
<pkgCache::PkgIterator
>::const_iterator
{/*{{{*/
72 const_iterator(std::set
<pkgCache::PkgIterator
>::const_iterator x
) :
73 std::set
<pkgCache::PkgIterator
>::const_iterator(x
) {}
75 operator pkgCache::PkgIterator(void) { return **this; }
77 inline const char *Name() const {return (**this).Name(); }
78 inline std::string
FullName(bool const &Pretty
) const { return (**this).FullName(Pretty
); }
79 inline std::string
FullName() const { return (**this).FullName(); }
80 inline const char *Section() const {return (**this).Section(); }
81 inline bool Purge() const {return (**this).Purge(); }
82 inline const char *Arch() const {return (**this).Arch(); }
83 inline pkgCache::GrpIterator
Group() const { return (**this).Group(); }
84 inline pkgCache::VerIterator
VersionList() const { return (**this).VersionList(); }
85 inline pkgCache::VerIterator
CurrentVer() const { return (**this).CurrentVer(); }
86 inline pkgCache::DepIterator
RevDependsList() const { return (**this).RevDependsList(); }
87 inline pkgCache::PrvIterator
ProvidesList() const { return (**this).ProvidesList(); }
88 inline pkgCache::PkgIterator::OkState
State() const { return (**this).State(); }
89 inline const char *CandVersion() const { return (**this).CandVersion(); }
90 inline const char *CurVersion() const { return (**this).CurVersion(); }
91 inline pkgCache
*Cache() const { return (**this).Cache(); };
92 inline unsigned long Index() const {return (**this).Index();};
93 // we have only valid iterators here
94 inline bool end() const { return false; };
96 friend std::ostream
& operator<<(std::ostream
& out
, const_iterator i
) { return operator<<(out
, (*i
)); }
98 inline pkgCache::Package
const * operator->() const {
102 // 103. set::iterator is required to be modifiable, but this allows modification of keys
103 typedef APT::PackageSet::const_iterator iterator
;
106 using std::set
<pkgCache::PkgIterator
>::insert
;
107 inline void insert(pkgCache::PkgIterator
const &P
) { if (P
.end() == false) std::set
<pkgCache::PkgIterator
>::insert(P
); };
108 inline void insert(PackageSet
const &pkgset
) { insert(pkgset
.begin(), pkgset
.end()); };
110 /** \brief returns all packages in the cache who belong to the given task
112 A simple helper responsible for search for all members of a task
113 in the cache. Optional it prints a a notice about the
114 packages chosen cause of the given task.
115 \param Cache the packages are in
116 \param pattern name of the task
117 \param out stream to print the notice to */
118 static APT::PackageSet
FromTask(pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
119 static APT::PackageSet
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
) {
120 CacheSetHelper helper
;
121 return APT::PackageSet::FromTask(Cache
, pattern
, helper
);
124 /** \brief returns all packages in the cache whose name matchs a given pattern
126 A simple helper responsible for executing a regular expression on all
127 package names in the cache. Optional it prints a a notice about the
128 packages chosen cause of the given package.
129 \param Cache the packages are in
130 \param pattern regular expression for package names
131 \param out stream to print the notice to */
132 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
133 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
134 CacheSetHelper helper
;
135 return APT::PackageSet::FromRegEx(Cache
, pattern
, helper
);
138 /** \brief returns all packages specified by a string
140 \param Cache the packages are in
141 \param string String the package name(s) should be extracted from
142 \param out stream to print various notices to */
143 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, std::string
const &string
, CacheSetHelper
&helper
);
144 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, std::string
const &string
) {
145 CacheSetHelper helper
;
146 return APT::PackageSet::FromString(Cache
, string
, helper
);
149 /** \brief returns all packages specified on the commandline
151 Get all package names from the commandline and executes regex's if needed.
152 No special package command is supported, just plain names.
153 \param Cache the packages are in
154 \param cmdline Command line the package names should be extracted from
155 \param out stream to print various notices to */
156 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
);
157 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
158 CacheSetHelper helper
;
159 return APT::PackageSet::FromCommandLine(Cache
, cmdline
, helper
);
163 enum Position
{ NONE
, PREFIX
, POSTFIX
};
165 const char * const Alias
;
167 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
) : ID(id
), Alias(alias
), Pos(pos
) {};
170 static std::map
<unsigned short, PackageSet
> GroupedFromCommandLine(
171 pkgCacheFile
&Cache
, const char **cmdline
,
172 std::list
<PackageSet::Modifier
> const &mods
,
173 unsigned short const &fallback
, CacheSetHelper
&helper
);
174 static std::map
<unsigned short, PackageSet
> GroupedFromCommandLine(
175 pkgCacheFile
&Cache
, const char **cmdline
,
176 std::list
<PackageSet::Modifier
> const &mods
,
177 unsigned short const &fallback
) {
178 CacheSetHelper helper
;
179 return APT::PackageSet::GroupedFromCommandLine(Cache
, cmdline
,
180 mods
, fallback
, helper
);
184 class VersionSet
: public std::set
<pkgCache::VerIterator
> { /*{{{*/
185 /** \class APT::VersionSet
187 Simple wrapper around a std::set to provide a similar interface to
188 a set of versions as to the complete set of all versions in the
191 /** \brief smell like a pkgCache::VerIterator */
192 class const_iterator
: public std::set
<pkgCache::VerIterator
>::const_iterator
{/*{{{*/
194 const_iterator(std::set
<pkgCache::VerIterator
>::const_iterator x
) :
195 std::set
<pkgCache::VerIterator
>::const_iterator(x
) {}
197 operator pkgCache::VerIterator(void) { return **this; }
199 inline pkgCache
*Cache() const { return (**this).Cache(); };
200 inline unsigned long Index() const {return (**this).Index();};
201 // we have only valid iterators here
202 inline bool end() const { return false; };
204 inline pkgCache::Version
const * operator->() const {
208 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return (**this).CompareVer(B
); };
209 inline const char *VerStr() const { return (**this).VerStr(); };
210 inline const char *Section() const { return (**this).Section(); };
211 inline const char *Arch() const { return (**this).Arch(); };
212 inline const char *Arch(bool const pseudo
) const { return (**this).Arch(pseudo
); };
213 inline pkgCache::PkgIterator
ParentPkg() const { return (**this).ParentPkg(); };
214 inline pkgCache::DescIterator
DescriptionList() const { return (**this).DescriptionList(); };
215 inline pkgCache::DescIterator
TranslatedDescription() const { return (**this).TranslatedDescription(); };
216 inline pkgCache::DepIterator
DependsList() const { return (**this).DependsList(); };
217 inline pkgCache::PrvIterator
ProvidesList() const { return (**this).ProvidesList(); };
218 inline pkgCache::VerFileIterator
FileList() const { return (**this).FileList(); };
219 inline bool Downloadable() const { return (**this).Downloadable(); };
220 inline const char *PriorityType() const { return (**this).PriorityType(); };
221 inline string
RelStr() const { return (**this).RelStr(); };
222 inline bool Automatic() const { return (**this).Automatic(); };
223 inline bool Pseudo() const { return (**this).Pseudo(); };
224 inline pkgCache::VerFileIterator
NewestFile() const { return (**this).NewestFile(); };
227 // 103. set::iterator is required to be modifiable, but this allows modification of keys
228 typedef APT::VersionSet::const_iterator iterator
;
230 using std::set
<pkgCache::VerIterator
>::insert
;
231 inline void insert(pkgCache::VerIterator
const &V
) { if (V
.end() == false) std::set
<pkgCache::VerIterator
>::insert(V
); };
232 inline void insert(VersionSet
const &verset
) { insert(verset
.begin(), verset
.end()); };
234 /** \brief specifies which version(s) will be returned if non is given */
238 /** Candidate and installed version */
240 /** Candidate version */
242 /** Installed version */
244 /** Candidate or if non installed version */
246 /** Installed or if non candidate version */
248 /** Newest version */
252 /** \brief returns all versions specified on the commandline
254 Get all versions from the commandline, uses given default version if
255 non specifically requested and executes regex's if needed on names.
256 \param Cache the packages and versions are in
257 \param cmdline Command line the versions should be extracted from
258 \param out stream to print various notices to */
259 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
260 APT::VersionSet::Version
const &fallback
, CacheSetHelper
&helper
);
261 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
262 APT::VersionSet::Version
const &fallback
) {
263 CacheSetHelper helper
;
264 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, fallback
, helper
);
266 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
267 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, CANDINST
);
270 static APT::VersionSet
FromString(pkgCacheFile
&Cache
, std::string pkg
,
271 APT::VersionSet::Version
const &fallback
, CacheSetHelper
&helper
);
272 static APT::VersionSet
FromString(pkgCacheFile
&Cache
, std::string pkg
,
273 APT::VersionSet::Version
const &fallback
) {
274 CacheSetHelper helper
;
275 return APT::VersionSet::FromString(Cache
, pkg
, fallback
, helper
);
277 static APT::VersionSet
FromString(pkgCacheFile
&Cache
, std::string pkg
) {
278 return APT::VersionSet::FromString(Cache
, pkg
, CANDINST
);
282 enum Position
{ NONE
, PREFIX
, POSTFIX
};
284 const char * const Alias
;
286 VersionSet::Version SelectVersion
;
287 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
,
288 VersionSet::Version
const &select
) : ID(id
), Alias(alias
), Pos(pos
),
289 SelectVersion(select
) {};
292 static std::map
<unsigned short, VersionSet
> GroupedFromCommandLine(
293 pkgCacheFile
&Cache
, const char **cmdline
,
294 std::list
<VersionSet::Modifier
> const &mods
,
295 unsigned short const &fallback
, CacheSetHelper
&helper
);
296 static std::map
<unsigned short, VersionSet
> GroupedFromCommandLine(
297 pkgCacheFile
&Cache
, const char **cmdline
,
298 std::list
<VersionSet::Modifier
> const &mods
,
299 unsigned short const &fallback
) {
300 CacheSetHelper helper
;
301 return APT::VersionSet::GroupedFromCommandLine(Cache
, cmdline
,
302 mods
, fallback
, helper
);
307 /** \brief returns the candidate version of the package
309 \param Cache to be used to query for information
310 \param Pkg we want the candidate version from this package */
311 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
312 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
314 /** \brief returns the installed version of the package
316 \param Cache to be used to query for information
317 \param Pkg we want the installed version from this package */
318 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
319 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
321 static void AddSelectedVersion(pkgCacheFile
&Cache
, VersionSet
&verset
,
322 pkgCache::PkgIterator
const &P
, VersionSet::Version
const &fallback
,
323 CacheSetHelper
&helper
);