]>
git.saurik.com Git - apt.git/blob - apt-pkg/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
;
66 using std::set
<pkgCache::PkgIterator
>::insert
;
67 inline void insert(pkgCache::PkgIterator
const &P
) { if (P
.end() == false) std::set
<pkgCache::PkgIterator
>::insert(P
); };
69 /** \brief returns all packages in the cache whose name matchs a given pattern
71 A simple helper responsible for executing a regular expression on all
72 package names in the cache. Optional it prints a a notice about the
73 packages chosen cause of the given package.
74 \param Cache the packages are in
75 \param pattern regular expression for package names
76 \param out stream to print the notice to */
77 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string pattern
, std::ostream
&out
);
78 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
79 std::ostream
out (std::ofstream("/dev/null").rdbuf());
80 return APT::PackageSet::FromRegEx(Cache
, pattern
, out
);
83 /** \brief returns all packages specified by a string
85 \param Cache the packages are in
86 \param string String the package name(s) should be extracted from
87 \param out stream to print various notices to */
88 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, std::string
const &string
, std::ostream
&out
);
89 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, std::string
const &string
) {
90 std::ostream
out (std::ofstream("/dev/null").rdbuf());
91 return APT::PackageSet::FromString(Cache
, string
, out
);
94 /** \brief returns all packages specified on the commandline
96 Get all package names from the commandline and executes regex's if needed.
97 No special package command is supported, just plain names.
98 \param Cache the packages are in
99 \param cmdline Command line the package names should be extracted from
100 \param out stream to print various notices to */
101 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, std::ostream
&out
);
102 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
103 std::ostream
out (std::ofstream("/dev/null").rdbuf());
104 return APT::PackageSet::FromCommandLine(Cache
, cmdline
, out
);
108 enum Position
{ NONE
, PREFIX
, POSTFIX
};
110 const char * const Alias
;
112 Modifier (unsigned short const &id
, const char * const alias
, Position
const &pos
) : ID(id
), Alias(alias
), Pos(pos
) {};
115 static std::map
<unsigned short, PackageSet
> GroupedFromCommandLine(
116 pkgCacheFile
&Cache
, const char **cmdline
,
117 std::list
<PackageSet::Modifier
> const &mods
,
118 unsigned short const &fallback
, std::ostream
&out
);
119 static std::map
<unsigned short, PackageSet
> GroupedFromCommandLine(
120 pkgCacheFile
&Cache
, const char **cmdline
,
121 std::list
<PackageSet::Modifier
> const &mods
,
122 unsigned short const &fallback
) {
123 std::ostream
out (std::ofstream("/dev/null").rdbuf());
124 return APT::PackageSet::GroupedFromCommandLine(Cache
, cmdline
,
125 mods
, fallback
, out
);
129 class VersionSet
: public std::set
<pkgCache::VerIterator
> { /*{{{*/
130 /** \class APT::VersionSet
132 Simple wrapper around a std::set to provide a similar interface to
133 a set of versions as to the complete set of all versions in the
136 /** \brief smell like a pkgCache::VerIterator */
137 class const_iterator
: public std::set
<pkgCache::VerIterator
>::const_iterator
{
139 const_iterator(std::set
<pkgCache::VerIterator
>::const_iterator x
) :
140 std::set
<pkgCache::VerIterator
>::const_iterator(x
) {}
142 operator pkgCache::VerIterator(void) { return **this; }
144 inline pkgCache
*Cache() const { return (**this).Cache(); };
145 inline unsigned long Index() const {return (**this).Index();};
146 // we have only valid iterators here
147 inline bool end() const { return false; };
149 inline pkgCache::Version
const * operator->() const {
153 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return (**this).CompareVer(B
); };
154 inline const char *VerStr() const { return (**this).VerStr(); };
155 inline const char *Section() const { return (**this).Section(); };
156 inline const char *Arch() const { return (**this).Arch(); };
157 inline const char *Arch(bool const pseudo
) const { return (**this).Arch(pseudo
); };
158 inline pkgCache::PkgIterator
ParentPkg() const { return (**this).ParentPkg(); };
159 inline pkgCache::DescIterator
DescriptionList() const { return (**this).DescriptionList(); };
160 inline pkgCache::DescIterator
TranslatedDescription() const { return (**this).TranslatedDescription(); };
161 inline pkgCache::DepIterator
DependsList() const { return (**this).DependsList(); };
162 inline pkgCache::PrvIterator
ProvidesList() const { return (**this).ProvidesList(); };
163 inline pkgCache::VerFileIterator
FileList() const { return (**this).FileList(); };
164 inline bool Downloadable() const { return (**this).Downloadable(); };
165 inline const char *PriorityType() const { return (**this).PriorityType(); };
166 inline string
RelStr() const { return (**this).RelStr(); };
167 inline bool Automatic() const { return (**this).Automatic(); };
168 inline bool Pseudo() const { return (**this).Pseudo(); };
169 inline pkgCache::VerFileIterator
NewestFile() const { return (**this).NewestFile(); };
171 // 103. set::iterator is required to be modifiable, but this allows modification of keys
172 typedef APT::VersionSet::const_iterator iterator
;
174 using std::set
<pkgCache::VerIterator
>::insert
;
175 inline void insert(pkgCache::VerIterator
const &V
) { if (V
.end() == false) std::set
<pkgCache::VerIterator
>::insert(V
); };
177 /** \brief specifies which version(s) will be returned if non is given */
181 /** Candidate and installed version */
183 /** Candidate version */
185 /** Installed version */
187 /** Candidate or if non installed version */
189 /** Installed or if non candidate version */
191 /** Newest version */
195 /** \brief returns all versions specified on the commandline
197 Get all versions from the commandline, uses given default version if
198 non specifically requested and executes regex's if needed on names.
199 \param Cache the packages and versions are in
200 \param cmdline Command line the versions should be extracted from
201 \param out stream to print various notices to */
202 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
203 APT::VersionSet::Version
const &fallback
, std::ostream
&out
);
204 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
205 APT::VersionSet::Version
const &fallback
) {
206 std::ostream
out (std::ofstream("/dev/null").rdbuf());
207 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, fallback
, out
);
209 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
210 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, CANDINST
);
215 /** \brief returns the candidate version of the package
217 \param Cache to be used to query for information
218 \param Pkg we want the candidate version from this package
219 \param AllowError add an error to the stack if not */
220 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
221 pkgCache::PkgIterator
const &Pkg
, bool const &AllowError
= false);
223 /** \brief returns the installed version of the package
225 \param Cache to be used to query for information
226 \param Pkg we want the installed version from this package
227 \param AllowError add an error to the stack if not */
228 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
229 pkgCache::PkgIterator
const &Pkg
, bool const &AllowError
= false);
232 static bool AddSelectedVersion(pkgCacheFile
&Cache
, VersionSet
&verset
,
233 pkgCache::PkgIterator
const &P
, VersionSet::Version
const &fallback
,
234 bool const &AllowError
= false);