Base revisions
[ntk/apt.git] / apt-pkg / pkgcache.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: pkgcache.h,v 1.1 1998/07/02 02:58:12 jgg Exp $
4 /* ######################################################################
5
6 Cache - Structure definitions for the cache file
7
8 Please see doc/pkglib/cache.sgml for a more detailed description of
9 this format. Also be sure to keep that file up-to-date!!
10
11 Clients should always use the CacheIterators classes for access to the
12 cache. They provide a simple STL-like method for traversing the links
13 of the datastructure.
14
15 See pkgcachegen.h for information about generating cache structures.
16
17 ##################################################################### */
18 /*}}}*/
19 // Header section: pkglib
20 #ifndef PKGLIB_PKGCACHE_H
21 #define PKGLIB_PKGCACHE_H
22
23 #include <string>
24 #include <time.h>
25 #include <pkglib/mmap.h>
26
27 // Definitions for Depends::Type
28 #define pkgDEP_Depends 1
29 #define pkgDEP_PreDepends 2
30 #define pkgDEP_Suggests 3
31 #define pkgDEP_Recommends 4
32 #define pkgDEP_Conflicts 5
33 #define pkgDEP_Replaces 6
34
35 // Definitions for Version::Priority
36 #define pkgPRIO_Important 1
37 #define pkgPRIO_Required 2
38 #define pkgPRIO_Standard 3
39 #define pkgPRIO_Optional 4
40 #define pkgPRIO_Extra 5
41
42 // Definitions for Package::SelectedState
43 #define pkgSTATE_Unkown 0
44 #define pkgSTATE_Install 1
45 #define pkgSTATE_Hold 2
46 #define pkgSTATE_DeInstall 3
47 #define pkgSTATE_Purge 4
48
49 // Definitions for Package::Flags
50 #define pkgFLAG_Auto (1 << 0)
51 #define pkgFLAG_New (1 << 1)
52 #define pkgFLAG_Obsolete (1 << 2)
53 #define pkgFLAG_Essential (1 << 3)
54 #define pkgFLAG_ImmediateConf (1 << 4)
55
56 // Definitions for Package::InstState
57 #define pkgSTATE_Ok 0
58 #define pkgSTATE_ReInstReq 1
59 #define pkgSTATE_Hold 2
60 #define pkgSTATE_HoldReInstReq 3
61
62 // Definitions for Package::CurrentState
63 #define pkgSTATE_NotInstalled 0
64 #define pkgSTATE_UnPacked 1
65 #define pkgSTATE_HalfConfigured 2
66 #define pkgSTATE_UnInstalled 3
67 #define pkgSTATE_HalfInstalled 4
68 #define pkgSTATE_ConfigFiles 5
69 #define pkgSTATE_Installed 6
70
71 // Definitions for PackageFile::Flags
72 #define pkgFLAG_NotSource (1 << 0)
73
74 // Definitions for Dependency::CompareOp
75 #define pkgOP_OR 0x10
76 #define pkgOP_LESSEQ 0x1
77 #define pkgOP_GREATEREQ 0x2
78 #define pkgOP_LESS 0x3
79 #define pkgOP_GREATER 0x4
80 #define pkgOP_EQUALS 0x5
81 #define pkgOP_NOTEQUALS 0x6
82
83 class pkgCache
84 {
85 public:
86 // Cache element predeclarations
87 struct Header;
88 struct Package;
89 struct PackageFile;
90 struct Version;
91 struct Provides;
92 struct Dependency;
93 struct StringItem;
94
95 // Iterators
96 class PkgIterator;
97 class VerIterator;
98 class DepIterator;
99 class PrvIterator;
100 class PkgFileIterator;
101 friend PkgIterator;
102 friend VerIterator;
103 friend DepIterator;
104 friend PrvIterator;
105 friend PkgFileIterator;
106
107 protected:
108
109 // Memory mapped cache file
110 string CacheFile;
111 MMap &Map;
112
113 bool Public;
114 bool ReadOnly;
115
116 static unsigned long sHash(string S);
117 static unsigned long sHash(const char *S);
118
119 public:
120
121 // Pointers to the arrays of items
122 Header *HeaderP;
123 Package *PkgP;
124 PackageFile *PkgFileP;
125 Version *VerP;
126 Provides *ProvideP;
127 Dependency *DepP;
128 StringItem *StringItemP;
129 char *StrP;
130
131 virtual bool ReMap();
132 inline bool Sync() {return Map.Sync();};
133
134 // String hashing function (512 range)
135 inline unsigned long Hash(string S) const {return sHash(S);};
136 inline unsigned long Hash(const char *S) const {return sHash(S);};
137
138 // Accessors
139 PkgIterator FindPkg(string Name);
140 Header &Head() {return *HeaderP;};
141 inline PkgIterator PkgBegin();
142 inline PkgIterator PkgEnd();
143
144 pkgCache(MMap &Map);
145 virtual ~pkgCache() {};
146 };
147
148 // Header structure
149 struct pkgCache::Header
150 {
151 // Signature information
152 unsigned long Signature;
153 short MajorVersion;
154 short MinorVersion;
155 bool Dirty;
156
157 // Size of structure values
158 unsigned short HeaderSz;
159 unsigned short PackageSz;
160 unsigned short PackageFileSz;
161 unsigned short VersionSz;
162 unsigned short DependencySz;
163 unsigned short ProvidesSz;
164
165 // Structure counts
166 unsigned long PackageCount;
167 unsigned long VersionCount;
168 unsigned long DependsCount;
169 unsigned long PackageFileCount;
170
171 // Offsets
172 unsigned long FileList; // struct PackageFile
173 unsigned long StringList; // struct StringItem
174
175 /* Allocation pools, there should be one of these for each structure
176 excluding the header */
177 DynamicMMap::Pool Pools[6];
178
179 // Rapid package name lookup
180 unsigned long HashTable[512];
181
182 bool CheckSizes(Header &Against) const;
183 Header();
184 };
185
186 struct pkgCache::Package
187 {
188 // Pointers
189 unsigned long Name; // Stringtable
190 unsigned long VersionList; // Version
191 unsigned long TargetVer; // Version
192 unsigned long CurrentVer; // Version
193 unsigned long TargetDist; // StringTable (StringItem)
194 unsigned long Section; // StringTable (StringItem)
195
196 // Linked list
197 unsigned long NextPackage; // Package
198 unsigned long RevDepends; // Dependency
199 unsigned long ProvidesList; // Provides
200
201 // Install/Remove/Purge etc
202 unsigned char SelectedState; // What
203 unsigned char InstState; // Flags
204 unsigned char CurrentState; // State
205
206 unsigned short ID;
207 unsigned short Flags;
208 };
209
210 struct pkgCache::PackageFile
211 {
212 // Names
213 unsigned long FileName; // Stringtable
214 unsigned long Version; // Stringtable
215 unsigned long Distribution; // Stringtable
216 unsigned long Size;
217
218 // Linked list
219 unsigned long NextFile; // PackageFile
220 unsigned short ID;
221 unsigned short Flags;
222 time_t mtime; // Modification time for the file
223 };
224
225 struct pkgCache::Version
226 {
227 unsigned long VerStr; // Stringtable
228 unsigned long File; // PackageFile
229 unsigned long Section; // StringTable (StringItem)
230
231 // Lists
232 unsigned long NextVer; // Version
233 unsigned long DependsList; // Dependency
234 unsigned long ParentPkg; // Package
235 unsigned long ProvidesList; // Provides
236
237 unsigned long Offset;
238 unsigned long Size;
239 unsigned long InstalledSize;
240 unsigned short ID;
241 unsigned char Priority;
242 };
243
244 struct pkgCache::Dependency
245 {
246 unsigned long Version; // Stringtable
247 unsigned long Package; // Package
248 unsigned long NextDepends; // Dependency
249 unsigned long NextRevDepends; // Dependency
250 unsigned long ParentVer; // Version
251
252 // Specific types of depends
253 unsigned char Type;
254 unsigned char CompareOp;
255 unsigned short ID;
256 };
257
258 struct pkgCache::Provides
259 {
260 unsigned long ParentPkg; // Pacakge
261 unsigned long Version; // Version
262 unsigned long ProvideVersion; // Stringtable
263 unsigned long NextProvides; // Provides
264 unsigned long NextPkgProv; // Provides
265 };
266
267 struct pkgCache::StringItem
268 {
269 unsigned long String; // Stringtable
270 unsigned long NextItem; // StringItem
271 };
272
273 #include <pkglib/cacheiterators.h>
274
275 inline pkgCache::PkgIterator pkgCache::PkgBegin()
276 {return PkgIterator(*this);};
277 inline pkgCache::PkgIterator pkgCache::PkgEnd()
278 {return PkgIterator(*this,PkgP);};
279
280 #endif