pkgcachegen.h 4.7 KB

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