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