]>
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>
25 #include <apt-pkg/macros.h>
34 class pkgCacheGenerator
/*{{{*/
38 pkgCache::StringItem
*UniqHash
[26];
39 map_ptrloc
WriteStringInMap(std::string
const &String
) { return WriteStringInMap(String
.c_str()); };
40 map_ptrloc
WriteStringInMap(const char *String
);
41 map_ptrloc
WriteStringInMap(const char *String
, const unsigned long &Len
);
42 map_ptrloc
AllocateInMap(const unsigned long &size
);
47 friend class ListParser
;
49 template<typename Iter
> class Dynamic
{
51 static std::vector
<Iter
*> toReMap
;
53 toReMap
.push_back(&I
);
67 std::string PkgFileName
;
68 pkgCache::PackageFile
*CurrentFile
;
70 // Flag file dependencies
73 bool NewGroup(pkgCache::GrpIterator
&Grp
,const std::string
&Name
);
74 bool NewPackage(pkgCache::PkgIterator
&Pkg
,const std::string
&Name
, const std::string
&Arch
);
75 bool NewFileVer(pkgCache::VerIterator
&Ver
,ListParser
&List
);
76 bool NewFileDesc(pkgCache::DescIterator
&Desc
,ListParser
&List
);
77 bool NewDepends(pkgCache::PkgIterator
&Pkg
, pkgCache::VerIterator
&Ver
,
78 std::string
const &Version
, unsigned int const &Op
,
79 unsigned int const &Type
, map_ptrloc
* &OldDepLast
);
80 unsigned long NewVersion(pkgCache::VerIterator
&Ver
,const std::string
&VerStr
,unsigned long Next
);
81 map_ptrloc
NewDescription(pkgCache::DescIterator
&Desc
,const std::string
&Lang
,const MD5SumValue
&md5sum
,map_ptrloc Next
);
85 unsigned long WriteUniqString(const char *S
,unsigned int Size
);
86 inline unsigned long WriteUniqString(const std::string
&S
) {return WriteUniqString(S
.c_str(),S
.length());};
88 void DropProgress() {Progress
= 0;};
89 bool SelectFile(const std::string
&File
,const std::string
&Site
,pkgIndexFile
const &Index
,
90 unsigned long Flags
= 0);
91 bool MergeList(ListParser
&List
,pkgCache::VerIterator
*Ver
= 0);
92 inline pkgCache
&GetCache() {return Cache
;};
93 inline pkgCache::PkgFileIterator
GetCurFile()
94 {return pkgCache::PkgFileIterator(Cache
,CurrentFile
);};
96 bool HasFileDeps() {return FoundFileDeps
;};
97 bool MergeFileProvides(ListParser
&List
);
98 __deprecated
bool FinishCache(OpProgress
*Progress
);
100 static bool MakeStatusCache(pkgSourceList
&List
,OpProgress
*Progress
,
101 MMap
**OutMap
= 0,bool AllowMem
= false);
102 static bool MakeOnlyStatusCache(OpProgress
*Progress
,DynamicMMap
**OutMap
);
103 static DynamicMMap
* CreateDynamicMMap(FileFd
*CacheF
, unsigned long Flags
= 0);
105 void ReMap(void const * const oldMap
, void const * const newMap
);
107 pkgCacheGenerator(DynamicMMap
*Map
,OpProgress
*Progress
);
108 ~pkgCacheGenerator();
111 bool MergeListGroup(ListParser
&List
, std::string
const &GrpName
);
112 bool MergeListPackage(ListParser
&List
, pkgCache::PkgIterator
&Pkg
);
113 bool MergeListVersion(ListParser
&List
, pkgCache::PkgIterator
&Pkg
,
114 std::string
const &Version
, pkgCache::VerIterator
* &OutVer
);
116 bool AddImplicitDepends(pkgCache::GrpIterator
&G
, pkgCache::PkgIterator
&P
,
117 pkgCache::VerIterator
&V
);
118 bool AddImplicitDepends(pkgCache::VerIterator
&V
, pkgCache::PkgIterator
&D
);
121 // This is the abstract package list parser class. /*{{{*/
122 class pkgCacheGenerator::ListParser
124 pkgCacheGenerator
*Owner
;
125 friend class pkgCacheGenerator
;
128 pkgCache::VerIterator OldDepVer
;
129 map_ptrloc
*OldDepLast
;
131 // Flag file dependencies
136 inline unsigned long WriteUniqString(std::string S
) {return Owner
->WriteUniqString(S
);};
137 inline unsigned long WriteUniqString(const char *S
,unsigned int Size
) {return Owner
->WriteUniqString(S
,Size
);};
138 inline unsigned long WriteString(const std::string
&S
) {return Owner
->WriteStringInMap(S
);};
139 inline unsigned long WriteString(const char *S
,unsigned int Size
) {return Owner
->WriteStringInMap(S
,Size
);};
140 bool NewDepends(pkgCache::VerIterator
&Ver
,const std::string
&Package
, const std::string
&Arch
,
141 const std::string
&Version
,unsigned int Op
,
143 bool NewProvides(pkgCache::VerIterator
&Ver
,const std::string
&PkgName
,
144 const std::string
&PkgArch
, const std::string
&Version
);
148 // These all operate against the current section
149 virtual std::string
Package() = 0;
150 virtual std::string
Architecture() = 0;
151 virtual bool ArchitectureAll() = 0;
152 virtual std::string
Version() = 0;
153 virtual bool NewVersion(pkgCache::VerIterator
&Ver
) = 0;
154 virtual std::string
Description() = 0;
155 virtual std::string
DescriptionLanguage() = 0;
156 virtual MD5SumValue
Description_md5() = 0;
157 virtual unsigned short VersionHash() = 0;
158 virtual bool UsePackage(pkgCache::PkgIterator
&Pkg
,
159 pkgCache::VerIterator
&Ver
) = 0;
160 virtual unsigned long Offset() = 0;
161 virtual unsigned long Size() = 0;
163 virtual bool Step() = 0;
165 inline bool HasFileDeps() {return FoundFileDeps
;};
166 virtual bool CollectFileProvides(pkgCache
&Cache
,
167 pkgCache::VerIterator
&Ver
) {return true;};
169 ListParser() : FoundFileDeps(false) {};
170 virtual ~ListParser() {};
174 bool pkgMakeStatusCache(pkgSourceList
&List
,OpProgress
&Progress
,
175 MMap
**OutMap
= 0,bool AllowMem
= false);
176 bool pkgMakeOnlyStatusCache(OpProgress
&Progress
,DynamicMMap
**OutMap
);