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