]> git.saurik.com Git - apt.git/blame - apt-pkg/cacheset.h
Merge remote-tracking branch 'upstream/debian/experimental' into feature/no-more...
[apt.git] / apt-pkg / cacheset.h
CommitLineData
e1dbde8d
DK
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
7959c5ed
DK
3/** \file cacheset.h
4 Wrappers around std::set to have set::iterators which behave
5 similar to the Iterators of the cache structures.
e1dbde8d 6
7959c5ed 7 Provides also a few helper methods which work with these sets */
e1dbde8d 8 /*}}}*/
7959c5ed
DK
9#ifndef APT_CACHESET_H
10#define APT_CACHESET_H
e1dbde8d 11// Include Files /*{{{*/
ffee1c2b 12#include <fstream>
9cc83a6f 13#include <map>
ffee1c2b 14#include <set>
c4cca791 15#include <list>
5c8c7321 16#include <vector>
e1dbde8d 17#include <string>
15fc8636 18#include <iterator>
5c8c7321 19#include <algorithm>
ffee1c2b 20
453b82a3
DK
21#include <stddef.h>
22
472ff00e 23#include <apt-pkg/error.h>
e1dbde8d 24#include <apt-pkg/pkgcache.h>
453b82a3 25#include <apt-pkg/cacheiterators.h>
b9dadc24
DK
26
27#ifndef APT_8_CLEANER_HEADERS
28#include <apt-pkg/cachefile.h>
453b82a3
DK
29#endif
30#ifndef APT_10_CLEANER_HEADERS
31#include <iostream>
b9dadc24 32#endif
e1dbde8d 33 /*}}}*/
472ff00e
DK
34
35class pkgCacheFile;
36
e1dbde8d 37namespace APT {
15fc8636
DK
38class PackageContainerInterface;
39class VersionContainerInterface;
40
70e706ad
DK
41class 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*/
50public: /*{{{*/
15fc8636 51 CacheSetHelper(bool const ShowError = true,
cd7bbc47 52 GlobalError::MsgType ErrorType = GlobalError::ERROR) :
d3e8fbb3
DK
53 ShowError(ShowError), ErrorType(ErrorType) {}
54 virtual ~CacheSetHelper() {}
70e706ad 55
1e064088
DK
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);
fdba4d53
DK
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 };
70e706ad 128
fdba4d53
DK
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);
15fc8636 145
fdba4d53
DK
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,
70e706ad 159 pkgCache::PkgIterator const &Pkg);
fdba4d53 160 APT_DEPRECATED virtual void canNotFindCandInstVer(VersionContainerInterface * const vci,
15fc8636 161 pkgCacheFile &Cache,
cf28bcad 162 pkgCache::PkgIterator const &Pkg);
15fc8636 163
fdba4d53
DK
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,
70e706ad 169 pkgCache::PkgIterator const &Pkg);
fdba4d53 170 APT_DEPRECATED virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache,
70e706ad 171 pkgCache::PkgIterator const &Pkg);
fdba4d53 172 APT_DEPRECATED virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache,
70e706ad
DK
173 pkgCache::PkgIterator const &Pkg);
174
fdba4d53
DK
175 virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str);
176
d3e8fbb3
DK
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; }
cd7bbc47
DK
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 }
d3e8fbb3 188 }
cd7bbc47 189
70e706ad
DK
190 /*}}}*/
191protected:
192 bool ShowError;
cd7bbc47 193 GlobalError::MsgType ErrorType;
fdba4d53
DK
194
195 pkgCache::VerIterator canNotGetInstCandVer(pkgCacheFile &Cache,
196 pkgCache::PkgIterator const &Pkg);
197 pkgCache::VerIterator canNotGetCandInstVer(pkgCacheFile &Cache,
198 pkgCache::PkgIterator const &Pkg);
1e064088
DK
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);
70e706ad 205}; /*}}}*/
5c8c7321 206
15fc8636
DK
207class 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 */
217public:
218 class const_iterator { /*{{{*/
e1dbde8d 219 public:
15fc8636
DK
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(); }
7a669774
DK
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 }
15fc8636
DK
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(); }
d3e8fbb3
DK
246 inline pkgCache *Cache() const { return getPkg().Cache(); }
247 inline unsigned long Index() const {return getPkg().Index();}
78c32596 248 // we have only valid iterators here
d3e8fbb3 249 inline bool end() const { return false; }
e1dbde8d 250
d3e8fbb3 251 inline pkgCache::Package const * operator->() const {return &*getPkg();}
15fc8636
DK
252 };
253 /*}}}*/
254
255 virtual bool insert(pkgCache::PkgIterator const &P) = 0;
256 virtual bool empty() const = 0;
257 virtual void clear() = 0;
258
fdba4d53
DK
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) {}
15fc8636 277
1e064088
DK
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;
15fc8636 292
1e064088
DK
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
fdba4d53
DK
306
307private:
308 CacheSetHelper::PkgSelector ConstructedBy;
15fc8636
DK
309};
310 /*}}}*/
311template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
312/** \class APT::PackageContainer
e1dbde8d 313
15fc8636
DK
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;
318public: /*{{{*/
319 /** \brief smell like a pkgCache::PkgIterator */
c4cca791
DK
320 class const_iterator : public PackageContainerInterface::const_iterator,/*{{{*/
321 public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {
15fc8636
DK
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; }
d3e8fbb3 326 inline pkgCache::PkgIterator operator*(void) const { return *_iter; }
15fc8636 327 operator typename Container::const_iterator(void) const { return _iter; }
63b70b21
DK
328 inline const_iterator& operator++() { ++_iter; return *this; }
329 inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; }
d3e8fbb3
DK
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; }
15fc8636 332 friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
e1dbde8d 333 };
c4cca791
DK
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; }
d3e8fbb3 340 inline pkgCache::PkgIterator operator*(void) const { return *_iter; }
c4cca791 341 operator typename Container::iterator(void) const { return _iter; }
bce0e0ff 342 operator typename PackageContainer<Container>::const_iterator() { return typename PackageContainer<Container>::const_iterator(_iter); }
63b70b21
DK
343 inline iterator& operator++() { ++_iter; return *this; }
344 inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; }
d3e8fbb3
DK
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; }
c4cca791
DK
349 friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
350 };
dc0f01f7 351 /*}}}*/
ffee1c2b 352
d3e8fbb3
DK
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); }
c4cca791 356
d3e8fbb3
DK
357 bool empty() const { return _cont.empty(); }
358 void clear() { return _cont.clear(); }
5eb9a474 359 //FIXME: on ABI break, replace the first with the second without bool
d3e8fbb3
DK
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(); }
15fc8636 365
d3e8fbb3
DK
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)); }
15fc8636 371
fdba4d53
DK
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
c45f2d19 382
5c8c7321
DK
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
dc0f01f7
DK
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
c8db3fff 402 \param helper responsible for error and message handling */
15fc8636 403 static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
fdba4d53 404 PackageContainer cont(CacheSetHelper::TASK);
1e064088 405 helper.PackageFrom(CacheSetHelper::TASK, &cont, Cache, pattern);
15fc8636
DK
406 return cont;
407 }
408 static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern) {
70e706ad 409 CacheSetHelper helper;
446bbcf4 410 return FromTask(Cache, pattern, helper);
dc0f01f7
DK
411 }
412
ffee1c2b
DK
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
c8db3fff 420 \param helper responsible for error and message handling */
fdba4d53
DK
421 static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
422 PackageContainer cont(CacheSetHelper::REGEX);
1e064088 423 helper.PackageFrom(CacheSetHelper::REGEX, &cont, Cache, pattern);
15fc8636
DK
424 return cont;
425 }
426
427 static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern) {
70e706ad 428 CacheSetHelper helper;
446bbcf4 429 return FromRegEx(Cache, pattern, helper);
ffee1c2b
DK
430 }
431
fdba4d53
DK
432 static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
433 PackageContainer cont(CacheSetHelper::FNMATCH);
1e064088 434 helper.PackageFrom(CacheSetHelper::FNMATCH, &cont, Cache, pattern);
b9179170
MV
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
1e064088
DK
442#if __GNUC__ >= 4
443 #pragma GCC diagnostic push
444 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
445#endif
15fc8636 446 /** \brief returns a package specified by a string
856d3b06 447
15fc8636
DK
448 \param Cache the package is in
449 \param pattern String the package name should be extracted from
c8db3fff 450 \param helper responsible for error and message handling */
1e064088
DK
451 APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
452 return helper.PackageFromName(Cache, pattern);
15fc8636 453 }
1e064088 454 APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) {
70e706ad 455 CacheSetHelper helper;
1e064088 456 return FromName(Cache, pattern, helper);
856d3b06 457 }
1e064088
DK
458#if __GNUC__ >= 4
459 #pragma GCC diagnostic pop
460#endif
856d3b06 461
15fc8636 462 /** \brief returns all packages specified by a string
bd631595 463
15fc8636
DK
464 \param Cache the packages are in
465 \param pattern String the package name(s) should be extracted from
c8db3fff 466 \param helper responsible for error and message handling */
15fc8636
DK
467 static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
468 PackageContainer cont;
1e064088 469 helper.PackageFrom(CacheSetHelper::PACKAGENAME, &cont, Cache, pattern);
15fc8636
DK
470 return cont;
471 }
472 static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern) {
bd631595 473 CacheSetHelper helper;
15fc8636 474 return FromString(Cache, pattern, helper);
bd631595
DK
475 }
476
78c32596
DK
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
c8db3fff 483 \param helper responsible for error and message handling */
15fc8636
DK
484 static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
485 PackageContainer cont;
1e064088 486 helper.PackageFromCommandLine(&cont, Cache, cmdline);
15fc8636
DK
487 return cont;
488 }
489 static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
70e706ad 490 CacheSetHelper helper;
446bbcf4 491 return FromCommandLine(Cache, cmdline, helper);
78c32596 492 }
9cc83a6f 493
c8db3fff
DK
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 */
15fc8636
DK
505 static std::map<unsigned short, PackageContainer> GroupedFromCommandLine(
506 pkgCacheFile &Cache,
507 const char **cmdline,
1e064088 508 std::list<CacheSetHelper::PkgModifier> const &mods,
15fc8636
DK
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;
1e064088 515 helper.PackageFromModifierCommandLine(modID, &pkgset, Cache, *I, mods);
15fc8636
DK
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,
1e064088 523 std::list<CacheSetHelper::PkgModifier> const &mods,
15fc8636 524 unsigned short const &fallback) {
70e706ad 525 CacheSetHelper helper;
446bbcf4 526 return GroupedFromCommandLine(Cache, cmdline,
70e706ad 527 mods, fallback, helper);
9cc83a6f 528 }
c8db3fff 529 /*}}}*/
d4489d49 530}; /*}}}*/
5c8c7321 531// specialisations for push_back containers: std::list & std::vector /*{{{*/
c4cca791
DK
532template<> 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);
d3e8fbb3 535}
5c8c7321
DK
536template<> 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}
c4cca791
DK
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
542template<> 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;
d3e8fbb3 547}
5c8c7321
DK
548template<> 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}
c4cca791
DK
554template<> 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);
d3e8fbb3 557}
5c8c7321
DK
558template<> 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
564template<> 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
840ca971
DK
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. */
3809194b 577class APT_HIDDEN PackageUniverse : public PackageContainerInterface {
840ca971
DK
578 pkgCache * const _cont;
579public:
580 typedef pkgCache::PkgIterator iterator;
581 typedef pkgCache::PkgIterator const_iterator;
582
3809194b
DK
583 APT_PUBLIC bool empty() const { return false; }
584 APT_PUBLIC size_t size() const { return _cont->Head().PackageCount; }
840ca971 585
3809194b
DK
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(); }
840ca971 590
3809194b 591 APT_PUBLIC PackageUniverse(pkgCache * const Owner) : _cont(Owner) { }
840ca971
DK
592
593private:
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) { }
840ca971
DK
602};
603 /*}}}*/
15fc8636 604typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
c4cca791 605typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList;
5c8c7321 606typedef PackageContainer<std::vector<pkgCache::PkgIterator> > PackageVector;
78c32596 607
15fc8636
DK
608class VersionContainerInterface { /*{{{*/
609/** \class APT::VersionContainerInterface
610
611 Same as APT::PackageContainerInterface, just for Versions */
612public:
d4489d49 613 /** \brief smell like a pkgCache::VerIterator */
15fc8636 614 class const_iterator { /*{{{*/
d4489d49 615 public:
15fc8636
DK
616 virtual pkgCache::VerIterator getVer() const = 0;
617 operator pkgCache::VerIterator(void) { return getVer(); }
618
d3e8fbb3
DK
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(); }
d4489d49 636 // we have only valid iterators here
d3e8fbb3 637 inline bool end() const { return false; }
d4489d49 638
d3e8fbb3 639 inline pkgCache::Version const * operator->() const { return &*getVer(); }
d4489d49 640 };
dc0f01f7 641 /*}}}*/
78c32596 642
15fc8636
DK
643 virtual bool insert(pkgCache::VerIterator const &V) = 0;
644 virtual bool empty() const = 0;
645 virtual void clear() = 0;
c45f2d19 646
856d3b06 647 /** \brief specifies which version(s) will be returned if non is given */
fdba4d53
DK
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
856d3b06
DK
656 };
657
15fc8636 658 struct Modifier {
fdba4d53 659 unsigned short const ID;
15fc8636 660 const char * const Alias;
fdba4d53
DK
661 enum Position { NONE, PREFIX, POSTFIX } const Pos;
662 enum CacheSetHelper::VerSelector const SelectVersion;
15fc8636 663 Modifier (unsigned short const &id, const char * const alias, Position const &pos,
fdba4d53 664 enum CacheSetHelper::VerSelector const select) : ID(id), Alias(alias), Pos(pos),
d3e8fbb3 665 SelectVersion(select) {}
fdba4d53
DK
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
15fc8636
DK
676 };
677
678 static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
fdba4d53 679 const char **cmdline, CacheSetHelper::VerSelector const fallback,
15fc8636 680 CacheSetHelper &helper);
fdba4d53
DK
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
15fc8636
DK
693
694 static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
fdba4d53 695 std::string pkg, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
15fc8636 696 bool const onlyFromName = false);
fdba4d53
DK
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
15fc8636
DK
709
710 static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
fdba4d53 711 pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback,
15fc8636 712 CacheSetHelper &helper);
fdba4d53
DK
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
15fc8636
DK
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
c4cca791
DK
732
733 static bool FromDependency(VersionContainerInterface * const vci,
734 pkgCacheFile &Cache,
735 pkgCache::DepIterator const &D,
fdba4d53 736 CacheSetHelper::VerSelector const selector,
c4cca791 737 CacheSetHelper &helper);
fdba4d53
DK
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
c4cca791 752
15fc8636
DK
753protected: /*{{{*/
754
755 /** \brief returns the candidate version of the package
756
757 \param Cache to be used to query for information
255c9e4b
DK
758 \param Pkg we want the candidate version from this package
759 \param helper used in this container instance */
15fc8636
DK
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
255c9e4b
DK
766 \param Pkg we want the installed version from this package
767 \param helper used in this container instance */
15fc8636
DK
768 static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache,
769 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
770 /*}}}*/
771};
772 /*}}}*/
773template<class Container> class VersionContainer : public VersionContainerInterface {/*{{{*/
c4cca791 774/** \class APT::VersionContainer
15fc8636
DK
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;
780public: /*{{{*/
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; }
d3e8fbb3 788 inline pkgCache::VerIterator operator*(void) const { return *_iter; }
15fc8636 789 operator typename Container::const_iterator(void) const { return _iter; }
63b70b21
DK
790 inline const_iterator& operator++() { ++_iter; return *this; }
791 inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; }
d3e8fbb3
DK
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; }
15fc8636
DK
794 friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
795 };
c4cca791
DK
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; }
d3e8fbb3 802 inline pkgCache::VerIterator operator*(void) const { return *_iter; }
c4cca791 803 operator typename Container::iterator(void) const { return _iter; }
bce0e0ff 804 operator typename VersionContainer<Container>::const_iterator() { return typename VersionContainer<Container>::const_iterator(_iter); }
63b70b21
DK
805 inline iterator& operator++() { ++_iter; return *this; }
806 inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; }
d3e8fbb3
DK
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; }
c4cca791
DK
811 friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
812 };
15fc8636
DK
813 /*}}}*/
814
d3e8fbb3
DK
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(); }
5eb9a474 820 //FIXME: on ABI break, replace the first with the second without bool
d3e8fbb3
DK
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)); }
15fc8636 832
5c8c7321
DK
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
856d3b06
DK
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
255c9e4b 851 \param fallback version specification
c8db3fff 852 \param helper responsible for error and message handling */
15fc8636 853 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
fdba4d53 854 CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
15fc8636
DK
855 VersionContainer vercon;
856 VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper);
857 return vercon;
858 }
859 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
fdba4d53 860 CacheSetHelper::VerSelector const fallback) {
70e706ad 861 CacheSetHelper helper;
446bbcf4 862 return FromCommandLine(Cache, cmdline, fallback, helper);
856d3b06 863 }
15fc8636 864 static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
fdba4d53 865 return FromCommandLine(Cache, cmdline, CacheSetHelper::CANDINST);
856d3b06 866 }
15fc8636 867 static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
fdba4d53 868 CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
80624be7 869 bool const /*onlyFromName = false*/) {
15fc8636
DK
870 VersionContainer vercon;
871 VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper);
872 return vercon;
873 }
874 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
fdba4d53 875 CacheSetHelper::VerSelector const fallback) {
70e706ad 876 CacheSetHelper helper;
446bbcf4 877 return FromString(Cache, pkg, fallback, helper);
55c59998 878 }
15fc8636 879 static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) {
fdba4d53
DK
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);
55c59998 896 }
fdba4d53
DK
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
55c59998 912
fb83c1d0
DK
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 */
15fc8636 919 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
fdba4d53 920 CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
15fc8636
DK
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,
fdba4d53 926 CacheSetHelper::VerSelector const fallback) {
c8db3fff 927 CacheSetHelper helper;
446bbcf4 928 return FromPackage(Cache, P, fallback, helper);
c8db3fff 929 }
fdba4d53
DK
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
15fc8636 948 static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
fdba4d53 949 return FromPackage(Cache, P, CacheSetHelper::CANDIDATE);
c8db3fff 950 }
fb83c1d0 951
15fc8636
DK
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;
55c59998 966
15fc8636
DK
967 }
968 static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
55c59998 969 pkgCacheFile &Cache, const char **cmdline,
15fc8636
DK
970 std::list<Modifier> const &mods,
971 unsigned short const fallback) {
70e706ad 972 CacheSetHelper helper;
446bbcf4 973 return GroupedFromCommandLine(Cache, cmdline,
70e706ad 974 mods, fallback, helper);
55c59998 975 }
c4cca791
DK
976
977 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
fdba4d53 978 CacheSetHelper::VerSelector const selector, CacheSetHelper &helper) {
c4cca791
DK
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,
fdba4d53 984 CacheSetHelper::VerSelector const selector) {
c4cca791
DK
985 CacheSetHelper helper;
986 return FromPackage(Cache, D, selector, helper);
987 }
fdba4d53
DK
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
c4cca791 1006 static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) {
fdba4d53 1007 return FromPackage(Cache, D, CacheSetHelper::CANDIDATE);
c4cca791 1008 }
856d3b06 1009 /*}}}*/
d4489d49 1010}; /*}}}*/
5c8c7321 1011// specialisations for push_back containers: std::list & std::vector /*{{{*/
c4cca791
DK
1012template<> 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);
d3e8fbb3 1015}
5c8c7321
DK
1016template<> 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}
c4cca791
DK
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
1022template<> 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;
d3e8fbb3 1027}
5c8c7321
DK
1028template<> 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}
c4cca791
DK
1034template<> 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);
d3e8fbb3 1037}
5c8c7321
DK
1038template<> 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
1044template<> 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
15fc8636 1049typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet;
c4cca791 1050typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList;
5c8c7321 1051typedef VersionContainer<std::vector<pkgCache::VerIterator> > VersionVector;
e1dbde8d
DK
1052}
1053#endif