]> git.saurik.com Git - apt.git/blob - apt-pkg/pkgcache.h
Fixed doc reference
[apt.git] / apt-pkg / pkgcache.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: pkgcache.h,v 1.8 1998/10/20 02:39:20 jgg Exp $
4 /* ######################################################################
5
6 Cache - Structure definitions for the cache file
7
8 Please see doc/apt-pkg/cache.sgml for a more detailed description of
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
23 #ifdef __GNUG__
24 #pragma interface "apt-pkg/pkgcache.h"
25 #endif
26
27 #include <string>
28 #include <time.h>
29 #include <apt-pkg/mmap.h>
30
31 class 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;
42 struct VerFile;
43
44 // Iterators
45 class PkgIterator;
46 class VerIterator;
47 class DepIterator;
48 class PrvIterator;
49 class PkgFileIterator;
50 class VerFileIterator;
51 friend PkgIterator;
52 friend VerIterator;
53 friend DepIterator;
54 friend PrvIterator;
55 friend PkgFileIterator;
56 friend VerFileIterator;
57
58 // These are all the constants used in the cache structures
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 {
69 enum VerPriority {Important=1,Required=2,Standard=3,Optional=5,Extra=5};
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,
73 UnInstalled=3,HalfInstalled=4,ConfigFiles=5,Installed=6};
74 };
75
76 struct Flag
77 {
78 enum PkgFlags {Auto=(1<<0),New=(1<<1),Obsolete=(1<<2),Essential=(1<<3),
79 ImmediateConf=(1<<4)};
80 enum PkgFFlags {NotSource=(1<<0)};
81 };
82
83 protected:
84
85 // Memory mapped cache file
86 string CacheFile;
87 MMap &Map;
88
89 static unsigned long sHash(string S);
90 static unsigned long sHash(const char *S);
91
92 public:
93
94 // Pointers to the arrays of items
95 Header *HeaderP;
96 Package *PkgP;
97 VerFile *VerFileP;
98 PackageFile *PkgFileP;
99 Version *VerP;
100 Provides *ProvideP;
101 Dependency *DepP;
102 StringItem *StringItemP;
103 char *StrP;
104
105 virtual bool ReMap();
106 inline bool Sync() {return Map.Sync();};
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
112 // Usefull transformation things
113 const char *Priority(unsigned char Priority);
114
115 // Accessors
116 PkgIterator FindPkg(string Name);
117 Header &Head() {return *HeaderP;};
118 inline PkgIterator PkgBegin();
119 inline PkgIterator PkgEnd();
120 inline PkgFileIterator FileBegin();
121 inline PkgFileIterator FileEnd();
122
123 pkgCache(MMap &Map);
124 virtual ~pkgCache() {};
125 };
126
127 // Header structure
128 struct pkgCache::Header
129 {
130 // Signature information
131 unsigned long Signature;
132 short MajorVersion;
133 short MinorVersion;
134 bool Dirty;
135
136 // Size of structure values
137 unsigned short HeaderSz;
138 unsigned short PackageSz;
139 unsigned short PackageFileSz;
140 unsigned short VersionSz;
141 unsigned short DependencySz;
142 unsigned short ProvidesSz;
143 unsigned short VerFileSz;
144
145 // Structure counts
146 unsigned long PackageCount;
147 unsigned long VersionCount;
148 unsigned long DependsCount;
149 unsigned long PackageFileCount;
150
151 // Offsets
152 unsigned long FileList; // struct PackageFile
153 unsigned long StringList; // struct StringItem
154 unsigned long MaxVerFileSize;
155
156 /* Allocation pools, there should be one of these for each structure
157 excluding the header */
158 DynamicMMap::Pool Pools[7];
159
160 // Rapid package name lookup
161 unsigned long HashTable[512];
162
163 bool CheckSizes(Header &Against) const;
164 Header();
165 };
166
167 struct pkgCache::Package
168 {
169 // Pointers
170 unsigned long Name; // Stringtable
171 unsigned long VersionList; // Version
172 unsigned long TargetVer; // Version
173 unsigned long CurrentVer; // Version
174 unsigned long TargetDist; // StringTable (StringItem)
175 unsigned long Section; // StringTable (StringItem)
176
177 // Linked list
178 unsigned long NextPackage; // Package
179 unsigned long RevDepends; // Dependency
180 unsigned long ProvidesList; // Provides
181
182 // Install/Remove/Purge etc
183 unsigned char SelectedState; // What
184 unsigned char InstState; // Flags
185 unsigned char CurrentState; // State
186
187 unsigned short ID;
188 unsigned long Flags;
189 };
190
191 struct pkgCache::PackageFile
192 {
193 // Names
194 unsigned long FileName; // Stringtable
195 unsigned long Version; // Stringtable
196 unsigned long Distribution; // Stringtable
197 unsigned long Size;
198
199 // Linked list
200 unsigned long NextFile; // PackageFile
201 unsigned short ID;
202 unsigned long Flags;
203 time_t mtime; // Modification time for the file
204 };
205
206 struct pkgCache::VerFile
207 {
208 unsigned long File; // PackageFile
209 unsigned long NextFile; // PkgVerFile
210 unsigned long Offset;
211 unsigned short Size;
212 };
213
214 struct pkgCache::Version
215 {
216 unsigned long VerStr; // Stringtable
217 unsigned long Section; // StringTable (StringItem)
218
219 // Lists
220 unsigned long FileList; // VerFile
221 unsigned long NextVer; // Version
222 unsigned long DependsList; // Dependency
223 unsigned long ParentPkg; // Package
224 unsigned long ProvidesList; // Provides
225
226 unsigned long Size;
227 unsigned long InstalledSize;
228 unsigned short ID;
229 unsigned char Priority;
230 };
231
232 struct pkgCache::Dependency
233 {
234 unsigned long Version; // Stringtable
235 unsigned long Package; // Package
236 unsigned long NextDepends; // Dependency
237 unsigned long NextRevDepends; // Dependency
238 unsigned long ParentVer; // Version
239
240 // Specific types of depends
241 unsigned char Type;
242 unsigned char CompareOp;
243 unsigned short ID;
244 };
245
246 struct pkgCache::Provides
247 {
248 unsigned long ParentPkg; // Pacakge
249 unsigned long Version; // Version
250 unsigned long ProvideVersion; // Stringtable
251 unsigned long NextProvides; // Provides
252 unsigned long NextPkgProv; // Provides
253 };
254
255 struct pkgCache::StringItem
256 {
257 unsigned long String; // Stringtable
258 unsigned long NextItem; // StringItem
259 };
260
261 #include <apt-pkg/cacheiterators.h>
262
263 inline pkgCache::PkgIterator pkgCache::PkgBegin()
264 {return PkgIterator(*this);};
265 inline pkgCache::PkgIterator pkgCache::PkgEnd()
266 {return PkgIterator(*this,PkgP);};
267 inline pkgCache::PkgFileIterator pkgCache::FileBegin()
268 {return PkgFileIterator(*this);};
269 inline pkgCache::PkgFileIterator pkgCache::FileEnd()
270 {return PkgFileIterator(*this,PkgFileP);};
271
272 #endif