apt @VERSION@

pkgcachegen.h

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 
00026 #include <vector>
00027 
00028 class pkgSourceList;
00029 class OpProgress;
00030 class MMap;
00031 class pkgIndexFile;
00032 
00033 class pkgCacheGenerator                                                 /*{{{*/
00034 {
00035    private:
00036 
00037    pkgCache::StringItem *UniqHash[26];
00038    map_ptrloc WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); };
00039    map_ptrloc WriteStringInMap(const char *String);
00040    map_ptrloc WriteStringInMap(const char *String, const unsigned long &Len);
00041    map_ptrloc AllocateInMap(const unsigned long &size);
00042 
00043    public:
00044    
00045    class ListParser;
00046    friend class ListParser;
00047 
00048    template<typename Iter> class Dynamic {
00049       public:
00050       static std::vector<Iter*> toReMap;
00051       Dynamic(Iter &I) {
00052          toReMap.push_back(&I);
00053       }
00054 
00055       ~Dynamic() {
00056          toReMap.pop_back();
00057       }
00058    };
00059 
00060    protected:
00061 
00062    DynamicMMap &Map;
00063    pkgCache Cache;
00064    OpProgress *Progress;
00065    
00066    string PkgFileName;
00067    pkgCache::PackageFile *CurrentFile;
00068 
00069    // Flag file dependencies
00070    bool FoundFileDeps;
00071    
00072    bool NewGroup(pkgCache::GrpIterator &Grp,const string &Name);
00073    bool NewPackage(pkgCache::PkgIterator &Pkg,const string &Name, const string &Arch);
00074    bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
00075    bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
00076    bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
00077                    string const &Version, unsigned int const &Op,
00078                    unsigned int const &Type, map_ptrloc *OldDepLast);
00079    unsigned long NewVersion(pkgCache::VerIterator &Ver,const string &VerStr,unsigned long Next);
00080    map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const string &Lang,const MD5SumValue &md5sum,map_ptrloc Next);
00081 
00082    public:
00083 
00084    unsigned long WriteUniqString(const char *S,unsigned int Size);
00085    inline unsigned long WriteUniqString(const string &S) {return WriteUniqString(S.c_str(),S.length());};
00086 
00087    void DropProgress() {Progress = 0;};
00088    bool SelectFile(const string &File,const string &Site,pkgIndexFile const &Index,
00089                    unsigned long Flags = 0);
00090    bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
00091    inline pkgCache &GetCache() {return Cache;};
00092    inline pkgCache::PkgFileIterator GetCurFile() 
00093          {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
00094 
00095    bool HasFileDeps() {return FoundFileDeps;};
00096    bool MergeFileProvides(ListParser &List);
00097    bool FinishCache(OpProgress *Progress);
00098 
00099    static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
00100                         MMap **OutMap = 0,bool AllowMem = false);
00101    static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap);
00102    static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0);
00103 
00104    void ReMap(void const * const oldMap, void const * const newMap);
00105 
00106    pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
00107    ~pkgCacheGenerator();
00108 };
00109                                                                         /*}}}*/
00110 // This is the abstract package list parser class.                      /*{{{*/
00111 class pkgCacheGenerator::ListParser
00112 {
00113    pkgCacheGenerator *Owner;
00114    friend class pkgCacheGenerator;
00115    
00116    // Some cache items
00117    pkgCache::VerIterator OldDepVer;
00118    map_ptrloc *OldDepLast;
00119 
00120    // Flag file dependencies
00121    bool FoundFileDeps;
00122       
00123    protected:
00124 
00125    inline unsigned long WriteUniqString(string S) {return Owner->WriteUniqString(S);};
00126    inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);};
00127    inline unsigned long WriteString(const string &S) {return Owner->WriteStringInMap(S);};
00128    inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
00129    bool NewDepends(pkgCache::VerIterator &Ver,const string &Package, const string &Arch,
00130                    const string &Version,unsigned int Op,
00131                    unsigned int Type);
00132    bool NewProvides(pkgCache::VerIterator &Ver,const string &PkgName,
00133                     const string &PkgArch, const string &Version);
00134    
00135    public:
00136    
00137    // These all operate against the current section
00138    virtual string Package() = 0;
00139    virtual string Architecture() = 0;
00140    virtual bool ArchitectureAll() = 0;
00141    virtual string Version() = 0;
00142    virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0;
00143    virtual string Description() = 0;
00144    virtual string DescriptionLanguage() = 0;
00145    virtual MD5SumValue Description_md5() = 0;
00146    virtual unsigned short VersionHash() = 0;
00147    virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
00148                            pkgCache::VerIterator &Ver) = 0;
00149    virtual unsigned long Offset() = 0;
00150    virtual unsigned long Size() = 0;
00151    
00152    virtual bool Step() = 0;
00153    
00154    inline bool HasFileDeps() {return FoundFileDeps;};
00155    virtual bool CollectFileProvides(pkgCache &Cache,
00156                                     pkgCache::VerIterator &Ver) {return true;};
00157 
00158    ListParser() : FoundFileDeps(false) {};
00159    virtual ~ListParser() {};
00160 };
00161                                                                         /*}}}*/
00162 
00163 bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
00164                         MMap **OutMap = 0,bool AllowMem = false);
00165 bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
00166 
00167 
00168 #ifdef APT_COMPATIBILITY
00169 #if APT_COMPATIBILITY != 986
00170 #warning "Using APT_COMPATIBILITY"
00171 #endif
00172 MMap *pkgMakeStatusCacheMem(pkgSourceList &List,OpProgress &Progress)
00173 {
00174    MMap *Map = 0;
00175    if (pkgCacheGenerator::MakeStatusCache(List,&Progress,&Map,true) == false)
00176       return 0;
00177    return Map;
00178 }
00179 #endif
00180 
00181 #endif