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