pkgcachegen.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcachegen.h,v 1.19 2002/07/08 03:13:30 jgg Exp $
  4. /* ######################################################################
  5. Package Cache Generator - Generator for the cache structure.
  6. This builds the cache structure from the abstract package list parser.
  7. Each archive source has it's own list parser that is instantiated by
  8. the caller to provide data for the generator.
  9. Parts of the cache are created by this generator class while other
  10. parts are created by the list parser. The list parser is responsible
  11. for creating version, depends and provides structures, and some of
  12. their contents
  13. ##################################################################### */
  14. /*}}}*/
  15. #ifndef PKGLIB_PKGCACHEGEN_H
  16. #define PKGLIB_PKGCACHEGEN_H
  17. #include <apt-pkg/pkgcache.h>
  18. #include <apt-pkg/md5.h>
  19. #include <vector>
  20. class pkgSourceList;
  21. class OpProgress;
  22. class MMap;
  23. class pkgIndexFile;
  24. class pkgCacheGenerator /*{{{*/
  25. {
  26. private:
  27. pkgCache::StringItem *UniqHash[26];
  28. map_ptrloc WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); };
  29. map_ptrloc WriteStringInMap(const char *String);
  30. map_ptrloc WriteStringInMap(const char *String, const unsigned long &Len);
  31. map_ptrloc AllocateInMap(const unsigned long &size);
  32. public:
  33. class ListParser;
  34. friend class ListParser;
  35. template<typename Iter> class Dynamic {
  36. public:
  37. static std::vector<Iter*> toReMap;
  38. Dynamic(Iter &I) {
  39. toReMap.push_back(&I);
  40. }
  41. ~Dynamic() {
  42. toReMap.pop_back();
  43. }
  44. };
  45. protected:
  46. DynamicMMap &Map;
  47. pkgCache Cache;
  48. OpProgress *Progress;
  49. std::string PkgFileName;
  50. pkgCache::PackageFile *CurrentFile;
  51. // Flag file dependencies
  52. bool FoundFileDeps;
  53. bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name);
  54. bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch);
  55. bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
  56. bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
  57. bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
  58. std::string const &Version, unsigned int const &Op,
  59. unsigned int const &Type, map_ptrloc* &OldDepLast);
  60. unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,unsigned long Next);
  61. map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_ptrloc Next);
  62. public:
  63. unsigned long WriteUniqString(const char *S,unsigned int Size);
  64. inline unsigned long WriteUniqString(const std::string &S) {return WriteUniqString(S.c_str(),S.length());};
  65. void DropProgress() {Progress = 0;};
  66. bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index,
  67. unsigned long Flags = 0);
  68. bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
  69. inline pkgCache &GetCache() {return Cache;};
  70. inline pkgCache::PkgFileIterator GetCurFile()
  71. {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
  72. bool HasFileDeps() {return FoundFileDeps;};
  73. bool MergeFileProvides(ListParser &List);
  74. bool FinishCache(OpProgress *Progress);
  75. static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
  76. MMap **OutMap = 0,bool AllowMem = false);
  77. static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap);
  78. static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0);
  79. void ReMap(void const * const oldMap, void const * const newMap);
  80. pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
  81. ~pkgCacheGenerator();
  82. };
  83. /*}}}*/
  84. // This is the abstract package list parser class. /*{{{*/
  85. class pkgCacheGenerator::ListParser
  86. {
  87. pkgCacheGenerator *Owner;
  88. friend class pkgCacheGenerator;
  89. // Some cache items
  90. pkgCache::VerIterator OldDepVer;
  91. map_ptrloc *OldDepLast;
  92. // Flag file dependencies
  93. bool FoundFileDeps;
  94. protected:
  95. inline unsigned long WriteUniqString(std::string S) {return Owner->WriteUniqString(S);};
  96. inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);};
  97. inline unsigned long WriteString(const std::string &S) {return Owner->WriteStringInMap(S);};
  98. inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
  99. bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch,
  100. const std::string &Version,unsigned int Op,
  101. unsigned int Type);
  102. bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName,
  103. const std::string &PkgArch, const std::string &Version);
  104. public:
  105. // These all operate against the current section
  106. virtual std::string Package() = 0;
  107. virtual std::string Architecture() = 0;
  108. virtual bool ArchitectureAll() = 0;
  109. virtual std::string Version() = 0;
  110. virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0;
  111. virtual std::string Description() = 0;
  112. virtual std::string DescriptionLanguage() = 0;
  113. virtual MD5SumValue Description_md5() = 0;
  114. virtual unsigned short VersionHash() = 0;
  115. virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
  116. pkgCache::VerIterator &Ver) = 0;
  117. virtual unsigned long Offset() = 0;
  118. virtual unsigned long Size() = 0;
  119. virtual bool Step() = 0;
  120. inline bool HasFileDeps() {return FoundFileDeps;};
  121. virtual bool CollectFileProvides(pkgCache &Cache,
  122. pkgCache::VerIterator &Ver) {return true;};
  123. ListParser() : FoundFileDeps(false) {};
  124. virtual ~ListParser() {};
  125. };
  126. /*}}}*/
  127. bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
  128. MMap **OutMap = 0,bool AllowMem = false);
  129. bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
  130. #endif