You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

161 lines
5.3 KiB

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