]>
Commit | Line | Data |
---|---|---|
e1dbde8d DK |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
7959c5ed DK |
3 | /** \file cacheset.h |
4 | Wrappers around std::set to have set::iterators which behave | |
5 | similar to the Iterators of the cache structures. | |
e1dbde8d | 6 | |
7959c5ed | 7 | Provides also a few helper methods which work with these sets */ |
e1dbde8d | 8 | /*}}}*/ |
7959c5ed DK |
9 | #ifndef APT_CACHESET_H |
10 | #define APT_CACHESET_H | |
e1dbde8d | 11 | // Include Files /*{{{*/ |
ffee1c2b DK |
12 | #include <iostream> |
13 | #include <fstream> | |
9cc83a6f DK |
14 | #include <list> |
15 | #include <map> | |
ffee1c2b | 16 | #include <set> |
e1dbde8d | 17 | #include <string> |
ffee1c2b | 18 | |
856d3b06 | 19 | #include <apt-pkg/cachefile.h> |
e1dbde8d DK |
20 | #include <apt-pkg/pkgcache.h> |
21 | /*}}}*/ | |
22 | namespace APT { | |
d4489d49 | 23 | class PackageSet : public std::set<pkgCache::PkgIterator> { /*{{{*/ |
7959c5ed DK |
24 | /** \class APT::PackageSet |
25 | ||
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 | |
28 | pkgCache. */ | |
e1dbde8d DK |
29 | public: /*{{{*/ |
30 | /** \brief smell like a pkgCache::PkgIterator */ | |
31 | class const_iterator : public std::set<pkgCache::PkgIterator>::const_iterator { | |
32 | public: | |
33 | const_iterator(std::set<pkgCache::PkgIterator>::const_iterator x) : | |
34 | std::set<pkgCache::PkgIterator>::const_iterator(x) {} | |
35 | ||
ffee1c2b DK |
36 | operator pkgCache::PkgIterator(void) { return **this; } |
37 | ||
78c32596 DK |
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; }; | |
e1dbde8d DK |
56 | |
57 | friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); } | |
58 | ||
78c32596 DK |
59 | inline pkgCache::Package const * operator->() const { |
60 | return &***this; | |
e1dbde8d DK |
61 | }; |
62 | }; | |
63 | // 103. set::iterator is required to be modifiable, but this allows modification of keys | |
6d052eba | 64 | typedef APT::PackageSet::const_iterator iterator; |
ffee1c2b | 65 | |
c45f2d19 DK |
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); }; | |
68 | ||
ffee1c2b DK |
69 | /** \brief returns all packages in the cache whose name matchs a given pattern |
70 | ||
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 */ | |
856d3b06 DK |
77 | static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out); |
78 | static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { | |
ffee1c2b DK |
79 | std::ostream out (std::ofstream("/dev/null").rdbuf()); |
80 | return APT::PackageSet::FromRegEx(Cache, pattern, out); | |
81 | } | |
82 | ||
856d3b06 DK |
83 | /** \brief returns all packages specified by a string |
84 | ||
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 */ | |
fe870feb DK |
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) { | |
856d3b06 DK |
90 | std::ostream out (std::ofstream("/dev/null").rdbuf()); |
91 | return APT::PackageSet::FromString(Cache, string, out); | |
92 | } | |
93 | ||
78c32596 DK |
94 | /** \brief returns all packages specified on the commandline |
95 | ||
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 */ | |
856d3b06 DK |
101 | static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out); |
102 | static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { | |
78c32596 DK |
103 | std::ostream out (std::ofstream("/dev/null").rdbuf()); |
104 | return APT::PackageSet::FromCommandLine(Cache, cmdline, out); | |
105 | } | |
9cc83a6f DK |
106 | |
107 | struct Modifier { | |
108 | enum Position { NONE, PREFIX, POSTFIX }; | |
109 | unsigned short ID; | |
110 | const char * const Alias; | |
111 | Position Pos; | |
112 | Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}; | |
113 | }; | |
114 | ||
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); | |
126 | } | |
d4489d49 DK |
127 | /*}}}*/ |
128 | }; /*}}}*/ | |
129 | class VersionSet : public std::set<pkgCache::VerIterator> { /*{{{*/ | |
130 | /** \class APT::VersionSet | |
78c32596 | 131 | |
d4489d49 DK |
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 | |
134 | pkgCache. */ | |
135 | public: /*{{{*/ | |
136 | /** \brief smell like a pkgCache::VerIterator */ | |
137 | class const_iterator : public std::set<pkgCache::VerIterator>::const_iterator { | |
138 | public: | |
139 | const_iterator(std::set<pkgCache::VerIterator>::const_iterator x) : | |
140 | std::set<pkgCache::VerIterator>::const_iterator(x) {} | |
78c32596 | 141 | |
d4489d49 DK |
142 | operator pkgCache::VerIterator(void) { return **this; } |
143 | ||
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; }; | |
148 | ||
149 | inline pkgCache::Version const * operator->() const { | |
150 | return &***this; | |
151 | }; | |
152 | ||
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(); }; | |
170 | }; | |
171 | // 103. set::iterator is required to be modifiable, but this allows modification of keys | |
6d052eba | 172 | typedef APT::VersionSet::const_iterator iterator; |
78c32596 | 173 | |
c45f2d19 DK |
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); }; | |
176 | ||
856d3b06 DK |
177 | /** \brief specifies which version(s) will be returned if non is given */ |
178 | enum Version { | |
179 | /** All versions */ | |
180 | ALL, | |
181 | /** Candidate and installed version */ | |
182 | CANDANDINST, | |
183 | /** Candidate version */ | |
184 | CANDIDATE, | |
185 | /** Installed version */ | |
186 | INSTALLED, | |
187 | /** Candidate or if non installed version */ | |
188 | CANDINST, | |
189 | /** Installed or if non candidate version */ | |
190 | INSTCAND, | |
191 | /** Newest version */ | |
192 | NEWEST | |
193 | }; | |
194 | ||
195 | /** \brief returns all versions specified on the commandline | |
196 | ||
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); | |
208 | } | |
209 | static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { | |
210 | return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); | |
211 | } | |
212 | /*}}}*/ | |
213 | protected: /*{{{*/ | |
214 | ||
215 | /** \brief returns the candidate version of the package | |
216 | ||
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); | |
222 | ||
223 | /** \brief returns the installed version of the package | |
224 | ||
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); | |
230 | ||
84910ad5 DK |
231 | |
232 | static bool AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, | |
233 | pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, | |
234 | bool const &AllowError = false); | |
235 | ||
e1dbde8d | 236 | /*}}}*/ |
d4489d49 | 237 | }; /*}}}*/ |
e1dbde8d DK |
238 | } |
239 | #endif |