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 | ||
6c139d6e | 22 | |
094a497d | 23 | #include <apt-pkg/pkgcache.h> |
a52f938b | 24 | #include <apt-pkg/md5.h> |
b35d2f5f | 25 | |
7635093c | 26 | #include <vector> |
a9fe5928 | 27 | |
b35d2f5f AL |
28 | class pkgSourceList; |
29 | class OpProgress; | |
2d11135a | 30 | class MMap; |
b2e465d6 | 31 | class pkgIndexFile; |
578bfd0a | 32 | |
92fcbfc1 | 33 | class pkgCacheGenerator /*{{{*/ |
578bfd0a | 34 | { |
f9eec0e7 | 35 | private: |
7e58ab0c | 36 | |
f9eec0e7 | 37 | pkgCache::StringItem *UniqHash[26]; |
a9fe5928 DK |
38 | map_ptrloc WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; |
39 | map_ptrloc WriteStringInMap(const char *String); | |
40 | map_ptrloc WriteStringInMap(const char *String, const unsigned long &Len); | |
41 | map_ptrloc AllocateInMap(const unsigned long &size); | |
7e58ab0c | 42 | |
578bfd0a AL |
43 | public: |
44 | ||
45 | class ListParser; | |
b2e465d6 | 46 | friend class ListParser; |
a9fe5928 DK |
47 | |
48 | template<typename Iter> class Dynamic { | |
a9fe5928 | 49 | public: |
7635093c DK |
50 | static std::vector<Iter*> toReMap; |
51 | Dynamic(Iter &I) { | |
52 | toReMap.push_back(&I); | |
a9fe5928 DK |
53 | } |
54 | ||
55 | ~Dynamic() { | |
7635093c | 56 | toReMap.pop_back(); |
a9fe5928 DK |
57 | } |
58 | }; | |
59 | ||
578bfd0a | 60 | protected: |
a9fe5928 | 61 | |
578bfd0a AL |
62 | DynamicMMap ⤅ |
63 | pkgCache Cache; | |
ddc1d8d0 | 64 | OpProgress *Progress; |
404ec98e | 65 | |
8f3ba4e8 | 66 | std::string PkgFileName; |
578bfd0a | 67 | pkgCache::PackageFile *CurrentFile; |
45415543 AL |
68 | |
69 | // Flag file dependencies | |
70 | bool FoundFileDeps; | |
578bfd0a | 71 | |
8f3ba4e8 DK |
72 | bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name); |
73 | bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch); | |
f55a958f | 74 | bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); |
a52f938b | 75 | bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); |
25396fb0 | 76 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
8f3ba4e8 | 77 | std::string const &Version, unsigned int const &Op, |
64dda04b | 78 | unsigned int const &Type, map_ptrloc* &OldDepLast); |
8f3ba4e8 DK |
79 | unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,unsigned long Next); |
80 | map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_ptrloc Next); | |
578bfd0a | 81 | |
b2e465d6 AL |
82 | public: |
83 | ||
f55a958f | 84 | unsigned long WriteUniqString(const char *S,unsigned int Size); |
8f3ba4e8 | 85 | inline unsigned long WriteUniqString(const std::string &S) {return WriteUniqString(S.c_str(),S.length());}; |
813c8eea | 86 | |
ddc1d8d0 | 87 | void DropProgress() {Progress = 0;}; |
8f3ba4e8 | 88 | bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index, |
b2e465d6 | 89 | unsigned long Flags = 0); |
ddc1d8d0 | 90 | bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0); |
ad00ae81 | 91 | inline pkgCache &GetCache() {return Cache;}; |
b0b4efb9 AL |
92 | inline pkgCache::PkgFileIterator GetCurFile() |
93 | {return pkgCache::PkgFileIterator(Cache,CurrentFile);}; | |
45415543 AL |
94 | |
95 | bool HasFileDeps() {return FoundFileDeps;}; | |
96 | bool MergeFileProvides(ListParser &List); | |
2e5f4e45 DK |
97 | bool FinishCache(OpProgress *Progress); |
98 | ||
99 | static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, | |
100 | MMap **OutMap = 0,bool AllowMem = false); | |
101 | static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap); | |
dcdf1ef1 | 102 | static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0); |
25396fb0 | 103 | |
a9fe5928 DK |
104 | void ReMap(void const * const oldMap, void const * const newMap); |
105 | ||
b2e465d6 | 106 | pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress); |
578bfd0a | 107 | ~pkgCacheGenerator(); |
99a2ea5a DK |
108 | |
109 | private: | |
110 | bool MergeListGroup(ListParser &List, std::string const &GrpName); | |
111 | bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg); | |
112 | bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, | |
113 | std::string const &Version, pkgCache::VerIterator* &OutVer); | |
578bfd0a | 114 | }; |
92fcbfc1 DK |
115 | /*}}}*/ |
116 | // This is the abstract package list parser class. /*{{{*/ | |
f55ece0e AL |
117 | class pkgCacheGenerator::ListParser |
118 | { | |
119 | pkgCacheGenerator *Owner; | |
b2e465d6 | 120 | friend class pkgCacheGenerator; |
f55ece0e | 121 | |
f9eec0e7 AL |
122 | // Some cache items |
123 | pkgCache::VerIterator OldDepVer; | |
349cd3b8 | 124 | map_ptrloc *OldDepLast; |
45415543 AL |
125 | |
126 | // Flag file dependencies | |
127 | bool FoundFileDeps; | |
f9eec0e7 | 128 | |
f55ece0e | 129 | protected: |
813c8eea | 130 | |
8f3ba4e8 | 131 | inline unsigned long WriteUniqString(std::string S) {return Owner->WriteUniqString(S);}; |
f55ece0e | 132 | inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);}; |
8f3ba4e8 | 133 | inline unsigned long WriteString(const std::string &S) {return Owner->WriteStringInMap(S);}; |
7e58ab0c | 134 | inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; |
8f3ba4e8 DK |
135 | bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch, |
136 | const std::string &Version,unsigned int Op, | |
f55ece0e | 137 | unsigned int Type); |
8f3ba4e8 DK |
138 | bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName, |
139 | const std::string &PkgArch, const std::string &Version); | |
f55ece0e AL |
140 | |
141 | public: | |
142 | ||
143 | // These all operate against the current section | |
8f3ba4e8 DK |
144 | virtual std::string Package() = 0; |
145 | virtual std::string Architecture() = 0; | |
857e9c13 | 146 | virtual bool ArchitectureAll() = 0; |
8f3ba4e8 | 147 | virtual std::string Version() = 0; |
32b9a14c | 148 | virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; |
8f3ba4e8 DK |
149 | virtual std::string Description() = 0; |
150 | virtual std::string DescriptionLanguage() = 0; | |
a52f938b | 151 | virtual MD5SumValue Description_md5() = 0; |
204fbdcc | 152 | virtual unsigned short VersionHash() = 0; |
32b9a14c DK |
153 | virtual bool UsePackage(pkgCache::PkgIterator &Pkg, |
154 | pkgCache::VerIterator &Ver) = 0; | |
f55ece0e AL |
155 | virtual unsigned long Offset() = 0; |
156 | virtual unsigned long Size() = 0; | |
157 | ||
158 | virtual bool Step() = 0; | |
159 | ||
45415543 AL |
160 | inline bool HasFileDeps() {return FoundFileDeps;}; |
161 | virtual bool CollectFileProvides(pkgCache &Cache, | |
32b9a14c | 162 | pkgCache::VerIterator &Ver) {return true;}; |
45415543 AL |
163 | |
164 | ListParser() : FoundFileDeps(false) {}; | |
f55ece0e AL |
165 | virtual ~ListParser() {}; |
166 | }; | |
92fcbfc1 | 167 | /*}}}*/ |
2e5f4e45 | 168 | |
b2e465d6 AL |
169 | bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, |
170 | MMap **OutMap = 0,bool AllowMem = false); | |
171 | bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); | |
172 | ||
578bfd0a | 173 | #endif |