]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | /** \file cacheset.h | |
4 | Wrappers around std::set to have set::iterators which behave | |
5 | similar to the Iterators of the cache structures. | |
6 | ||
7 | Provides also a few helper methods which work with these sets */ | |
8 | /*}}}*/ | |
9 | #ifndef APT_CACHESET_H | |
10 | #define APT_CACHESET_H | |
11 | // Include Files /*{{{*/ | |
12 | #include <fstream> | |
13 | #include <map> | |
14 | #include <set> | |
15 | #include <list> | |
16 | #include <vector> | |
17 | #include <string> | |
18 | #include <iterator> | |
19 | #include <algorithm> | |
20 | ||
21 | #include <stddef.h> | |
22 | ||
23 | #include <apt-pkg/error.h> | |
24 | #include <apt-pkg/pkgcache.h> | |
25 | #include <apt-pkg/cacheiterators.h> | |
26 | ||
27 | #ifndef APT_8_CLEANER_HEADERS | |
28 | #include <apt-pkg/cachefile.h> | |
29 | #endif | |
30 | #ifndef APT_10_CLEANER_HEADERS | |
31 | #include <iostream> | |
32 | #endif | |
33 | /*}}}*/ | |
34 | ||
35 | class pkgCacheFile; | |
36 | ||
37 | namespace APT { | |
38 | class PackageContainerInterface; | |
39 | class VersionContainerInterface; | |
40 | ||
41 | class CacheSetHelper { /*{{{*/ | |
42 | /** \class APT::CacheSetHelper | |
43 | Simple base class with a lot of virtual methods which can be overridden | |
44 | to alter the behavior or the output of the CacheSets. | |
45 | ||
46 | This helper is passed around by the static methods in the CacheSets and | |
47 | used every time they hit an error condition or something could be | |
48 | printed out. | |
49 | */ | |
50 | public: /*{{{*/ | |
51 | CacheSetHelper(bool const ShowError = true, | |
52 | GlobalError::MsgType ErrorType = GlobalError::ERROR) : | |
53 | ShowError(ShowError), ErrorType(ErrorType) {} | |
54 | virtual ~CacheSetHelper() {} | |
55 | ||
56 | enum PkgSelector { UNKNOWN, REGEX, TASK, FNMATCH, PACKAGENAME, STRING }; | |
57 | ||
58 | virtual bool PackageFrom(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern); | |
59 | ||
60 | virtual bool PackageFromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline); | |
61 | ||
62 | struct PkgModifier { | |
63 | enum Position { NONE, PREFIX, POSTFIX }; | |
64 | unsigned short ID; | |
65 | const char * const Alias; | |
66 | Position Pos; | |
67 | PkgModifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {} | |
68 | }; | |
69 | virtual bool PackageFromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, | |
70 | pkgCacheFile &Cache, const char * cmdline, | |
71 | std::list<PkgModifier> const &mods); | |
72 | ||
73 | // use PackageFrom(PACKAGENAME, …) instead | |
74 | APT_DEPRECATED pkgCache::PkgIterator PackageFromName(pkgCacheFile &Cache, std::string const &pattern); | |
75 | ||
76 | /** \brief be notified about the package being selected via pattern | |
77 | * | |
78 | * Main use is probably to show a message to the user what happened | |
79 | * | |
80 | * \param pkg is the package which was selected | |
81 | * \param select is the selection method which choose the package | |
82 | * \param pattern is the string used by the selection method to pick the package | |
83 | */ | |
84 | virtual void showPackageSelection(pkgCache::PkgIterator const &pkg, PkgSelector const select, std::string const &pattern); | |
85 | // use the method above instead, react only on the type you need and let the base handle the rest if need be | |
86 | // this allows use to add new selection methods without breaking the ABI constantly with new virtual methods | |
87 | APT_DEPRECATED virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); | |
88 | APT_DEPRECATED virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); | |
89 | APT_DEPRECATED virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); | |
90 | ||
91 | /** \brief be notified if a package can't be found via pattern | |
92 | * | |
93 | * Can be used to show a message as well as to try something else to make it match | |
94 | * | |
95 | * \param select is the method tried for selection | |
96 | * \param pci is the container the package should be inserted in | |
97 | * \param Cache is the package universe available | |
98 | * \param pattern is the string not matching anything | |
99 | */ | |
100 | virtual void canNotFindPackage(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern); | |
101 | // same as above for showPackageSelection | |
102 | APT_DEPRECATED virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); | |
103 | APT_DEPRECATED virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); | |
104 | APT_DEPRECATED virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); | |
105 | APT_DEPRECATED virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str); | |
106 | ||
107 | /** \brief specifies which version(s) we want to refer to */ | |
108 | enum VerSelector { | |
109 | /** by release string */ | |
110 | RELEASE, | |
111 | /** by version number string */ | |
112 | VERSIONNUMBER, | |
113 | /** All versions */ | |
114 | ALL, | |
115 | /** Candidate and installed version */ | |
116 | CANDANDINST, | |
117 | /** Candidate version */ | |
118 | CANDIDATE, | |
119 | /** Installed version */ | |
120 | INSTALLED, | |
121 | /** Candidate or if non installed version */ | |
122 | CANDINST, | |
123 | /** Installed or if non candidate version */ | |
124 | INSTCAND, | |
125 | /** Newest version */ | |
126 | NEWEST | |
127 | }; | |
128 | ||
129 | /** \brief be notified about the version being selected via pattern | |
130 | * | |
131 | * Main use is probably to show a message to the user what happened | |
132 | * Note that at the moment this method is only called for RELEASE | |
133 | * and VERSION selections, not for the others. | |
134 | * | |
135 | * \param Pkg is the package which was selected for | |
136 | * \param Ver is the version selected | |
137 | * \param select is the selection method which choose the version | |
138 | * \param pattern is the string used by the selection method to pick the version | |
139 | */ | |
140 | virtual void showVersionSelection(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver, | |
141 | enum VerSelector const select, std::string const &pattern); | |
142 | // renamed to have a similar interface to showPackageSelection | |
143 | APT_DEPRECATED virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, | |
144 | std::string const &ver, bool const verIsRel); | |
145 | ||
146 | /** \brief be notified if a version can't be found for a package | |
147 | * | |
148 | * Main use is probably to show a message to the user what happened | |
149 | * | |
150 | * \param select is the method tried for selection | |
151 | * \param vci is the container the version should be inserted in | |
152 | * \param Cache is the package universe available | |
153 | * \param Pkg is the package we wanted a version from | |
154 | */ | |
155 | virtual void canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); | |
156 | // same as above for showPackageSelection | |
157 | APT_DEPRECATED virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); | |
158 | APT_DEPRECATED virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
159 | pkgCache::PkgIterator const &Pkg); | |
160 | APT_DEPRECATED virtual void canNotFindCandInstVer(VersionContainerInterface * const vci, | |
161 | pkgCacheFile &Cache, | |
162 | pkgCache::PkgIterator const &Pkg); | |
163 | ||
164 | // the difference between canNotFind and canNotGet is that the later is more low-level | |
165 | // and called from other places: In this case looking into the code is the only real answer… | |
166 | virtual pkgCache::VerIterator canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); | |
167 | // same as above for showPackageSelection | |
168 | APT_DEPRECATED virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, | |
169 | pkgCache::PkgIterator const &Pkg); | |
170 | APT_DEPRECATED virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, | |
171 | pkgCache::PkgIterator const &Pkg); | |
172 | APT_DEPRECATED virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, | |
173 | pkgCache::PkgIterator const &Pkg); | |
174 | ||
175 | virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str); | |
176 | ||
177 | bool showErrors() const { return ShowError; } | |
178 | bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); } | |
179 | GlobalError::MsgType errorType() const { return ErrorType; } | |
180 | GlobalError::MsgType errorType(GlobalError::MsgType const &newValue) | |
181 | { | |
182 | if (ErrorType == newValue) return ErrorType; | |
183 | else { | |
184 | GlobalError::MsgType const &oldValue = ErrorType; | |
185 | ErrorType = newValue; | |
186 | return oldValue; | |
187 | } | |
188 | } | |
189 | ||
190 | /*}}}*/ | |
191 | protected: | |
192 | bool ShowError; | |
193 | GlobalError::MsgType ErrorType; | |
194 | ||
195 | pkgCache::VerIterator canNotGetInstCandVer(pkgCacheFile &Cache, | |
196 | pkgCache::PkgIterator const &Pkg); | |
197 | pkgCache::VerIterator canNotGetCandInstVer(pkgCacheFile &Cache, | |
198 | pkgCache::PkgIterator const &Pkg); | |
199 | ||
200 | bool PackageFromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); | |
201 | bool PackageFromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); | |
202 | bool PackageFromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); | |
203 | bool PackageFromPackageName(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); | |
204 | bool PackageFromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern); | |
205 | }; /*}}}*/ | |
206 | ||
207 | class PackageContainerInterface { /*{{{*/ | |
208 | /** \class PackageContainerInterface | |
209 | ||
210 | * Interface ensuring that all operations can be executed on the yet to | |
211 | * define concrete PackageContainer - access to all methods is possible, | |
212 | * but in general the wrappers provided by the PackageContainer template | |
213 | * are nicer to use. | |
214 | ||
215 | * This class mostly protects use from the need to write all implementation | |
216 | * of the methods working on containers in the template */ | |
217 | public: | |
218 | class const_iterator { /*{{{*/ | |
219 | public: | |
220 | virtual pkgCache::PkgIterator getPkg() const = 0; | |
221 | operator pkgCache::PkgIterator(void) const { return getPkg(); } | |
222 | ||
223 | inline const char *Name() const {return getPkg().Name(); } | |
224 | inline std::string FullName(bool const Pretty) const { return getPkg().FullName(Pretty); } | |
225 | inline std::string FullName() const { return getPkg().FullName(); } | |
226 | APT_DEPRECATED inline const char *Section() const { | |
227 | #if __GNUC__ >= 4 | |
228 | #pragma GCC diagnostic push | |
229 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
230 | #endif | |
231 | return getPkg().Section(); | |
232 | #if __GNUC__ >= 4 | |
233 | #pragma GCC diagnostic pop | |
234 | #endif | |
235 | } | |
236 | inline bool Purge() const {return getPkg().Purge(); } | |
237 | inline const char *Arch() const {return getPkg().Arch(); } | |
238 | inline pkgCache::GrpIterator Group() const { return getPkg().Group(); } | |
239 | inline pkgCache::VerIterator VersionList() const { return getPkg().VersionList(); } | |
240 | inline pkgCache::VerIterator CurrentVer() const { return getPkg().CurrentVer(); } | |
241 | inline pkgCache::DepIterator RevDependsList() const { return getPkg().RevDependsList(); } | |
242 | inline pkgCache::PrvIterator ProvidesList() const { return getPkg().ProvidesList(); } | |
243 | inline pkgCache::PkgIterator::OkState State() const { return getPkg().State(); } | |
244 | inline const char *CandVersion() const { return getPkg().CandVersion(); } | |
245 | inline const char *CurVersion() const { return getPkg().CurVersion(); } | |
246 | inline pkgCache *Cache() const { return getPkg().Cache(); } | |
247 | inline unsigned long Index() const {return getPkg().Index();} | |
248 | // we have only valid iterators here | |
249 | inline bool end() const { return false; } | |
250 | ||
251 | inline pkgCache::Package const * operator->() const {return &*getPkg();} | |
252 | }; | |
253 | /*}}}*/ | |
254 | ||
255 | virtual bool insert(pkgCache::PkgIterator const &P) = 0; | |
256 | virtual bool empty() const = 0; | |
257 | virtual void clear() = 0; | |
258 | ||
259 | // FIXME: This is a bloody hack removed soon. Use CacheSetHelper::PkgSelector ! | |
260 | enum APT_DEPRECATED Constructor { UNKNOWN = CacheSetHelper::UNKNOWN, | |
261 | REGEX = CacheSetHelper::REGEX, | |
262 | TASK = CacheSetHelper::TASK, | |
263 | FNMATCH = CacheSetHelper::FNMATCH }; | |
264 | #if __GNUC__ >= 4 | |
265 | #pragma GCC diagnostic push | |
266 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
267 | #endif | |
268 | void setConstructor(Constructor const by) { ConstructedBy = (CacheSetHelper::PkgSelector)by; } | |
269 | #if __GNUC__ >= 4 | |
270 | #pragma GCC diagnostic pop | |
271 | #endif | |
272 | ||
273 | void setConstructor(CacheSetHelper::PkgSelector const by) { ConstructedBy = by; } | |
274 | CacheSetHelper::PkgSelector getConstructor() const { return ConstructedBy; } | |
275 | PackageContainerInterface() : ConstructedBy(CacheSetHelper::UNKNOWN) {} | |
276 | PackageContainerInterface(CacheSetHelper::PkgSelector const by) : ConstructedBy(by) {} | |
277 | ||
278 | APT_DEPRECATED static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { | |
279 | return helper.PackageFrom(CacheSetHelper::TASK, pci, Cache, pattern); } | |
280 | APT_DEPRECATED static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { | |
281 | return helper.PackageFrom(CacheSetHelper::REGEX, pci, Cache, pattern); } | |
282 | APT_DEPRECATED static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { | |
283 | return helper.PackageFrom(CacheSetHelper::FNMATCH, pci, Cache, pattern); } | |
284 | APT_DEPRECATED static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { | |
285 | return helper.PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, pattern); } | |
286 | APT_DEPRECATED static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
287 | return helper.PackageFrom(CacheSetHelper::STRING, pci, Cache, pattern); } | |
288 | APT_DEPRECATED static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { | |
289 | return helper.PackageFromCommandLine(pci, Cache, cmdline); } | |
290 | ||
291 | APT_DEPRECATED typedef CacheSetHelper::PkgModifier Modifier; | |
292 | ||
293 | #if __GNUC__ >= 4 | |
294 | #pragma GCC diagnostic push | |
295 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
296 | #endif | |
297 | APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
298 | return helper.PackageFromName(Cache, pattern); } | |
299 | APT_DEPRECATED static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, | |
300 | pkgCacheFile &Cache, const char * cmdline, | |
301 | std::list<Modifier> const &mods, CacheSetHelper &helper) { | |
302 | return helper.PackageFromModifierCommandLine(modID, pci, Cache, cmdline, mods); } | |
303 | #if __GNUC__ >= 4 | |
304 | #pragma GCC diagnostic pop | |
305 | #endif | |
306 | ||
307 | private: | |
308 | CacheSetHelper::PkgSelector ConstructedBy; | |
309 | }; | |
310 | /*}}}*/ | |
311 | template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/ | |
312 | /** \class APT::PackageContainer | |
313 | ||
314 | Simple wrapper around a container class like std::set to provide a similar | |
315 | interface to a set of packages as to the complete set of all packages in the | |
316 | pkgCache. */ | |
317 | Container _cont; | |
318 | public: /*{{{*/ | |
319 | /** \brief smell like a pkgCache::PkgIterator */ | |
320 | class const_iterator : public PackageContainerInterface::const_iterator,/*{{{*/ | |
321 | public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> { | |
322 | typename Container::const_iterator _iter; | |
323 | public: | |
324 | const_iterator(typename Container::const_iterator i) : _iter(i) {} | |
325 | pkgCache::PkgIterator getPkg(void) const { return *_iter; } | |
326 | inline pkgCache::PkgIterator operator*(void) const { return *_iter; } | |
327 | operator typename Container::const_iterator(void) const { return _iter; } | |
328 | inline const_iterator& operator++() { ++_iter; return *this; } | |
329 | inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; } | |
330 | inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; } | |
331 | inline bool operator==(const_iterator const &i) const { return _iter == i._iter; } | |
332 | friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); } | |
333 | }; | |
334 | class iterator : public PackageContainerInterface::const_iterator, | |
335 | public std::iterator<std::forward_iterator_tag, typename Container::iterator> { | |
336 | typename Container::iterator _iter; | |
337 | public: | |
338 | iterator(typename Container::iterator i) : _iter(i) {} | |
339 | pkgCache::PkgIterator getPkg(void) const { return *_iter; } | |
340 | inline pkgCache::PkgIterator operator*(void) const { return *_iter; } | |
341 | operator typename Container::iterator(void) const { return _iter; } | |
342 | operator typename PackageContainer<Container>::const_iterator() { return typename PackageContainer<Container>::const_iterator(_iter); } | |
343 | inline iterator& operator++() { ++_iter; return *this; } | |
344 | inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } | |
345 | inline bool operator!=(iterator const &i) const { return _iter != i._iter; } | |
346 | inline bool operator==(iterator const &i) const { return _iter == i._iter; } | |
347 | inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; } | |
348 | inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; } | |
349 | friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } | |
350 | }; | |
351 | /*}}}*/ | |
352 | ||
353 | bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; } | |
354 | template<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); } | |
355 | void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); } | |
356 | ||
357 | bool empty() const { return _cont.empty(); } | |
358 | void clear() { return _cont.clear(); } | |
359 | //FIXME: on ABI break, replace the first with the second without bool | |
360 | void erase(iterator position) { _cont.erase((typename Container::iterator)position); } | |
361 | iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); } | |
362 | size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); } | |
363 | void erase(iterator first, iterator last) { _cont.erase(first, last); } | |
364 | size_t size() const { return _cont.size(); } | |
365 | ||
366 | const_iterator begin() const { return const_iterator(_cont.begin()); } | |
367 | const_iterator end() const { return const_iterator(_cont.end()); } | |
368 | iterator begin() { return iterator(_cont.begin()); } | |
369 | iterator end() { return iterator(_cont.end()); } | |
370 | const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); } | |
371 | ||
372 | PackageContainer() : PackageContainerInterface() {} | |
373 | PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {} | |
374 | #if __GNUC__ >= 4 | |
375 | #pragma GCC diagnostic push | |
376 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
377 | #endif | |
378 | APT_DEPRECATED PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {} | |
379 | #if __GNUC__ >= 4 | |
380 | #pragma GCC diagnostic pop | |
381 | #endif | |
382 | ||
383 | /** \brief sort all included versions with given comparer | |
384 | ||
385 | Some containers are sorted by default, some are not and can't be, | |
386 | but a few like std::vector can be sorted if need be, so this can be | |
387 | specialized in later on. The default is that this will fail though. | |
388 | Specifically, already sorted containers like std::set will return | |
389 | false as well as there is no easy way to check that the given comparer | |
390 | would sort in the same way the set is currently sorted | |
391 | ||
392 | \return \b true if the set was sorted, \b false if not. */ | |
393 | template<class Compare> bool sort(Compare /*Comp*/) { return false; } | |
394 | ||
395 | /** \brief returns all packages in the cache who belong to the given task | |
396 | ||
397 | A simple helper responsible for search for all members of a task | |
398 | in the cache. Optional it prints a a notice about the | |
399 | packages chosen cause of the given task. | |
400 | \param Cache the packages are in | |
401 | \param pattern name of the task | |
402 | \param helper responsible for error and message handling */ | |
403 | static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
404 | PackageContainer cont(CacheSetHelper::TASK); | |
405 | helper.PackageFrom(CacheSetHelper::TASK, &cont, Cache, pattern); | |
406 | return cont; | |
407 | } | |
408 | static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern) { | |
409 | CacheSetHelper helper; | |
410 | return FromTask(Cache, pattern, helper); | |
411 | } | |
412 | ||
413 | /** \brief returns all packages in the cache whose name matchs a given pattern | |
414 | ||
415 | A simple helper responsible for executing a regular expression on all | |
416 | package names in the cache. Optional it prints a a notice about the | |
417 | packages chosen cause of the given package. | |
418 | \param Cache the packages are in | |
419 | \param pattern regular expression for package names | |
420 | \param helper responsible for error and message handling */ | |
421 | static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
422 | PackageContainer cont(CacheSetHelper::REGEX); | |
423 | helper.PackageFrom(CacheSetHelper::REGEX, &cont, Cache, pattern); | |
424 | return cont; | |
425 | } | |
426 | ||
427 | static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { | |
428 | CacheSetHelper helper; | |
429 | return FromRegEx(Cache, pattern, helper); | |
430 | } | |
431 | ||
432 | static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
433 | PackageContainer cont(CacheSetHelper::FNMATCH); | |
434 | helper.PackageFrom(CacheSetHelper::FNMATCH, &cont, Cache, pattern); | |
435 | return cont; | |
436 | } | |
437 | static PackageContainer FromFnMatch(pkgCacheFile &Cache, std::string const &pattern) { | |
438 | CacheSetHelper helper; | |
439 | return FromFnmatch(Cache, pattern, helper); | |
440 | } | |
441 | ||
442 | #if __GNUC__ >= 4 | |
443 | #pragma GCC diagnostic push | |
444 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
445 | #endif | |
446 | /** \brief returns a package specified by a string | |
447 | ||
448 | \param Cache the package is in | |
449 | \param pattern String the package name should be extracted from | |
450 | \param helper responsible for error and message handling */ | |
451 | APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
452 | return helper.PackageFromName(Cache, pattern); | |
453 | } | |
454 | APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) { | |
455 | CacheSetHelper helper; | |
456 | return FromName(Cache, pattern, helper); | |
457 | } | |
458 | #if __GNUC__ >= 4 | |
459 | #pragma GCC diagnostic pop | |
460 | #endif | |
461 | ||
462 | /** \brief returns all packages specified by a string | |
463 | ||
464 | \param Cache the packages are in | |
465 | \param pattern String the package name(s) should be extracted from | |
466 | \param helper responsible for error and message handling */ | |
467 | static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
468 | PackageContainer cont; | |
469 | helper.PackageFrom(CacheSetHelper::PACKAGENAME, &cont, Cache, pattern); | |
470 | return cont; | |
471 | } | |
472 | static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern) { | |
473 | CacheSetHelper helper; | |
474 | return FromString(Cache, pattern, helper); | |
475 | } | |
476 | ||
477 | /** \brief returns all packages specified on the commandline | |
478 | ||
479 | Get all package names from the commandline and executes regex's if needed. | |
480 | No special package command is supported, just plain names. | |
481 | \param Cache the packages are in | |
482 | \param cmdline Command line the package names should be extracted from | |
483 | \param helper responsible for error and message handling */ | |
484 | static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { | |
485 | PackageContainer cont; | |
486 | helper.PackageFromCommandLine(&cont, Cache, cmdline); | |
487 | return cont; | |
488 | } | |
489 | static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { | |
490 | CacheSetHelper helper; | |
491 | return FromCommandLine(Cache, cmdline, helper); | |
492 | } | |
493 | ||
494 | /** \brief group packages by a action modifiers | |
495 | ||
496 | At some point it is needed to get from the same commandline | |
497 | different package sets grouped by a modifier. Take | |
498 | apt-get install apt awesome- | |
499 | as an example. | |
500 | \param Cache the packages are in | |
501 | \param cmdline Command line the package names should be extracted from | |
502 | \param mods list of modifiers the method should accept | |
503 | \param fallback the default modifier group for a package | |
504 | \param helper responsible for error and message handling */ | |
505 | static std::map<unsigned short, PackageContainer> GroupedFromCommandLine( | |
506 | pkgCacheFile &Cache, | |
507 | const char **cmdline, | |
508 | std::list<CacheSetHelper::PkgModifier> const &mods, | |
509 | unsigned short const &fallback, | |
510 | CacheSetHelper &helper) { | |
511 | std::map<unsigned short, PackageContainer> pkgsets; | |
512 | for (const char **I = cmdline; *I != 0; ++I) { | |
513 | unsigned short modID = fallback; | |
514 | PackageContainer pkgset; | |
515 | helper.PackageFromModifierCommandLine(modID, &pkgset, Cache, *I, mods); | |
516 | pkgsets[modID].insert(pkgset); | |
517 | } | |
518 | return pkgsets; | |
519 | } | |
520 | static std::map<unsigned short, PackageContainer> GroupedFromCommandLine( | |
521 | pkgCacheFile &Cache, | |
522 | const char **cmdline, | |
523 | std::list<CacheSetHelper::PkgModifier> const &mods, | |
524 | unsigned short const &fallback) { | |
525 | CacheSetHelper helper; | |
526 | return GroupedFromCommandLine(Cache, cmdline, | |
527 | mods, fallback, helper); | |
528 | } | |
529 | /*}}}*/ | |
530 | }; /*}}}*/ | |
531 | // specialisations for push_back containers: std::list & std::vector /*{{{*/ | |
532 | template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) { | |
533 | for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) | |
534 | _cont.push_back(*p); | |
535 | } | |
536 | template<> template<class Cont> void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) { | |
537 | for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) | |
538 | _cont.push_back(*p); | |
539 | } | |
540 | // these two are 'inline' as otherwise the linker has problems with seeing these untemplated | |
541 | // specializations again and again - but we need to see them, so that library users can use them | |
542 | template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) { | |
543 | if (P.end() == true) | |
544 | return false; | |
545 | _cont.push_back(P); | |
546 | return true; | |
547 | } | |
548 | template<> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) { | |
549 | if (P.end() == true) | |
550 | return false; | |
551 | _cont.push_back(P); | |
552 | return true; | |
553 | } | |
554 | template<> inline void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) { | |
555 | for (const_iterator p = begin; p != end; ++p) | |
556 | _cont.push_back(*p); | |
557 | } | |
558 | template<> inline void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) { | |
559 | for (const_iterator p = begin; p != end; ++p) | |
560 | _cont.push_back(*p); | |
561 | } | |
562 | /*}}}*/ | |
563 | ||
564 | template<> template<class Compare> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::sort(Compare Comp) { | |
565 | std::sort(_cont.begin(), _cont.end(), Comp); | |
566 | return true; | |
567 | } | |
568 | ||
569 | // class PackageUniverse - pkgCache as PackageContainerInterface /*{{{*/ | |
570 | /** \class PackageUniverse | |
571 | ||
572 | Wraps around our usual pkgCache, so that it can be stuffed into methods | |
573 | expecting a PackageContainer. | |
574 | ||
575 | The wrapping is read-only in practice modeled by making erase and co | |
576 | private methods. */ | |
577 | class APT_HIDDEN PackageUniverse : public PackageContainerInterface { | |
578 | pkgCache * const _cont; | |
579 | public: | |
580 | typedef pkgCache::PkgIterator iterator; | |
581 | typedef pkgCache::PkgIterator const_iterator; | |
582 | ||
583 | APT_PUBLIC bool empty() const { return false; } | |
584 | APT_PUBLIC size_t size() const { return _cont->Head().PackageCount; } | |
585 | ||
586 | APT_PUBLIC const_iterator begin() const { return _cont->PkgBegin(); } | |
587 | APT_PUBLIC const_iterator end() const { return _cont->PkgEnd(); } | |
588 | APT_PUBLIC iterator begin() { return _cont->PkgBegin(); } | |
589 | APT_PUBLIC iterator end() { return _cont->PkgEnd(); } | |
590 | ||
591 | APT_PUBLIC PackageUniverse(pkgCache * const Owner) : _cont(Owner) { } | |
592 | ||
593 | private: | |
594 | bool insert(pkgCache::PkgIterator const &) { return true; } | |
595 | template<class Cont> void insert(PackageContainer<Cont> const &) { } | |
596 | void insert(const_iterator, const_iterator) { } | |
597 | ||
598 | void clear() { } | |
599 | iterator& erase(iterator &iter) { return iter; } | |
600 | size_t erase(const pkgCache::PkgIterator) { return 0; } | |
601 | void erase(iterator, iterator) { } | |
602 | }; | |
603 | /*}}}*/ | |
604 | typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet; | |
605 | typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList; | |
606 | typedef PackageContainer<std::vector<pkgCache::PkgIterator> > PackageVector; | |
607 | ||
608 | class VersionContainerInterface { /*{{{*/ | |
609 | /** \class APT::VersionContainerInterface | |
610 | ||
611 | Same as APT::PackageContainerInterface, just for Versions */ | |
612 | public: | |
613 | /** \brief smell like a pkgCache::VerIterator */ | |
614 | class const_iterator { /*{{{*/ | |
615 | public: | |
616 | virtual pkgCache::VerIterator getVer() const = 0; | |
617 | operator pkgCache::VerIterator(void) { return getVer(); } | |
618 | ||
619 | inline pkgCache *Cache() const { return getVer().Cache(); } | |
620 | inline unsigned long Index() const {return getVer().Index();} | |
621 | inline int CompareVer(const pkgCache::VerIterator &B) const { return getVer().CompareVer(B); } | |
622 | inline const char *VerStr() const { return getVer().VerStr(); } | |
623 | inline const char *Section() const { return getVer().Section(); } | |
624 | inline const char *Arch() const { return getVer().Arch(); } | |
625 | inline pkgCache::PkgIterator ParentPkg() const { return getVer().ParentPkg(); } | |
626 | inline pkgCache::DescIterator DescriptionList() const { return getVer().DescriptionList(); } | |
627 | inline pkgCache::DescIterator TranslatedDescription() const { return getVer().TranslatedDescription(); } | |
628 | inline pkgCache::DepIterator DependsList() const { return getVer().DependsList(); } | |
629 | inline pkgCache::PrvIterator ProvidesList() const { return getVer().ProvidesList(); } | |
630 | inline pkgCache::VerFileIterator FileList() const { return getVer().FileList(); } | |
631 | inline bool Downloadable() const { return getVer().Downloadable(); } | |
632 | inline const char *PriorityType() const { return getVer().PriorityType(); } | |
633 | inline std::string RelStr() const { return getVer().RelStr(); } | |
634 | inline bool Automatic() const { return getVer().Automatic(); } | |
635 | inline pkgCache::VerFileIterator NewestFile() const { return getVer().NewestFile(); } | |
636 | // we have only valid iterators here | |
637 | inline bool end() const { return false; } | |
638 | ||
639 | inline pkgCache::Version const * operator->() const { return &*getVer(); } | |
640 | }; | |
641 | /*}}}*/ | |
642 | ||
643 | virtual bool insert(pkgCache::VerIterator const &V) = 0; | |
644 | virtual bool empty() const = 0; | |
645 | virtual void clear() = 0; | |
646 | ||
647 | /** \brief specifies which version(s) will be returned if non is given */ | |
648 | enum APT_DEPRECATED Version { | |
649 | ALL = CacheSetHelper::ALL, | |
650 | CANDANDINST = CacheSetHelper::CANDANDINST, | |
651 | CANDIDATE = CacheSetHelper::CANDIDATE, | |
652 | INSTALLED = CacheSetHelper::INSTALLED, | |
653 | CANDINST = CacheSetHelper::CANDINST, | |
654 | INSTCAND = CacheSetHelper::INSTCAND, | |
655 | NEWEST = CacheSetHelper::NEWEST | |
656 | }; | |
657 | ||
658 | struct Modifier { | |
659 | unsigned short const ID; | |
660 | const char * const Alias; | |
661 | enum Position { NONE, PREFIX, POSTFIX } const Pos; | |
662 | enum CacheSetHelper::VerSelector const SelectVersion; | |
663 | Modifier (unsigned short const &id, const char * const alias, Position const &pos, | |
664 | enum CacheSetHelper::VerSelector const select) : ID(id), Alias(alias), Pos(pos), | |
665 | SelectVersion(select) {} | |
666 | #if __GNUC__ >= 4 | |
667 | #pragma GCC diagnostic push | |
668 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
669 | #endif | |
670 | APT_DEPRECATED Modifier(unsigned short const &id, const char * const alias, Position const &pos, | |
671 | Version const &select) : ID(id), Alias(alias), Pos(pos), | |
672 | SelectVersion((CacheSetHelper::VerSelector)select) {} | |
673 | #if __GNUC__ >= 4 | |
674 | #pragma GCC diagnostic pop | |
675 | #endif | |
676 | }; | |
677 | ||
678 | static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
679 | const char **cmdline, CacheSetHelper::VerSelector const fallback, | |
680 | CacheSetHelper &helper); | |
681 | #if __GNUC__ >= 4 | |
682 | #pragma GCC diagnostic push | |
683 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
684 | #endif | |
685 | APT_DEPRECATED static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
686 | const char **cmdline, Version const &fallback, | |
687 | CacheSetHelper &helper) { | |
688 | return FromCommandLine(vci, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper); | |
689 | } | |
690 | #if __GNUC__ >= 4 | |
691 | #pragma GCC diagnostic pop | |
692 | #endif | |
693 | ||
694 | static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
695 | std::string pkg, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper, | |
696 | bool const onlyFromName = false); | |
697 | #if __GNUC__ >= 4 | |
698 | #pragma GCC diagnostic push | |
699 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
700 | #endif | |
701 | APT_DEPRECATED static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
702 | std::string pkg, Version const &fallback, CacheSetHelper &helper, | |
703 | bool const onlyFromName = false) { | |
704 | return FromString(vci, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper, onlyFromName); | |
705 | } | |
706 | #if __GNUC__ >= 4 | |
707 | #pragma GCC diagnostic pop | |
708 | #endif | |
709 | ||
710 | static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
711 | pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback, | |
712 | CacheSetHelper &helper); | |
713 | #if __GNUC__ >= 4 | |
714 | #pragma GCC diagnostic push | |
715 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
716 | #endif | |
717 | APT_DEPRECATED static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
718 | pkgCache::PkgIterator const &P, Version const &fallback, | |
719 | CacheSetHelper &helper) { | |
720 | return FromPackage(vci, Cache, P, (CacheSetHelper::VerSelector)fallback, helper); | |
721 | } | |
722 | #if __GNUC__ >= 4 | |
723 | #pragma GCC diagnostic pop | |
724 | #endif | |
725 | ||
726 | static bool FromModifierCommandLine(unsigned short &modID, | |
727 | VersionContainerInterface * const vci, | |
728 | pkgCacheFile &Cache, const char * cmdline, | |
729 | std::list<Modifier> const &mods, | |
730 | CacheSetHelper &helper); | |
731 | ||
732 | ||
733 | static bool FromDependency(VersionContainerInterface * const vci, | |
734 | pkgCacheFile &Cache, | |
735 | pkgCache::DepIterator const &D, | |
736 | CacheSetHelper::VerSelector const selector, | |
737 | CacheSetHelper &helper); | |
738 | #if __GNUC__ >= 4 | |
739 | #pragma GCC diagnostic push | |
740 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
741 | #endif | |
742 | APT_DEPRECATED static bool FromDependency(VersionContainerInterface * const vci, | |
743 | pkgCacheFile &Cache, | |
744 | pkgCache::DepIterator const &D, | |
745 | Version const &selector, | |
746 | CacheSetHelper &helper) { | |
747 | return FromDependency(vci, Cache, D, (CacheSetHelper::VerSelector)selector, helper); | |
748 | } | |
749 | #if __GNUC__ >= 4 | |
750 | #pragma GCC diagnostic pop | |
751 | #endif | |
752 | ||
753 | protected: /*{{{*/ | |
754 | ||
755 | /** \brief returns the candidate version of the package | |
756 | ||
757 | \param Cache to be used to query for information | |
758 | \param Pkg we want the candidate version from this package | |
759 | \param helper used in this container instance */ | |
760 | static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, | |
761 | pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); | |
762 | ||
763 | /** \brief returns the installed version of the package | |
764 | ||
765 | \param Cache to be used to query for information | |
766 | \param Pkg we want the installed version from this package | |
767 | \param helper used in this container instance */ | |
768 | static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, | |
769 | pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); | |
770 | /*}}}*/ | |
771 | }; | |
772 | /*}}}*/ | |
773 | template<class Container> class VersionContainer : public VersionContainerInterface {/*{{{*/ | |
774 | /** \class APT::VersionContainer | |
775 | ||
776 | Simple wrapper around a container class like std::set to provide a similar | |
777 | interface to a set of versions as to the complete set of all versions in the | |
778 | pkgCache. */ | |
779 | Container _cont; | |
780 | public: /*{{{*/ | |
781 | /** \brief smell like a pkgCache::VerIterator */ | |
782 | class const_iterator : public VersionContainerInterface::const_iterator, | |
783 | public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {/*{{{*/ | |
784 | typename Container::const_iterator _iter; | |
785 | public: | |
786 | const_iterator(typename Container::const_iterator i) : _iter(i) {} | |
787 | pkgCache::VerIterator getVer(void) const { return *_iter; } | |
788 | inline pkgCache::VerIterator operator*(void) const { return *_iter; } | |
789 | operator typename Container::const_iterator(void) const { return _iter; } | |
790 | inline const_iterator& operator++() { ++_iter; return *this; } | |
791 | inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; } | |
792 | inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; } | |
793 | inline bool operator==(const_iterator const &i) const { return _iter == i._iter; } | |
794 | friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); } | |
795 | }; | |
796 | class iterator : public VersionContainerInterface::const_iterator, | |
797 | public std::iterator<std::forward_iterator_tag, typename Container::iterator> { | |
798 | typename Container::iterator _iter; | |
799 | public: | |
800 | iterator(typename Container::iterator i) : _iter(i) {} | |
801 | pkgCache::VerIterator getVer(void) const { return *_iter; } | |
802 | inline pkgCache::VerIterator operator*(void) const { return *_iter; } | |
803 | operator typename Container::iterator(void) const { return _iter; } | |
804 | operator typename VersionContainer<Container>::const_iterator() { return typename VersionContainer<Container>::const_iterator(_iter); } | |
805 | inline iterator& operator++() { ++_iter; return *this; } | |
806 | inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } | |
807 | inline bool operator!=(iterator const &i) const { return _iter != i._iter; } | |
808 | inline bool operator==(iterator const &i) const { return _iter == i._iter; } | |
809 | inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; } | |
810 | inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; } | |
811 | friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } | |
812 | }; | |
813 | /*}}}*/ | |
814 | ||
815 | bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; } | |
816 | template<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); } | |
817 | void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); } | |
818 | bool empty() const { return _cont.empty(); } | |
819 | void clear() { return _cont.clear(); } | |
820 | //FIXME: on ABI break, replace the first with the second without bool | |
821 | void erase(iterator position) { _cont.erase((typename Container::iterator)position); } | |
822 | iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); } | |
823 | size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); } | |
824 | void erase(iterator first, iterator last) { _cont.erase(first, last); } | |
825 | size_t size() const { return _cont.size(); } | |
826 | ||
827 | const_iterator begin() const { return const_iterator(_cont.begin()); } | |
828 | const_iterator end() const { return const_iterator(_cont.end()); } | |
829 | iterator begin() { return iterator(_cont.begin()); } | |
830 | iterator end() { return iterator(_cont.end()); } | |
831 | const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); } | |
832 | ||
833 | /** \brief sort all included versions with given comparer | |
834 | ||
835 | Some containers are sorted by default, some are not and can't be, | |
836 | but a few like std::vector can be sorted if need be, so this can be | |
837 | specialized in later on. The default is that this will fail though. | |
838 | Specifically, already sorted containers like std::set will return | |
839 | false as well as there is no easy way to check that the given comparer | |
840 | would sort in the same way the set is currently sorted | |
841 | ||
842 | \return \b true if the set was sorted, \b false if not. */ | |
843 | template<class Compare> bool sort(Compare /*Comp*/) { return false; } | |
844 | ||
845 | /** \brief returns all versions specified on the commandline | |
846 | ||
847 | Get all versions from the commandline, uses given default version if | |
848 | non specifically requested and executes regex's if needed on names. | |
849 | \param Cache the packages and versions are in | |
850 | \param cmdline Command line the versions should be extracted from | |
851 | \param fallback version specification | |
852 | \param helper responsible for error and message handling */ | |
853 | static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, | |
854 | CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) { | |
855 | VersionContainer vercon; | |
856 | VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper); | |
857 | return vercon; | |
858 | } | |
859 | static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, | |
860 | CacheSetHelper::VerSelector const fallback) { | |
861 | CacheSetHelper helper; | |
862 | return FromCommandLine(Cache, cmdline, fallback, helper); | |
863 | } | |
864 | static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { | |
865 | return FromCommandLine(Cache, cmdline, CacheSetHelper::CANDINST); | |
866 | } | |
867 | static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg, | |
868 | CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper, | |
869 | bool const /*onlyFromName = false*/) { | |
870 | VersionContainer vercon; | |
871 | VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper); | |
872 | return vercon; | |
873 | } | |
874 | static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg, | |
875 | CacheSetHelper::VerSelector const fallback) { | |
876 | CacheSetHelper helper; | |
877 | return FromString(Cache, pkg, fallback, helper); | |
878 | } | |
879 | static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) { | |
880 | return FromString(Cache, pkg, CacheSetHelper::CANDINST); | |
881 | } | |
882 | #if __GNUC__ >= 4 | |
883 | #pragma GCC diagnostic push | |
884 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
885 | #endif | |
886 | static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, | |
887 | Version const &fallback, CacheSetHelper &helper) { | |
888 | VersionContainer vercon; | |
889 | VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper); | |
890 | return vercon; | |
891 | } | |
892 | static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, | |
893 | Version const &fallback) { | |
894 | CacheSetHelper helper; | |
895 | return FromCommandLine(Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper); | |
896 | } | |
897 | static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg, | |
898 | Version const &fallback, CacheSetHelper &helper, | |
899 | bool const /*onlyFromName = false*/) { | |
900 | VersionContainer vercon; | |
901 | VersionContainerInterface::FromString(&vercon, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper); | |
902 | return vercon; | |
903 | } | |
904 | static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg, | |
905 | Version const &fallback) { | |
906 | CacheSetHelper helper; | |
907 | return FromString(Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper); | |
908 | } | |
909 | #if __GNUC__ >= 4 | |
910 | #pragma GCC diagnostic pop | |
911 | #endif | |
912 | ||
913 | /** \brief returns all versions specified for the package | |
914 | ||
915 | \param Cache the package and versions are in | |
916 | \param P the package in question | |
917 | \param fallback the version(s) you want to get | |
918 | \param helper the helper used for display and error handling */ | |
919 | static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, | |
920 | CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) { | |
921 | VersionContainer vercon; | |
922 | VersionContainerInterface::FromPackage(&vercon, Cache, P, fallback, helper); | |
923 | return vercon; | |
924 | } | |
925 | static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, | |
926 | CacheSetHelper::VerSelector const fallback) { | |
927 | CacheSetHelper helper; | |
928 | return FromPackage(Cache, P, fallback, helper); | |
929 | } | |
930 | #if __GNUC__ >= 4 | |
931 | #pragma GCC diagnostic push | |
932 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
933 | #endif | |
934 | static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, | |
935 | Version const &fallback, CacheSetHelper &helper) { | |
936 | VersionContainer vercon; | |
937 | VersionContainerInterface::FromPackage(&vercon, Cache, P, (CacheSetHelper::VerSelector)fallback, helper); | |
938 | return vercon; | |
939 | } | |
940 | static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, | |
941 | Version const &fallback) { | |
942 | CacheSetHelper helper; | |
943 | return FromPackage(Cache, P, (CacheSetHelper::VerSelector)fallback, helper); | |
944 | } | |
945 | #if __GNUC__ >= 4 | |
946 | #pragma GCC diagnostic pop | |
947 | #endif | |
948 | static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) { | |
949 | return FromPackage(Cache, P, CacheSetHelper::CANDIDATE); | |
950 | } | |
951 | ||
952 | static std::map<unsigned short, VersionContainer> GroupedFromCommandLine( | |
953 | pkgCacheFile &Cache, | |
954 | const char **cmdline, | |
955 | std::list<Modifier> const &mods, | |
956 | unsigned short const fallback, | |
957 | CacheSetHelper &helper) { | |
958 | std::map<unsigned short, VersionContainer> versets; | |
959 | for (const char **I = cmdline; *I != 0; ++I) { | |
960 | unsigned short modID = fallback; | |
961 | VersionContainer verset; | |
962 | VersionContainerInterface::FromModifierCommandLine(modID, &verset, Cache, *I, mods, helper); | |
963 | versets[modID].insert(verset); | |
964 | } | |
965 | return versets; | |
966 | ||
967 | } | |
968 | static std::map<unsigned short, VersionContainer> GroupedFromCommandLine( | |
969 | pkgCacheFile &Cache, const char **cmdline, | |
970 | std::list<Modifier> const &mods, | |
971 | unsigned short const fallback) { | |
972 | CacheSetHelper helper; | |
973 | return GroupedFromCommandLine(Cache, cmdline, | |
974 | mods, fallback, helper); | |
975 | } | |
976 | ||
977 | static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, | |
978 | CacheSetHelper::VerSelector const selector, CacheSetHelper &helper) { | |
979 | VersionContainer vercon; | |
980 | VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper); | |
981 | return vercon; | |
982 | } | |
983 | static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, | |
984 | CacheSetHelper::VerSelector const selector) { | |
985 | CacheSetHelper helper; | |
986 | return FromPackage(Cache, D, selector, helper); | |
987 | } | |
988 | #if __GNUC__ >= 4 | |
989 | #pragma GCC diagnostic push | |
990 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
991 | #endif | |
992 | static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, | |
993 | Version const &selector, CacheSetHelper &helper) { | |
994 | VersionContainer vercon; | |
995 | VersionContainerInterface::FromDependency(&vercon, Cache, D, (CacheSetHelper::VerSelector)selector, helper); | |
996 | return vercon; | |
997 | } | |
998 | static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, | |
999 | Version const &selector) { | |
1000 | CacheSetHelper helper; | |
1001 | return FromPackage(Cache, D, (CacheSetHelper::VerSelector)selector, helper); | |
1002 | } | |
1003 | #if __GNUC__ >= 4 | |
1004 | #pragma GCC diagnostic pop | |
1005 | #endif | |
1006 | static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) { | |
1007 | return FromPackage(Cache, D, CacheSetHelper::CANDIDATE); | |
1008 | } | |
1009 | /*}}}*/ | |
1010 | }; /*}}}*/ | |
1011 | // specialisations for push_back containers: std::list & std::vector /*{{{*/ | |
1012 | template<> template<class Cont> void VersionContainer<std::list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) { | |
1013 | for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v) | |
1014 | _cont.push_back(*v); | |
1015 | } | |
1016 | template<> template<class Cont> void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) { | |
1017 | for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v) | |
1018 | _cont.push_back(*v); | |
1019 | } | |
1020 | // these two are 'inline' as otherwise the linker has problems with seeing these untemplated | |
1021 | // specializations again and again - but we need to see them, so that library users can use them | |
1022 | template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) { | |
1023 | if (V.end() == true) | |
1024 | return false; | |
1025 | _cont.push_back(V); | |
1026 | return true; | |
1027 | } | |
1028 | template<> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) { | |
1029 | if (V.end() == true) | |
1030 | return false; | |
1031 | _cont.push_back(V); | |
1032 | return true; | |
1033 | } | |
1034 | template<> inline void VersionContainer<std::list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) { | |
1035 | for (const_iterator v = begin; v != end; ++v) | |
1036 | _cont.push_back(*v); | |
1037 | } | |
1038 | template<> inline void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) { | |
1039 | for (const_iterator v = begin; v != end; ++v) | |
1040 | _cont.push_back(*v); | |
1041 | } | |
1042 | /*}}}*/ | |
1043 | ||
1044 | template<> template<class Compare> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::sort(Compare Comp) { | |
1045 | std::sort(_cont.begin(), _cont.end(), Comp); | |
1046 | return true; | |
1047 | } | |
1048 | ||
1049 | typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet; | |
1050 | typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList; | |
1051 | typedef VersionContainer<std::vector<pkgCache::VerIterator> > VersionVector; | |
1052 | } | |
1053 | #endif |