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