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