]>
git.saurik.com Git - apt.git/blob - cmdline/cacheset.h
21c42c51109bdc5c2e7078158afc31bf57749870
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 pkgCache::PkgIterator
canNotFindPkgName(pkgCacheFile
&Cache
, std::string
const &str
);
44 virtual PackageSet
canNotFindTask(pkgCacheFile
&Cache
, std::string pattern
);
45 virtual PackageSet
canNotFindRegEx(pkgCacheFile
&Cache
, std::string pattern
);
46 virtual PackageSet
canNotFindPackage(pkgCacheFile
&Cache
, std::string
const &str
);
47 virtual VersionSet
canNotFindAllVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
);
48 virtual VersionSet
canNotFindInstCandVer(pkgCacheFile
&Cache
,
49 pkgCache::PkgIterator
const &Pkg
);
50 virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
,
51 pkgCache::PkgIterator
const &Pkg
);
52 virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
,
53 pkgCache::PkgIterator
const &Pkg
);
54 virtual pkgCache::VerIterator
canNotFindInstalledVer(pkgCacheFile
&Cache
,
55 pkgCache::PkgIterator
const &Pkg
);
57 bool showErrors() const { return ShowError
; };
58 bool showErrors(bool const &newValue
) { if (ShowError
== newValue
) return ShowError
; else return ((ShowError
= newValue
) == false); };
63 class PackageSet
: public std::set
<pkgCache::PkgIterator
> { /*{{{*/
64 /** \class APT::PackageSet
66 Simple wrapper around a std::set to provide a similar interface to
67 a set of packages as to the complete set of all packages in the
70 /** \brief smell like a pkgCache::PkgIterator */
71 class const_iterator
: public std::set
<pkgCache::PkgIterator
>::const_iterator
{/*{{{*/
73 const_iterator(std::set
<pkgCache::PkgIterator
>::const_iterator x
) :
74 std::set
<pkgCache::PkgIterator
>::const_iterator(x
) {}
76 operator pkgCache::PkgIterator(void) { return **this; }
78 inline const char *Name() const {return (**this).Name(); }
79 inline std::string
FullName(bool const &Pretty
) const { return (**this).FullName(Pretty
); }
80 inline std::string
FullName() const { return (**this).FullName(); }
81 inline const char *Section() const {return (**this).Section(); }
82 inline bool Purge() const {return (**this).Purge(); }
83 inline const char *Arch() const {return (**this).Arch(); }
84 inline pkgCache::GrpIterator
Group() const { return (**this).Group(); }
85 inline pkgCache::VerIterator
VersionList() const { return (**this).VersionList(); }
86 inline pkgCache::VerIterator
CurrentVer() const { return (**this).CurrentVer(); }
87 inline pkgCache::DepIterator
RevDependsList() const { return (**this).RevDependsList(); }
88 inline pkgCache::PrvIterator
ProvidesList() const { return (**this).ProvidesList(); }
89 inline pkgCache::PkgIterator::OkState
State() const { return (**this).State(); }
90 inline const char *CandVersion() const { return (**this).CandVersion(); }
91 inline const char *CurVersion() const { return (**this).CurVersion(); }
92 inline pkgCache
*Cache() const { return (**this).Cache(); };
93 inline unsigned long Index() const {return (**this).Index();};
94 // we have only valid iterators here
95 inline bool end() const { return false; };
97 friend std::ostream
& operator<<(std::ostream
& out
, const_iterator i
) { return operator<<(out
, (*i
)); }
99 inline pkgCache::Package
const * operator->() const {
103 // 103. set::iterator is required to be modifiable, but this allows modification of keys
104 typedef APT::PackageSet::const_iterator iterator
;
107 using std::set
<pkgCache::PkgIterator
>::insert
;
108 inline void insert(pkgCache::PkgIterator
const &P
) { if (P
.end() == false) std::set
<pkgCache::PkgIterator
>::insert(P
); };
109 inline void insert(PackageSet
const &pkgset
) { insert(pkgset
.begin(), pkgset
.end()); };
111 /** \brief returns all packages in the cache who belong to the given task
113 A simple helper responsible for search for all members of a task
114 in the cache. Optional it prints a a notice about the
115 packages chosen cause of the given task.
116 \param Cache the packages are in
117 \param pattern name of the task
118 \param out stream to print the notice to */
119 static APT::PackageSet
FromTask(pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
120 static APT::PackageSet
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
) {
121 CacheSetHelper helper
;
122 return APT::PackageSet::FromTask(Cache
, pattern
, helper
);
125 /** \brief returns all packages in the cache whose name matchs a given pattern
127 A simple helper responsible for executing a regular expression on all
128 package names in the cache. Optional it prints a a notice about the
129 packages chosen cause of the given package.
130 \param Cache the packages are in
131 \param pattern regular expression for package names
132 \param out stream to print the notice to */
133 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string pattern
, CacheSetHelper
&helper
);
134 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
135 CacheSetHelper helper
;
136 return APT::PackageSet::FromRegEx(Cache
, pattern
, helper
);
139 /** \brief returns all packages specified by a string
141 \param Cache the packages are in
142 \param string String the package name(s) should be extracted from
143 \param out stream to print various notices to */
144 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, std::string
const &string
, CacheSetHelper
&helper
);
145 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, std::string
const &string
) {
146 CacheSetHelper helper
;
147 return APT::PackageSet::FromString(Cache
, string
, helper
);
150 /** \brief returns a package specified by a string
152 \param Cache the package is in
153 \param string String the package name should be extracted from
154 \param out stream to print various notices to */
155 static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &string
, CacheSetHelper
&helper
);
156 static pkgCache::PkgIterator
FromName(pkgCacheFile
&Cache
, std::string
const &string
) {
157 CacheSetHelper helper
;
158 return APT::PackageSet::FromName(Cache
, string
, helper
);
161 /** \brief returns all packages specified on the commandline
163 Get all package names from the commandline and executes regex's if needed.
164 No special package command is supported, just plain names.
165 \param Cache the packages are in
166 \param cmdline Command line the package names should be extracted from
167 \param out stream to print various notices to */
168 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, CacheSetHelper
&helper
);
169 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
170 CacheSetHelper helper
;
171 return APT::PackageSet::FromCommandLine(Cache
, cmdline
, helper
);
175 enum Position
{ NONE
, PREFIX
, POSTFIX
};
177 const char * const Alias
;
179 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
) : ID(id
), Alias(alias
), Pos(pos
) {};
182 static std::map
<unsigned short, PackageSet
> GroupedFromCommandLine(
183 pkgCacheFile
&Cache
, const char **cmdline
,
184 std::list
<PackageSet::Modifier
> const &mods
,
185 unsigned short const &fallback
, CacheSetHelper
&helper
);
186 static std::map
<unsigned short, PackageSet
> GroupedFromCommandLine(
187 pkgCacheFile
&Cache
, const char **cmdline
,
188 std::list
<PackageSet::Modifier
> const &mods
,
189 unsigned short const &fallback
) {
190 CacheSetHelper helper
;
191 return APT::PackageSet::GroupedFromCommandLine(Cache
, cmdline
,
192 mods
, fallback
, helper
);
196 class VersionSet
: public std::set
<pkgCache::VerIterator
> { /*{{{*/
197 /** \class APT::VersionSet
199 Simple wrapper around a std::set to provide a similar interface to
200 a set of versions as to the complete set of all versions in the
203 /** \brief smell like a pkgCache::VerIterator */
204 class const_iterator
: public std::set
<pkgCache::VerIterator
>::const_iterator
{/*{{{*/
206 const_iterator(std::set
<pkgCache::VerIterator
>::const_iterator x
) :
207 std::set
<pkgCache::VerIterator
>::const_iterator(x
) {}
209 operator pkgCache::VerIterator(void) { return **this; }
211 inline pkgCache
*Cache() const { return (**this).Cache(); };
212 inline unsigned long Index() const {return (**this).Index();};
213 // we have only valid iterators here
214 inline bool end() const { return false; };
216 inline pkgCache::Version
const * operator->() const {
220 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return (**this).CompareVer(B
); };
221 inline const char *VerStr() const { return (**this).VerStr(); };
222 inline const char *Section() const { return (**this).Section(); };
223 inline const char *Arch() const { return (**this).Arch(); };
224 inline const char *Arch(bool const pseudo
) const { return (**this).Arch(pseudo
); };
225 inline pkgCache::PkgIterator
ParentPkg() const { return (**this).ParentPkg(); };
226 inline pkgCache::DescIterator
DescriptionList() const { return (**this).DescriptionList(); };
227 inline pkgCache::DescIterator
TranslatedDescription() const { return (**this).TranslatedDescription(); };
228 inline pkgCache::DepIterator
DependsList() const { return (**this).DependsList(); };
229 inline pkgCache::PrvIterator
ProvidesList() const { return (**this).ProvidesList(); };
230 inline pkgCache::VerFileIterator
FileList() const { return (**this).FileList(); };
231 inline bool Downloadable() const { return (**this).Downloadable(); };
232 inline const char *PriorityType() const { return (**this).PriorityType(); };
233 inline string
RelStr() const { return (**this).RelStr(); };
234 inline bool Automatic() const { return (**this).Automatic(); };
235 inline bool Pseudo() const { return (**this).Pseudo(); };
236 inline pkgCache::VerFileIterator
NewestFile() const { return (**this).NewestFile(); };
239 // 103. set::iterator is required to be modifiable, but this allows modification of keys
240 typedef APT::VersionSet::const_iterator iterator
;
242 using std::set
<pkgCache::VerIterator
>::insert
;
243 inline void insert(pkgCache::VerIterator
const &V
) { if (V
.end() == false) std::set
<pkgCache::VerIterator
>::insert(V
); };
244 inline void insert(VersionSet
const &verset
) { insert(verset
.begin(), verset
.end()); };
246 /** \brief specifies which version(s) will be returned if non is given */
250 /** Candidate and installed version */
252 /** Candidate version */
254 /** Installed version */
256 /** Candidate or if non installed version */
258 /** Installed or if non candidate version */
260 /** Newest version */
264 /** \brief returns all versions specified on the commandline
266 Get all versions from the commandline, uses given default version if
267 non specifically requested and executes regex's if needed on names.
268 \param Cache the packages and versions are in
269 \param cmdline Command line the versions should be extracted from
270 \param out stream to print various notices to */
271 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
272 APT::VersionSet::Version
const &fallback
, CacheSetHelper
&helper
);
273 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
274 APT::VersionSet::Version
const &fallback
) {
275 CacheSetHelper helper
;
276 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, fallback
, helper
);
278 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
279 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, CANDINST
);
282 static APT::VersionSet
FromString(pkgCacheFile
&Cache
, std::string pkg
,
283 APT::VersionSet::Version
const &fallback
, CacheSetHelper
&helper
,
284 bool const &onlyFromName
= false);
285 static APT::VersionSet
FromString(pkgCacheFile
&Cache
, std::string pkg
,
286 APT::VersionSet::Version
const &fallback
) {
287 CacheSetHelper helper
;
288 return APT::VersionSet::FromString(Cache
, pkg
, fallback
, helper
);
290 static APT::VersionSet
FromString(pkgCacheFile
&Cache
, std::string pkg
) {
291 return APT::VersionSet::FromString(Cache
, pkg
, CANDINST
);
295 enum Position
{ NONE
, PREFIX
, POSTFIX
};
297 const char * const Alias
;
299 VersionSet::Version SelectVersion
;
300 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
,
301 VersionSet::Version
const &select
) : ID(id
), Alias(alias
), Pos(pos
),
302 SelectVersion(select
) {};
305 static std::map
<unsigned short, VersionSet
> GroupedFromCommandLine(
306 pkgCacheFile
&Cache
, const char **cmdline
,
307 std::list
<VersionSet::Modifier
> const &mods
,
308 unsigned short const &fallback
, CacheSetHelper
&helper
);
309 static std::map
<unsigned short, VersionSet
> GroupedFromCommandLine(
310 pkgCacheFile
&Cache
, const char **cmdline
,
311 std::list
<VersionSet::Modifier
> const &mods
,
312 unsigned short const &fallback
) {
313 CacheSetHelper helper
;
314 return APT::VersionSet::GroupedFromCommandLine(Cache
, cmdline
,
315 mods
, fallback
, helper
);
320 /** \brief returns the candidate version of the package
322 \param Cache to be used to query for information
323 \param Pkg we want the candidate version from this package */
324 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
325 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
327 /** \brief returns the installed version of the package
329 \param Cache to be used to query for information
330 \param Pkg we want the installed version from this package */
331 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
332 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
);
334 static void AddSelectedVersion(pkgCacheFile
&Cache
, VersionSet
&verset
,
335 pkgCache::PkgIterator
const &P
, VersionSet::Version
const &fallback
,
336 CacheSetHelper
&helper
);