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