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