]> git.saurik.com Git - apt.git/blob - apt-pkg/pkgcachegen.h
pkgcachegen.h: Hack around unordered_map not existing before C++11
[apt.git] / apt-pkg / pkgcachegen.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /* ######################################################################
4
5 Package Cache Generator - Generator for the cache structure.
6
7 This builds the cache structure from the abstract package list parser.
8 Each archive source has it's own list parser that is instantiated by
9 the caller to provide data for the generator.
10
11 Parts of the cache are created by this generator class while other
12 parts are created by the list parser. The list parser is responsible
13 for creating version, depends and provides structures, and some of
14 their contents
15
16 ##################################################################### */
17 /*}}}*/
18 #ifndef PKGLIB_PKGCACHEGEN_H
19 #define PKGLIB_PKGCACHEGEN_H
20
21 #include <apt-pkg/md5.h>
22 #include <apt-pkg/mmap.h>
23 #include <apt-pkg/pkgcache.h>
24 #include <apt-pkg/cacheiterators.h>
25 #include <apt-pkg/macros.h>
26
27 #include <vector>
28 #include <string>
29 #if __cplusplus >= 201103L
30 #include <unordered_map>
31 #endif
32
33 class FileFd;
34 class pkgSourceList;
35 class OpProgress;
36 class pkgIndexFile;
37 class pkgCacheListParser;
38
39 class APT_HIDDEN pkgCacheGenerator /*{{{*/
40 {
41 APT_HIDDEN map_stringitem_t WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); };
42 APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String);
43 APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String, const unsigned long &Len);
44 APT_HIDDEN map_pointer_t AllocateInMap(const unsigned long &size);
45
46 // Dirty hack for public users that do not use C++11 yet
47 #if __cplusplus >= 201103L
48 std::unordered_map<std::string,map_stringitem_t> strMixed;
49 std::unordered_map<std::string,map_stringitem_t> strSections;
50 std::unordered_map<std::string,map_stringitem_t> strPkgNames;
51 std::unordered_map<std::string,map_stringitem_t> strVersions;
52 #endif
53
54 friend class pkgCacheListParser;
55 typedef pkgCacheListParser ListParser;
56
57 public:
58
59 template<typename Iter> class Dynamic {
60 public:
61 static std::vector<Iter*> toReMap;
62 explicit Dynamic(Iter &I) {
63 toReMap.push_back(&I);
64 }
65
66 ~Dynamic() {
67 toReMap.pop_back();
68 }
69 };
70
71 protected:
72
73 DynamicMMap &Map;
74 pkgCache Cache;
75 OpProgress *Progress;
76
77 std::string RlsFileName;
78 pkgCache::ReleaseFile *CurrentRlsFile;
79 std::string PkgFileName;
80 pkgCache::PackageFile *CurrentFile;
81
82 bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name);
83 bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch);
84 bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
85 bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
86 bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
87 map_pointer_t const Version, uint8_t const Op,
88 uint8_t const Type, map_pointer_t* &OldDepLast);
89 map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,map_pointer_t const Next) APT_DEPRECATED
90 { return NewVersion(Ver, VerStr, 0, 0, Next); }
91 map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,
92 map_pointer_t const ParentPkg, unsigned short const Hash,
93 map_pointer_t const Next);
94 map_pointer_t NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_stringitem_t const idxmd5str);
95 bool NewProvides(pkgCache::VerIterator &Ver, pkgCache::PkgIterator &Pkg,
96 map_stringitem_t const ProvidesVersion, uint8_t const Flags);
97
98 public:
99
100 enum StringType { MIXED, PKGNAME, VERSIONNUMBER, SECTION };
101 map_stringitem_t StoreString(StringType const type, const char * S, unsigned int const Size);
102 inline map_stringitem_t StoreString(enum StringType const type, const std::string &S) {return StoreString(type, S.c_str(),S.length());};
103
104 void DropProgress() {Progress = 0;};
105 bool SelectFile(const std::string &File,pkgIndexFile const &Index, std::string const &Architecture, std::string const &Component, unsigned long Flags = 0);
106 bool SelectReleaseFile(const std::string &File, const std::string &Site, unsigned long Flags = 0);
107 bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
108 inline pkgCache &GetCache() {return Cache;};
109 inline pkgCache::PkgFileIterator GetCurFile()
110 {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
111 inline pkgCache::RlsFileIterator GetCurRlsFile()
112 {return pkgCache::RlsFileIterator(Cache,CurrentRlsFile);};
113
114 APT_PUBLIC static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
115 MMap **OutMap = 0,bool AllowMem = false);
116 APT_PUBLIC static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap);
117
118 void ReMap(void const * const oldMap, void const * const newMap);
119
120 pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
121 virtual ~pkgCacheGenerator();
122
123 private:
124 void * const d;
125 APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName);
126 APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg);
127 APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg,
128 std::string const &Version, pkgCache::VerIterator* &OutVer);
129
130 APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P,
131 pkgCache::VerIterator &V);
132 APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D);
133
134 APT_HIDDEN bool AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver,
135 std::string const &lang, MD5SumValue const &CurMd5, map_stringitem_t &md5idx);
136 };
137 /*}}}*/
138 // This is the abstract package list parser class. /*{{{*/
139 class APT_HIDDEN pkgCacheListParser
140 {
141 pkgCacheGenerator *Owner;
142 friend class pkgCacheGenerator;
143
144 // Some cache items
145 pkgCache::VerIterator OldDepVer;
146 map_pointer_t *OldDepLast;
147
148 void * const d;
149
150 protected:
151
152 inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, std::string const &S) {return Owner->StoreString(type, S);};
153 inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S,unsigned int Size) {return Owner->StoreString(type, S, Size);};
154
155 inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);};
156 inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
157 bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch,
158 const std::string &Version,uint8_t const Op,
159 uint8_t const Type);
160 bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName,
161 const std::string &PkgArch, const std::string &Version,
162 uint8_t const Flags);
163 bool NewProvidesAllArch(pkgCache::VerIterator &Ver, std::string const &Package,
164 std::string const &Version, uint8_t const Flags);
165
166 public:
167
168 // These all operate against the current section
169 virtual std::string Package() = 0;
170 virtual std::string Architecture() = 0;
171 virtual bool ArchitectureAll() = 0;
172 virtual std::string Version() = 0;
173 virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0;
174 virtual std::string Description(std::string const &lang) = 0;
175 virtual std::vector<std::string> AvailableDescriptionLanguages() = 0;
176 virtual MD5SumValue Description_md5() = 0;
177 virtual unsigned short VersionHash() = 0;
178 /** compare currently parsed version with given version
179 *
180 * \param Hash of the currently parsed version
181 * \param Ver to compare with
182 */
183 virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
184 virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
185 pkgCache::VerIterator &Ver) = 0;
186 virtual map_filesize_t Offset() = 0;
187 virtual map_filesize_t Size() = 0;
188
189 virtual bool Step() = 0;
190
191 virtual bool CollectFileProvides(pkgCache &/*Cache*/,
192 pkgCache::VerIterator &/*Ver*/) {return true;};
193
194 pkgCacheListParser();
195 virtual ~pkgCacheListParser();
196 };
197 /*}}}*/
198
199 APT_DEPRECATED_MSG("Use pkgCacheGenerator::MakeStatusCache instead") bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
200 MMap **OutMap = 0,bool AllowMem = false);
201 APT_DEPRECATED_MSG("Use pkgCacheGenerator::MakeOnlyStatusCache instead") bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
202
203 #endif