]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgcache.h
More touch ups
[apt.git] / apt-pkg / pkgcache.h
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
a005475e 3// $Id: pkgcache.h,v 1.22 1999/07/30 02:54:25 jgg Exp $
578bfd0a
AL
4/* ######################################################################
5
6 Cache - Structure definitions for the cache file
7
094a497d 8 Please see doc/apt-pkg/cache.sgml for a more detailed description of
578bfd0a
AL
9 this format. Also be sure to keep that file up-to-date!!
10
11 Clients should always use the CacheIterators classes for access to the
12 cache. They provide a simple STL-like method for traversing the links
13 of the datastructure.
14
15 See pkgcachegen.h for information about generating cache structures.
16
17 ##################################################################### */
18 /*}}}*/
19// Header section: pkglib
20#ifndef PKGLIB_PKGCACHE_H
21#define PKGLIB_PKGCACHE_H
22
6c139d6e 23#ifdef __GNUG__
094a497d 24#pragma interface "apt-pkg/pkgcache.h"
6c139d6e
AL
25#endif
26
578bfd0a
AL
27#include <string>
28#include <time.h>
094a497d 29#include <apt-pkg/mmap.h>
578bfd0a 30
578bfd0a
AL
31class pkgCache
32{
33 public:
34 // Cache element predeclarations
35 struct Header;
36 struct Package;
37 struct PackageFile;
38 struct Version;
39 struct Provides;
40 struct Dependency;
41 struct StringItem;
dcb79bae 42 struct VerFile;
578bfd0a
AL
43
44 // Iterators
45 class PkgIterator;
46 class VerIterator;
47 class DepIterator;
48 class PrvIterator;
49 class PkgFileIterator;
dcb79bae 50 class VerFileIterator;
578bfd0a
AL
51 friend PkgIterator;
52 friend VerIterator;
53 friend DepIterator;
54 friend PrvIterator;
55 friend PkgFileIterator;
dcb79bae
AL
56 friend VerFileIterator;
57
f55a958f 58 // These are all the constants used in the cache structures
6c139d6e
AL
59 struct Dep
60 {
61 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
62 Conflicts=5,Replaces=6};
63 enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
64 Greater=0x4,Equals=0x5,NotEquals=0x6};
65 };
66
67 struct State
68 {
fbfb2a7c 69 enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
6c139d6e
AL
70 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
71 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
72 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
a005475e 73 HalfInstalled=4,ConfigFiles=5,Installed=6};
6c139d6e
AL
74 };
75
76 struct Flag
77 {
138d4b3d 78 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
3c124dde 79 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
6c139d6e 80 };
578bfd0a
AL
81
82 protected:
83
84 // Memory mapped cache file
85 string CacheFile;
86 MMap &Map;
87
f9eec0e7
AL
88 unsigned long sHash(string S) const;
89 unsigned long sHash(const char *S) const;
578bfd0a
AL
90
91 public:
92
93 // Pointers to the arrays of items
94 Header *HeaderP;
95 Package *PkgP;
dcb79bae 96 VerFile *VerFileP;
578bfd0a
AL
97 PackageFile *PkgFileP;
98 Version *VerP;
99 Provides *ProvideP;
100 Dependency *DepP;
101 StringItem *StringItemP;
102 char *StrP;
dcb79bae 103
578bfd0a
AL
104 virtual bool ReMap();
105 inline bool Sync() {return Map.Sync();};
981d20eb 106 inline MMap &GetMap() {return Map;};
578bfd0a
AL
107
108 // String hashing function (512 range)
109 inline unsigned long Hash(string S) const {return sHash(S);};
110 inline unsigned long Hash(const char *S) const {return sHash(S);};
111
0149949b
AL
112 // Usefull transformation things
113 const char *Priority(unsigned char Priority);
114
578bfd0a
AL
115 // Accessors
116 PkgIterator FindPkg(string Name);
117 Header &Head() {return *HeaderP;};
118 inline PkgIterator PkgBegin();
119 inline PkgIterator PkgEnd();
ad00ae81
AL
120 inline PkgFileIterator FileBegin();
121 inline PkgFileIterator FileEnd();
1fcbfcb8 122 VerIterator GetCandidateVer(PkgIterator Pkg,bool AllowCurrent = true);
ad00ae81 123
578bfd0a
AL
124 pkgCache(MMap &Map);
125 virtual ~pkgCache() {};
126};
127
128// Header structure
129struct pkgCache::Header
130{
131 // Signature information
132 unsigned long Signature;
133 short MajorVersion;
134 short MinorVersion;
135 bool Dirty;
136
137 // Size of structure values
138 unsigned short HeaderSz;
139 unsigned short PackageSz;
140 unsigned short PackageFileSz;
141 unsigned short VersionSz;
142 unsigned short DependencySz;
143 unsigned short ProvidesSz;
dcb79bae
AL
144 unsigned short VerFileSz;
145
578bfd0a
AL
146 // Structure counts
147 unsigned long PackageCount;
148 unsigned long VersionCount;
149 unsigned long DependsCount;
150 unsigned long PackageFileCount;
a7e66b17
AL
151 unsigned long VerFileCount;
152 unsigned long ProvidesCount;
578bfd0a
AL
153
154 // Offsets
349cd3b8
AL
155 map_ptrloc FileList; // struct PackageFile
156 map_ptrloc StringList; // struct StringItem
ad00ae81 157 unsigned long MaxVerFileSize;
578bfd0a
AL
158
159 /* Allocation pools, there should be one of these for each structure
160 excluding the header */
dcb79bae 161 DynamicMMap::Pool Pools[7];
578bfd0a
AL
162
163 // Rapid package name lookup
349cd3b8 164 map_ptrloc HashTable[2*1048];
578bfd0a
AL
165
166 bool CheckSizes(Header &Against) const;
167 Header();
168};
169
170struct pkgCache::Package
171{
172 // Pointers
349cd3b8
AL
173 map_ptrloc Name; // Stringtable
174 map_ptrloc VersionList; // Version
175 map_ptrloc TargetVer; // Version
176 map_ptrloc CurrentVer; // Version
177 map_ptrloc TargetDist; // StringTable (StringItem)
178 map_ptrloc Section; // StringTable (StringItem)
578bfd0a
AL
179
180 // Linked list
349cd3b8
AL
181 map_ptrloc NextPackage; // Package
182 map_ptrloc RevDepends; // Dependency
183 map_ptrloc ProvidesList; // Provides
578bfd0a
AL
184
185 // Install/Remove/Purge etc
186 unsigned char SelectedState; // What
187 unsigned char InstState; // Flags
188 unsigned char CurrentState; // State
189
190 unsigned short ID;
f55a958f 191 unsigned long Flags;
578bfd0a
AL
192};
193
194struct pkgCache::PackageFile
195{
196 // Names
349cd3b8
AL
197 map_ptrloc FileName; // Stringtable
198 map_ptrloc Archive; // Stringtable
199 map_ptrloc Component; // Stringtable
200 map_ptrloc Version; // Stringtable
201 map_ptrloc Origin; // Stringtable
202 map_ptrloc Label; // Stringtable
203 map_ptrloc Architecture; // Stringtable
b0b4efb9 204 unsigned long Size;
3c124dde 205 unsigned long Flags;
578bfd0a
AL
206
207 // Linked list
349cd3b8 208 map_ptrloc NextFile; // PackageFile
578bfd0a 209 unsigned short ID;
578bfd0a
AL
210 time_t mtime; // Modification time for the file
211};
212
dcb79bae
AL
213struct pkgCache::VerFile
214{
349cd3b8
AL
215 map_ptrloc File; // PackageFile
216 map_ptrloc NextFile; // PkgVerFile
217 map_ptrloc Offset; // File offset
dcb79bae
AL
218 unsigned short Size;
219};
220
578bfd0a
AL
221struct pkgCache::Version
222{
349cd3b8
AL
223 map_ptrloc VerStr; // Stringtable
224 map_ptrloc Section; // StringTable (StringItem)
225 map_ptrloc Arch; // StringTable
17caf1b1 226
578bfd0a 227 // Lists
349cd3b8
AL
228 map_ptrloc FileList; // VerFile
229 map_ptrloc NextVer; // Version
230 map_ptrloc DependsList; // Dependency
231 map_ptrloc ParentPkg; // Package
232 map_ptrloc ProvidesList; // Provides
578bfd0a 233
349cd3b8
AL
234 map_ptrloc Size; // These are the .deb size
235 map_ptrloc InstalledSize;
204fbdcc 236 unsigned short Hash;
578bfd0a
AL
237 unsigned short ID;
238 unsigned char Priority;
239};
240
241struct pkgCache::Dependency
242{
349cd3b8
AL
243 map_ptrloc Version; // Stringtable
244 map_ptrloc Package; // Package
245 map_ptrloc NextDepends; // Dependency
246 map_ptrloc NextRevDepends; // Dependency
247 map_ptrloc ParentVer; // Version
578bfd0a
AL
248
249 // Specific types of depends
250 unsigned char Type;
251 unsigned char CompareOp;
252 unsigned short ID;
253};
254
255struct pkgCache::Provides
256{
349cd3b8
AL
257 map_ptrloc ParentPkg; // Pacakge
258 map_ptrloc Version; // Version
259 map_ptrloc ProvideVersion; // Stringtable
260 map_ptrloc NextProvides; // Provides
261 map_ptrloc NextPkgProv; // Provides
578bfd0a
AL
262};
263
264struct pkgCache::StringItem
265{
349cd3b8
AL
266 map_ptrloc String; // Stringtable
267 map_ptrloc NextItem; // StringItem
578bfd0a
AL
268};
269
094a497d 270#include <apt-pkg/cacheiterators.h>
578bfd0a
AL
271
272inline pkgCache::PkgIterator pkgCache::PkgBegin()
273 {return PkgIterator(*this);};
274inline pkgCache::PkgIterator pkgCache::PkgEnd()
275 {return PkgIterator(*this,PkgP);};
ad00ae81
AL
276inline pkgCache::PkgFileIterator pkgCache::FileBegin()
277 {return PkgFileIterator(*this);};
278inline pkgCache::PkgFileIterator pkgCache::FileEnd()
279 {return PkgFileIterator(*this,PkgFileP);};
578bfd0a
AL
280
281#endif