pkgcachegen.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. class pkgSourceList;
  20. class OpProgress;
  21. class MMap;
  22. class pkgIndexFile;
  23. class pkgCacheGenerator /*{{{*/
  24. {
  25. private:
  26. pkgCache::StringItem *UniqHash[26];
  27. unsigned long WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); };
  28. unsigned long WriteStringInMap(const char *String);
  29. unsigned long WriteStringInMap(const char *String, const unsigned long &Len);
  30. unsigned long AllocateInMap(const unsigned long &size);
  31. public:
  32. class ListParser;
  33. friend class ListParser;
  34. protected:
  35. DynamicMMap &Map;
  36. pkgCache Cache;
  37. OpProgress *Progress;
  38. string PkgFileName;
  39. pkgCache::PackageFile *CurrentFile;
  40. // Flag file dependencies
  41. bool FoundFileDeps;
  42. bool NewGroup(pkgCache::GrpIterator &Grp,const string &Name);
  43. bool NewPackage(pkgCache::PkgIterator &Pkg,const string &Name, const string &Arch);
  44. bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
  45. bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
  46. bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
  47. string const &Version, unsigned int const &Op,
  48. unsigned int const &Type, map_ptrloc *OldDepLast);
  49. unsigned long NewVersion(pkgCache::VerIterator &Ver,const string &VerStr,unsigned long Next);
  50. map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const string &Lang,const MD5SumValue &md5sum,map_ptrloc Next);
  51. public:
  52. unsigned long WriteUniqString(const char *S,unsigned int Size);
  53. inline unsigned long WriteUniqString(const string &S) {return WriteUniqString(S.c_str(),S.length());};
  54. void DropProgress() {Progress = 0;};
  55. bool SelectFile(const string &File,const string &Site,pkgIndexFile const &Index,
  56. unsigned long Flags = 0);
  57. bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
  58. inline pkgCache &GetCache() {return Cache;};
  59. inline pkgCache::PkgFileIterator GetCurFile()
  60. {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
  61. bool HasFileDeps() {return FoundFileDeps;};
  62. bool MergeFileProvides(ListParser &List);
  63. bool FinishCache(OpProgress *Progress);
  64. static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
  65. MMap **OutMap = 0,bool AllowMem = false);
  66. static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap);
  67. pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
  68. ~pkgCacheGenerator();
  69. };
  70. /*}}}*/
  71. // This is the abstract package list parser class. /*{{{*/
  72. class pkgCacheGenerator::ListParser
  73. {
  74. pkgCacheGenerator *Owner;
  75. friend class pkgCacheGenerator;
  76. // Some cache items
  77. pkgCache::VerIterator OldDepVer;
  78. map_ptrloc *OldDepLast;
  79. // Flag file dependencies
  80. bool FoundFileDeps;
  81. protected:
  82. inline unsigned long WriteUniqString(string S) {return Owner->WriteUniqString(S);};
  83. inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);};
  84. inline unsigned long WriteString(const string &S) {return Owner->WriteStringInMap(S);};
  85. inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
  86. bool NewDepends(pkgCache::VerIterator Ver,const string &Package, const string &Arch,
  87. const string &Version,unsigned int Op,
  88. unsigned int Type);
  89. bool NewProvides(pkgCache::VerIterator Ver,const string &PkgName,
  90. const string &PkgArch, const string &Version);
  91. public:
  92. // These all operate against the current section
  93. virtual string Package() = 0;
  94. virtual string Architecture() = 0;
  95. virtual bool ArchitectureAll() = 0;
  96. virtual string Version() = 0;
  97. virtual bool NewVersion(pkgCache::VerIterator Ver) = 0;
  98. virtual string Description() = 0;
  99. virtual string DescriptionLanguage() = 0;
  100. virtual MD5SumValue Description_md5() = 0;
  101. virtual unsigned short VersionHash() = 0;
  102. virtual bool UsePackage(pkgCache::PkgIterator Pkg,
  103. pkgCache::VerIterator Ver) = 0;
  104. virtual unsigned long Offset() = 0;
  105. virtual unsigned long Size() = 0;
  106. virtual bool Step() = 0;
  107. inline bool HasFileDeps() {return FoundFileDeps;};
  108. virtual bool CollectFileProvides(pkgCache &Cache,
  109. pkgCache::VerIterator Ver) {return true;};
  110. ListParser() : FoundFileDeps(false) {};
  111. virtual ~ListParser() {};
  112. };
  113. /*}}}*/
  114. bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
  115. MMap **OutMap = 0,bool AllowMem = false);
  116. bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
  117. #ifdef APT_COMPATIBILITY
  118. #if APT_COMPATIBILITY != 986
  119. #warning "Using APT_COMPATIBILITY"
  120. #endif
  121. MMap *pkgMakeStatusCacheMem(pkgSourceList &List,OpProgress &Progress)
  122. {
  123. MMap *Map = 0;
  124. if (pkgCacheGenerator::MakeStatusCache(List,&Progress,&Map,true) == false)
  125. return 0;
  126. return Map;
  127. }
  128. #endif
  129. #endif