mark the Error/Warning method as __cold
[ntk/apt.git] / apt-pkg / pkgcache.h
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
6a3da7a6 3// $Id: pkgcache.h,v 1.25 2001/07/01 22:28:24 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 /*}}}*/
578bfd0a
AL
19#ifndef PKGLIB_PKGCACHE_H
20#define PKGLIB_PKGCACHE_H
21
6c139d6e 22
578bfd0a
AL
23#include <string>
24#include <time.h>
094a497d 25#include <apt-pkg/mmap.h>
0a843901
AL
26
27using std::string;
b2e465d6
AL
28
29class pkgVersioningSystem;
92fcbfc1 30class pkgCache /*{{{*/
578bfd0a
AL
31{
32 public:
33 // Cache element predeclarations
34 struct Header;
35 struct Package;
36 struct PackageFile;
37 struct Version;
a52f938b 38 struct Description;
578bfd0a
AL
39 struct Provides;
40 struct Dependency;
41 struct StringItem;
dcb79bae 42 struct VerFile;
a52f938b 43 struct DescFile;
578bfd0a
AL
44
45 // Iterators
773e2c1f 46 template<typename Str, typename Itr> class Iterator;
578bfd0a
AL
47 class PkgIterator;
48 class VerIterator;
a52f938b 49 class DescIterator;
578bfd0a
AL
50 class DepIterator;
51 class PrvIterator;
52 class PkgFileIterator;
dcb79bae 53 class VerFileIterator;
a52f938b 54 class DescFileIterator;
b2e465d6
AL
55
56 class Namespace;
dcb79bae 57
f55a958f 58 // These are all the constants used in the cache structures
308c7d30
IJ
59
60 // WARNING - if you change these lists you must also edit
61 // the stringification in pkgcache.cc and also consider whether
62 // the cache file will become incompatible.
6c139d6e
AL
63 struct Dep
64 {
65 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
f8ae7e8b 66 Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9};
6c139d6e
AL
67 enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
68 Greater=0x4,Equals=0x5,NotEquals=0x6};
69 };
70
71 struct State
72 {
fbfb2a7c 73 enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
6c139d6e
AL
74 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
75 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
76 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
9d06bc80
MV
77 HalfInstalled=4,ConfigFiles=5,Installed=6,
78 TriggersAwaited=7,TriggersPending=8};
6c139d6e
AL
79 };
80
81 struct Flag
82 {
138d4b3d 83 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
3c124dde 84 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
6c139d6e 85 };
578bfd0a
AL
86
87 protected:
88
89 // Memory mapped cache file
90 string CacheFile;
91 MMap &Map;
92
171c75f1 93 unsigned long sHash(const string &S) const;
f9eec0e7 94 unsigned long sHash(const char *S) const;
578bfd0a
AL
95
96 public:
97
98 // Pointers to the arrays of items
99 Header *HeaderP;
100 Package *PkgP;
dcb79bae 101 VerFile *VerFileP;
a52f938b 102 DescFile *DescFileP;
578bfd0a
AL
103 PackageFile *PkgFileP;
104 Version *VerP;
a52f938b 105 Description *DescP;
578bfd0a
AL
106 Provides *ProvideP;
107 Dependency *DepP;
108 StringItem *StringItemP;
109 char *StrP;
dcb79bae 110
578bfd0a
AL
111 virtual bool ReMap();
112 inline bool Sync() {return Map.Sync();};
981d20eb 113 inline MMap &GetMap() {return Map;};
b2e465d6
AL
114 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
115
578bfd0a 116 // String hashing function (512 range)
171c75f1 117 inline unsigned long Hash(const string &S) const {return sHash(S);};
578bfd0a
AL
118 inline unsigned long Hash(const char *S) const {return sHash(S);};
119
0149949b
AL
120 // Usefull transformation things
121 const char *Priority(unsigned char Priority);
122
578bfd0a 123 // Accessors
171c75f1 124 PkgIterator FindPkg(const string &Name);
578bfd0a
AL
125 Header &Head() {return *HeaderP;};
126 inline PkgIterator PkgBegin();
127 inline PkgIterator PkgEnd();
ad00ae81
AL
128 inline PkgFileIterator FileBegin();
129 inline PkgFileIterator FileEnd();
b2e465d6
AL
130
131 // Make me a function
132 pkgVersioningSystem *VS;
133
134 // Converters
135 static const char *CompTypeDeb(unsigned char Comp);
136 static const char *CompType(unsigned char Comp);
137 static const char *DepType(unsigned char Dep);
ad00ae81 138
b2e465d6 139 pkgCache(MMap *Map,bool DoMap = true);
578bfd0a
AL
140 virtual ~pkgCache() {};
141};
92fcbfc1
DK
142 /*}}}*/
143// Header structure /*{{{*/
578bfd0a
AL
144struct pkgCache::Header
145{
146 // Signature information
147 unsigned long Signature;
148 short MajorVersion;
149 short MinorVersion;
150 bool Dirty;
151
152 // Size of structure values
153 unsigned short HeaderSz;
154 unsigned short PackageSz;
155 unsigned short PackageFileSz;
156 unsigned short VersionSz;
a52f938b 157 unsigned short DescriptionSz;
578bfd0a
AL
158 unsigned short DependencySz;
159 unsigned short ProvidesSz;
dcb79bae 160 unsigned short VerFileSz;
a52f938b 161 unsigned short DescFileSz;
dcb79bae 162
578bfd0a
AL
163 // Structure counts
164 unsigned long PackageCount;
165 unsigned long VersionCount;
a52f938b 166 unsigned long DescriptionCount;
578bfd0a
AL
167 unsigned long DependsCount;
168 unsigned long PackageFileCount;
a7e66b17 169 unsigned long VerFileCount;
a52f938b 170 unsigned long DescFileCount;
a7e66b17 171 unsigned long ProvidesCount;
578bfd0a
AL
172
173 // Offsets
349cd3b8
AL
174 map_ptrloc FileList; // struct PackageFile
175 map_ptrloc StringList; // struct StringItem
b2e465d6
AL
176 map_ptrloc VerSysName; // StringTable
177 map_ptrloc Architecture; // StringTable
ad00ae81 178 unsigned long MaxVerFileSize;
a52f938b 179 unsigned long MaxDescFileSize;
578bfd0a
AL
180
181 /* Allocation pools, there should be one of these for each structure
182 excluding the header */
a52f938b 183 DynamicMMap::Pool Pools[8];
578bfd0a
AL
184
185 // Rapid package name lookup
349cd3b8 186 map_ptrloc HashTable[2*1048];
578bfd0a
AL
187
188 bool CheckSizes(Header &Against) const;
189 Header();
190};
92fcbfc1
DK
191 /*}}}*/
192struct pkgCache::Package /*{{{*/
578bfd0a
AL
193{
194 // Pointers
349cd3b8
AL
195 map_ptrloc Name; // Stringtable
196 map_ptrloc VersionList; // Version
349cd3b8 197 map_ptrloc CurrentVer; // Version
349cd3b8 198 map_ptrloc Section; // StringTable (StringItem)
578bfd0a
AL
199
200 // Linked list
349cd3b8
AL
201 map_ptrloc NextPackage; // Package
202 map_ptrloc RevDepends; // Dependency
203 map_ptrloc ProvidesList; // Provides
a52f938b 204
578bfd0a
AL
205 // Install/Remove/Purge etc
206 unsigned char SelectedState; // What
207 unsigned char InstState; // Flags
208 unsigned char CurrentState; // State
209
09fab244 210 unsigned int ID;
f55a958f 211 unsigned long Flags;
578bfd0a 212};
92fcbfc1
DK
213 /*}}}*/
214struct pkgCache::PackageFile /*{{{*/
578bfd0a
AL
215{
216 // Names
349cd3b8
AL
217 map_ptrloc FileName; // Stringtable
218 map_ptrloc Archive; // Stringtable
efc487fb 219 map_ptrloc Codename; // Stringtable
349cd3b8
AL
220 map_ptrloc Component; // Stringtable
221 map_ptrloc Version; // Stringtable
222 map_ptrloc Origin; // Stringtable
223 map_ptrloc Label; // Stringtable
224 map_ptrloc Architecture; // Stringtable
b2e465d6
AL
225 map_ptrloc Site; // Stringtable
226 map_ptrloc IndexType; // Stringtable
b0b4efb9 227 unsigned long Size;
3c124dde 228 unsigned long Flags;
578bfd0a
AL
229
230 // Linked list
349cd3b8 231 map_ptrloc NextFile; // PackageFile
09fab244 232 unsigned int ID;
578bfd0a
AL
233 time_t mtime; // Modification time for the file
234};
92fcbfc1
DK
235 /*}}}*/
236struct pkgCache::VerFile /*{{{*/
dcb79bae 237{
349cd3b8
AL
238 map_ptrloc File; // PackageFile
239 map_ptrloc NextFile; // PkgVerFile
240 map_ptrloc Offset; // File offset
6d3176fb 241 unsigned long Size;
dcb79bae 242};
92fcbfc1
DK
243 /*}}}*/
244struct pkgCache::DescFile /*{{{*/
a52f938b
OS
245{
246 map_ptrloc File; // PackageFile
247 map_ptrloc NextFile; // PkgVerFile
248 map_ptrloc Offset; // File offset
6d3176fb 249 unsigned long Size;
a52f938b 250};
92fcbfc1
DK
251 /*}}}*/
252struct pkgCache::Version /*{{{*/
578bfd0a 253{
349cd3b8
AL
254 map_ptrloc VerStr; // Stringtable
255 map_ptrloc Section; // StringTable (StringItem)
256 map_ptrloc Arch; // StringTable
17caf1b1 257
578bfd0a 258 // Lists
349cd3b8
AL
259 map_ptrloc FileList; // VerFile
260 map_ptrloc NextVer; // Version
a52f938b 261 map_ptrloc DescriptionList; // Description
349cd3b8
AL
262 map_ptrloc DependsList; // Dependency
263 map_ptrloc ParentPkg; // Package
264 map_ptrloc ProvidesList; // Provides
578bfd0a 265
349cd3b8
AL
266 map_ptrloc Size; // These are the .deb size
267 map_ptrloc InstalledSize;
204fbdcc 268 unsigned short Hash;
09fab244 269 unsigned int ID;
578bfd0a
AL
270 unsigned char Priority;
271};
92fcbfc1
DK
272 /*}}}*/
273struct pkgCache::Description /*{{{*/
a52f938b
OS
274{
275 // Language Code store the description translation language code. If
276 // the value has a 0 lenght then this is readed using the Package
277 // file else the Translation-CODE are used.
278 map_ptrloc language_code; // StringTable
279 map_ptrloc md5sum; // StringTable
280
281 // Linked list
282 map_ptrloc FileList; // DescFile
283 map_ptrloc NextDesc; // Description
284 map_ptrloc ParentPkg; // Package
285
09fab244 286 unsigned int ID;
a52f938b 287};
92fcbfc1
DK
288 /*}}}*/
289struct pkgCache::Dependency /*{{{*/
578bfd0a 290{
349cd3b8
AL
291 map_ptrloc Version; // Stringtable
292 map_ptrloc Package; // Package
293 map_ptrloc NextDepends; // Dependency
294 map_ptrloc NextRevDepends; // Dependency
295 map_ptrloc ParentVer; // Version
578bfd0a
AL
296
297 // Specific types of depends
6a3da7a6 298 map_ptrloc ID;
578bfd0a
AL
299 unsigned char Type;
300 unsigned char CompareOp;
578bfd0a 301};
92fcbfc1
DK
302 /*}}}*/
303struct pkgCache::Provides /*{{{*/
578bfd0a 304{
349cd3b8
AL
305 map_ptrloc ParentPkg; // Pacakge
306 map_ptrloc Version; // Version
307 map_ptrloc ProvideVersion; // Stringtable
308 map_ptrloc NextProvides; // Provides
309 map_ptrloc NextPkgProv; // Provides
578bfd0a 310};
92fcbfc1
DK
311 /*}}}*/
312struct pkgCache::StringItem /*{{{*/
578bfd0a 313{
349cd3b8
AL
314 map_ptrloc String; // Stringtable
315 map_ptrloc NextItem; // StringItem
578bfd0a 316};
92fcbfc1 317 /*}}}*/
094a497d 318#include <apt-pkg/cacheiterators.h>
578bfd0a
AL
319
320inline pkgCache::PkgIterator pkgCache::PkgBegin()
321 {return PkgIterator(*this);};
322inline pkgCache::PkgIterator pkgCache::PkgEnd()
323 {return PkgIterator(*this,PkgP);};
ad00ae81 324inline pkgCache::PkgFileIterator pkgCache::FileBegin()
b2e465d6 325 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
ad00ae81
AL
326inline pkgCache::PkgFileIterator pkgCache::FileEnd()
327 {return PkgFileIterator(*this,PkgFileP);};
578bfd0a 328
b2e465d6 329// Oh I wish for Real Name Space Support
92fcbfc1 330class pkgCache::Namespace /*{{{*/
b2e465d6
AL
331{
332 public:
333
334 typedef pkgCache::PkgIterator PkgIterator;
335 typedef pkgCache::VerIterator VerIterator;
a52f938b 336 typedef pkgCache::DescIterator DescIterator;
b2e465d6
AL
337 typedef pkgCache::DepIterator DepIterator;
338 typedef pkgCache::PrvIterator PrvIterator;
339 typedef pkgCache::PkgFileIterator PkgFileIterator;
340 typedef pkgCache::VerFileIterator VerFileIterator;
341 typedef pkgCache::Version Version;
a52f938b 342 typedef pkgCache::Description Description;
b2e465d6
AL
343 typedef pkgCache::Package Package;
344 typedef pkgCache::Header Header;
345 typedef pkgCache::Dep Dep;
346 typedef pkgCache::Flag Flag;
347};
92fcbfc1 348 /*}}}*/
578bfd0a 349#endif