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