* removed the pragma mess
[ntk/apt.git] / apt-pkg / pkgcache.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: pkgcache.h,v 1.25 2001/07/01 22:28:24 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 #ifndef PKGLIB_PKGCACHE_H
20 #define PKGLIB_PKGCACHE_H
21
22
23 #include <string>
24 #include <time.h>
25 #include <apt-pkg/mmap.h>
26
27 using std::string;
28
29 class pkgVersioningSystem;
30 class pkgCache
31 {
32 public:
33 // Cache element predeclarations
34 struct Header;
35 struct Package;
36 struct PackageFile;
37 struct Version;
38 struct Provides;
39 struct Dependency;
40 struct StringItem;
41 struct VerFile;
42
43 // Iterators
44 class PkgIterator;
45 class VerIterator;
46 class DepIterator;
47 class PrvIterator;
48 class PkgFileIterator;
49 class VerFileIterator;
50 friend class PkgIterator;
51 friend class VerIterator;
52 friend class DepIterator;
53 friend class PrvIterator;
54 friend class PkgFileIterator;
55 friend class VerFileIterator;
56
57 class Namespace;
58
59 // These are all the constants used in the cache structures
60 struct Dep
61 {
62 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
63 Conflicts=5,Replaces=6,Obsoletes=7};
64 enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
65 Greater=0x4,Equals=0x5,NotEquals=0x6};
66 };
67
68 struct State
69 {
70 enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
71 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
72 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
73 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
74 HalfInstalled=4,ConfigFiles=5,Installed=6};
75 };
76
77 struct Flag
78 {
79 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
80 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
81 };
82
83 protected:
84
85 // Memory mapped cache file
86 string CacheFile;
87 MMap &Map;
88
89 unsigned long sHash(const string &S) const;
90 unsigned long sHash(const char *S) const;
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 inline MMap &GetMap() {return Map;};
108 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
109
110 // String hashing function (512 range)
111 inline unsigned long Hash(const string &S) const {return sHash(S);};
112 inline unsigned long Hash(const char *S) const {return sHash(S);};
113
114 // Usefull transformation things
115 const char *Priority(unsigned char Priority);
116
117 // Accessors
118 PkgIterator FindPkg(const string &Name);
119 Header &Head() {return *HeaderP;};
120 inline PkgIterator PkgBegin();
121 inline PkgIterator PkgEnd();
122 inline PkgFileIterator FileBegin();
123 inline PkgFileIterator FileEnd();
124
125 // Make me a function
126 pkgVersioningSystem *VS;
127
128 // Converters
129 static const char *CompTypeDeb(unsigned char Comp);
130 static const char *CompType(unsigned char Comp);
131 static const char *DepType(unsigned char Dep);
132
133 pkgCache(MMap *Map,bool DoMap = true);
134 virtual ~pkgCache() {};
135 };
136
137 // Header structure
138 struct pkgCache::Header
139 {
140 // Signature information
141 unsigned long Signature;
142 short MajorVersion;
143 short MinorVersion;
144 bool Dirty;
145
146 // Size of structure values
147 unsigned short HeaderSz;
148 unsigned short PackageSz;
149 unsigned short PackageFileSz;
150 unsigned short VersionSz;
151 unsigned short DependencySz;
152 unsigned short ProvidesSz;
153 unsigned short VerFileSz;
154
155 // Structure counts
156 unsigned long PackageCount;
157 unsigned long VersionCount;
158 unsigned long DependsCount;
159 unsigned long PackageFileCount;
160 unsigned long VerFileCount;
161 unsigned long ProvidesCount;
162
163 // Offsets
164 map_ptrloc FileList; // struct PackageFile
165 map_ptrloc StringList; // struct StringItem
166 map_ptrloc VerSysName; // StringTable
167 map_ptrloc Architecture; // StringTable
168 unsigned long MaxVerFileSize;
169
170 /* Allocation pools, there should be one of these for each structure
171 excluding the header */
172 DynamicMMap::Pool Pools[7];
173
174 // Rapid package name lookup
175 map_ptrloc HashTable[2*1048];
176
177 bool CheckSizes(Header &Against) const;
178 Header();
179 };
180
181 struct pkgCache::Package
182 {
183 // Pointers
184 map_ptrloc Name; // Stringtable
185 map_ptrloc VersionList; // Version
186 map_ptrloc CurrentVer; // Version
187 map_ptrloc Section; // StringTable (StringItem)
188
189 // Linked list
190 map_ptrloc NextPackage; // Package
191 map_ptrloc RevDepends; // Dependency
192 map_ptrloc ProvidesList; // Provides
193
194 // Install/Remove/Purge etc
195 unsigned char SelectedState; // What
196 unsigned char InstState; // Flags
197 unsigned char CurrentState; // State
198
199 unsigned short ID;
200 unsigned long Flags;
201 };
202
203 struct pkgCache::PackageFile
204 {
205 // Names
206 map_ptrloc FileName; // Stringtable
207 map_ptrloc Archive; // Stringtable
208 map_ptrloc Component; // Stringtable
209 map_ptrloc Version; // Stringtable
210 map_ptrloc Origin; // Stringtable
211 map_ptrloc Label; // Stringtable
212 map_ptrloc Architecture; // Stringtable
213 map_ptrloc Site; // Stringtable
214 map_ptrloc IndexType; // Stringtable
215 unsigned long Size;
216 unsigned long Flags;
217
218 // Linked list
219 map_ptrloc NextFile; // PackageFile
220 unsigned short ID;
221 time_t mtime; // Modification time for the file
222 };
223
224 struct pkgCache::VerFile
225 {
226 map_ptrloc File; // PackageFile
227 map_ptrloc NextFile; // PkgVerFile
228 map_ptrloc Offset; // File offset
229 unsigned short Size;
230 };
231
232 struct pkgCache::Version
233 {
234 map_ptrloc VerStr; // Stringtable
235 map_ptrloc Section; // StringTable (StringItem)
236 map_ptrloc Arch; // StringTable
237
238 // Lists
239 map_ptrloc FileList; // VerFile
240 map_ptrloc NextVer; // Version
241 map_ptrloc DependsList; // Dependency
242 map_ptrloc ParentPkg; // Package
243 map_ptrloc ProvidesList; // Provides
244
245 map_ptrloc Size; // These are the .deb size
246 map_ptrloc InstalledSize;
247 unsigned short Hash;
248 unsigned short ID;
249 unsigned char Priority;
250 };
251
252 struct pkgCache::Dependency
253 {
254 map_ptrloc Version; // Stringtable
255 map_ptrloc Package; // Package
256 map_ptrloc NextDepends; // Dependency
257 map_ptrloc NextRevDepends; // Dependency
258 map_ptrloc ParentVer; // Version
259
260 // Specific types of depends
261 map_ptrloc ID;
262 unsigned char Type;
263 unsigned char CompareOp;
264 };
265
266 struct pkgCache::Provides
267 {
268 map_ptrloc ParentPkg; // Pacakge
269 map_ptrloc Version; // Version
270 map_ptrloc ProvideVersion; // Stringtable
271 map_ptrloc NextProvides; // Provides
272 map_ptrloc NextPkgProv; // Provides
273 };
274
275 struct pkgCache::StringItem
276 {
277 map_ptrloc String; // Stringtable
278 map_ptrloc NextItem; // StringItem
279 };
280
281 #include <apt-pkg/cacheiterators.h>
282
283 inline pkgCache::PkgIterator pkgCache::PkgBegin()
284 {return PkgIterator(*this);};
285 inline pkgCache::PkgIterator pkgCache::PkgEnd()
286 {return PkgIterator(*this,PkgP);};
287 inline pkgCache::PkgFileIterator pkgCache::FileBegin()
288 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
289 inline pkgCache::PkgFileIterator pkgCache::FileEnd()
290 {return PkgFileIterator(*this,PkgFileP);};
291
292 // Oh I wish for Real Name Space Support
293 class pkgCache::Namespace
294 {
295 public:
296
297 typedef pkgCache::PkgIterator PkgIterator;
298 typedef pkgCache::VerIterator VerIterator;
299 typedef pkgCache::DepIterator DepIterator;
300 typedef pkgCache::PrvIterator PrvIterator;
301 typedef pkgCache::PkgFileIterator PkgFileIterator;
302 typedef pkgCache::VerFileIterator VerFileIterator;
303 typedef pkgCache::Version Version;
304 typedef pkgCache::Package Package;
305 typedef pkgCache::Header Header;
306 typedef pkgCache::Dep Dep;
307 typedef pkgCache::Flag Flag;
308 };
309
310 #endif