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