]> git.saurik.com Git - apt.git/blob - apt-pkg/pkgcachegen.h
99795bb1c4ff86f7c3e85d0784b8650d992c7872
[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 <vector>
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 public:
50 static std::vector<Iter*> toReMap;
51 Dynamic(Iter &I) {
52 toReMap.push_back(&I);
53 }
54
55 ~Dynamic() {
56 toReMap.pop_back();
57 }
58 };
59
60 protected:
61
62 DynamicMMap &Map;
63 pkgCache Cache;
64 OpProgress *Progress;
65
66 std::string PkgFileName;
67 pkgCache::PackageFile *CurrentFile;
68
69 // Flag file dependencies
70 bool FoundFileDeps;
71
72 bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name);
73 bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch);
74 bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
75 bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
76 bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
77 std::string const &Version, unsigned int const &Op,
78 unsigned int const &Type, map_ptrloc* &OldDepLast);
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);
81
82 public:
83
84 unsigned long WriteUniqString(const char *S,unsigned int Size);
85 inline unsigned long WriteUniqString(const std::string &S) {return WriteUniqString(S.c_str(),S.length());};
86
87 void DropProgress() {Progress = 0;};
88 bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index,
89 unsigned long Flags = 0);
90 bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
91 inline pkgCache &GetCache() {return Cache;};
92 inline pkgCache::PkgFileIterator GetCurFile()
93 {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
94
95 bool HasFileDeps() {return FoundFileDeps;};
96 bool MergeFileProvides(ListParser &List);
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);
102 static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0);
103
104 void ReMap(void const * const oldMap, void const * const newMap);
105
106 pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
107 ~pkgCacheGenerator();
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);
114 };
115 /*}}}*/
116 // This is the abstract package list parser class. /*{{{*/
117 class pkgCacheGenerator::ListParser
118 {
119 pkgCacheGenerator *Owner;
120 friend class pkgCacheGenerator;
121
122 // Some cache items
123 pkgCache::VerIterator OldDepVer;
124 map_ptrloc *OldDepLast;
125
126 // Flag file dependencies
127 bool FoundFileDeps;
128
129 protected:
130
131 inline unsigned long WriteUniqString(std::string S) {return Owner->WriteUniqString(S);};
132 inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);};
133 inline unsigned long WriteString(const std::string &S) {return Owner->WriteStringInMap(S);};
134 inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
135 bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch,
136 const std::string &Version,unsigned int Op,
137 unsigned int Type);
138 bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName,
139 const std::string &PkgArch, const std::string &Version);
140
141 public:
142
143 // These all operate against the current section
144 virtual std::string Package() = 0;
145 virtual std::string Architecture() = 0;
146 virtual bool ArchitectureAll() = 0;
147 virtual std::string Version() = 0;
148 virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0;
149 virtual std::string Description() = 0;
150 virtual std::string DescriptionLanguage() = 0;
151 virtual MD5SumValue Description_md5() = 0;
152 virtual unsigned short VersionHash() = 0;
153 virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
154 pkgCache::VerIterator &Ver) = 0;
155 virtual unsigned long Offset() = 0;
156 virtual unsigned long Size() = 0;
157
158 virtual bool Step() = 0;
159
160 inline bool HasFileDeps() {return FoundFileDeps;};
161 virtual bool CollectFileProvides(pkgCache &Cache,
162 pkgCache::VerIterator &Ver) {return true;};
163
164 ListParser() : FoundFileDeps(false) {};
165 virtual ~ListParser() {};
166 };
167 /*}}}*/
168
169 bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
170 MMap **OutMap = 0,bool AllowMem = false);
171 bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
172
173 #endif