]>
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> | |
14 | #include <set> | |
e1dbde8d | 15 | #include <string> |
ffee1c2b | 16 | |
856d3b06 | 17 | #include <apt-pkg/cachefile.h> |
e1dbde8d DK |
18 | #include <apt-pkg/pkgcache.h> |
19 | /*}}}*/ | |
20 | namespace APT { | |
d4489d49 | 21 | class PackageSet : public std::set<pkgCache::PkgIterator> { /*{{{*/ |
7959c5ed DK |
22 | /** \class APT::PackageSet |
23 | ||
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 | |
26 | pkgCache. */ | |
e1dbde8d DK |
27 | public: /*{{{*/ |
28 | /** \brief smell like a pkgCache::PkgIterator */ | |
29 | class const_iterator : public std::set<pkgCache::PkgIterator>::const_iterator { | |
30 | public: | |
31 | const_iterator(std::set<pkgCache::PkgIterator>::const_iterator x) : | |
32 | std::set<pkgCache::PkgIterator>::const_iterator(x) {} | |
33 | ||
ffee1c2b DK |
34 | operator pkgCache::PkgIterator(void) { return **this; } |
35 | ||
78c32596 DK |
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; }; | |
e1dbde8d DK |
54 | |
55 | friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); } | |
56 | ||
78c32596 DK |
57 | inline pkgCache::Package const * operator->() const { |
58 | return &***this; | |
e1dbde8d DK |
59 | }; |
60 | }; | |
61 | // 103. set::iterator is required to be modifiable, but this allows modification of keys | |
62 | typedef typename APT::PackageSet::const_iterator iterator; | |
ffee1c2b | 63 | |
c45f2d19 DK |
64 | using std::set<pkgCache::PkgIterator>::insert; |
65 | inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set<pkgCache::PkgIterator>::insert(P); }; | |
66 | ||
ffee1c2b DK |
67 | /** \brief returns all packages in the cache whose name matchs a given pattern |
68 | ||
69 | A simple helper responsible for executing a regular expression on all | |
70 | package names in the cache. Optional it prints a a notice about the | |
71 | packages chosen cause of the given package. | |
72 | \param Cache the packages are in | |
73 | \param pattern regular expression for package names | |
74 | \param out stream to print the notice to */ | |
856d3b06 DK |
75 | static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out); |
76 | static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { | |
ffee1c2b DK |
77 | std::ostream out (std::ofstream("/dev/null").rdbuf()); |
78 | return APT::PackageSet::FromRegEx(Cache, pattern, out); | |
79 | } | |
80 | ||
856d3b06 DK |
81 | /** \brief returns all packages specified by a string |
82 | ||
83 | \param Cache the packages are in | |
84 | \param string String the package name(s) should be extracted from | |
85 | \param out stream to print various notices to */ | |
fe870feb DK |
86 | static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, std::ostream &out); |
87 | static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { | |
856d3b06 DK |
88 | std::ostream out (std::ofstream("/dev/null").rdbuf()); |
89 | return APT::PackageSet::FromString(Cache, string, out); | |
90 | } | |
91 | ||
78c32596 DK |
92 | /** \brief returns all packages specified on the commandline |
93 | ||
94 | Get all package names from the commandline and executes regex's if needed. | |
95 | No special package command is supported, just plain names. | |
96 | \param Cache the packages are in | |
97 | \param cmdline Command line the package names should be extracted from | |
98 | \param out stream to print various notices to */ | |
856d3b06 DK |
99 | static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out); |
100 | static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { | |
78c32596 DK |
101 | std::ostream out (std::ofstream("/dev/null").rdbuf()); |
102 | return APT::PackageSet::FromCommandLine(Cache, cmdline, out); | |
103 | } | |
d4489d49 DK |
104 | /*}}}*/ |
105 | }; /*}}}*/ | |
106 | class VersionSet : public std::set<pkgCache::VerIterator> { /*{{{*/ | |
107 | /** \class APT::VersionSet | |
78c32596 | 108 | |
d4489d49 DK |
109 | Simple wrapper around a std::set to provide a similar interface to |
110 | a set of versions as to the complete set of all versions in the | |
111 | pkgCache. */ | |
112 | public: /*{{{*/ | |
113 | /** \brief smell like a pkgCache::VerIterator */ | |
114 | class const_iterator : public std::set<pkgCache::VerIterator>::const_iterator { | |
115 | public: | |
116 | const_iterator(std::set<pkgCache::VerIterator>::const_iterator x) : | |
117 | std::set<pkgCache::VerIterator>::const_iterator(x) {} | |
78c32596 | 118 | |
d4489d49 DK |
119 | operator pkgCache::VerIterator(void) { return **this; } |
120 | ||
121 | inline pkgCache *Cache() const { return (**this).Cache(); }; | |
122 | inline unsigned long Index() const {return (**this).Index();}; | |
123 | // we have only valid iterators here | |
124 | inline bool end() const { return false; }; | |
125 | ||
126 | inline pkgCache::Version const * operator->() const { | |
127 | return &***this; | |
128 | }; | |
129 | ||
130 | inline int CompareVer(const pkgCache::VerIterator &B) const { return (**this).CompareVer(B); }; | |
131 | inline const char *VerStr() const { return (**this).VerStr(); }; | |
132 | inline const char *Section() const { return (**this).Section(); }; | |
133 | inline const char *Arch() const { return (**this).Arch(); }; | |
134 | inline const char *Arch(bool const pseudo) const { return (**this).Arch(pseudo); }; | |
135 | inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); }; | |
136 | inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); }; | |
137 | inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); }; | |
138 | inline pkgCache::DepIterator DependsList() const { return (**this).DependsList(); }; | |
139 | inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); }; | |
140 | inline pkgCache::VerFileIterator FileList() const { return (**this).FileList(); }; | |
141 | inline bool Downloadable() const { return (**this).Downloadable(); }; | |
142 | inline const char *PriorityType() const { return (**this).PriorityType(); }; | |
143 | inline string RelStr() const { return (**this).RelStr(); }; | |
144 | inline bool Automatic() const { return (**this).Automatic(); }; | |
145 | inline bool Pseudo() const { return (**this).Pseudo(); }; | |
146 | inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); }; | |
147 | }; | |
148 | // 103. set::iterator is required to be modifiable, but this allows modification of keys | |
149 | typedef typename APT::VersionSet::const_iterator iterator; | |
78c32596 | 150 | |
c45f2d19 DK |
151 | using std::set<pkgCache::VerIterator>::insert; |
152 | inline void insert(pkgCache::VerIterator const &V) { if (V.end() == false) std::set<pkgCache::VerIterator>::insert(V); }; | |
153 | ||
856d3b06 DK |
154 | /** \brief specifies which version(s) will be returned if non is given */ |
155 | enum Version { | |
156 | /** All versions */ | |
157 | ALL, | |
158 | /** Candidate and installed version */ | |
159 | CANDANDINST, | |
160 | /** Candidate version */ | |
161 | CANDIDATE, | |
162 | /** Installed version */ | |
163 | INSTALLED, | |
164 | /** Candidate or if non installed version */ | |
165 | CANDINST, | |
166 | /** Installed or if non candidate version */ | |
167 | INSTCAND, | |
168 | /** Newest version */ | |
169 | NEWEST | |
170 | }; | |
171 | ||
172 | /** \brief returns all versions specified on the commandline | |
173 | ||
174 | Get all versions from the commandline, uses given default version if | |
175 | non specifically requested and executes regex's if needed on names. | |
176 | \param Cache the packages and versions are in | |
177 | \param cmdline Command line the versions should be extracted from | |
178 | \param out stream to print various notices to */ | |
179 | static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, | |
180 | APT::VersionSet::Version const &fallback, std::ostream &out); | |
181 | static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, | |
182 | APT::VersionSet::Version const &fallback) { | |
183 | std::ostream out (std::ofstream("/dev/null").rdbuf()); | |
184 | return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, out); | |
185 | } | |
186 | static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { | |
187 | return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); | |
188 | } | |
189 | /*}}}*/ | |
190 | protected: /*{{{*/ | |
191 | ||
192 | /** \brief returns the candidate version of the package | |
193 | ||
194 | \param Cache to be used to query for information | |
195 | \param Pkg we want the candidate version from this package | |
196 | \param AllowError add an error to the stack if not */ | |
197 | static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, | |
198 | pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); | |
199 | ||
200 | /** \brief returns the installed version of the package | |
201 | ||
202 | \param Cache to be used to query for information | |
203 | \param Pkg we want the installed version from this package | |
204 | \param AllowError add an error to the stack if not */ | |
205 | static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, | |
206 | pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); | |
207 | ||
e1dbde8d | 208 | /*}}}*/ |
d4489d49 | 209 | }; /*}}}*/ |
e1dbde8d DK |
210 | } |
211 | #endif |