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