pkgcache.h 27 KB

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