]>
Commit | Line | Data |
---|---|---|
578bfd0a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
45415543 | 3 | // $Id: pkgcachegen.h,v 1.19 2002/07/08 03:13:30 jgg Exp $ |
578bfd0a AL |
4 | /* ###################################################################### |
5 | ||
6 | Package Cache Generator - Generator for the cache structure. | |
7 | ||
8 | This builds the cache structure from the abstract package list parser. | |
6fc33863 AL |
9 | Each archive source has it's own list parser that is instantiated by |
10 | the caller to provide data for the generator. | |
11 | ||
12 | Parts of the cache are created by this generator class while other | |
13 | parts are created by the list parser. The list parser is responsible | |
14 | for creating version, depends and provides structures, and some of | |
15 | their contents | |
578bfd0a AL |
16 | |
17 | ##################################################################### */ | |
18 | /*}}}*/ | |
578bfd0a AL |
19 | #ifndef PKGLIB_PKGCACHEGEN_H |
20 | #define PKGLIB_PKGCACHEGEN_H | |
21 | ||
a52f938b | 22 | #include <apt-pkg/md5.h> |
453b82a3 DK |
23 | #include <apt-pkg/mmap.h> |
24 | #include <apt-pkg/pkgcache.h> | |
25 | #include <apt-pkg/cacheiterators.h> | |
5a8e963b | 26 | #include <apt-pkg/macros.h> |
b35d2f5f | 27 | |
7635093c | 28 | #include <vector> |
453b82a3 | 29 | #include <string> |
a9fe5928 | 30 | |
453b82a3 | 31 | class FileFd; |
b35d2f5f AL |
32 | class pkgSourceList; |
33 | class OpProgress; | |
b2e465d6 | 34 | class pkgIndexFile; |
578bfd0a | 35 | |
92fcbfc1 | 36 | class pkgCacheGenerator /*{{{*/ |
578bfd0a | 37 | { |
f9eec0e7 | 38 | private: |
7e58ab0c | 39 | |
f9eec0e7 | 40 | pkgCache::StringItem *UniqHash[26]; |
ce62f1de DK |
41 | APT_HIDDEN map_ptrloc WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; |
42 | APT_HIDDEN map_ptrloc WriteStringInMap(const char *String); | |
43 | APT_HIDDEN map_ptrloc WriteStringInMap(const char *String, const unsigned long &Len); | |
44 | APT_HIDDEN map_ptrloc AllocateInMap(const unsigned long &size); | |
7e58ab0c | 45 | |
578bfd0a AL |
46 | public: |
47 | ||
48 | class ListParser; | |
b2e465d6 | 49 | friend class ListParser; |
a9fe5928 DK |
50 | |
51 | template<typename Iter> class Dynamic { | |
a9fe5928 | 52 | public: |
7635093c DK |
53 | static std::vector<Iter*> toReMap; |
54 | Dynamic(Iter &I) { | |
55 | toReMap.push_back(&I); | |
a9fe5928 DK |
56 | } |
57 | ||
58 | ~Dynamic() { | |
7635093c | 59 | toReMap.pop_back(); |
a9fe5928 DK |
60 | } |
61 | }; | |
62 | ||
578bfd0a | 63 | protected: |
a9fe5928 | 64 | |
578bfd0a AL |
65 | DynamicMMap ⤅ |
66 | pkgCache Cache; | |
ddc1d8d0 | 67 | OpProgress *Progress; |
404ec98e | 68 | |
8f3ba4e8 | 69 | std::string PkgFileName; |
578bfd0a | 70 | pkgCache::PackageFile *CurrentFile; |
45415543 AL |
71 | |
72 | // Flag file dependencies | |
73 | bool FoundFileDeps; | |
578bfd0a | 74 | |
8f3ba4e8 DK |
75 | bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name); |
76 | bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch); | |
f55a958f | 77 | bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); |
a52f938b | 78 | bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); |
25396fb0 | 79 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
8f3ba4e8 | 80 | std::string const &Version, unsigned int const &Op, |
64dda04b | 81 | unsigned int const &Type, map_ptrloc* &OldDepLast); |
9c44383f DK |
82 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
83 | map_ptrloc const Version, unsigned int const &Op, | |
84 | unsigned int const &Type, map_ptrloc* &OldDepLast); | |
453b82a3 | 85 | unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,unsigned long Next) APT_DEPRECATED |
885594fc DK |
86 | { return NewVersion(Ver, VerStr, 0, 0, Next); } |
87 | unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr, | |
88 | map_ptrloc const ParentPkg, unsigned long const Hash, | |
89 | unsigned long Next); | |
8f3ba4e8 | 90 | map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_ptrloc Next); |
578bfd0a | 91 | |
b2e465d6 AL |
92 | public: |
93 | ||
f55a958f | 94 | unsigned long WriteUniqString(const char *S,unsigned int Size); |
8f3ba4e8 | 95 | inline unsigned long WriteUniqString(const std::string &S) {return WriteUniqString(S.c_str(),S.length());}; |
813c8eea | 96 | |
ddc1d8d0 | 97 | void DropProgress() {Progress = 0;}; |
8f3ba4e8 | 98 | bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index, |
b2e465d6 | 99 | unsigned long Flags = 0); |
ddc1d8d0 | 100 | bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0); |
ad00ae81 | 101 | inline pkgCache &GetCache() {return Cache;}; |
b0b4efb9 AL |
102 | inline pkgCache::PkgFileIterator GetCurFile() |
103 | {return pkgCache::PkgFileIterator(Cache,CurrentFile);}; | |
45415543 AL |
104 | |
105 | bool HasFileDeps() {return FoundFileDeps;}; | |
106 | bool MergeFileProvides(ListParser &List); | |
a02db58f | 107 | bool FinishCache(OpProgress *Progress) APT_DEPRECATED APT_CONST; |
2e5f4e45 DK |
108 | |
109 | static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, | |
110 | MMap **OutMap = 0,bool AllowMem = false); | |
111 | static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap); | |
dcdf1ef1 | 112 | static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0); |
25396fb0 | 113 | |
a9fe5928 DK |
114 | void ReMap(void const * const oldMap, void const * const newMap); |
115 | ||
b2e465d6 | 116 | pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress); |
578bfd0a | 117 | ~pkgCacheGenerator(); |
99a2ea5a DK |
118 | |
119 | private: | |
ce62f1de DK |
120 | APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName); |
121 | APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg); | |
122 | APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, | |
99a2ea5a | 123 | std::string const &Version, pkgCache::VerIterator* &OutVer); |
5a8e963b | 124 | |
ce62f1de | 125 | APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P, |
5a8e963b | 126 | pkgCache::VerIterator &V); |
ce62f1de | 127 | APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D); |
ffe3c68e DK |
128 | |
129 | APT_HIDDEN bool AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver, | |
130 | std::string const &lang, MD5SumValue const &CurMd5, map_ptrloc &md5idx); | |
578bfd0a | 131 | }; |
92fcbfc1 DK |
132 | /*}}}*/ |
133 | // This is the abstract package list parser class. /*{{{*/ | |
f55ece0e AL |
134 | class pkgCacheGenerator::ListParser |
135 | { | |
136 | pkgCacheGenerator *Owner; | |
b2e465d6 | 137 | friend class pkgCacheGenerator; |
f55ece0e | 138 | |
f9eec0e7 AL |
139 | // Some cache items |
140 | pkgCache::VerIterator OldDepVer; | |
349cd3b8 | 141 | map_ptrloc *OldDepLast; |
45415543 AL |
142 | |
143 | // Flag file dependencies | |
144 | bool FoundFileDeps; | |
f9eec0e7 | 145 | |
f55ece0e | 146 | protected: |
813c8eea | 147 | |
8f3ba4e8 | 148 | inline unsigned long WriteUniqString(std::string S) {return Owner->WriteUniqString(S);}; |
f55ece0e | 149 | inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);}; |
8f3ba4e8 | 150 | inline unsigned long WriteString(const std::string &S) {return Owner->WriteStringInMap(S);}; |
7e58ab0c | 151 | inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; |
8f3ba4e8 DK |
152 | bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch, |
153 | const std::string &Version,unsigned int Op, | |
f55ece0e | 154 | unsigned int Type); |
8f3ba4e8 DK |
155 | bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName, |
156 | const std::string &PkgArch, const std::string &Version); | |
f55ece0e AL |
157 | |
158 | public: | |
159 | ||
160 | // These all operate against the current section | |
8f3ba4e8 DK |
161 | virtual std::string Package() = 0; |
162 | virtual std::string Architecture() = 0; | |
857e9c13 | 163 | virtual bool ArchitectureAll() = 0; |
8f3ba4e8 | 164 | virtual std::string Version() = 0; |
32b9a14c | 165 | virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; |
ffe3c68e DK |
166 | virtual std::string Description(std::string const &lang) = 0; |
167 | virtual std::vector<std::string> AvailableDescriptionLanguages() = 0; | |
a52f938b | 168 | virtual MD5SumValue Description_md5() = 0; |
204fbdcc | 169 | virtual unsigned short VersionHash() = 0; |
68134bda DK |
170 | /** compare currently parsed version with given version |
171 | * | |
172 | * \param Hash of the currently parsed version | |
173 | * \param Ver to compare with | |
174 | */ | |
175 | #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13) | |
176 | virtual | |
177 | #endif | |
178 | APT_PURE bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver); | |
32b9a14c DK |
179 | virtual bool UsePackage(pkgCache::PkgIterator &Pkg, |
180 | pkgCache::VerIterator &Ver) = 0; | |
f55ece0e AL |
181 | virtual unsigned long Offset() = 0; |
182 | virtual unsigned long Size() = 0; | |
183 | ||
184 | virtual bool Step() = 0; | |
185 | ||
45415543 | 186 | inline bool HasFileDeps() {return FoundFileDeps;}; |
65512241 DK |
187 | virtual bool CollectFileProvides(pkgCache &/*Cache*/, |
188 | pkgCache::VerIterator &/*Ver*/) {return true;}; | |
45415543 AL |
189 | |
190 | ListParser() : FoundFileDeps(false) {}; | |
f55ece0e AL |
191 | virtual ~ListParser() {}; |
192 | }; | |
92fcbfc1 | 193 | /*}}}*/ |
2e5f4e45 | 194 | |
b2e465d6 AL |
195 | bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, |
196 | MMap **OutMap = 0,bool AllowMem = false); | |
197 | bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); | |
198 | ||
578bfd0a | 199 | #endif |