]> git.saurik.com Git - apt.git/blob - apt-pkg/indexfile.h
042e5c2f715882f61f6a7168048025b9dca22a85
[apt.git] / apt-pkg / indexfile.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: indexfile.h,v 1.6.2.1 2003/12/24 23:09:17 mdz Exp $
4 /* ######################################################################
5
6 Index File - Abstraction for an index of archive/source file.
7
8 There are 4 primary sorts of index files, all represented by this
9 class:
10
11 Binary index files
12 Binary translation files
13 Binary index files describing the local system
14 Source index files
15
16 They are all bundled together here, and the interfaces for
17 sources.list, acquire, cache gen and record parsing all use this class
18 to access the underlying representation.
19
20 ##################################################################### */
21 /*}}}*/
22 #ifndef PKGLIB_INDEXFILE_H
23 #define PKGLIB_INDEXFILE_H
24
25 #include <apt-pkg/srcrecords.h>
26 #include <apt-pkg/pkgrecords.h>
27 #include <apt-pkg/pkgcache.h>
28 #include <apt-pkg/cacheiterators.h>
29 #include <apt-pkg/macros.h>
30
31 #include <map>
32 #include <string>
33
34 #ifndef APT_8_CLEANER_HEADERS
35 using std::string;
36 #endif
37 #ifndef APT_10_CLEANER_HEADERS
38 class pkgAcquire;
39 #endif
40
41 class pkgCacheGenerator;
42 class OpProgress;
43
44 class IndexTarget /*{{{*/
45 /** \brief Information about an index file. */
46 {
47 public:
48 /** \brief A URI from which the index file can be downloaded. */
49 std::string URI;
50
51 /** \brief A description of the index file. */
52 std::string Description;
53
54 /** \brief A shorter description of the index file. */
55 std::string ShortDesc;
56
57 /** \brief The key by which this index file should be
58 looked up within the meta index file. */
59 std::string MetaKey;
60
61 /** \brief Is it okay if the file isn't found in the meta index */
62 bool IsOptional;
63
64 /** \brief options with which this target was created
65 Prefer the usage of #Option if at all possible.
66 Beware: Not all of these options are intended for public use */
67 std::map<std::string, std::string> Options;
68
69 IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
70 std::string const &LongDesc, std::string const &URI, bool const IsOptional,
71 std::map<std::string, std::string> const &Options);
72
73 enum OptionKeys {
74 SITE,
75 RELEASE,
76 COMPONENT,
77 LANGUAGE,
78 ARCHITECTURE,
79 BASE_URI,
80 REPO_URI,
81 CREATED_BY,
82 TARGET_OF,
83 FILENAME,
84 EXISTING_FILENAME,
85 };
86 std::string Option(OptionKeys const Key) const;
87 std::string Format(std::string format) const;
88 };
89 /*}}}*/
90
91 class pkgIndexFile
92 {
93 protected:
94 bool Trusted;
95
96 public:
97
98 class Type
99 {
100 public:
101
102 // Global list of Items supported
103 static Type **GlobalList;
104 static unsigned long GlobalListLen;
105 static Type *GetType(const char *Type) APT_PURE;
106
107 const char *Label;
108
109 virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator /*File*/) const {return 0;};
110 virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string /*File*/) const {return 0;};
111 Type();
112 virtual ~Type() {};
113 };
114
115 virtual const Type *GetType() const = 0;
116
117 // Return descriptive strings of various sorts
118 virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const;
119 virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
120 pkgSrcRecords::File const &File) const;
121 virtual std::string Describe(bool Short = false) const = 0;
122
123 // Interface for acquire
124 virtual std::string ArchiveURI(std::string /*File*/) const {return std::string();};
125
126 // Interface for the record parsers
127 virtual pkgSrcRecords::Parser *CreateSrcParser() const {return 0;};
128
129 // Interface for the Cache Generator
130 virtual bool Exists() const = 0;
131 virtual bool HasPackages() const = 0;
132 virtual unsigned long Size() const = 0;
133 virtual bool Merge(pkgCacheGenerator &/*Gen*/, OpProgress* /*Prog*/) const { return false; };
134 APT_DEPRECATED virtual bool Merge(pkgCacheGenerator &Gen, OpProgress &Prog) const
135 { return Merge(Gen, &Prog); };
136 virtual bool MergeFileProvides(pkgCacheGenerator &/*Gen*/,OpProgress* /*Prog*/) const {return true;};
137 APT_DEPRECATED virtual bool MergeFileProvides(pkgCacheGenerator &Gen, OpProgress &Prog) const
138 {return MergeFileProvides(Gen, &Prog);};
139 virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
140
141 static bool TranslationsAvailable();
142 static bool CheckLanguageCode(const char *Lang);
143 static std::string LanguageCode();
144
145 bool IsTrusted() const { return Trusted; };
146
147 pkgIndexFile(bool Trusted);
148 virtual ~pkgIndexFile() {};
149 };
150
151 class pkgIndexTargetFile : public pkgIndexFile
152 {
153 protected:
154 IndexTarget const Target;
155
156 std::string IndexFileName() const;
157
158 public:
159 virtual std::string ArchiveURI(std::string File) const;
160 virtual std::string Describe(bool Short = false) const;
161 virtual bool Exists() const;
162 virtual unsigned long Size() const;
163
164 pkgIndexTargetFile(IndexTarget const &Target, bool const Trusted);
165 };
166
167 #endif