* doc/apt.conf.5.xml:
[ntk/apt.git] / apt-pkg / pkgcachegen.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: pkgcachegen.h,v 1.19 2002/07/08 03:13:30 jgg Exp $
4 /* ######################################################################
5
6 Package Cache Generator - Generator for the cache structure.
7
8 This builds the cache structure from the abstract package list parser.
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
16
17 ##################################################################### */
18 /*}}}*/
19 #ifndef PKGLIB_PKGCACHEGEN_H
20 #define PKGLIB_PKGCACHEGEN_H
21
22
23 #include <apt-pkg/pkgcache.h>
24 #include <apt-pkg/md5.h>
25
26 #include <set>
27
28 class pkgSourceList;
29 class OpProgress;
30 class MMap;
31 class pkgIndexFile;
32
33 class pkgCacheGenerator /*{{{*/
34 {
35 private:
36
37 pkgCache::StringItem *UniqHash[26];
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);
42
43 public:
44
45 class ListParser;
46 friend class ListParser;
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
62 protected:
63
64 DynamicMMap &Map;
65 pkgCache Cache;
66 OpProgress *Progress;
67
68 string PkgFileName;
69 pkgCache::PackageFile *CurrentFile;
70
71 // Flag file dependencies
72 bool FoundFileDeps;
73
74 bool NewGroup(pkgCache::GrpIterator &Grp,const string &Name);
75 bool NewPackage(pkgCache::PkgIterator &Pkg,const string &Name, const string &Arch);
76 bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
77 bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
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);
81 unsigned long NewVersion(pkgCache::VerIterator &Ver,const string &VerStr,unsigned long Next);
82 map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const string &Lang,const MD5SumValue &md5sum,map_ptrloc Next);
83
84 public:
85
86 unsigned long WriteUniqString(const char *S,unsigned int Size);
87 inline unsigned long WriteUniqString(const string &S) {return WriteUniqString(S.c_str(),S.length());};
88
89 void DropProgress() {Progress = 0;};
90 bool SelectFile(const string &File,const string &Site,pkgIndexFile const &Index,
91 unsigned long Flags = 0);
92 bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
93 inline pkgCache &GetCache() {return Cache;};
94 inline pkgCache::PkgFileIterator GetCurFile()
95 {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
96
97 bool HasFileDeps() {return FoundFileDeps;};
98 bool MergeFileProvides(ListParser &List);
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);
104 static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0);
105
106 void ReMap(void const * const oldMap, void const * const newMap);
107
108 pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
109 ~pkgCacheGenerator();
110 };
111 /*}}}*/
112 // This is the abstract package list parser class. /*{{{*/
113 class pkgCacheGenerator::ListParser
114 {
115 pkgCacheGenerator *Owner;
116 friend class pkgCacheGenerator;
117
118 // Some cache items
119 pkgCache::VerIterator OldDepVer;
120 map_ptrloc *OldDepLast;
121
122 // Flag file dependencies
123 bool FoundFileDeps;
124
125 protected:
126
127 inline unsigned long WriteUniqString(string S) {return Owner->WriteUniqString(S);};
128 inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);};
129 inline unsigned long WriteString(const string &S) {return Owner->WriteStringInMap(S);};
130 inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
131 bool NewDepends(pkgCache::VerIterator &Ver,const string &Package, const string &Arch,
132 const string &Version,unsigned int Op,
133 unsigned int Type);
134 bool NewProvides(pkgCache::VerIterator &Ver,const string &PkgName,
135 const string &PkgArch, const string &Version);
136
137 public:
138
139 // These all operate against the current section
140 virtual string Package() = 0;
141 virtual string Architecture() = 0;
142 virtual bool ArchitectureAll() = 0;
143 virtual string Version() = 0;
144 virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0;
145 virtual string Description() = 0;
146 virtual string DescriptionLanguage() = 0;
147 virtual MD5SumValue Description_md5() = 0;
148 virtual unsigned short VersionHash() = 0;
149 virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
150 pkgCache::VerIterator &Ver) = 0;
151 virtual unsigned long Offset() = 0;
152 virtual unsigned long Size() = 0;
153
154 virtual bool Step() = 0;
155
156 inline bool HasFileDeps() {return FoundFileDeps;};
157 virtual bool CollectFileProvides(pkgCache &Cache,
158 pkgCache::VerIterator &Ver) {return true;};
159
160 ListParser() : FoundFileDeps(false) {};
161 virtual ~ListParser() {};
162 };
163 /*}}}*/
164
165 bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
166 MMap **OutMap = 0,bool AllowMem = false);
167 bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
168
169
170 #ifdef APT_COMPATIBILITY
171 #if APT_COMPATIBILITY != 986
172 #warning "Using APT_COMPATIBILITY"
173 #endif
174 MMap *pkgMakeStatusCacheMem(pkgSourceList &List,OpProgress &Progress)
175 {
176 MMap *Map = 0;
177 if (pkgCacheGenerator::MakeStatusCache(List,&Progress,&Map,true) == false)
178 return 0;
179 return Map;
180 }
181 #endif
182
183 #endif