]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgcache.h
merged r1970 lp:~vorlon/apt/lp.968828
[apt.git] / apt-pkg / pkgcache.h
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
94449d7c
DK
3/**\file pkgcache.h
4 \brief pkgCache - Structure definitions for the cache file
5
6 The goal of the cache file is two fold:
7 Firstly to speed loading and processing of the package file array and
8 secondly to reduce memory consumption of the package file array.
9
10 The implementation is aimed at an environment with many primary package
11 files, for instance someone that has a Package file for their CD-ROM, a
12 Package file for the latest version of the distribution on the CD-ROM and a
13 package file for the development version. Always present is the information
14 contained in the status file which might be considered a separate package
15 file.
16
17 Please understand, this is designed as a <b>Cache file</b> it is not meant to be
18 used on any system other than the one it was created for. It is not meant to
19 be authoritative either, i.e. if a system crash or software failure occurs it
20 must be perfectly acceptable for the cache file to be in an inconsistent
21 state. Furthermore at any time the cache file may be erased without losing
22 any information.
23
24 Also the structures and storage layout is optimized for use by the APT
25 and may not be suitable for all purposes. However it should be possible
26 to extend it with associate cache files that contain other information.
27
28 To keep memory use down the cache file only contains often used fields and
29 fields that are inexpensive to store, the Package file has a full list of
30 fields. Also the client may assume that all items are perfectly valid and
31 need not perform checks against their correctness. Removal of information
32 from the cache is possible, but blanks will be left in the file, and
33 unused strings will also be present. The recommended implementation is to
34 simply rebuild the cache each time any of the data files change. It is
35 possible to add a new package file to the cache without any negative side
36 effects.
37
38 <b>Note on Pointer access</b>
578bfd0a 39 Clients should always use the CacheIterators classes for access to the
94449d7c
DK
40 cache and the data in it. They also provide a simple STL-like method for
41 traversing the links of the datastructure.
42
43 Every item in every structure is stored as the index to that structure.
44 What this means is that once the files is mmaped every data access has to
45 go through a fix up stage to get a real memory pointer. This is done
46 by taking the index, multiplying it by the type size and then adding
47 it to the start address of the memory block. This sounds complex, but
48 in C it is a single array dereference. Because all items are aligned to
49 their size and indexes are stored as multiples of the size of the structure
50 the format is immediately portable to all possible architectures - BUT the
51 generated files are -NOT-.
52
53 This scheme allows code like this to be written:
54 <example>
55 void *Map = mmap(...);
56 Package *PkgList = (Package *)Map;
57 Header *Head = (Header *)Map;
58 char *Strings = (char *)Map;
59 cout << (Strings + PkgList[Head->HashTable[0]]->Name) << endl;
60 </example>
61 Notice the lack of casting or multiplication. The net result is to return
62 the name of the first package in the first hash bucket, without error
63 checks.
64
65 The generator uses allocation pools to group similarly sized structures in
66 large blocks to eliminate any alignment overhead. The generator also
67 assures that no structures overlap and all indexes are unique. Although
68 at first glance it may seem like there is the potential for two structures
69 to exist at the same point the generator never allows this to happen.
70 (See the discussion of free space pools)
71
72 See \ref pkgcachegen.h for more information about generating cache structures. */
578bfd0a 73 /*}}}*/
578bfd0a
AL
74#ifndef PKGLIB_PKGCACHE_H
75#define PKGLIB_PKGCACHE_H
76
77#include <string>
78#include <time.h>
094a497d 79#include <apt-pkg/mmap.h>
0a843901 80
a4f6bdc8
DK
81#ifndef APT_8_CLEANER_HEADERS
82using std::string;
83#endif
84
b2e465d6 85class pkgVersioningSystem;
92fcbfc1 86class pkgCache /*{{{*/
578bfd0a
AL
87{
88 public:
89 // Cache element predeclarations
90 struct Header;
5bf15716 91 struct Group;
578bfd0a
AL
92 struct Package;
93 struct PackageFile;
94 struct Version;
a52f938b 95 struct Description;
578bfd0a
AL
96 struct Provides;
97 struct Dependency;
98 struct StringItem;
dcb79bae 99 struct VerFile;
a52f938b 100 struct DescFile;
578bfd0a
AL
101
102 // Iterators
773e2c1f 103 template<typename Str, typename Itr> class Iterator;
5bf15716 104 class GrpIterator;
578bfd0a
AL
105 class PkgIterator;
106 class VerIterator;
a52f938b 107 class DescIterator;
578bfd0a
AL
108 class DepIterator;
109 class PrvIterator;
110 class PkgFileIterator;
dcb79bae 111 class VerFileIterator;
a52f938b 112 class DescFileIterator;
b2e465d6
AL
113
114 class Namespace;
dcb79bae 115
f55a958f 116 // These are all the constants used in the cache structures
308c7d30
IJ
117
118 // WARNING - if you change these lists you must also edit
119 // the stringification in pkgcache.cc and also consider whether
120 // the cache file will become incompatible.
6c139d6e
AL
121 struct Dep
122 {
123 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
f8ae7e8b 124 Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9};
94449d7c
DK
125 /** \brief available compare operators
126
127 The lower 4 bits are used to indicate what operator is being specified and
128 the upper 4 bits are flags. OR indicates that the next package is
129 or'd with the current package. */
6c139d6e
AL
130 enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
131 Greater=0x4,Equals=0x5,NotEquals=0x6};
132 };
133
134 struct State
135 {
94449d7c
DK
136 /** \brief priority of a package version
137
138 Zero is used for unparsable or absent Priority fields. */
fbfb2a7c 139 enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
6c139d6e
AL
140 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
141 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
142 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
9d06bc80
MV
143 HalfInstalled=4,ConfigFiles=5,Installed=6,
144 TriggersAwaited=7,TriggersPending=8};
6c139d6e
AL
145 };
146
147 struct Flag
148 {
138d4b3d 149 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
5ed56f93 150 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1),ButAutomaticUpgrades=(1<<2)};
6c139d6e 151 };
578bfd0a
AL
152
153 protected:
154
155 // Memory mapped cache file
8f3ba4e8 156 std::string CacheFile;
578bfd0a
AL
157 MMap &Map;
158
8f3ba4e8 159 unsigned long sHash(const std::string &S) const;
f9eec0e7 160 unsigned long sHash(const char *S) const;
578bfd0a
AL
161
162 public:
163
164 // Pointers to the arrays of items
165 Header *HeaderP;
5bf15716 166 Group *GrpP;
578bfd0a 167 Package *PkgP;
dcb79bae 168 VerFile *VerFileP;
a52f938b 169 DescFile *DescFileP;
578bfd0a
AL
170 PackageFile *PkgFileP;
171 Version *VerP;
a52f938b 172 Description *DescP;
578bfd0a
AL
173 Provides *ProvideP;
174 Dependency *DepP;
175 StringItem *StringItemP;
176 char *StrP;
dcb79bae 177
a9fe5928 178 virtual bool ReMap(bool const &Errorchecks = true);
578bfd0a 179 inline bool Sync() {return Map.Sync();};
981d20eb 180 inline MMap &GetMap() {return Map;};
b2e465d6
AL
181 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
182
578bfd0a 183 // String hashing function (512 range)
8f3ba4e8 184 inline unsigned long Hash(const std::string &S) const {return sHash(S);};
578bfd0a
AL
185 inline unsigned long Hash(const char *S) const {return sHash(S);};
186
94449d7c 187 // Useful transformation things
0149949b
AL
188 const char *Priority(unsigned char Priority);
189
578bfd0a 190 // Accessors
8f3ba4e8
DK
191 GrpIterator FindGrp(const std::string &Name);
192 PkgIterator FindPkg(const std::string &Name);
193 PkgIterator FindPkg(const std::string &Name, const std::string &Arch);
5bf15716 194
578bfd0a 195 Header &Head() {return *HeaderP;};
25396fb0
DK
196 inline GrpIterator GrpBegin();
197 inline GrpIterator GrpEnd();
578bfd0a
AL
198 inline PkgIterator PkgBegin();
199 inline PkgIterator PkgEnd();
ad00ae81
AL
200 inline PkgFileIterator FileBegin();
201 inline PkgFileIterator FileEnd();
b2e465d6 202
8d4c859d 203 inline bool MultiArchCache() const { return MultiArchEnabled; };
2b5c35c7 204 inline char const * const NativeArch() const;
8d4c859d 205
b2e465d6
AL
206 // Make me a function
207 pkgVersioningSystem *VS;
208
209 // Converters
210 static const char *CompTypeDeb(unsigned char Comp);
211 static const char *CompType(unsigned char Comp);
212 static const char *DepType(unsigned char Dep);
ad00ae81 213
b2e465d6 214 pkgCache(MMap *Map,bool DoMap = true);
578bfd0a 215 virtual ~pkgCache() {};
8d4c859d
DK
216
217private:
218 bool MultiArchEnabled;
8f3ba4e8 219 PkgIterator SingleArchFindPkg(const std::string &Name);
578bfd0a 220};
92fcbfc1
DK
221 /*}}}*/
222// Header structure /*{{{*/
578bfd0a
AL
223struct pkgCache::Header
224{
94449d7c
DK
225 /** \brief Signature information
226
227 This must contain the hex value 0x98FE76DC which is designed to
228 verify that the system loading the image has the same byte order
229 and byte size as the system saving the image */
578bfd0a 230 unsigned long Signature;
94449d7c 231 /** These contain the version of the cache file */
578bfd0a
AL
232 short MajorVersion;
233 short MinorVersion;
94449d7c
DK
234 /** \brief indicates if the cache should be erased
235
236 Dirty is true if the cache file was opened for reading, the client
237 expects to have written things to it and have not fully synced it.
238 The file should be erased and rebuilt if it is true. */
578bfd0a 239 bool Dirty;
94449d7c
DK
240
241 /** \brief Size of structure values
242
243 All *Sz variables contains the sizeof() that particular structure.
244 It is used as an extra consistency check on the structure of the file.
245
246 If any of the size values do not exactly match what the client expects
247 then the client should refuse the load the file. */
578bfd0a 248 unsigned short HeaderSz;
52c41485 249 unsigned short GroupSz;
578bfd0a
AL
250 unsigned short PackageSz;
251 unsigned short PackageFileSz;
252 unsigned short VersionSz;
a52f938b 253 unsigned short DescriptionSz;
578bfd0a
AL
254 unsigned short DependencySz;
255 unsigned short ProvidesSz;
dcb79bae 256 unsigned short VerFileSz;
a52f938b 257 unsigned short DescFileSz;
94449d7c
DK
258
259 /** \brief Structure counts
260
261 These indicate the number of each structure contained in the cache.
262 PackageCount is especially useful for generating user state structures.
263 See Package::Id for more info. */
5bf15716 264 unsigned long GroupCount;
578bfd0a
AL
265 unsigned long PackageCount;
266 unsigned long VersionCount;
a52f938b 267 unsigned long DescriptionCount;
578bfd0a
AL
268 unsigned long DependsCount;
269 unsigned long PackageFileCount;
a7e66b17 270 unsigned long VerFileCount;
a52f938b 271 unsigned long DescFileCount;
a7e66b17 272 unsigned long ProvidesCount;
94449d7c
DK
273
274 /** \brief index of the first PackageFile structure
275
276 The PackageFile structures are singly linked lists that represent
277 all package files that have been merged into the cache. */
278 map_ptrloc FileList;
279 /** \brief index of the first StringItem structure
280
281 The cache contains a list of all the unique strings (StringItems).
282 The parser reads this list into memory so it can match strings
283 against it.*/
284 map_ptrloc StringList;
285 /** \brief String representing the version system used */
286 map_ptrloc VerSysName;
287 /** \brief Architecture(s) the cache was built against */
288 map_ptrloc Architecture;
289 /** \brief The maximum size of a raw entry from the original Package file */
ad00ae81 290 unsigned long MaxVerFileSize;
94449d7c 291 /** \brief The maximum size of a raw entry from the original Translation file */
a52f938b 292 unsigned long MaxDescFileSize;
578bfd0a 293
94449d7c
DK
294 /** \brief The Pool structures manage the allocation pools that the generator uses
295
296 Start indicates the first byte of the pool, Count is the number of objects
297 remaining in the pool and ItemSize is the structure size (alignment factor)
298 of the pool. An ItemSize of 0 indicates the pool is empty. There should be
299 the same number of pools as there are structure types. The generator
300 stores this information so future additions can make use of any unused pool
301 blocks. */
5bf15716 302 DynamicMMap::Pool Pools[9];
578bfd0a 303
94449d7c
DK
304 /** \brief hash tables providing rapid group/package name lookup
305
306 Each group/package name is inserted into the hash table using pkgCache::Hash(const &string)
307 By iterating over each entry in the hash table it is possible to iterate over
308 the entire list of packages. Hash Collisions are handled with a singly linked
309 list of packages based at the hash item. The linked list contains only
310 packages that match the hashing function.
311 In the PkgHashTable is it possible that multiple packages have the same name -
312 these packages are stored as a sequence in the list.
313
314 Beware: The Hashmethod assumes that the hash table sizes are equal */
5bf15716
DK
315 map_ptrloc PkgHashTable[2*1048];
316 map_ptrloc GrpHashTable[2*1048];
578bfd0a 317
0688ccd8
JAK
318 /** \brief Size of the complete cache file */
319 unsigned long CacheFileSize;
320
578bfd0a
AL
321 bool CheckSizes(Header &Against) const;
322 Header();
323};
92fcbfc1 324 /*}}}*/
94449d7c
DK
325// Group structure /*{{{*/
326/** \brief groups architecture depending packages together
5bf15716 327
94449d7c
DK
328 On or more packages with the same name form a group, so we have
329 a simple way to access a package built for different architectures
330 Group exists in a singly linked list of group records starting at
331 the hash index of the name in the pkgCache::Header::GrpHashTable */
332struct pkgCache::Group
333{
334 /** \brief Name of the group */
335 map_ptrloc Name; // StringItem
336
337 // Linked List
52c41485 338 /** \brief Link to the first package which belongs to the group */
94449d7c 339 map_ptrloc FirstPackage; // Package
52c41485 340 /** \brief Link to the last package which belongs to the group */
94449d7c 341 map_ptrloc LastPackage; // Package
52c41485 342 /** \brief Link to the next Group */
94449d7c 343 map_ptrloc Next; // Group
52c41485
DK
344 /** \brief unique sequel ID */
345 unsigned int ID;
346
5bf15716
DK
347};
348 /*}}}*/
94449d7c
DK
349// Package structure /*{{{*/
350/** \brief contains information for a single unique package
351
352 There can be any number of versions of a given package.
353 Package exists in a singly linked list of package records starting at
354 the hash index of the name in the pkgCache::Header::PkgHashTable
355
356 A package can be created for every architecture so package names are
357 not unique, but it is garanteed that packages with the same name
358 are sequencel ordered in the list. Packages with the same name can be
359 accessed with the Group.
360*/
361struct pkgCache::Package
578bfd0a 362{
94449d7c
DK
363 /** \brief Name of the package */
364 map_ptrloc Name; // StringItem
365 /** \brief Architecture of the package */
366 map_ptrloc Arch; // StringItem
367 /** \brief Base of a singly linked list of versions
368
369 Each structure represents a unique version of the package.
370 The version structures contain links into PackageFile and the
371 original text file as well as detailed information about the size
372 and dependencies of the specific package. In this way multiple
373 versions of a package can be cleanly handled by the system.
374 Furthermore, this linked list is guaranteed to be sorted
375 from Highest version to lowest version with no duplicate entries. */
349cd3b8 376 map_ptrloc VersionList; // Version
94449d7c 377 /** \brief index to the installed version */
349cd3b8 378 map_ptrloc CurrentVer; // Version
94449d7c
DK
379 /** \brief indicates the deduced section
380
381 Should be the index to the string "Unknown" or to the section
382 of the last parsed item. */
383 map_ptrloc Section; // StringItem
384 /** \brief index of the group this package belongs to */
5bf15716 385 map_ptrloc Group; // Group the Package belongs to
94449d7c
DK
386
387 // Linked list
388 /** \brief Link to the next package in the same bucket */
349cd3b8 389 map_ptrloc NextPackage; // Package
94449d7c 390 /** \brief List of all dependencies on this package */
349cd3b8 391 map_ptrloc RevDepends; // Dependency
94449d7c 392 /** \brief List of all "packages" this package provide */
349cd3b8 393 map_ptrloc ProvidesList; // Provides
a52f938b 394
578bfd0a 395 // Install/Remove/Purge etc
94449d7c 396 /** \brief state that the user wishes the package to be in */
578bfd0a 397 unsigned char SelectedState; // What
94449d7c
DK
398 /** \brief installation state of the package
399
400 This should be "ok" but in case the installation failed
401 it will be different.
402 */
578bfd0a 403 unsigned char InstState; // Flags
94449d7c 404 /** \brief indicates if the package is installed */
578bfd0a 405 unsigned char CurrentState; // State
94449d7c
DK
406
407 /** \brief unique sequel ID
408
409 ID is a unique value from 0 to Header->PackageCount assigned by the generator.
410 This allows clients to create an array of size PackageCount and use it to store
411 state information for the package map. For instance the status file emitter uses
412 this to track which packages have been emitted already. */
09fab244 413 unsigned int ID;
94449d7c 414 /** \brief some useful indicators of the package's state */
f55a958f 415 unsigned long Flags;
578bfd0a 416};
92fcbfc1 417 /*}}}*/
94449d7c
DK
418// Package File structure /*{{{*/
419/** \brief stores information about the files used to generate the cache
420
421 Package files are referenced by Version structures to be able to know
422 after the generation still from which Packages file includes this Version
423 as we need this information later on e.g. for pinning. */
424struct pkgCache::PackageFile
578bfd0a 425{
94449d7c
DK
426 /** \brief physical disk file that this PackageFile represents */
427 map_ptrloc FileName; // StringItem
428 /** \brief the release information
429
430 Please see the files document for a description of what the
431 release information means. */
432 map_ptrloc Archive; // StringItem
433 map_ptrloc Codename; // StringItem
434 map_ptrloc Component; // StringItem
435 map_ptrloc Version; // StringItem
436 map_ptrloc Origin; // StringItem
437 map_ptrloc Label; // StringItem
438 map_ptrloc Architecture; // StringItem
439 /** \brief The site the index file was fetched from */
440 map_ptrloc Site; // StringItem
441 /** \brief indicates what sort of index file this is
442
443 @TODO enumerate at least the possible indexes */
444 map_ptrloc IndexType; // StringItem
445 /** \brief Size of the file
446
447 Used together with the modification time as a
448 simple check to ensure that the Packages
449 file has not been altered since Cache generation. */
450 unsigned long Size;
451 /** \brief Modification time for the file */
452 time_t mtime;
453
454 /* @TODO document PackageFile::Flags */
3c124dde 455 unsigned long Flags;
94449d7c 456
578bfd0a 457 // Linked list
94449d7c 458 /** \brief Link to the next PackageFile in the Cache */
349cd3b8 459 map_ptrloc NextFile; // PackageFile
94449d7c 460 /** \brief unique sequel ID */
09fab244 461 unsigned int ID;
578bfd0a 462};
92fcbfc1 463 /*}}}*/
94449d7c
DK
464// VerFile structure /*{{{*/
465/** \brief associates a version with a PackageFile
466
467 This allows a full description of all Versions in all files
468 (and hence all sources) under consideration. */
469struct pkgCache::VerFile
dcb79bae 470{
94449d7c 471 /** \brief index of the package file that this version was found in */
349cd3b8 472 map_ptrloc File; // PackageFile
94449d7c 473 /** \brief next step in the linked list */
349cd3b8 474 map_ptrloc NextFile; // PkgVerFile
94449d7c 475 /** \brief position in the package file */
349cd3b8 476 map_ptrloc Offset; // File offset
94449d7c 477 /* @TODO document pkgCache::VerFile::Size */
6d3176fb 478 unsigned long Size;
dcb79bae 479};
92fcbfc1 480 /*}}}*/
94449d7c
DK
481// DescFile structure /*{{{*/
482/** \brief associates a description with a Translation file */
483struct pkgCache::DescFile
a52f938b 484{
94449d7c 485 /** \brief index of the file that this description was found in */
a52f938b 486 map_ptrloc File; // PackageFile
94449d7c 487 /** \brief next step in the linked list */
a52f938b 488 map_ptrloc NextFile; // PkgVerFile
94449d7c 489 /** \brief position in the file */
a52f938b 490 map_ptrloc Offset; // File offset
94449d7c 491 /* @TODO document pkgCache::DescFile::Size */
6d3176fb 492 unsigned long Size;
a52f938b 493};
92fcbfc1 494 /*}}}*/
94449d7c
DK
495// Version structure /*{{{*/
496/** \brief information for a single version of a package
497
498 The version list is always sorted from highest version to lowest
499 version by the generator. Equal version numbers are either merged
500 or handled as separate versions based on the Hash value. */
501struct pkgCache::Version
578bfd0a 502{
94449d7c
DK
503 /** \brief complete version string */
504 map_ptrloc VerStr; // StringItem
505 /** \brief section this version is filled in */
506 map_ptrloc Section; // StringItem
894d672e
DK
507
508 /** \brief Multi-Arch capabilities of a package version */
509 enum VerMultiArch { None = 0, /*!< is the default and doesn't trigger special behaviour */
510 All = (1<<0), /*!< will cause that Ver.Arch() will report "all" */
511 Foreign = (1<<1), /*!< can satisfy dependencies in another architecture */
512 Same = (1<<2), /*!< can be co-installed with itself from other architectures */
00b6a181
DK
513 Allowed = (1<<3), /*!< other packages are allowed to depend on thispkg:any */
514 AllForeign = All | Foreign,
515 AllAllowed = All | Allowed };
94449d7c
DK
516 /** \brief stores the MultiArch capabilities of this version
517
894d672e
DK
518 Flags used are defined in pkgCache::Version::VerMultiArch
519 */
520 unsigned char MultiArch;
25396fb0 521
94449d7c
DK
522 /** \brief references all the PackageFile's that this version came from
523
524 FileList can be used to determine what distribution(s) the Version
525 applies to. If FileList is 0 then this is a blank version.
526 The structure should also have a 0 in all other fields excluding
527 pkgCache::Version::VerStr and Possibly pkgCache::Version::NextVer. */
349cd3b8 528 map_ptrloc FileList; // VerFile
94449d7c 529 /** \brief next (lower or equal) version in the linked list */
349cd3b8 530 map_ptrloc NextVer; // Version
94449d7c 531 /** \brief next description in the linked list */
a52f938b 532 map_ptrloc DescriptionList; // Description
94449d7c 533 /** \brief base of the dependency list */
349cd3b8 534 map_ptrloc DependsList; // Dependency
94449d7c
DK
535 /** \brief links to the owning package
536
537 This allows reverse dependencies to determine the package */
349cd3b8 538 map_ptrloc ParentPkg; // Package
94449d7c 539 /** \brief list of pkgCache::Provides */
349cd3b8 540 map_ptrloc ProvidesList; // Provides
94449d7c
DK
541
542 /** \brief archive size for this version
543
544 For Debian this is the size of the .deb file. */
e2c66de5 545 unsigned long long Size; // These are the .deb size
94449d7c 546 /** \brief uncompressed size for this version */
e2c66de5 547 unsigned long long InstalledSize;
94449d7c
DK
548 /** \brief characteristic value representing this version
549
550 No two packages in existence should have the same VerStr
551 and Hash with different contents. */
204fbdcc 552 unsigned short Hash;
94449d7c 553 /** \brief unique sequel ID */
09fab244 554 unsigned int ID;
94449d7c 555 /** \brief parsed priority value */
578bfd0a
AL
556 unsigned char Priority;
557};
92fcbfc1 558 /*}}}*/
94449d7c
DK
559// Description structure /*{{{*/
560/** \brief datamember of a linked list of available description for a version */
561struct pkgCache::Description
a52f938b 562{
94449d7c
DK
563 /** \brief Language code of this description (translation)
564
565 If the value has a 0 length then this is read using the Package
566 file else the Translation-CODE file is used. */
567 map_ptrloc language_code; // StringItem
568 /** \brief MD5sum of the original description
569
570 Used to map Translations of a description to a version
571 and to check that the Translation is up-to-date. */
572 map_ptrloc md5sum; // StringItem
a52f938b 573
94449d7c 574 /* @TODO document pkgCache::Description::FileList */
a52f938b 575 map_ptrloc FileList; // DescFile
94449d7c 576 /** \brief next translation for this description */
a52f938b 577 map_ptrloc NextDesc; // Description
94449d7c 578 /** \brief the text is a description of this package */
a52f938b
OS
579 map_ptrloc ParentPkg; // Package
580
94449d7c 581 /** \brief unique sequel ID */
09fab244 582 unsigned int ID;
a52f938b 583};
92fcbfc1 584 /*}}}*/
94449d7c
DK
585// Dependency structure /*{{{*/
586/** \brief information for a single dependency record
587
588 The records are split up like this to ease processing by the client.
589 The base of the linked list is pkgCache::Version::DependsList.
590 All forms of dependencies are recorded here including Depends,
591 Recommends, Suggests, Enhances, Conflicts, Replaces and Breaks. */
592struct pkgCache::Dependency
578bfd0a 593{
94449d7c
DK
594 /** \brief string of the version the dependency is applied against */
595 map_ptrloc Version; // StringItem
596 /** \brief index of the package this depends applies to
597
598 The generator will - if the package does not already exist -
599 create a blank (no version records) package. */
349cd3b8 600 map_ptrloc Package; // Package
94449d7c 601 /** \brief next dependency of this version */
349cd3b8 602 map_ptrloc NextDepends; // Dependency
94449d7c 603 /** \brief next reverse dependency of this package */
349cd3b8 604 map_ptrloc NextRevDepends; // Dependency
94449d7c 605 /** \brief version of the package which has the reverse depends */
349cd3b8 606 map_ptrloc ParentVer; // Version
94449d7c
DK
607
608 /** \brief unique sequel ID */
609 map_ptrloc ID;
610 /** \brief Dependency type - Depends, Recommends, Conflicts, etc */
578bfd0a 611 unsigned char Type;
94449d7c
DK
612 /** \brief comparison operator specified on the depends line
613
614 If the high bit is set then it is a logical OR with the previous record. */
578bfd0a 615 unsigned char CompareOp;
578bfd0a 616};
92fcbfc1 617 /*}}}*/
94449d7c
DK
618// Provides structure /*{{{*/
619/** \brief handles virtual packages
620
621 When a Provides: line is encountered a new provides record is added
622 associating the package with a virtual package name.
623 The provides structures are linked off the package structures.
624 This simplifies the analysis of dependencies and other aspects A provides
625 refers to a specific version of a specific package, not all versions need to
626 provide that provides.*/
627struct pkgCache::Provides
578bfd0a 628{
94449d7c
DK
629 /** \brief index of the package providing this */
630 map_ptrloc ParentPkg; // Package
631 /** \brief index of the version this provide line applies to */
349cd3b8 632 map_ptrloc Version; // Version
94449d7c
DK
633 /** \brief version in the provides line (if any)
634
635 This version allows dependencies to depend on specific versions of a
636 Provides, as well as allowing Provides to override existing packages.
637 This is experimental. Note that Debian doesn't allow versioned provides */
638 map_ptrloc ProvideVersion; // StringItem
639 /** \brief next provides (based of package) */
349cd3b8 640 map_ptrloc NextProvides; // Provides
94449d7c 641 /** \brief next provides (based of version) */
349cd3b8 642 map_ptrloc NextPkgProv; // Provides
578bfd0a 643};
92fcbfc1 644 /*}}}*/
94449d7c
DK
645// StringItem structure /*{{{*/
646/** \brief used for generating single instances of strings
647
648 Some things like Section Name are are useful to have as unique tags.
649 It is part of a linked list based at pkgCache::Header::StringList
650
651 All strings are simply inlined any place in the file that is natural
652 for the writer. The client should make no assumptions about the positioning
653 of strings. All StringItems should be null-terminated. */
654struct pkgCache::StringItem
578bfd0a 655{
94449d7c
DK
656 /** \brief string this refers to */
657 map_ptrloc String; // StringItem
658 /** \brief Next link in the chain */
349cd3b8 659 map_ptrloc NextItem; // StringItem
578bfd0a 660};
92fcbfc1 661 /*}}}*/
959470da
DK
662
663
664inline char const * const pkgCache::NativeArch() const
665 { return StrP + HeaderP->Architecture; };
666
094a497d 667#include <apt-pkg/cacheiterators.h>
578bfd0a 668
25396fb0
DK
669inline pkgCache::GrpIterator pkgCache::GrpBegin()
670 {return GrpIterator(*this);};
671inline pkgCache::GrpIterator pkgCache::GrpEnd()
672 {return GrpIterator(*this,GrpP);};
578bfd0a
AL
673inline pkgCache::PkgIterator pkgCache::PkgBegin()
674 {return PkgIterator(*this);};
675inline pkgCache::PkgIterator pkgCache::PkgEnd()
676 {return PkgIterator(*this,PkgP);};
ad00ae81 677inline pkgCache::PkgFileIterator pkgCache::FileBegin()
b2e465d6 678 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
ad00ae81
AL
679inline pkgCache::PkgFileIterator pkgCache::FileEnd()
680 {return PkgFileIterator(*this,PkgFileP);};
578bfd0a 681
b2e465d6 682// Oh I wish for Real Name Space Support
92fcbfc1 683class pkgCache::Namespace /*{{{*/
b2e465d6
AL
684{
685 public:
803ea2a8 686 typedef pkgCache::GrpIterator GrpIterator;
b2e465d6
AL
687 typedef pkgCache::PkgIterator PkgIterator;
688 typedef pkgCache::VerIterator VerIterator;
a52f938b 689 typedef pkgCache::DescIterator DescIterator;
b2e465d6
AL
690 typedef pkgCache::DepIterator DepIterator;
691 typedef pkgCache::PrvIterator PrvIterator;
692 typedef pkgCache::PkgFileIterator PkgFileIterator;
693 typedef pkgCache::VerFileIterator VerFileIterator;
694 typedef pkgCache::Version Version;
a52f938b 695 typedef pkgCache::Description Description;
b2e465d6
AL
696 typedef pkgCache::Package Package;
697 typedef pkgCache::Header Header;
698 typedef pkgCache::Dep Dep;
699 typedef pkgCache::Flag Flag;
700};
92fcbfc1 701 /*}}}*/
578bfd0a 702#endif