]>
git.saurik.com Git - apt.git/blob - apt-pkg/pkgcachegen.h
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: pkgcachegen.h,v 1.19 2002/07/08 03:13:30 jgg Exp $
4 /* ######################################################################
6 Package Cache Generator - Generator for the cache structure.
8 This builds the cache structure from the abstract package list parser.
9 Each archive source has it's own list parser that is instantiated by
10 the caller to provide data for the generator.
12 Parts of the cache are created by this generator class while other
13 parts are created by the list parser. The list parser is responsible
14 for creating version, depends and provides structures, and some of
17 ##################################################################### */
19 #ifndef PKGLIB_PKGCACHEGEN_H
20 #define PKGLIB_PKGCACHEGEN_H
23 #include <apt-pkg/pkgcache.h>
24 #include <apt-pkg/md5.h>
33 class pkgCacheGenerator
/*{{{*/
37 pkgCache::StringItem
*UniqHash
[26];
38 map_ptrloc
WriteStringInMap(std::string
const &String
) { return WriteStringInMap(String
.c_str()); };
39 map_ptrloc
WriteStringInMap(const char *String
);
40 map_ptrloc
WriteStringInMap(const char *String
, const unsigned long &Len
);
41 map_ptrloc
AllocateInMap(const unsigned long &size
);
46 friend class ListParser
;
48 template<typename Iter
> class Dynamic
{
50 static std::vector
<Iter
*> toReMap
;
52 toReMap
.push_back(&I
);
67 pkgCache::PackageFile
*CurrentFile
;
69 // Flag file dependencies
72 bool NewGroup(pkgCache::GrpIterator
&Grp
,const string
&Name
);
73 bool NewPackage(pkgCache::PkgIterator
&Pkg
,const string
&Name
, const string
&Arch
);
74 bool NewFileVer(pkgCache::VerIterator
&Ver
,ListParser
&List
);
75 bool NewFileDesc(pkgCache::DescIterator
&Desc
,ListParser
&List
);
76 bool NewDepends(pkgCache::PkgIterator
&Pkg
, pkgCache::VerIterator
&Ver
,
77 string
const &Version
, unsigned int const &Op
,
78 unsigned int const &Type
, map_ptrloc
*OldDepLast
);
79 unsigned long NewVersion(pkgCache::VerIterator
&Ver
,const string
&VerStr
,unsigned long Next
);
80 map_ptrloc
NewDescription(pkgCache::DescIterator
&Desc
,const string
&Lang
,const MD5SumValue
&md5sum
,map_ptrloc Next
);
84 unsigned long WriteUniqString(const char *S
,unsigned int Size
);
85 inline unsigned long WriteUniqString(const string
&S
) {return WriteUniqString(S
.c_str(),S
.length());};
87 void DropProgress() {Progress
= 0;};
88 bool SelectFile(const string
&File
,const string
&Site
,pkgIndexFile
const &Index
,
89 unsigned long Flags
= 0);
90 bool MergeList(ListParser
&List
,pkgCache::VerIterator
*Ver
= 0);
91 inline pkgCache
&GetCache() {return Cache
;};
92 inline pkgCache::PkgFileIterator
GetCurFile()
93 {return pkgCache::PkgFileIterator(Cache
,CurrentFile
);};
95 bool HasFileDeps() {return FoundFileDeps
;};
96 bool MergeFileProvides(ListParser
&List
);
97 bool FinishCache(OpProgress
*Progress
);
99 static bool MakeStatusCache(pkgSourceList
&List
,OpProgress
*Progress
,
100 MMap
**OutMap
= 0,bool AllowMem
= false);
101 static bool MakeOnlyStatusCache(OpProgress
*Progress
,DynamicMMap
**OutMap
);
102 static DynamicMMap
* CreateDynamicMMap(FileFd
*CacheF
, unsigned long Flags
= 0);
104 void ReMap(void const * const oldMap
, void const * const newMap
);
106 pkgCacheGenerator(DynamicMMap
*Map
,OpProgress
*Progress
);
107 ~pkgCacheGenerator();
110 // This is the abstract package list parser class. /*{{{*/
111 class pkgCacheGenerator::ListParser
113 pkgCacheGenerator
*Owner
;
114 friend class pkgCacheGenerator
;
117 pkgCache::VerIterator OldDepVer
;
118 map_ptrloc
*OldDepLast
;
120 // Flag file dependencies
125 inline unsigned long WriteUniqString(string S
) {return Owner
->WriteUniqString(S
);};
126 inline unsigned long WriteUniqString(const char *S
,unsigned int Size
) {return Owner
->WriteUniqString(S
,Size
);};
127 inline unsigned long WriteString(const string
&S
) {return Owner
->WriteStringInMap(S
);};
128 inline unsigned long WriteString(const char *S
,unsigned int Size
) {return Owner
->WriteStringInMap(S
,Size
);};
129 bool NewDepends(pkgCache::VerIterator
&Ver
,const string
&Package
, const string
&Arch
,
130 const string
&Version
,unsigned int Op
,
132 bool NewProvides(pkgCache::VerIterator
&Ver
,const string
&PkgName
,
133 const string
&PkgArch
, const string
&Version
);
137 // These all operate against the current section
138 virtual string
Package() = 0;
139 virtual string
Architecture() = 0;
140 virtual bool ArchitectureAll() = 0;
141 virtual string
Version() = 0;
142 virtual bool NewVersion(pkgCache::VerIterator
&Ver
) = 0;
143 virtual string
Description() = 0;
144 virtual string
DescriptionLanguage() = 0;
145 virtual MD5SumValue
Description_md5() = 0;
146 virtual unsigned short VersionHash() = 0;
147 virtual bool UsePackage(pkgCache::PkgIterator
&Pkg
,
148 pkgCache::VerIterator
&Ver
) = 0;
149 virtual unsigned long Offset() = 0;
150 virtual unsigned long Size() = 0;
152 virtual bool Step() = 0;
154 inline bool HasFileDeps() {return FoundFileDeps
;};
155 virtual bool CollectFileProvides(pkgCache
&Cache
,
156 pkgCache::VerIterator
&Ver
) {return true;};
158 ListParser() : FoundFileDeps(false) {};
159 virtual ~ListParser() {};
163 bool pkgMakeStatusCache(pkgSourceList
&List
,OpProgress
&Progress
,
164 MMap
**OutMap
= 0,bool AllowMem
= false);
165 bool pkgMakeOnlyStatusCache(OpProgress
&Progress
,DynamicMMap
**OutMap
);
168 #ifdef APT_COMPATIBILITY
169 #if APT_COMPATIBILITY != 986
170 #warning "Using APT_COMPATIBILITY"
172 MMap
*pkgMakeStatusCacheMem(pkgSourceList
&List
,OpProgress
&Progress
)
175 if (pkgCacheGenerator::MakeStatusCache(List
,&Progress
,&Map
,true) == false)