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