]>
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 | |
578bfd0a AL |
66 | string PkgFileName; |
67 | pkgCache::PackageFile *CurrentFile; | |
45415543 AL |
68 | |
69 | // Flag file dependencies | |
70 | bool FoundFileDeps; | |
578bfd0a | 71 | |
5bf15716 DK |
72 | bool NewGroup(pkgCache::GrpIterator &Grp,const string &Name); |
73 | bool NewPackage(pkgCache::PkgIterator &Pkg,const string &Name, const string &Arch); | |
f55a958f | 74 | bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); |
a52f938b | 75 | bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); |
25396fb0 DK |
76 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
77 | string const &Version, unsigned int const &Op, | |
78 | unsigned int const &Type, map_ptrloc *OldDepLast); | |
171c75f1 | 79 | unsigned long NewVersion(pkgCache::VerIterator &Ver,const string &VerStr,unsigned long Next); |
a52f938b | 80 | map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const 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); |
171c75f1 | 85 | inline unsigned long WriteUniqString(const string &S) {return WriteUniqString(S.c_str(),S.length());}; |
813c8eea | 86 | |
ddc1d8d0 | 87 | void DropProgress() {Progress = 0;}; |
171c75f1 | 88 | bool SelectFile(const string &File,const 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 AL |
107 | ~pkgCacheGenerator(); |
108 | }; | |
92fcbfc1 DK |
109 | /*}}}*/ |
110 | // This is the abstract package list parser class. /*{{{*/ | |
f55ece0e AL |
111 | class pkgCacheGenerator::ListParser |
112 | { | |
113 | pkgCacheGenerator *Owner; | |
b2e465d6 | 114 | friend class pkgCacheGenerator; |
f55ece0e | 115 | |
f9eec0e7 AL |
116 | // Some cache items |
117 | pkgCache::VerIterator OldDepVer; | |
349cd3b8 | 118 | map_ptrloc *OldDepLast; |
45415543 AL |
119 | |
120 | // Flag file dependencies | |
121 | bool FoundFileDeps; | |
f9eec0e7 | 122 | |
f55ece0e | 123 | protected: |
813c8eea | 124 | |
f55ece0e AL |
125 | inline unsigned long WriteUniqString(string S) {return Owner->WriteUniqString(S);}; |
126 | inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);}; | |
7e58ab0c DK |
127 | inline unsigned long WriteString(const string &S) {return Owner->WriteStringInMap(S);}; |
128 | inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; | |
32b9a14c | 129 | bool NewDepends(pkgCache::VerIterator &Ver,const string &Package, const string &Arch, |
171c75f1 | 130 | const string &Version,unsigned int Op, |
f55ece0e | 131 | unsigned int Type); |
32b9a14c | 132 | bool NewProvides(pkgCache::VerIterator &Ver,const string &PkgName, |
67e0766f | 133 | const string &PkgArch, const string &Version); |
f55ece0e AL |
134 | |
135 | public: | |
136 | ||
137 | // These all operate against the current section | |
138 | virtual string Package() = 0; | |
5bf15716 | 139 | virtual string Architecture() = 0; |
857e9c13 | 140 | virtual bool ArchitectureAll() = 0; |
f55ece0e | 141 | virtual string Version() = 0; |
32b9a14c | 142 | virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; |
a52f938b OS |
143 | virtual string Description() = 0; |
144 | virtual string DescriptionLanguage() = 0; | |
145 | virtual MD5SumValue Description_md5() = 0; | |
204fbdcc | 146 | virtual unsigned short VersionHash() = 0; |
32b9a14c DK |
147 | virtual bool UsePackage(pkgCache::PkgIterator &Pkg, |
148 | pkgCache::VerIterator &Ver) = 0; | |
f55ece0e AL |
149 | virtual unsigned long Offset() = 0; |
150 | virtual unsigned long Size() = 0; | |
151 | ||
152 | virtual bool Step() = 0; | |
153 | ||
45415543 AL |
154 | inline bool HasFileDeps() {return FoundFileDeps;}; |
155 | virtual bool CollectFileProvides(pkgCache &Cache, | |
32b9a14c | 156 | pkgCache::VerIterator &Ver) {return true;}; |
45415543 AL |
157 | |
158 | ListParser() : FoundFileDeps(false) {}; | |
f55ece0e AL |
159 | virtual ~ListParser() {}; |
160 | }; | |
92fcbfc1 | 161 | /*}}}*/ |
2e5f4e45 | 162 | |
b2e465d6 AL |
163 | bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, |
164 | MMap **OutMap = 0,bool AllowMem = false); | |
165 | bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); | |
166 | ||
2e5f4e45 | 167 | |
b2e465d6 AL |
168 | #ifdef APT_COMPATIBILITY |
169 | #if APT_COMPATIBILITY != 986 | |
170 | #warning "Using APT_COMPATIBILITY" | |
171 | #endif | |
172 | MMap *pkgMakeStatusCacheMem(pkgSourceList &List,OpProgress &Progress) | |
173 | { | |
174 | MMap *Map = 0; | |
2e5f4e45 | 175 | if (pkgCacheGenerator::MakeStatusCache(List,&Progress,&Map,true) == false) |
b2e465d6 AL |
176 | return 0; |
177 | return Map; | |
178 | } | |
179 | #endif | |
ddc1d8d0 | 180 | |
578bfd0a | 181 | #endif |