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