]>
Commit | Line | Data |
---|---|---|
1 | #ifndef APT_PRIVATE_CACHESET_H | |
2 | #define APT_PRIVATE_CACHESET_H | |
3 | ||
4 | #include <apt-pkg/cacheset.h> | |
5 | #include <apt-pkg/macros.h> | |
6 | ||
7 | #include <apt-private/private-output.h> | |
8 | ||
9 | #include <vector> | |
10 | #include <list> | |
11 | #include <set> | |
12 | #include <string> | |
13 | ||
14 | #include <apti18n.h> | |
15 | ||
16 | class OpProgress; | |
17 | ||
18 | class VerIteratorWithCaching | |
19 | { | |
20 | const pkgCache::VerIterator iter; | |
21 | const pkgCache::DescFile * descFile; | |
22 | public: | |
23 | VerIteratorWithCaching(const pkgCache::VerIterator& iter) : | |
24 | iter(iter), | |
25 | descFile(iter->DescriptionList != 0 | |
26 | ? (const pkgCache::DescFile *) iter.TranslatedDescription().FileList() | |
27 | : nullptr) | |
28 | {} | |
29 | const pkgCache::DescFile * CachedDescFile() const { return descFile; } | |
30 | operator pkgCache::VerIterator() const { return iter; } | |
31 | }; | |
32 | ||
33 | struct VersionSortDescriptionLocality /*{{{*/ | |
34 | { | |
35 | bool operator () (const VerIteratorWithCaching &v_lhs, | |
36 | const VerIteratorWithCaching &v_rhs) | |
37 | { | |
38 | pkgCache::DescFile const *A = v_lhs.CachedDescFile(); | |
39 | pkgCache::DescFile const *B = v_rhs.CachedDescFile(); | |
40 | ||
41 | if (A == nullptr && B == nullptr) | |
42 | return false; | |
43 | ||
44 | if (A == nullptr) | |
45 | return true; | |
46 | ||
47 | if (B == nullptr) | |
48 | return false; | |
49 | ||
50 | if (A->File == B->File) | |
51 | return A->Offset < B->Offset; | |
52 | ||
53 | return A->File < B->File; | |
54 | } | |
55 | }; | |
56 | /*}}}*/ | |
57 | // sorted by locality which makes iterating much faster | |
58 | typedef APT::VersionContainer< | |
59 | std::set<VerIteratorWithCaching, | |
60 | VersionSortDescriptionLocality> > LocalitySortedVersionSet; | |
61 | ||
62 | class Matcher { | |
63 | public: | |
64 | virtual bool operator () (const pkgCache::PkgIterator &/*P*/) { | |
65 | return true;} | |
66 | }; | |
67 | ||
68 | // FIXME: add default argument for OpProgress (or overloaded function) | |
69 | bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, | |
70 | APT::VersionContainerInterface * const vci, | |
71 | Matcher &matcher, | |
72 | OpProgress * const progress); | |
73 | bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, | |
74 | APT::VersionContainerInterface * const vci, | |
75 | OpProgress * const progress); | |
76 | ||
77 | ||
78 | // CacheSetHelper saving virtual packages /*{{{*/ | |
79 | class CacheSetHelperVirtuals: public APT::CacheSetHelper { | |
80 | public: | |
81 | APT::PackageSet virtualPkgs; | |
82 | ||
83 | virtual pkgCache::VerIterator canNotGetVersion(enum CacheSetHelper::VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE; | |
84 | virtual void canNotFindVersion(enum CacheSetHelper::VerSelector const select, APT::VersionContainerInterface * vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE; | |
85 | virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str) APT_OVERRIDE; | |
86 | ||
87 | CacheSetHelperVirtuals(bool const ShowErrors = true, GlobalError::MsgType const &ErrorType = GlobalError::NOTICE); | |
88 | }; | |
89 | /*}}}*/ | |
90 | ||
91 | // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/ | |
92 | class CacheSetHelperAPTGet : public APT::CacheSetHelper { | |
93 | /** \brief stream message should be printed to */ | |
94 | std::ostream &out; | |
95 | /** \brief were things like Task or RegEx used to select packages? */ | |
96 | bool explicitlyNamed; | |
97 | ||
98 | APT::PackageSet virtualPkgs; | |
99 | ||
100 | public: | |
101 | std::list<std::pair<pkgCache::VerIterator, std::string> > selectedByRelease; | |
102 | ||
103 | explicit CacheSetHelperAPTGet(std::ostream &out); | |
104 | ||
105 | virtual void showTaskSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE; | |
106 | virtual void showFnmatchSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE; | |
107 | virtual void showRegExSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE; | |
108 | virtual void showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/, pkgCache::VerIterator const Ver, | |
109 | std::string const &ver, bool const /*verIsRel*/) APT_OVERRIDE; | |
110 | bool showVirtualPackageErrors(pkgCacheFile &Cache); | |
111 | ||
112 | virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE; | |
113 | virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE; | |
114 | virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str) APT_OVERRIDE; | |
115 | ||
116 | APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, | |
117 | CacheSetHelper::VerSelector const select); | |
118 | ||
119 | inline bool allPkgNamedExplicitly() const { return explicitlyNamed; } | |
120 | }; | |
121 | /*}}}*/ | |
122 | ||
123 | #endif |