]>
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>
23 class PackageSet
: public std::set
<pkgCache::PkgIterator
> { /*{{{*/
24 /** \class APT::PackageSet
26 Simple wrapper around a std::set to provide a similar interface to
27 a set of packages as to the complete set of all packages in the
30 /** \brief smell like a pkgCache::PkgIterator */
31 class const_iterator
: public std::set
<pkgCache::PkgIterator
>::const_iterator
{/*{{{*/
33 const_iterator(std::set
<pkgCache::PkgIterator
>::const_iterator x
) :
34 std::set
<pkgCache::PkgIterator
>::const_iterator(x
) {}
36 operator pkgCache::PkgIterator(void) { return **this; }
38 inline const char *Name() const {return (**this).Name(); }
39 inline std::string
FullName(bool const &Pretty
) const { return (**this).FullName(Pretty
); }
40 inline std::string
FullName() const { return (**this).FullName(); }
41 inline const char *Section() const {return (**this).Section(); }
42 inline bool Purge() const {return (**this).Purge(); }
43 inline const char *Arch() const {return (**this).Arch(); }
44 inline pkgCache::GrpIterator
Group() const { return (**this).Group(); }
45 inline pkgCache::VerIterator
VersionList() const { return (**this).VersionList(); }
46 inline pkgCache::VerIterator
CurrentVer() const { return (**this).CurrentVer(); }
47 inline pkgCache::DepIterator
RevDependsList() const { return (**this).RevDependsList(); }
48 inline pkgCache::PrvIterator
ProvidesList() const { return (**this).ProvidesList(); }
49 inline pkgCache::PkgIterator::OkState
State() const { return (**this).State(); }
50 inline const char *CandVersion() const { return (**this).CandVersion(); }
51 inline const char *CurVersion() const { return (**this).CurVersion(); }
52 inline pkgCache
*Cache() const { return (**this).Cache(); };
53 inline unsigned long Index() const {return (**this).Index();};
54 // we have only valid iterators here
55 inline bool end() const { return false; };
57 friend std::ostream
& operator<<(std::ostream
& out
, const_iterator i
) { return operator<<(out
, (*i
)); }
59 inline pkgCache::Package
const * operator->() const {
63 // 103. set::iterator is required to be modifiable, but this allows modification of keys
64 typedef APT::PackageSet::const_iterator iterator
;
67 using std::set
<pkgCache::PkgIterator
>::insert
;
68 inline void insert(pkgCache::PkgIterator
const &P
) { if (P
.end() == false) std::set
<pkgCache::PkgIterator
>::insert(P
); };
70 /** \brief returns all packages in the cache who belong to the given task
72 A simple helper responsible for search for all members of a task
73 in the cache. Optional it prints a a notice about the
74 packages chosen cause of the given task.
75 \param Cache the packages are in
76 \param pattern name of the task
77 \param out stream to print the notice to */
78 static APT::PackageSet
FromTask(pkgCacheFile
&Cache
, std::string pattern
, std::ostream
&out
);
79 static APT::PackageSet
FromTask(pkgCacheFile
&Cache
, std::string
const &pattern
) {
80 std::ostream
out (std::ofstream("/dev/null").rdbuf());
81 return APT::PackageSet::FromTask(Cache
, pattern
, out
);
84 /** \brief returns all packages in the cache whose name matchs a given pattern
86 A simple helper responsible for executing a regular expression on all
87 package names in the cache. Optional it prints a a notice about the
88 packages chosen cause of the given package.
89 \param Cache the packages are in
90 \param pattern regular expression for package names
91 \param out stream to print the notice to */
92 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string pattern
, std::ostream
&out
);
93 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
94 std::ostream
out (std::ofstream("/dev/null").rdbuf());
95 return APT::PackageSet::FromRegEx(Cache
, pattern
, out
);
98 /** \brief returns all packages specified by a string
100 \param Cache the packages are in
101 \param string String the package name(s) should be extracted from
102 \param out stream to print various notices to */
103 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, std::string
const &string
, std::ostream
&out
);
104 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, std::string
const &string
) {
105 std::ostream
out (std::ofstream("/dev/null").rdbuf());
106 return APT::PackageSet::FromString(Cache
, string
, out
);
109 /** \brief returns all packages specified on the commandline
111 Get all package names from the commandline and executes regex's if needed.
112 No special package command is supported, just plain names.
113 \param Cache the packages are in
114 \param cmdline Command line the package names should be extracted from
115 \param out stream to print various notices to */
116 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, std::ostream
&out
);
117 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
118 std::ostream
out (std::ofstream("/dev/null").rdbuf());
119 return APT::PackageSet::FromCommandLine(Cache
, cmdline
, out
);
123 enum Position
{ NONE
, PREFIX
, POSTFIX
};
125 const char * const Alias
;
127 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
) : ID(id
), Alias(alias
), Pos(pos
) {};
130 static std::map
<unsigned short, PackageSet
> GroupedFromCommandLine(
131 pkgCacheFile
&Cache
, const char **cmdline
,
132 std::list
<PackageSet::Modifier
> const &mods
,
133 unsigned short const &fallback
, std::ostream
&out
);
134 static std::map
<unsigned short, PackageSet
> GroupedFromCommandLine(
135 pkgCacheFile
&Cache
, const char **cmdline
,
136 std::list
<PackageSet::Modifier
> const &mods
,
137 unsigned short const &fallback
) {
138 std::ostream
out (std::ofstream("/dev/null").rdbuf());
139 return APT::PackageSet::GroupedFromCommandLine(Cache
, cmdline
,
140 mods
, fallback
, out
);
144 class VersionSet
: public std::set
<pkgCache::VerIterator
> { /*{{{*/
145 /** \class APT::VersionSet
147 Simple wrapper around a std::set to provide a similar interface to
148 a set of versions as to the complete set of all versions in the
151 /** \brief smell like a pkgCache::VerIterator */
152 class const_iterator
: public std::set
<pkgCache::VerIterator
>::const_iterator
{/*{{{*/
154 const_iterator(std::set
<pkgCache::VerIterator
>::const_iterator x
) :
155 std::set
<pkgCache::VerIterator
>::const_iterator(x
) {}
157 operator pkgCache::VerIterator(void) { return **this; }
159 inline pkgCache
*Cache() const { return (**this).Cache(); };
160 inline unsigned long Index() const {return (**this).Index();};
161 // we have only valid iterators here
162 inline bool end() const { return false; };
164 inline pkgCache::Version
const * operator->() const {
168 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return (**this).CompareVer(B
); };
169 inline const char *VerStr() const { return (**this).VerStr(); };
170 inline const char *Section() const { return (**this).Section(); };
171 inline const char *Arch() const { return (**this).Arch(); };
172 inline const char *Arch(bool const pseudo
) const { return (**this).Arch(pseudo
); };
173 inline pkgCache::PkgIterator
ParentPkg() const { return (**this).ParentPkg(); };
174 inline pkgCache::DescIterator
DescriptionList() const { return (**this).DescriptionList(); };
175 inline pkgCache::DescIterator
TranslatedDescription() const { return (**this).TranslatedDescription(); };
176 inline pkgCache::DepIterator
DependsList() const { return (**this).DependsList(); };
177 inline pkgCache::PrvIterator
ProvidesList() const { return (**this).ProvidesList(); };
178 inline pkgCache::VerFileIterator
FileList() const { return (**this).FileList(); };
179 inline bool Downloadable() const { return (**this).Downloadable(); };
180 inline const char *PriorityType() const { return (**this).PriorityType(); };
181 inline string
RelStr() const { return (**this).RelStr(); };
182 inline bool Automatic() const { return (**this).Automatic(); };
183 inline bool Pseudo() const { return (**this).Pseudo(); };
184 inline pkgCache::VerFileIterator
NewestFile() const { return (**this).NewestFile(); };
187 // 103. set::iterator is required to be modifiable, but this allows modification of keys
188 typedef APT::VersionSet::const_iterator iterator
;
190 using std::set
<pkgCache::VerIterator
>::insert
;
191 inline void insert(pkgCache::VerIterator
const &V
) { if (V
.end() == false) std::set
<pkgCache::VerIterator
>::insert(V
); };
193 /** \brief specifies which version(s) will be returned if non is given */
197 /** Candidate and installed version */
199 /** Candidate version */
201 /** Installed version */
203 /** Candidate or if non installed version */
205 /** Installed or if non candidate version */
207 /** Newest version */
211 /** \brief returns all versions specified on the commandline
213 Get all versions from the commandline, uses given default version if
214 non specifically requested and executes regex's if needed on names.
215 \param Cache the packages and versions are in
216 \param cmdline Command line the versions should be extracted from
217 \param out stream to print various notices to */
218 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
219 APT::VersionSet::Version
const &fallback
, std::ostream
&out
);
220 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
221 APT::VersionSet::Version
const &fallback
) {
222 std::ostream
out (std::ofstream("/dev/null").rdbuf());
223 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, fallback
, out
);
225 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
226 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, CANDINST
);
229 static APT::VersionSet
FromString(pkgCacheFile
&Cache
, std::string pkg
,
230 APT::VersionSet::Version
const &fallback
, std::ostream
&out
);
231 static APT::VersionSet
FromString(pkgCacheFile
&Cache
, std::string pkg
,
232 APT::VersionSet::Version
const &fallback
) {
233 std::ostream
out (std::ofstream("/dev/null").rdbuf());
234 return APT::VersionSet::FromString(Cache
, pkg
, fallback
, out
);
236 static APT::VersionSet
FromString(pkgCacheFile
&Cache
, std::string pkg
) {
237 return APT::VersionSet::FromString(Cache
, pkg
, CANDINST
);
241 enum Position
{ NONE
, PREFIX
, POSTFIX
};
243 const char * const Alias
;
245 VersionSet::Version SelectVersion
;
246 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
,
247 VersionSet::Version
const &select
) : ID(id
), Alias(alias
), Pos(pos
),
248 SelectVersion(select
) {};
251 static std::map
<unsigned short, VersionSet
> GroupedFromCommandLine(
252 pkgCacheFile
&Cache
, const char **cmdline
,
253 std::list
<VersionSet::Modifier
> const &mods
,
254 unsigned short const &fallback
, std::ostream
&out
);
255 static std::map
<unsigned short, VersionSet
> GroupedFromCommandLine(
256 pkgCacheFile
&Cache
, const char **cmdline
,
257 std::list
<VersionSet::Modifier
> const &mods
,
258 unsigned short const &fallback
) {
259 std::ostream
out (std::ofstream("/dev/null").rdbuf());
260 return APT::VersionSet::GroupedFromCommandLine(Cache
, cmdline
,
261 mods
, fallback
, out
);
266 /** \brief returns the candidate version of the package
268 \param Cache to be used to query for information
269 \param Pkg we want the candidate version from this package
270 \param AllowError add an error to the stack if not */
271 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
272 pkgCache::PkgIterator
const &Pkg
, bool const &AllowError
= false);
274 /** \brief returns the installed version of the package
276 \param Cache to be used to query for information
277 \param Pkg we want the installed version from this package
278 \param AllowError add an error to the stack if not */
279 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
280 pkgCache::PkgIterator
const &Pkg
, bool const &AllowError
= false);
283 static bool AddSelectedVersion(pkgCacheFile
&Cache
, VersionSet
&verset
,
284 pkgCache::PkgIterator
const &P
, VersionSet::Version
const &fallback
,
285 bool const &AllowError
= false);