apt
1.5
|
00001 // -*- mode: cpp; mode: fold -*- 00002 // Description /*{{{*/ 00003 // $Id: pkgcachegen.h,v 1.19 2002/07/08 03:13:30 jgg Exp $ 00004 /* ###################################################################### 00005 00006 Package Cache Generator - Generator for the cache structure. 00007 00008 This builds the cache structure from the abstract package list parser. 00009 Each archive source has it's own list parser that is instantiated by 00010 the caller to provide data for the generator. 00011 00012 Parts of the cache are created by this generator class while other 00013 parts are created by the list parser. The list parser is responsible 00014 for creating version, depends and provides structures, and some of 00015 their contents 00016 00017 ##################################################################### */ 00018 /*}}}*/ 00019 #ifndef PKGLIB_PKGCACHEGEN_H 00020 #define PKGLIB_PKGCACHEGEN_H 00021 00022 00023 #include <apt-pkg/pkgcache.h> 00024 #include <apt-pkg/md5.h> 00025 #include <apt-pkg/macros.h> 00026 00027 #include <vector> 00028 00029 class pkgSourceList; 00030 class OpProgress; 00031 class MMap; 00032 class pkgIndexFile; 00033 00034 class pkgCacheGenerator /*{{{*/ 00035 { 00036 private: 00037 00038 pkgCache::StringItem *UniqHash[26]; 00039 map_ptrloc WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; 00040 map_ptrloc WriteStringInMap(const char *String); 00041 map_ptrloc WriteStringInMap(const char *String, const unsigned long &Len); 00042 map_ptrloc AllocateInMap(const unsigned long &size); 00043 00044 public: 00045 00046 class ListParser; 00047 friend class ListParser; 00048 00049 template<typename Iter> class Dynamic { 00050 public: 00051 static std::vector<Iter*> toReMap; 00052 Dynamic(Iter &I) { 00053 toReMap.push_back(&I); 00054 } 00055 00056 ~Dynamic() { 00057 toReMap.pop_back(); 00058 } 00059 }; 00060 00061 protected: 00062 00063 DynamicMMap ⤅ 00064 pkgCache Cache; 00065 OpProgress *Progress; 00066 00067 std::string PkgFileName; 00068 pkgCache::PackageFile *CurrentFile; 00069 00070 // Flag file dependencies 00071 bool FoundFileDeps; 00072 00073 bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name); 00074 bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch); 00075 bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); 00076 bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); 00077 bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, 00078 std::string const &Version, unsigned int const &Op, 00079 unsigned int const &Type, map_ptrloc* &OldDepLast); 00080 unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,unsigned long Next); 00081 map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_ptrloc Next); 00082 00083 public: 00084 00085 unsigned long WriteUniqString(const char *S,unsigned int Size); 00086 inline unsigned long WriteUniqString(const std::string &S) {return WriteUniqString(S.c_str(),S.length());}; 00087 00088 void DropProgress() {Progress = 0;}; 00089 bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index, 00090 unsigned long Flags = 0); 00091 bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0); 00092 inline pkgCache &GetCache() {return Cache;}; 00093 inline pkgCache::PkgFileIterator GetCurFile() 00094 {return pkgCache::PkgFileIterator(Cache,CurrentFile);}; 00095 00096 bool HasFileDeps() {return FoundFileDeps;}; 00097 bool MergeFileProvides(ListParser &List); 00098 __deprecated bool FinishCache(OpProgress *Progress); 00099 00100 static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, 00101 MMap **OutMap = 0,bool AllowMem = false); 00102 static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap); 00103 static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0); 00104 00105 void ReMap(void const * const oldMap, void const * const newMap); 00106 00107 pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress); 00108 ~pkgCacheGenerator(); 00109 00110 private: 00111 bool MergeListGroup(ListParser &List, std::string const &GrpName); 00112 bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg); 00113 bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, 00114 std::string const &Version, pkgCache::VerIterator* &OutVer); 00115 00116 bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P, 00117 pkgCache::VerIterator &V); 00118 bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D); 00119 }; 00120 /*}}}*/ 00121 // This is the abstract package list parser class. /*{{{*/ 00122 class pkgCacheGenerator::ListParser 00123 { 00124 pkgCacheGenerator *Owner; 00125 friend class pkgCacheGenerator; 00126 00127 // Some cache items 00128 pkgCache::VerIterator OldDepVer; 00129 map_ptrloc *OldDepLast; 00130 00131 // Flag file dependencies 00132 bool FoundFileDeps; 00133 00134 protected: 00135 00136 inline unsigned long WriteUniqString(std::string S) {return Owner->WriteUniqString(S);}; 00137 inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);}; 00138 inline unsigned long WriteString(const std::string &S) {return Owner->WriteStringInMap(S);}; 00139 inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; 00140 bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch, 00141 const std::string &Version,unsigned int Op, 00142 unsigned int Type); 00143 bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName, 00144 const std::string &PkgArch, const std::string &Version); 00145 00146 public: 00147 00148 // These all operate against the current section 00149 virtual std::string Package() = 0; 00150 virtual std::string Architecture() = 0; 00151 virtual bool ArchitectureAll() = 0; 00152 virtual std::string Version() = 0; 00153 virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; 00154 virtual std::string Description() = 0; 00155 virtual std::string DescriptionLanguage() = 0; 00156 virtual MD5SumValue Description_md5() = 0; 00157 virtual unsigned short VersionHash() = 0; 00158 virtual bool UsePackage(pkgCache::PkgIterator &Pkg, 00159 pkgCache::VerIterator &Ver) = 0; 00160 virtual unsigned long Offset() = 0; 00161 virtual unsigned long Size() = 0; 00162 00163 virtual bool Step() = 0; 00164 00165 inline bool HasFileDeps() {return FoundFileDeps;}; 00166 virtual bool CollectFileProvides(pkgCache &Cache, 00167 pkgCache::VerIterator &Ver) {return true;}; 00168 00169 ListParser() : FoundFileDeps(false) {}; 00170 virtual ~ListParser() {}; 00171 }; 00172 /*}}}*/ 00173 00174 bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, 00175 MMap **OutMap = 0,bool AllowMem = false); 00176 bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); 00177 00178 #endif