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