pkgcachegen.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcachegen.h,v 1.18 2001/02/20 07:03:17 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. #ifdef __GNUG__
  18. #pragma interface "apt-pkg/pkgcachegen.h"
  19. #endif
  20. #include <apt-pkg/pkgcache.h>
  21. class pkgSourceList;
  22. class OpProgress;
  23. class MMap;
  24. class pkgIndexFile;
  25. class pkgCacheGenerator
  26. {
  27. private:
  28. pkgCache::StringItem *UniqHash[26];
  29. public:
  30. class ListParser;
  31. friend class ListParser;
  32. protected:
  33. DynamicMMap &Map;
  34. pkgCache Cache;
  35. OpProgress *Progress;
  36. string PkgFileName;
  37. pkgCache::PackageFile *CurrentFile;
  38. bool NewPackage(pkgCache::PkgIterator &Pkg,string Pkg);
  39. bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
  40. unsigned long NewVersion(pkgCache::VerIterator &Ver,string VerStr,unsigned long Next);
  41. public:
  42. unsigned long WriteUniqString(const char *S,unsigned int Size);
  43. inline unsigned long WriteUniqString(string S) {return WriteUniqString(S.c_str(),S.length());};
  44. void DropProgress() {Progress = 0;};
  45. bool SelectFile(string File,string Site,pkgIndexFile const &Index,
  46. unsigned long Flags = 0);
  47. bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
  48. inline pkgCache &GetCache() {return Cache;};
  49. inline pkgCache::PkgFileIterator GetCurFile()
  50. {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
  51. pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
  52. ~pkgCacheGenerator();
  53. };
  54. // This is the abstract package list parser class.
  55. class pkgCacheGenerator::ListParser
  56. {
  57. pkgCacheGenerator *Owner;
  58. friend class pkgCacheGenerator;
  59. // Some cache items
  60. pkgCache::VerIterator OldDepVer;
  61. map_ptrloc *OldDepLast;
  62. protected:
  63. inline unsigned long WriteUniqString(string S) {return Owner->WriteUniqString(S);};
  64. inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);};
  65. inline unsigned long WriteString(string S) {return Owner->Map.WriteString(S);};
  66. inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->Map.WriteString(S,Size);};
  67. bool NewDepends(pkgCache::VerIterator Ver,string Package,
  68. string Version,unsigned int Op,
  69. unsigned int Type);
  70. bool NewProvides(pkgCache::VerIterator Ver,string Package,string Version);
  71. public:
  72. // These all operate against the current section
  73. virtual string Package() = 0;
  74. virtual string Version() = 0;
  75. virtual bool NewVersion(pkgCache::VerIterator Ver) = 0;
  76. virtual unsigned short VersionHash() = 0;
  77. virtual bool UsePackage(pkgCache::PkgIterator Pkg,
  78. pkgCache::VerIterator Ver) = 0;
  79. virtual unsigned long Offset() = 0;
  80. virtual unsigned long Size() = 0;
  81. virtual bool Step() = 0;
  82. virtual ~ListParser() {};
  83. };
  84. bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
  85. MMap **OutMap = 0,bool AllowMem = false);
  86. bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
  87. #ifdef APT_COMPATIBILITY
  88. #if APT_COMPATIBILITY != 986
  89. #warning "Using APT_COMPATIBILITY"
  90. #endif
  91. MMap *pkgMakeStatusCacheMem(pkgSourceList &List,OpProgress &Progress)
  92. {
  93. MMap *Map = 0;
  94. if (pkgMakeStatusCache(List,Progress,&Map,true) == false)
  95. return 0;
  96. return Map;
  97. }
  98. #endif
  99. #endif