]>
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 /*{{{*/
17 #include <apt-pkg/cachefile.h>
18 #include <apt-pkg/pkgcache.h>
21 class PackageSet
: public std::set
<pkgCache::PkgIterator
> { /*{{{*/
22 /** \class APT::PackageSet
24 Simple wrapper around a std::set to provide a similar interface to
25 a set of packages as to the complete set of all packages in the
28 /** \brief smell like a pkgCache::PkgIterator */
29 class const_iterator
: public std::set
<pkgCache::PkgIterator
>::const_iterator
{
31 const_iterator(std::set
<pkgCache::PkgIterator
>::const_iterator x
) :
32 std::set
<pkgCache::PkgIterator
>::const_iterator(x
) {}
34 operator pkgCache::PkgIterator(void) { return **this; }
36 inline const char *Name() const {return (**this).Name(); }
37 inline std::string
FullName(bool const &Pretty
) const { return (**this).FullName(Pretty
); }
38 inline std::string
FullName() const { return (**this).FullName(); }
39 inline const char *Section() const {return (**this).Section(); }
40 inline bool Purge() const {return (**this).Purge(); }
41 inline const char *Arch() const {return (**this).Arch(); }
42 inline pkgCache::GrpIterator
Group() const { return (**this).Group(); }
43 inline pkgCache::VerIterator
VersionList() const { return (**this).VersionList(); }
44 inline pkgCache::VerIterator
CurrentVer() const { return (**this).CurrentVer(); }
45 inline pkgCache::DepIterator
RevDependsList() const { return (**this).RevDependsList(); }
46 inline pkgCache::PrvIterator
ProvidesList() const { return (**this).ProvidesList(); }
47 inline pkgCache::PkgIterator::OkState
State() const { return (**this).State(); }
48 inline const char *CandVersion() const { return (**this).CandVersion(); }
49 inline const char *CurVersion() const { return (**this).CurVersion(); }
50 inline pkgCache
*Cache() const { return (**this).Cache(); };
51 inline unsigned long Index() const {return (**this).Index();};
52 // we have only valid iterators here
53 inline bool end() const { return false; };
55 friend std::ostream
& operator<<(std::ostream
& out
, const_iterator i
) { return operator<<(out
, (*i
)); }
57 inline pkgCache::Package
const * operator->() const {
61 // 103. set::iterator is required to be modifiable, but this allows modification of keys
62 typedef typename
APT::PackageSet::const_iterator iterator
;
64 /** \brief returns all packages in the cache whose name matchs a given pattern
66 A simple helper responsible for executing a regular expression on all
67 package names in the cache. Optional it prints a a notice about the
68 packages chosen cause of the given package.
69 \param Cache the packages are in
70 \param pattern regular expression for package names
71 \param out stream to print the notice to */
72 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string pattern
, std::ostream
&out
);
73 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
74 std::ostream
out (std::ofstream("/dev/null").rdbuf());
75 return APT::PackageSet::FromRegEx(Cache
, pattern
, out
);
78 /** \brief returns all packages specified by a string
80 \param Cache the packages are in
81 \param string String the package name(s) should be extracted from
82 \param out stream to print various notices to */
83 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, const char * const string
, std::ostream
&out
);
84 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, const char * const string
) {
85 std::ostream
out (std::ofstream("/dev/null").rdbuf());
86 return APT::PackageSet::FromString(Cache
, string
, out
);
89 /** \brief returns all packages specified on the commandline
91 Get all package names from the commandline and executes regex's if needed.
92 No special package command is supported, just plain names.
93 \param Cache the packages are in
94 \param cmdline Command line the package names should be extracted from
95 \param out stream to print various notices to */
96 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, std::ostream
&out
);
97 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
98 std::ostream
out (std::ofstream("/dev/null").rdbuf());
99 return APT::PackageSet::FromCommandLine(Cache
, cmdline
, out
);
103 class VersionSet
: public std::set
<pkgCache::VerIterator
> { /*{{{*/
104 /** \class APT::VersionSet
106 Simple wrapper around a std::set to provide a similar interface to
107 a set of versions as to the complete set of all versions in the
110 /** \brief smell like a pkgCache::VerIterator */
111 class const_iterator
: public std::set
<pkgCache::VerIterator
>::const_iterator
{
113 const_iterator(std::set
<pkgCache::VerIterator
>::const_iterator x
) :
114 std::set
<pkgCache::VerIterator
>::const_iterator(x
) {}
116 operator pkgCache::VerIterator(void) { return **this; }
118 inline pkgCache
*Cache() const { return (**this).Cache(); };
119 inline unsigned long Index() const {return (**this).Index();};
120 // we have only valid iterators here
121 inline bool end() const { return false; };
123 inline pkgCache::Version
const * operator->() const {
127 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return (**this).CompareVer(B
); };
128 inline const char *VerStr() const { return (**this).VerStr(); };
129 inline const char *Section() const { return (**this).Section(); };
130 inline const char *Arch() const { return (**this).Arch(); };
131 inline const char *Arch(bool const pseudo
) const { return (**this).Arch(pseudo
); };
132 inline pkgCache::PkgIterator
ParentPkg() const { return (**this).ParentPkg(); };
133 inline pkgCache::DescIterator
DescriptionList() const { return (**this).DescriptionList(); };
134 inline pkgCache::DescIterator
TranslatedDescription() const { return (**this).TranslatedDescription(); };
135 inline pkgCache::DepIterator
DependsList() const { return (**this).DependsList(); };
136 inline pkgCache::PrvIterator
ProvidesList() const { return (**this).ProvidesList(); };
137 inline pkgCache::VerFileIterator
FileList() const { return (**this).FileList(); };
138 inline bool Downloadable() const { return (**this).Downloadable(); };
139 inline const char *PriorityType() const { return (**this).PriorityType(); };
140 inline string
RelStr() const { return (**this).RelStr(); };
141 inline bool Automatic() const { return (**this).Automatic(); };
142 inline bool Pseudo() const { return (**this).Pseudo(); };
143 inline pkgCache::VerFileIterator
NewestFile() const { return (**this).NewestFile(); };
145 // 103. set::iterator is required to be modifiable, but this allows modification of keys
146 typedef typename
APT::VersionSet::const_iterator iterator
;
148 /** \brief specifies which version(s) will be returned if non is given */
152 /** Candidate and installed version */
154 /** Candidate version */
156 /** Installed version */
158 /** Candidate or if non installed version */
160 /** Installed or if non candidate version */
162 /** Newest version */
166 /** \brief returns all versions specified on the commandline
168 Get all versions from the commandline, uses given default version if
169 non specifically requested and executes regex's if needed on names.
170 \param Cache the packages and versions are in
171 \param cmdline Command line the versions should be extracted from
172 \param out stream to print various notices to */
173 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
174 APT::VersionSet::Version
const &fallback
, std::ostream
&out
);
175 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
176 APT::VersionSet::Version
const &fallback
) {
177 std::ostream
out (std::ofstream("/dev/null").rdbuf());
178 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, fallback
, out
);
180 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
181 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, CANDINST
);
186 /** \brief returns the candidate version of the package
188 \param Cache to be used to query for information
189 \param Pkg we want the candidate version from this package
190 \param AllowError add an error to the stack if not */
191 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
192 pkgCache::PkgIterator
const &Pkg
, bool const &AllowError
= false);
194 /** \brief returns the installed version of the package
196 \param Cache to be used to query for information
197 \param Pkg we want the installed version from this package
198 \param AllowError add an error to the stack if not */
199 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
200 pkgCache::PkgIterator
const &Pkg
, bool const &AllowError
= false);