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