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