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