]>
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 | #include <apt-pkg/macros.h> | |
27 | ||
28 | #ifndef APT_8_CLEANER_HEADERS | |
29 | #include <apt-pkg/cachefile.h> | |
30 | #endif | |
31 | #ifndef APT_10_CLEANER_HEADERS | |
32 | #include <iostream> | |
33 | #endif | |
34 | /*}}}*/ | |
35 | ||
36 | class pkgCacheFile; | |
37 | ||
38 | namespace APT { | |
39 | class PackageContainerInterface; | |
40 | class VersionContainerInterface; | |
41 | ||
42 | class CacheSetHelper { /*{{{*/ | |
43 | /** \class APT::CacheSetHelper | |
44 | Simple base class with a lot of virtual methods which can be overridden | |
45 | to alter the behavior or the output of the CacheSets. | |
46 | ||
47 | This helper is passed around by the static methods in the CacheSets and | |
48 | used every time they hit an error condition or something could be | |
49 | printed out. | |
50 | */ | |
51 | public: /*{{{*/ | |
52 | CacheSetHelper(bool const ShowError = true, | |
53 | GlobalError::MsgType ErrorType = GlobalError::ERROR); | |
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 | private: | |
206 | void * const d; | |
207 | }; /*}}}*/ | |
208 | ||
209 | class PackageContainerInterface { /*{{{*/ | |
210 | /** \class PackageContainerInterface | |
211 | ||
212 | * Interface ensuring that all operations can be executed on the yet to | |
213 | * define concrete PackageContainer - access to all methods is possible, | |
214 | * but in general the wrappers provided by the PackageContainer template | |
215 | * are nicer to use. | |
216 | ||
217 | * This class mostly protects use from the need to write all implementation | |
218 | * of the methods working on containers in the template */ | |
219 | public: | |
220 | class const_iterator { /*{{{*/ | |
221 | public: | |
222 | virtual pkgCache::PkgIterator getPkg() const = 0; | |
223 | operator pkgCache::PkgIterator(void) const { return getPkg(); } | |
224 | ||
225 | inline const char *Name() const {return getPkg().Name(); } | |
226 | inline std::string FullName(bool const Pretty) const { return getPkg().FullName(Pretty); } | |
227 | inline std::string FullName() const { return getPkg().FullName(); } | |
228 | APT_DEPRECATED inline const char *Section() const { | |
229 | APT_IGNORE_DEPRECATED_PUSH | |
230 | return getPkg().Section(); | |
231 | APT_IGNORE_DEPRECATED_POP | |
232 | } | |
233 | inline bool Purge() const {return getPkg().Purge(); } | |
234 | inline const char *Arch() const {return getPkg().Arch(); } | |
235 | inline pkgCache::GrpIterator Group() const { return getPkg().Group(); } | |
236 | inline pkgCache::VerIterator VersionList() const { return getPkg().VersionList(); } | |
237 | inline pkgCache::VerIterator CurrentVer() const { return getPkg().CurrentVer(); } | |
238 | inline pkgCache::DepIterator RevDependsList() const { return getPkg().RevDependsList(); } | |
239 | inline pkgCache::PrvIterator ProvidesList() const { return getPkg().ProvidesList(); } | |
240 | inline pkgCache::PkgIterator::OkState State() const { return getPkg().State(); } | |
241 | inline const char *CandVersion() const { return getPkg().CandVersion(); } | |
242 | inline const char *CurVersion() const { return getPkg().CurVersion(); } | |
243 | inline pkgCache *Cache() const { return getPkg().Cache(); } | |
244 | inline unsigned long Index() const {return getPkg().Index();} | |
245 | // we have only valid iterators here | |
246 | inline bool end() const { return false; } | |
247 | ||
248 | inline pkgCache::Package const * operator->() const {return &*getPkg();} | |
249 | }; | |
250 | /*}}}*/ | |
251 | ||
252 | virtual bool insert(pkgCache::PkgIterator const &P) = 0; | |
253 | virtual bool empty() const = 0; | |
254 | virtual void clear() = 0; | |
255 | ||
256 | // FIXME: This is a bloody hack removed soon. Use CacheSetHelper::PkgSelector ! | |
257 | enum APT_DEPRECATED Constructor { UNKNOWN = CacheSetHelper::UNKNOWN, | |
258 | REGEX = CacheSetHelper::REGEX, | |
259 | TASK = CacheSetHelper::TASK, | |
260 | FNMATCH = CacheSetHelper::FNMATCH }; | |
261 | APT_IGNORE_DEPRECATED_PUSH | |
262 | void setConstructor(Constructor const by) { ConstructedBy = (CacheSetHelper::PkgSelector)by; } | |
263 | APT_IGNORE_DEPRECATED_POP | |
264 | ||
265 | void setConstructor(CacheSetHelper::PkgSelector const by) { ConstructedBy = by; } | |
266 | CacheSetHelper::PkgSelector getConstructor() const { return ConstructedBy; } | |
267 | PackageContainerInterface(); | |
268 | explicit PackageContainerInterface(CacheSetHelper::PkgSelector const by); | |
269 | PackageContainerInterface& operator=(PackageContainerInterface const &other); | |
270 | virtual ~PackageContainerInterface(); | |
271 | ||
272 | APT_DEPRECATED static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { | |
273 | return helper.PackageFrom(CacheSetHelper::TASK, pci, Cache, pattern); } | |
274 | APT_DEPRECATED static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { | |
275 | return helper.PackageFrom(CacheSetHelper::REGEX, pci, Cache, pattern); } | |
276 | APT_DEPRECATED static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { | |
277 | return helper.PackageFrom(CacheSetHelper::FNMATCH, pci, Cache, pattern); } | |
278 | APT_DEPRECATED static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { | |
279 | return helper.PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, pattern); } | |
280 | APT_DEPRECATED static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
281 | return helper.PackageFrom(CacheSetHelper::STRING, pci, Cache, pattern); } | |
282 | APT_DEPRECATED static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { | |
283 | return helper.PackageFromCommandLine(pci, Cache, cmdline); } | |
284 | ||
285 | APT_DEPRECATED typedef CacheSetHelper::PkgModifier Modifier; | |
286 | ||
287 | APT_IGNORE_DEPRECATED_PUSH | |
288 | APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
289 | return helper.PackageFromName(Cache, pattern); } | |
290 | APT_DEPRECATED static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, | |
291 | pkgCacheFile &Cache, const char * cmdline, | |
292 | std::list<Modifier> const &mods, CacheSetHelper &helper) { | |
293 | return helper.PackageFromModifierCommandLine(modID, pci, Cache, cmdline, mods); } | |
294 | APT_IGNORE_DEPRECATED_POP | |
295 | ||
296 | private: | |
297 | CacheSetHelper::PkgSelector ConstructedBy; | |
298 | void * const d; | |
299 | }; | |
300 | /*}}}*/ | |
301 | template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/ | |
302 | /** \class APT::PackageContainer | |
303 | ||
304 | Simple wrapper around a container class like std::set to provide a similar | |
305 | interface to a set of packages as to the complete set of all packages in the | |
306 | pkgCache. */ | |
307 | Container _cont; | |
308 | public: /*{{{*/ | |
309 | /** \brief smell like a pkgCache::PkgIterator */ | |
310 | class const_iterator : public PackageContainerInterface::const_iterator,/*{{{*/ | |
311 | public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> { | |
312 | typename Container::const_iterator _iter; | |
313 | public: | |
314 | explicit const_iterator(typename Container::const_iterator i) : _iter(i) {} | |
315 | pkgCache::PkgIterator getPkg(void) const { return *_iter; } | |
316 | inline pkgCache::PkgIterator operator*(void) const { return *_iter; } | |
317 | operator typename Container::const_iterator(void) const { return _iter; } | |
318 | inline const_iterator& operator++() { ++_iter; return *this; } | |
319 | inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; } | |
320 | inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; } | |
321 | inline bool operator==(const_iterator const &i) const { return _iter == i._iter; } | |
322 | friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); } | |
323 | }; | |
324 | class iterator : public PackageContainerInterface::const_iterator, | |
325 | public std::iterator<std::forward_iterator_tag, typename Container::iterator> { | |
326 | typename Container::iterator _iter; | |
327 | public: | |
328 | explicit iterator(typename Container::iterator i) : _iter(i) {} | |
329 | pkgCache::PkgIterator getPkg(void) const { return *_iter; } | |
330 | inline pkgCache::PkgIterator operator*(void) const { return *_iter; } | |
331 | operator typename Container::iterator(void) const { return _iter; } | |
332 | operator typename PackageContainer<Container>::const_iterator() { return typename PackageContainer<Container>::const_iterator(_iter); } | |
333 | inline iterator& operator++() { ++_iter; return *this; } | |
334 | inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } | |
335 | inline bool operator!=(iterator const &i) const { return _iter != i._iter; } | |
336 | inline bool operator==(iterator const &i) const { return _iter == i._iter; } | |
337 | inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; } | |
338 | inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; } | |
339 | friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } | |
340 | }; | |
341 | /*}}}*/ | |
342 | ||
343 | bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; } | |
344 | template<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); } | |
345 | void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); } | |
346 | ||
347 | bool empty() const { return _cont.empty(); } | |
348 | void clear() { return _cont.clear(); } | |
349 | //FIXME: on ABI break, replace the first with the second without bool | |
350 | void erase(iterator position) { _cont.erase((typename Container::iterator)position); } | |
351 | iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); } | |
352 | size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); } | |
353 | void erase(iterator first, iterator last) { _cont.erase(first, last); } | |
354 | size_t size() const { return _cont.size(); } | |
355 | ||
356 | const_iterator begin() const { return const_iterator(_cont.begin()); } | |
357 | const_iterator end() const { return const_iterator(_cont.end()); } | |
358 | iterator begin() { return iterator(_cont.begin()); } | |
359 | iterator end() { return iterator(_cont.end()); } | |
360 | const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); } | |
361 | ||
362 | PackageContainer() : PackageContainerInterface(CacheSetHelper::UNKNOWN) {} | |
363 | explicit PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {} | |
364 | APT_IGNORE_DEPRECATED_PUSH | |
365 | APT_DEPRECATED PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {} | |
366 | APT_IGNORE_DEPRECATED_POP | |
367 | ||
368 | /** \brief sort all included versions with given comparer | |
369 | ||
370 | Some containers are sorted by default, some are not and can't be, | |
371 | but a few like std::vector can be sorted if need be, so this can be | |
372 | specialized in later on. The default is that this will fail though. | |
373 | Specifically, already sorted containers like std::set will return | |
374 | false as well as there is no easy way to check that the given comparer | |
375 | would sort in the same way the set is currently sorted | |
376 | ||
377 | \return \b true if the set was sorted, \b false if not. */ | |
378 | template<class Compare> bool sort(Compare /*Comp*/) { return false; } | |
379 | ||
380 | /** \brief returns all packages in the cache who belong to the given task | |
381 | ||
382 | A simple helper responsible for search for all members of a task | |
383 | in the cache. Optional it prints a a notice about the | |
384 | packages chosen cause of the given task. | |
385 | \param Cache the packages are in | |
386 | \param pattern name of the task | |
387 | \param helper responsible for error and message handling */ | |
388 | static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
389 | PackageContainer cont(CacheSetHelper::TASK); | |
390 | helper.PackageFrom(CacheSetHelper::TASK, &cont, Cache, pattern); | |
391 | return cont; | |
392 | } | |
393 | static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern) { | |
394 | CacheSetHelper helper; | |
395 | return FromTask(Cache, pattern, helper); | |
396 | } | |
397 | ||
398 | /** \brief returns all packages in the cache whose name matchs a given pattern | |
399 | ||
400 | A simple helper responsible for executing a regular expression on all | |
401 | package names in the cache. Optional it prints a a notice about the | |
402 | packages chosen cause of the given package. | |
403 | \param Cache the packages are in | |
404 | \param pattern regular expression for package names | |
405 | \param helper responsible for error and message handling */ | |
406 | static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
407 | PackageContainer cont(CacheSetHelper::REGEX); | |
408 | helper.PackageFrom(CacheSetHelper::REGEX, &cont, Cache, pattern); | |
409 | return cont; | |
410 | } | |
411 | ||
412 | static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { | |
413 | CacheSetHelper helper; | |
414 | return FromRegEx(Cache, pattern, helper); | |
415 | } | |
416 | ||
417 | static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
418 | PackageContainer cont(CacheSetHelper::FNMATCH); | |
419 | helper.PackageFrom(CacheSetHelper::FNMATCH, &cont, Cache, pattern); | |
420 | return cont; | |
421 | } | |
422 | static PackageContainer FromFnMatch(pkgCacheFile &Cache, std::string const &pattern) { | |
423 | CacheSetHelper helper; | |
424 | return FromFnmatch(Cache, pattern, helper); | |
425 | } | |
426 | ||
427 | APT_IGNORE_DEPRECATED_PUSH | |
428 | /** \brief returns a package specified by a string | |
429 | ||
430 | \param Cache the package is in | |
431 | \param pattern String the package name should be extracted from | |
432 | \param helper responsible for error and message handling */ | |
433 | APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
434 | return helper.PackageFromName(Cache, pattern); | |
435 | } | |
436 | APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) { | |
437 | CacheSetHelper helper; | |
438 | return FromName(Cache, pattern, helper); | |
439 | } | |
440 | APT_IGNORE_DEPRECATED_POP | |
441 | ||
442 | /** \brief returns all packages specified by a string | |
443 | ||
444 | \param Cache the packages are in | |
445 | \param pattern String the package name(s) should be extracted from | |
446 | \param helper responsible for error and message handling */ | |
447 | static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { | |
448 | PackageContainer cont; | |
449 | helper.PackageFrom(CacheSetHelper::PACKAGENAME, &cont, Cache, pattern); | |
450 | return cont; | |
451 | } | |
452 | static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern) { | |
453 | CacheSetHelper helper; | |
454 | return FromString(Cache, pattern, helper); | |
455 | } | |
456 | ||
457 | /** \brief returns all packages specified on the commandline | |
458 | ||
459 | Get all package names from the commandline and executes regex's if needed. | |
460 | No special package command is supported, just plain names. | |
461 | \param Cache the packages are in | |
462 | \param cmdline Command line the package names should be extracted from | |
463 | \param helper responsible for error and message handling */ | |
464 | static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { | |
465 | PackageContainer cont; | |
466 | helper.PackageFromCommandLine(&cont, Cache, cmdline); | |
467 | return cont; | |
468 | } | |
469 | static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { | |
470 | CacheSetHelper helper; | |
471 | return FromCommandLine(Cache, cmdline, helper); | |
472 | } | |
473 | ||
474 | /** \brief group packages by a action modifiers | |
475 | ||
476 | At some point it is needed to get from the same commandline | |
477 | different package sets grouped by a modifier. Take | |
478 | apt-get install apt awesome- | |
479 | as an example. | |
480 | \param Cache the packages are in | |
481 | \param cmdline Command line the package names should be extracted from | |
482 | \param mods list of modifiers the method should accept | |
483 | \param fallback the default modifier group for a package | |
484 | \param helper responsible for error and message handling */ | |
485 | static std::map<unsigned short, PackageContainer> GroupedFromCommandLine( | |
486 | pkgCacheFile &Cache, | |
487 | const char **cmdline, | |
488 | std::list<CacheSetHelper::PkgModifier> const &mods, | |
489 | unsigned short const &fallback, | |
490 | CacheSetHelper &helper) { | |
491 | std::map<unsigned short, PackageContainer> pkgsets; | |
492 | for (const char **I = cmdline; *I != 0; ++I) { | |
493 | unsigned short modID = fallback; | |
494 | PackageContainer pkgset; | |
495 | helper.PackageFromModifierCommandLine(modID, &pkgset, Cache, *I, mods); | |
496 | pkgsets[modID].insert(pkgset); | |
497 | } | |
498 | return pkgsets; | |
499 | } | |
500 | static std::map<unsigned short, PackageContainer> GroupedFromCommandLine( | |
501 | pkgCacheFile &Cache, | |
502 | const char **cmdline, | |
503 | std::list<CacheSetHelper::PkgModifier> const &mods, | |
504 | unsigned short const &fallback) { | |
505 | CacheSetHelper helper; | |
506 | return GroupedFromCommandLine(Cache, cmdline, | |
507 | mods, fallback, helper); | |
508 | } | |
509 | /*}}}*/ | |
510 | }; /*}}}*/ | |
511 | // specialisations for push_back containers: std::list & std::vector /*{{{*/ | |
512 | template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) { | |
513 | for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) | |
514 | _cont.push_back(*p); | |
515 | } | |
516 | template<> template<class Cont> void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) { | |
517 | for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) | |
518 | _cont.push_back(*p); | |
519 | } | |
520 | // these two are 'inline' as otherwise the linker has problems with seeing these untemplated | |
521 | // specializations again and again - but we need to see them, so that library users can use them | |
522 | template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) { | |
523 | if (P.end() == true) | |
524 | return false; | |
525 | _cont.push_back(P); | |
526 | return true; | |
527 | } | |
528 | template<> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) { | |
529 | if (P.end() == true) | |
530 | return false; | |
531 | _cont.push_back(P); | |
532 | return true; | |
533 | } | |
534 | template<> inline void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) { | |
535 | for (const_iterator p = begin; p != end; ++p) | |
536 | _cont.push_back(*p); | |
537 | } | |
538 | template<> inline void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) { | |
539 | for (const_iterator p = begin; p != end; ++p) | |
540 | _cont.push_back(*p); | |
541 | } | |
542 | /*}}}*/ | |
543 | ||
544 | template<> template<class Compare> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::sort(Compare Comp) { | |
545 | std::sort(_cont.begin(), _cont.end(), Comp); | |
546 | return true; | |
547 | } | |
548 | ||
549 | // class PackageUniverse - pkgCache as PackageContainerInterface /*{{{*/ | |
550 | /** \class PackageUniverse | |
551 | ||
552 | Wraps around our usual pkgCache, so that it can be stuffed into methods | |
553 | expecting a PackageContainer. | |
554 | ||
555 | The wrapping is read-only in practice modeled by making erase and co | |
556 | private methods. */ | |
557 | class APT_HIDDEN PackageUniverse : public PackageContainerInterface { | |
558 | pkgCache * const _cont; | |
559 | void * const d; | |
560 | public: | |
561 | typedef pkgCache::PkgIterator iterator; | |
562 | typedef pkgCache::PkgIterator const_iterator; | |
563 | ||
564 | APT_PUBLIC bool empty() const { return false; } | |
565 | APT_PUBLIC size_t size() const { return _cont->Head().PackageCount; } | |
566 | ||
567 | APT_PUBLIC const_iterator begin() const { return _cont->PkgBegin(); } | |
568 | APT_PUBLIC const_iterator end() const { return _cont->PkgEnd(); } | |
569 | APT_PUBLIC iterator begin() { return _cont->PkgBegin(); } | |
570 | APT_PUBLIC iterator end() { return _cont->PkgEnd(); } | |
571 | ||
572 | explicit APT_PUBLIC PackageUniverse(pkgCache * const Owner); | |
573 | APT_PUBLIC virtual ~PackageUniverse(); | |
574 | ||
575 | private: | |
576 | bool insert(pkgCache::PkgIterator const &) { return true; } | |
577 | template<class Cont> void insert(PackageContainer<Cont> const &) { } | |
578 | void insert(const_iterator, const_iterator) { } | |
579 | ||
580 | void clear() { } | |
581 | iterator& erase(iterator &iter) { return iter; } | |
582 | size_t erase(const pkgCache::PkgIterator) { return 0; } | |
583 | void erase(iterator, iterator) { } | |
584 | }; | |
585 | /*}}}*/ | |
586 | typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet; | |
587 | typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList; | |
588 | typedef PackageContainer<std::vector<pkgCache::PkgIterator> > PackageVector; | |
589 | ||
590 | class VersionContainerInterface { /*{{{*/ | |
591 | /** \class APT::VersionContainerInterface | |
592 | ||
593 | Same as APT::PackageContainerInterface, just for Versions */ | |
594 | public: | |
595 | /** \brief smell like a pkgCache::VerIterator */ | |
596 | class const_iterator { /*{{{*/ | |
597 | public: | |
598 | virtual pkgCache::VerIterator getVer() const = 0; | |
599 | operator pkgCache::VerIterator(void) { return getVer(); } | |
600 | ||
601 | inline pkgCache *Cache() const { return getVer().Cache(); } | |
602 | inline unsigned long Index() const {return getVer().Index();} | |
603 | inline int CompareVer(const pkgCache::VerIterator &B) const { return getVer().CompareVer(B); } | |
604 | inline const char *VerStr() const { return getVer().VerStr(); } | |
605 | inline const char *Section() const { return getVer().Section(); } | |
606 | inline const char *Arch() const { return getVer().Arch(); } | |
607 | inline pkgCache::PkgIterator ParentPkg() const { return getVer().ParentPkg(); } | |
608 | inline pkgCache::DescIterator DescriptionList() const { return getVer().DescriptionList(); } | |
609 | inline pkgCache::DescIterator TranslatedDescription() const { return getVer().TranslatedDescription(); } | |
610 | inline pkgCache::DepIterator DependsList() const { return getVer().DependsList(); } | |
611 | inline pkgCache::PrvIterator ProvidesList() const { return getVer().ProvidesList(); } | |
612 | inline pkgCache::VerFileIterator FileList() const { return getVer().FileList(); } | |
613 | inline bool Downloadable() const { return getVer().Downloadable(); } | |
614 | inline const char *PriorityType() const { return getVer().PriorityType(); } | |
615 | inline std::string RelStr() const { return getVer().RelStr(); } | |
616 | inline bool Automatic() const { return getVer().Automatic(); } | |
617 | inline pkgCache::VerFileIterator NewestFile() const { return getVer().NewestFile(); } | |
618 | // we have only valid iterators here | |
619 | inline bool end() const { return false; } | |
620 | ||
621 | inline pkgCache::Version const * operator->() const { return &*getVer(); } | |
622 | }; | |
623 | /*}}}*/ | |
624 | ||
625 | virtual bool insert(pkgCache::VerIterator const &V) = 0; | |
626 | virtual bool empty() const = 0; | |
627 | virtual void clear() = 0; | |
628 | ||
629 | /** \brief specifies which version(s) will be returned if non is given */ | |
630 | enum APT_DEPRECATED Version { | |
631 | ALL = CacheSetHelper::ALL, | |
632 | CANDANDINST = CacheSetHelper::CANDANDINST, | |
633 | CANDIDATE = CacheSetHelper::CANDIDATE, | |
634 | INSTALLED = CacheSetHelper::INSTALLED, | |
635 | CANDINST = CacheSetHelper::CANDINST, | |
636 | INSTCAND = CacheSetHelper::INSTCAND, | |
637 | NEWEST = CacheSetHelper::NEWEST | |
638 | }; | |
639 | ||
640 | struct Modifier { | |
641 | unsigned short const ID; | |
642 | const char * const Alias; | |
643 | enum Position { NONE, PREFIX, POSTFIX } const Pos; | |
644 | enum CacheSetHelper::VerSelector const SelectVersion; | |
645 | Modifier (unsigned short const &id, const char * const alias, Position const &pos, | |
646 | enum CacheSetHelper::VerSelector const select) : ID(id), Alias(alias), Pos(pos), | |
647 | SelectVersion(select) {} | |
648 | APT_IGNORE_DEPRECATED_PUSH | |
649 | APT_DEPRECATED Modifier(unsigned short const &id, const char * const alias, Position const &pos, | |
650 | Version const &select) : ID(id), Alias(alias), Pos(pos), | |
651 | SelectVersion((CacheSetHelper::VerSelector)select) {} | |
652 | APT_IGNORE_DEPRECATED_POP | |
653 | }; | |
654 | ||
655 | static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
656 | const char **cmdline, CacheSetHelper::VerSelector const fallback, | |
657 | CacheSetHelper &helper); | |
658 | APT_IGNORE_DEPRECATED_PUSH | |
659 | APT_DEPRECATED static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
660 | const char **cmdline, Version const &fallback, | |
661 | CacheSetHelper &helper) { | |
662 | return FromCommandLine(vci, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper); | |
663 | } | |
664 | APT_IGNORE_DEPRECATED_POP | |
665 | ||
666 | static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
667 | std::string pkg, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper, | |
668 | bool const onlyFromName = false); | |
669 | APT_IGNORE_DEPRECATED_PUSH | |
670 | APT_DEPRECATED static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
671 | std::string pkg, Version const &fallback, CacheSetHelper &helper, | |
672 | bool const onlyFromName = false) { | |
673 | return FromString(vci, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper, onlyFromName); | |
674 | } | |
675 | APT_IGNORE_DEPRECATED_POP | |
676 | ||
677 | static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
678 | pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback, | |
679 | CacheSetHelper &helper); | |
680 | APT_IGNORE_DEPRECATED_PUSH | |
681 | APT_DEPRECATED static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache, | |
682 | pkgCache::PkgIterator const &P, Version const &fallback, | |
683 | CacheSetHelper &helper) { | |
684 | return FromPackage(vci, Cache, P, (CacheSetHelper::VerSelector)fallback, helper); | |
685 | } | |
686 | APT_IGNORE_DEPRECATED_POP | |
687 | ||
688 | static bool FromModifierCommandLine(unsigned short &modID, | |
689 | VersionContainerInterface * const vci, | |
690 | pkgCacheFile &Cache, const char * cmdline, | |
691 | std::list<Modifier> const &mods, | |
692 | CacheSetHelper &helper); | |
693 | ||
694 | ||
695 | static bool FromDependency(VersionContainerInterface * const vci, | |
696 | pkgCacheFile &Cache, | |
697 | pkgCache::DepIterator const &D, | |
698 | CacheSetHelper::VerSelector const selector, | |
699 | CacheSetHelper &helper); | |
700 | APT_IGNORE_DEPRECATED_PUSH | |
701 | APT_DEPRECATED static bool FromDependency(VersionContainerInterface * const vci, | |
702 | pkgCacheFile &Cache, | |
703 | pkgCache::DepIterator const &D, | |
704 | Version const &selector, | |
705 | CacheSetHelper &helper) { | |
706 | return FromDependency(vci, Cache, D, (CacheSetHelper::VerSelector)selector, helper); | |
707 | } | |
708 | APT_IGNORE_DEPRECATED_POP | |
709 | ||
710 | VersionContainerInterface(); | |
711 | VersionContainerInterface& operator=(VersionContainerInterface const &other); | |
712 | virtual ~VersionContainerInterface(); | |
713 | private: | |
714 | void * const d; | |
715 | ||
716 | protected: /*{{{*/ | |
717 | ||
718 | /** \brief returns the candidate version of the package | |
719 | ||
720 | \param Cache to be used to query for information | |
721 | \param Pkg we want the candidate version from this package | |
722 | \param helper used in this container instance */ | |
723 | static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, | |
724 | pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); | |
725 | ||
726 | /** \brief returns the installed version of the package | |
727 | ||
728 | \param Cache to be used to query for information | |
729 | \param Pkg we want the installed version from this package | |
730 | \param helper used in this container instance */ | |
731 | static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, | |
732 | pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); | |
733 | /*}}}*/ | |
734 | }; | |
735 | /*}}}*/ | |
736 | template<class Container> class VersionContainer : public VersionContainerInterface {/*{{{*/ | |
737 | /** \class APT::VersionContainer | |
738 | ||
739 | Simple wrapper around a container class like std::set to provide a similar | |
740 | interface to a set of versions as to the complete set of all versions in the | |
741 | pkgCache. */ | |
742 | Container _cont; | |
743 | public: /*{{{*/ | |
744 | /** \brief smell like a pkgCache::VerIterator */ | |
745 | class const_iterator : public VersionContainerInterface::const_iterator, | |
746 | public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {/*{{{*/ | |
747 | typename Container::const_iterator _iter; | |
748 | public: | |
749 | explicit const_iterator(typename Container::const_iterator i) : _iter(i) {} | |
750 | pkgCache::VerIterator getVer(void) const { return *_iter; } | |
751 | inline pkgCache::VerIterator operator*(void) const { return *_iter; } | |
752 | operator typename Container::const_iterator(void) const { return _iter; } | |
753 | inline const_iterator& operator++() { ++_iter; return *this; } | |
754 | inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; } | |
755 | inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; } | |
756 | inline bool operator==(const_iterator const &i) const { return _iter == i._iter; } | |
757 | friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); } | |
758 | }; | |
759 | class iterator : public VersionContainerInterface::const_iterator, | |
760 | public std::iterator<std::forward_iterator_tag, typename Container::iterator> { | |
761 | typename Container::iterator _iter; | |
762 | public: | |
763 | explicit iterator(typename Container::iterator i) : _iter(i) {} | |
764 | pkgCache::VerIterator getVer(void) const { return *_iter; } | |
765 | inline pkgCache::VerIterator operator*(void) const { return *_iter; } | |
766 | operator typename Container::iterator(void) const { return _iter; } | |
767 | operator typename VersionContainer<Container>::const_iterator() { return typename VersionContainer<Container>::const_iterator(_iter); } | |
768 | inline iterator& operator++() { ++_iter; return *this; } | |
769 | inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } | |
770 | inline bool operator!=(iterator const &i) const { return _iter != i._iter; } | |
771 | inline bool operator==(iterator const &i) const { return _iter == i._iter; } | |
772 | inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; } | |
773 | inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; } | |
774 | friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } | |
775 | }; | |
776 | /*}}}*/ | |
777 | ||
778 | bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; } | |
779 | template<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); } | |
780 | void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); } | |
781 | bool empty() const { return _cont.empty(); } | |
782 | void clear() { return _cont.clear(); } | |
783 | //FIXME: on ABI break, replace the first with the second without bool | |
784 | void erase(iterator position) { _cont.erase((typename Container::iterator)position); } | |
785 | iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); } | |
786 | size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); } | |
787 | void erase(iterator first, iterator last) { _cont.erase(first, last); } | |
788 | size_t size() const { return _cont.size(); } | |
789 | ||
790 | const_iterator begin() const { return const_iterator(_cont.begin()); } | |
791 | const_iterator end() const { return const_iterator(_cont.end()); } | |
792 | iterator begin() { return iterator(_cont.begin()); } | |
793 | iterator end() { return iterator(_cont.end()); } | |
794 | const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); } | |
795 | ||
796 | /** \brief sort all included versions with given comparer | |
797 | ||
798 | Some containers are sorted by default, some are not and can't be, | |
799 | but a few like std::vector can be sorted if need be, so this can be | |
800 | specialized in later on. The default is that this will fail though. | |
801 | Specifically, already sorted containers like std::set will return | |
802 | false as well as there is no easy way to check that the given comparer | |
803 | would sort in the same way the set is currently sorted | |
804 | ||
805 | \return \b true if the set was sorted, \b false if not. */ | |
806 | template<class Compare> bool sort(Compare /*Comp*/) { return false; } | |
807 | ||
808 | /** \brief returns all versions specified on the commandline | |
809 | ||
810 | Get all versions from the commandline, uses given default version if | |
811 | non specifically requested and executes regex's if needed on names. | |
812 | \param Cache the packages and versions are in | |
813 | \param cmdline Command line the versions should be extracted from | |
814 | \param fallback version specification | |
815 | \param helper responsible for error and message handling */ | |
816 | static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, | |
817 | CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) { | |
818 | VersionContainer vercon; | |
819 | VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper); | |
820 | return vercon; | |
821 | } | |
822 | static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, | |
823 | CacheSetHelper::VerSelector const fallback) { | |
824 | CacheSetHelper helper; | |
825 | return FromCommandLine(Cache, cmdline, fallback, helper); | |
826 | } | |
827 | static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { | |
828 | return FromCommandLine(Cache, cmdline, CacheSetHelper::CANDINST); | |
829 | } | |
830 | static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg, | |
831 | CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper, | |
832 | bool const /*onlyFromName = false*/) { | |
833 | VersionContainer vercon; | |
834 | VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper); | |
835 | return vercon; | |
836 | } | |
837 | static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg, | |
838 | CacheSetHelper::VerSelector const fallback) { | |
839 | CacheSetHelper helper; | |
840 | return FromString(Cache, pkg, fallback, helper); | |
841 | } | |
842 | static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) { | |
843 | return FromString(Cache, pkg, CacheSetHelper::CANDINST); | |
844 | } | |
845 | APT_IGNORE_DEPRECATED_PUSH | |
846 | static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, | |
847 | Version const &fallback, CacheSetHelper &helper) { | |
848 | VersionContainer vercon; | |
849 | VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper); | |
850 | return vercon; | |
851 | } | |
852 | static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, | |
853 | Version const &fallback) { | |
854 | CacheSetHelper helper; | |
855 | return FromCommandLine(Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper); | |
856 | } | |
857 | static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg, | |
858 | Version const &fallback, CacheSetHelper &helper, | |
859 | bool const /*onlyFromName = false*/) { | |
860 | VersionContainer vercon; | |
861 | VersionContainerInterface::FromString(&vercon, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper); | |
862 | return vercon; | |
863 | } | |
864 | static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg, | |
865 | Version const &fallback) { | |
866 | CacheSetHelper helper; | |
867 | return FromString(Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper); | |
868 | } | |
869 | APT_IGNORE_DEPRECATED_POP | |
870 | ||
871 | /** \brief returns all versions specified for the package | |
872 | ||
873 | \param Cache the package and versions are in | |
874 | \param P the package in question | |
875 | \param fallback the version(s) you want to get | |
876 | \param helper the helper used for display and error handling */ | |
877 | static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, | |
878 | CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) { | |
879 | VersionContainer vercon; | |
880 | VersionContainerInterface::FromPackage(&vercon, Cache, P, fallback, helper); | |
881 | return vercon; | |
882 | } | |
883 | static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, | |
884 | CacheSetHelper::VerSelector const fallback) { | |
885 | CacheSetHelper helper; | |
886 | return FromPackage(Cache, P, fallback, helper); | |
887 | } | |
888 | APT_IGNORE_DEPRECATED_PUSH | |
889 | static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, | |
890 | Version const &fallback, CacheSetHelper &helper) { | |
891 | VersionContainer vercon; | |
892 | VersionContainerInterface::FromPackage(&vercon, Cache, P, (CacheSetHelper::VerSelector)fallback, helper); | |
893 | return vercon; | |
894 | } | |
895 | static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, | |
896 | Version const &fallback) { | |
897 | CacheSetHelper helper; | |
898 | return FromPackage(Cache, P, (CacheSetHelper::VerSelector)fallback, helper); | |
899 | } | |
900 | APT_IGNORE_DEPRECATED_POP | |
901 | static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) { | |
902 | return FromPackage(Cache, P, CacheSetHelper::CANDIDATE); | |
903 | } | |
904 | ||
905 | static std::map<unsigned short, VersionContainer> GroupedFromCommandLine( | |
906 | pkgCacheFile &Cache, | |
907 | const char **cmdline, | |
908 | std::list<Modifier> const &mods, | |
909 | unsigned short const fallback, | |
910 | CacheSetHelper &helper) { | |
911 | std::map<unsigned short, VersionContainer> versets; | |
912 | for (const char **I = cmdline; *I != 0; ++I) { | |
913 | unsigned short modID = fallback; | |
914 | VersionContainer verset; | |
915 | VersionContainerInterface::FromModifierCommandLine(modID, &verset, Cache, *I, mods, helper); | |
916 | versets[modID].insert(verset); | |
917 | } | |
918 | return versets; | |
919 | ||
920 | } | |
921 | static std::map<unsigned short, VersionContainer> GroupedFromCommandLine( | |
922 | pkgCacheFile &Cache, const char **cmdline, | |
923 | std::list<Modifier> const &mods, | |
924 | unsigned short const fallback) { | |
925 | CacheSetHelper helper; | |
926 | return GroupedFromCommandLine(Cache, cmdline, | |
927 | mods, fallback, helper); | |
928 | } | |
929 | ||
930 | static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, | |
931 | CacheSetHelper::VerSelector const selector, CacheSetHelper &helper) { | |
932 | VersionContainer vercon; | |
933 | VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper); | |
934 | return vercon; | |
935 | } | |
936 | static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, | |
937 | CacheSetHelper::VerSelector const selector) { | |
938 | CacheSetHelper helper; | |
939 | return FromPackage(Cache, D, selector, helper); | |
940 | } | |
941 | APT_IGNORE_DEPRECATED_PUSH | |
942 | static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, | |
943 | Version const &selector, CacheSetHelper &helper) { | |
944 | VersionContainer vercon; | |
945 | VersionContainerInterface::FromDependency(&vercon, Cache, D, (CacheSetHelper::VerSelector)selector, helper); | |
946 | return vercon; | |
947 | } | |
948 | static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, | |
949 | Version const &selector) { | |
950 | CacheSetHelper helper; | |
951 | return FromPackage(Cache, D, (CacheSetHelper::VerSelector)selector, helper); | |
952 | } | |
953 | APT_IGNORE_DEPRECATED_POP | |
954 | static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) { | |
955 | return FromPackage(Cache, D, CacheSetHelper::CANDIDATE); | |
956 | } | |
957 | /*}}}*/ | |
958 | }; /*}}}*/ | |
959 | // specialisations for push_back containers: std::list & std::vector /*{{{*/ | |
960 | template<> template<class Cont> void VersionContainer<std::list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) { | |
961 | for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v) | |
962 | _cont.push_back(*v); | |
963 | } | |
964 | template<> template<class Cont> void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) { | |
965 | for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v) | |
966 | _cont.push_back(*v); | |
967 | } | |
968 | // these two are 'inline' as otherwise the linker has problems with seeing these untemplated | |
969 | // specializations again and again - but we need to see them, so that library users can use them | |
970 | template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) { | |
971 | if (V.end() == true) | |
972 | return false; | |
973 | _cont.push_back(V); | |
974 | return true; | |
975 | } | |
976 | template<> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) { | |
977 | if (V.end() == true) | |
978 | return false; | |
979 | _cont.push_back(V); | |
980 | return true; | |
981 | } | |
982 | template<> inline void VersionContainer<std::list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) { | |
983 | for (const_iterator v = begin; v != end; ++v) | |
984 | _cont.push_back(*v); | |
985 | } | |
986 | template<> inline void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) { | |
987 | for (const_iterator v = begin; v != end; ++v) | |
988 | _cont.push_back(*v); | |
989 | } | |
990 | /*}}}*/ | |
991 | ||
992 | template<> template<class Compare> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::sort(Compare Comp) { | |
993 | std::sort(_cont.begin(), _cont.end(), Comp); | |
994 | return true; | |
995 | } | |
996 | ||
997 | typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet; | |
998 | typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList; | |
999 | typedef VersionContainer<std::vector<pkgCache::VerIterator> > VersionVector; | |
1000 | } | |
1001 | #endif |