]> git.saurik.com Git - apt.git/blob - apt-pkg/pkgcache.h
836418c2ce84f07e5eb68ca28309e3165e10e71f
[apt.git] / apt-pkg / pkgcache.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: pkgcache.h,v 1.4 1998/07/05 05:33:55 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 class pkgCache
28 {
29 public:
30 // Cache element predeclarations
31 struct Header;
32 struct Package;
33 struct PackageFile;
34 struct Version;
35 struct Provides;
36 struct Dependency;
37 struct StringItem;
38 struct VerFile;
39
40 // Iterators
41 class PkgIterator;
42 class VerIterator;
43 class DepIterator;
44 class PrvIterator;
45 class PkgFileIterator;
46 class VerFileIterator;
47 friend PkgIterator;
48 friend VerIterator;
49 friend DepIterator;
50 friend PrvIterator;
51 friend PkgFileIterator;
52 friend VerFileIterator;
53
54 // These are all the constants used in the cache structures
55 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
56 Conflicts=5,Replaces=6};
57 enum VerPriority {Important=1,Required=2,Standard=3,Optional=5,Extra=5};
58 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
59 enum PkgFlags {Auto=(1<<0),New=(1<<1),Obsolete=(1<<2),Essential=(1<<3),
60 ImmediateConf=(1<<4)};
61 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
62 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
63 UnInstalled=3,HalfInstalled=4,ConfigFiles=5,
64 Installed=6};
65 enum PkgFFlags {NotSource=(1<<0)};
66 enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
67 Greater=0x4,Equals=0x5,NotEquals=0x6};
68
69 protected:
70
71 // Memory mapped cache file
72 string CacheFile;
73 MMap &Map;
74
75 bool Public;
76 bool ReadOnly;
77
78 static unsigned long sHash(string S);
79 static unsigned long sHash(const char *S);
80
81 public:
82
83 // Pointers to the arrays of items
84 Header *HeaderP;
85 Package *PkgP;
86 VerFile *VerFileP;
87 PackageFile *PkgFileP;
88 Version *VerP;
89 Provides *ProvideP;
90 Dependency *DepP;
91 StringItem *StringItemP;
92 char *StrP;
93
94 virtual bool ReMap();
95 inline bool Sync() {return Map.Sync();};
96
97 // String hashing function (512 range)
98 inline unsigned long Hash(string S) const {return sHash(S);};
99 inline unsigned long Hash(const char *S) const {return sHash(S);};
100
101 // Usefull transformation things
102 const char *Priority(unsigned char Priority);
103
104 // Accessors
105 PkgIterator FindPkg(string Name);
106 Header &Head() {return *HeaderP;};
107 inline PkgIterator PkgBegin();
108 inline PkgIterator PkgEnd();
109
110 pkgCache(MMap &Map);
111 virtual ~pkgCache() {};
112 };
113
114 // Header structure
115 struct pkgCache::Header
116 {
117 // Signature information
118 unsigned long Signature;
119 short MajorVersion;
120 short MinorVersion;
121 bool Dirty;
122
123 // Size of structure values
124 unsigned short HeaderSz;
125 unsigned short PackageSz;
126 unsigned short PackageFileSz;
127 unsigned short VersionSz;
128 unsigned short DependencySz;
129 unsigned short ProvidesSz;
130 unsigned short VerFileSz;
131
132 // Structure counts
133 unsigned long PackageCount;
134 unsigned long VersionCount;
135 unsigned long DependsCount;
136 unsigned long PackageFileCount;
137
138 // Offsets
139 unsigned long FileList; // struct PackageFile
140 unsigned long StringList; // struct StringItem
141
142 /* Allocation pools, there should be one of these for each structure
143 excluding the header */
144 DynamicMMap::Pool Pools[7];
145
146 // Rapid package name lookup
147 unsigned long HashTable[512];
148
149 bool CheckSizes(Header &Against) const;
150 Header();
151 };
152
153 struct pkgCache::Package
154 {
155 // Pointers
156 unsigned long Name; // Stringtable
157 unsigned long VersionList; // Version
158 unsigned long TargetVer; // Version
159 unsigned long CurrentVer; // Version
160 unsigned long TargetDist; // StringTable (StringItem)
161 unsigned long Section; // StringTable (StringItem)
162
163 // Linked list
164 unsigned long NextPackage; // Package
165 unsigned long RevDepends; // Dependency
166 unsigned long ProvidesList; // Provides
167
168 // Install/Remove/Purge etc
169 unsigned char SelectedState; // What
170 unsigned char InstState; // Flags
171 unsigned char CurrentState; // State
172
173 unsigned short ID;
174 unsigned long Flags;
175 };
176
177 struct pkgCache::PackageFile
178 {
179 // Names
180 unsigned long FileName; // Stringtable
181 unsigned long Version; // Stringtable
182 unsigned long Distribution; // Stringtable
183 unsigned long Size;
184
185 // Linked list
186 unsigned long NextFile; // PackageFile
187 unsigned short ID;
188 unsigned long Flags;
189 time_t mtime; // Modification time for the file
190 };
191
192 struct pkgCache::VerFile
193 {
194 unsigned long File; // PackageFile
195 unsigned long NextFile; // PkgVerFile
196 unsigned long Offset;
197 unsigned short Size;
198 };
199
200 struct pkgCache::Version
201 {
202 unsigned long VerStr; // Stringtable
203 unsigned long Section; // StringTable (StringItem)
204
205 // Lists
206 unsigned long FileList; // VerFile
207 unsigned long NextVer; // Version
208 unsigned long DependsList; // Dependency
209 unsigned long ParentPkg; // Package
210 unsigned long ProvidesList; // Provides
211
212 unsigned long Size;
213 unsigned long InstalledSize;
214 unsigned short ID;
215 unsigned char Priority;
216 };
217
218 struct pkgCache::Dependency
219 {
220 unsigned long Version; // Stringtable
221 unsigned long Package; // Package
222 unsigned long NextDepends; // Dependency
223 unsigned long NextRevDepends; // Dependency
224 unsigned long ParentVer; // Version
225
226 // Specific types of depends
227 unsigned char Type;
228 unsigned char CompareOp;
229 unsigned short ID;
230 };
231
232 struct pkgCache::Provides
233 {
234 unsigned long ParentPkg; // Pacakge
235 unsigned long Version; // Version
236 unsigned long ProvideVersion; // Stringtable
237 unsigned long NextProvides; // Provides
238 unsigned long NextPkgProv; // Provides
239 };
240
241 struct pkgCache::StringItem
242 {
243 unsigned long String; // Stringtable
244 unsigned long NextItem; // StringItem
245 };
246
247 #include <pkglib/cacheiterators.h>
248
249 inline pkgCache::PkgIterator pkgCache::PkgBegin()
250 {return PkgIterator(*this);};
251 inline pkgCache::PkgIterator pkgCache::PkgEnd()
252 {return PkgIterator(*this,PkgP);};
253
254 #endif