]> git.saurik.com Git - apt.git/blob - apt-pkg/pkgcachegen.h
53f09b99123adf76f78e4dbd84ae5c832b7ccd50
[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 class pkgSourceList;
27 class OpProgress;
28 class MMap;
29 class pkgIndexFile;
30
31 class pkgCacheGenerator /*{{{*/
32 {
33 private:
34
35 pkgCache::StringItem *UniqHash[26];
36
37 public:
38
39 class ListParser;
40 friend class ListParser;
41
42 protected:
43
44 DynamicMMap &Map;
45 pkgCache Cache;
46 OpProgress *Progress;
47
48 string PkgFileName;
49 pkgCache::PackageFile *CurrentFile;
50
51 // Flag file dependencies
52 bool FoundFileDeps;
53
54 bool NewGroup(pkgCache::GrpIterator &Grp,const string &Name);
55 bool NewPackage(pkgCache::PkgIterator &Pkg,const string &Name, const string &Arch);
56 bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
57 bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
58 bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
59 string const &Version, unsigned int const &Op,
60 unsigned int const &Type, map_ptrloc *OldDepLast);
61 unsigned long NewVersion(pkgCache::VerIterator &Ver,const string &VerStr,unsigned long Next);
62 map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const string &Lang,const MD5SumValue &md5sum,map_ptrloc Next);
63
64 public:
65
66 unsigned long WriteUniqString(const char *S,unsigned int Size);
67 inline unsigned long WriteUniqString(const string &S) {return WriteUniqString(S.c_str(),S.length());};
68
69 void DropProgress() {Progress = 0;};
70 bool SelectFile(const string &File,const string &Site,pkgIndexFile const &Index,
71 unsigned long Flags = 0);
72 bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
73 inline pkgCache &GetCache() {return Cache;};
74 inline pkgCache::PkgFileIterator GetCurFile()
75 {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
76
77 bool HasFileDeps() {return FoundFileDeps;};
78 bool MergeFileProvides(ListParser &List);
79 bool FinishCache(OpProgress &Progress);
80
81 pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
82 ~pkgCacheGenerator();
83 };
84 /*}}}*/
85 // This is the abstract package list parser class. /*{{{*/
86 class pkgCacheGenerator::ListParser
87 {
88 pkgCacheGenerator *Owner;
89 friend class pkgCacheGenerator;
90
91 // Some cache items
92 pkgCache::VerIterator OldDepVer;
93 map_ptrloc *OldDepLast;
94
95 // Flag file dependencies
96 bool FoundFileDeps;
97
98 protected:
99
100 inline unsigned long WriteUniqString(string S) {return Owner->WriteUniqString(S);};
101 inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);};
102 inline unsigned long WriteString(const string &S) {return Owner->Map.WriteString(S);};
103 inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->Map.WriteString(S,Size);};
104 bool NewDepends(pkgCache::VerIterator Ver,const string &Package, const string &Arch,
105 const string &Version,unsigned int Op,
106 unsigned int Type);
107 bool NewProvides(pkgCache::VerIterator Ver,const string &Package,
108 const string &Version);
109
110 public:
111
112 // These all operate against the current section
113 virtual string Package() = 0;
114 virtual string Architecture() = 0;
115 virtual string Version() = 0;
116 virtual bool NewVersion(pkgCache::VerIterator Ver) = 0;
117 virtual string Description() = 0;
118 virtual string DescriptionLanguage() = 0;
119 virtual MD5SumValue Description_md5() = 0;
120 virtual unsigned short VersionHash() = 0;
121 virtual bool UsePackage(pkgCache::PkgIterator Pkg,
122 pkgCache::VerIterator Ver) = 0;
123 virtual unsigned long Offset() = 0;
124 virtual unsigned long Size() = 0;
125
126 virtual bool Step() = 0;
127
128 inline bool HasFileDeps() {return FoundFileDeps;};
129 virtual bool CollectFileProvides(pkgCache &Cache,
130 pkgCache::VerIterator Ver) {return true;};
131
132 ListParser() : FoundFileDeps(false) {};
133 virtual ~ListParser() {};
134 };
135 /*}}}*/
136 bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
137 MMap **OutMap = 0,bool AllowMem = false);
138 bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
139
140 #ifdef APT_COMPATIBILITY
141 #if APT_COMPATIBILITY != 986
142 #warning "Using APT_COMPATIBILITY"
143 #endif
144 MMap *pkgMakeStatusCacheMem(pkgSourceList &List,OpProgress &Progress)
145 {
146 MMap *Map = 0;
147 if (pkgMakeStatusCache(List,Progress,&Map,true) == false)
148 return 0;
149 return Map;
150 }
151 #endif
152
153 #endif