]>
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 | |
a9fe5928 DK |
26 | #include <set> |
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 { | |
49 | Iter *I; | |
50 | ||
51 | public: | |
52 | static std::set<Iter*> toReMap; | |
53 | Dynamic(Iter &It) : I(&It) { | |
54 | toReMap.insert(I); | |
55 | } | |
56 | ||
57 | ~Dynamic() { | |
58 | toReMap.erase(I); | |
59 | } | |
60 | }; | |
61 | ||
578bfd0a | 62 | protected: |
a9fe5928 | 63 | |
578bfd0a AL |
64 | DynamicMMap ⤅ |
65 | pkgCache Cache; | |
ddc1d8d0 | 66 | OpProgress *Progress; |
404ec98e | 67 | |
578bfd0a AL |
68 | string PkgFileName; |
69 | pkgCache::PackageFile *CurrentFile; | |
45415543 AL |
70 | |
71 | // Flag file dependencies | |
72 | bool FoundFileDeps; | |
578bfd0a | 73 | |
5bf15716 DK |
74 | bool NewGroup(pkgCache::GrpIterator &Grp,const string &Name); |
75 | bool NewPackage(pkgCache::PkgIterator &Pkg,const string &Name, const string &Arch); | |
f55a958f | 76 | bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); |
a52f938b | 77 | bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); |
25396fb0 DK |
78 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
79 | string const &Version, unsigned int const &Op, | |
80 | unsigned int const &Type, map_ptrloc *OldDepLast); | |
171c75f1 | 81 | unsigned long NewVersion(pkgCache::VerIterator &Ver,const string &VerStr,unsigned long Next); |
a52f938b | 82 | map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const string &Lang,const MD5SumValue &md5sum,map_ptrloc Next); |
578bfd0a | 83 | |
b2e465d6 AL |
84 | public: |
85 | ||
f55a958f | 86 | unsigned long WriteUniqString(const char *S,unsigned int Size); |
171c75f1 | 87 | inline unsigned long WriteUniqString(const string &S) {return WriteUniqString(S.c_str(),S.length());}; |
813c8eea | 88 | |
ddc1d8d0 | 89 | void DropProgress() {Progress = 0;}; |
171c75f1 | 90 | bool SelectFile(const string &File,const string &Site,pkgIndexFile const &Index, |
b2e465d6 | 91 | unsigned long Flags = 0); |
ddc1d8d0 | 92 | bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0); |
ad00ae81 | 93 | inline pkgCache &GetCache() {return Cache;}; |
b0b4efb9 AL |
94 | inline pkgCache::PkgFileIterator GetCurFile() |
95 | {return pkgCache::PkgFileIterator(Cache,CurrentFile);}; | |
45415543 AL |
96 | |
97 | bool HasFileDeps() {return FoundFileDeps;}; | |
98 | bool MergeFileProvides(ListParser &List); | |
2e5f4e45 DK |
99 | bool FinishCache(OpProgress *Progress); |
100 | ||
101 | static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, | |
102 | MMap **OutMap = 0,bool AllowMem = false); | |
103 | static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap); | |
25396fb0 | 104 | |
a9fe5928 DK |
105 | void ReMap(void const * const oldMap, void const * const newMap); |
106 | ||
b2e465d6 | 107 | pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress); |
578bfd0a AL |
108 | ~pkgCacheGenerator(); |
109 | }; | |
92fcbfc1 DK |
110 | /*}}}*/ |
111 | // This is the abstract package list parser class. /*{{{*/ | |
f55ece0e AL |
112 | class pkgCacheGenerator::ListParser |
113 | { | |
114 | pkgCacheGenerator *Owner; | |
b2e465d6 | 115 | friend class pkgCacheGenerator; |
f55ece0e | 116 | |
f9eec0e7 AL |
117 | // Some cache items |
118 | pkgCache::VerIterator OldDepVer; | |
349cd3b8 | 119 | map_ptrloc *OldDepLast; |
45415543 AL |
120 | |
121 | // Flag file dependencies | |
122 | bool FoundFileDeps; | |
f9eec0e7 | 123 | |
f55ece0e | 124 | protected: |
813c8eea | 125 | |
f55ece0e AL |
126 | inline unsigned long WriteUniqString(string S) {return Owner->WriteUniqString(S);}; |
127 | inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);}; | |
7e58ab0c DK |
128 | inline unsigned long WriteString(const string &S) {return Owner->WriteStringInMap(S);}; |
129 | inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; | |
32b9a14c | 130 | bool NewDepends(pkgCache::VerIterator &Ver,const string &Package, const string &Arch, |
171c75f1 | 131 | const string &Version,unsigned int Op, |
f55ece0e | 132 | unsigned int Type); |
32b9a14c | 133 | bool NewProvides(pkgCache::VerIterator &Ver,const string &PkgName, |
67e0766f | 134 | const string &PkgArch, const string &Version); |
f55ece0e AL |
135 | |
136 | public: | |
137 | ||
138 | // These all operate against the current section | |
139 | virtual string Package() = 0; | |
5bf15716 | 140 | virtual string Architecture() = 0; |
857e9c13 | 141 | virtual bool ArchitectureAll() = 0; |
f55ece0e | 142 | virtual string Version() = 0; |
32b9a14c | 143 | virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; |
a52f938b OS |
144 | virtual string Description() = 0; |
145 | virtual string DescriptionLanguage() = 0; | |
146 | virtual MD5SumValue Description_md5() = 0; | |
204fbdcc | 147 | virtual unsigned short VersionHash() = 0; |
32b9a14c DK |
148 | virtual bool UsePackage(pkgCache::PkgIterator &Pkg, |
149 | pkgCache::VerIterator &Ver) = 0; | |
f55ece0e AL |
150 | virtual unsigned long Offset() = 0; |
151 | virtual unsigned long Size() = 0; | |
152 | ||
153 | virtual bool Step() = 0; | |
154 | ||
45415543 AL |
155 | inline bool HasFileDeps() {return FoundFileDeps;}; |
156 | virtual bool CollectFileProvides(pkgCache &Cache, | |
32b9a14c | 157 | pkgCache::VerIterator &Ver) {return true;}; |
45415543 AL |
158 | |
159 | ListParser() : FoundFileDeps(false) {}; | |
f55ece0e AL |
160 | virtual ~ListParser() {}; |
161 | }; | |
92fcbfc1 | 162 | /*}}}*/ |
2e5f4e45 | 163 | |
b2e465d6 AL |
164 | bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, |
165 | MMap **OutMap = 0,bool AllowMem = false); | |
166 | bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); | |
167 | ||
2e5f4e45 | 168 | |
b2e465d6 AL |
169 | #ifdef APT_COMPATIBILITY |
170 | #if APT_COMPATIBILITY != 986 | |
171 | #warning "Using APT_COMPATIBILITY" | |
172 | #endif | |
173 | MMap *pkgMakeStatusCacheMem(pkgSourceList &List,OpProgress &Progress) | |
174 | { | |
175 | MMap *Map = 0; | |
2e5f4e45 | 176 | if (pkgCacheGenerator::MakeStatusCache(List,&Progress,&Map,true) == false) |
b2e465d6 AL |
177 | return 0; |
178 | return Map; | |
179 | } | |
180 | #endif | |
ddc1d8d0 | 181 | |
578bfd0a | 182 | #endif |