]> git.saurik.com Git - apt.git/blame - apt-pkg/cacheset.h
Don't increase the commandline parameter in the library but in the
[apt.git] / apt-pkg / cacheset.h
CommitLineData
e1dbde8d
DK
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
7959c5ed
DK
3/** \file cacheset.h
4 Wrappers around std::set to have set::iterators which behave
5 similar to the Iterators of the cache structures.
e1dbde8d 6
7959c5ed 7 Provides also a few helper methods which work with these sets */
e1dbde8d 8 /*}}}*/
7959c5ed
DK
9#ifndef APT_CACHESET_H
10#define APT_CACHESET_H
e1dbde8d 11// Include Files /*{{{*/
ffee1c2b
DK
12#include <iostream>
13#include <fstream>
14#include <set>
e1dbde8d 15#include <string>
ffee1c2b 16
856d3b06 17#include <apt-pkg/cachefile.h>
e1dbde8d
DK
18#include <apt-pkg/pkgcache.h>
19 /*}}}*/
20namespace APT {
d4489d49 21class PackageSet : public std::set<pkgCache::PkgIterator> { /*{{{*/
7959c5ed
DK
22/** \class APT::PackageSet
23
24 Simple wrapper around a std::set to provide a similar interface to
25 a set of packages as to the complete set of all packages in the
26 pkgCache. */
e1dbde8d
DK
27public: /*{{{*/
28 /** \brief smell like a pkgCache::PkgIterator */
29 class const_iterator : public std::set<pkgCache::PkgIterator>::const_iterator {
30 public:
31 const_iterator(std::set<pkgCache::PkgIterator>::const_iterator x) :
32 std::set<pkgCache::PkgIterator>::const_iterator(x) {}
33
ffee1c2b
DK
34 operator pkgCache::PkgIterator(void) { return **this; }
35
78c32596
DK
36 inline const char *Name() const {return (**this).Name(); }
37 inline std::string FullName(bool const &Pretty) const { return (**this).FullName(Pretty); }
38 inline std::string FullName() const { return (**this).FullName(); }
39 inline const char *Section() const {return (**this).Section(); }
40 inline bool Purge() const {return (**this).Purge(); }
41 inline const char *Arch() const {return (**this).Arch(); }
42 inline pkgCache::GrpIterator Group() const { return (**this).Group(); }
43 inline pkgCache::VerIterator VersionList() const { return (**this).VersionList(); }
44 inline pkgCache::VerIterator CurrentVer() const { return (**this).CurrentVer(); }
45 inline pkgCache::DepIterator RevDependsList() const { return (**this).RevDependsList(); }
46 inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); }
47 inline pkgCache::PkgIterator::OkState State() const { return (**this).State(); }
48 inline const char *CandVersion() const { return (**this).CandVersion(); }
49 inline const char *CurVersion() const { return (**this).CurVersion(); }
50 inline pkgCache *Cache() const { return (**this).Cache(); };
51 inline unsigned long Index() const {return (**this).Index();};
52 // we have only valid iterators here
53 inline bool end() const { return false; };
e1dbde8d
DK
54
55 friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); }
56
78c32596
DK
57 inline pkgCache::Package const * operator->() const {
58 return &***this;
e1dbde8d
DK
59 };
60 };
61 // 103. set::iterator is required to be modifiable, but this allows modification of keys
62 typedef typename APT::PackageSet::const_iterator iterator;
ffee1c2b
DK
63
64 /** \brief returns all packages in the cache whose name matchs a given pattern
65
66 A simple helper responsible for executing a regular expression on all
67 package names in the cache. Optional it prints a a notice about the
68 packages chosen cause of the given package.
69 \param Cache the packages are in
70 \param pattern regular expression for package names
71 \param out stream to print the notice to */
856d3b06
DK
72 static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out);
73 static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) {
ffee1c2b
DK
74 std::ostream out (std::ofstream("/dev/null").rdbuf());
75 return APT::PackageSet::FromRegEx(Cache, pattern, out);
76 }
77
856d3b06
DK
78 /** \brief returns all packages specified by a string
79
80 \param Cache the packages are in
81 \param string String the package name(s) should be extracted from
82 \param out stream to print various notices to */
83 static APT::PackageSet FromString(pkgCacheFile &Cache, const char * const string, std::ostream &out);
84 static APT::PackageSet FromString(pkgCacheFile &Cache, const char * const string) {
85 std::ostream out (std::ofstream("/dev/null").rdbuf());
86 return APT::PackageSet::FromString(Cache, string, out);
87 }
88
78c32596
DK
89 /** \brief returns all packages specified on the commandline
90
91 Get all package names from the commandline and executes regex's if needed.
92 No special package command is supported, just plain names.
93 \param Cache the packages are in
94 \param cmdline Command line the package names should be extracted from
95 \param out stream to print various notices to */
856d3b06
DK
96 static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out);
97 static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
78c32596
DK
98 std::ostream out (std::ofstream("/dev/null").rdbuf());
99 return APT::PackageSet::FromCommandLine(Cache, cmdline, out);
100 }
d4489d49
DK
101 /*}}}*/
102}; /*}}}*/
103class VersionSet : public std::set<pkgCache::VerIterator> { /*{{{*/
104/** \class APT::VersionSet
78c32596 105
d4489d49
DK
106 Simple wrapper around a std::set to provide a similar interface to
107 a set of versions as to the complete set of all versions in the
108 pkgCache. */
109public: /*{{{*/
110 /** \brief smell like a pkgCache::VerIterator */
111 class const_iterator : public std::set<pkgCache::VerIterator>::const_iterator {
112 public:
113 const_iterator(std::set<pkgCache::VerIterator>::const_iterator x) :
114 std::set<pkgCache::VerIterator>::const_iterator(x) {}
78c32596 115
d4489d49
DK
116 operator pkgCache::VerIterator(void) { return **this; }
117
118 inline pkgCache *Cache() const { return (**this).Cache(); };
119 inline unsigned long Index() const {return (**this).Index();};
120 // we have only valid iterators here
121 inline bool end() const { return false; };
122
123 inline pkgCache::Version const * operator->() const {
124 return &***this;
125 };
126
127 inline int CompareVer(const pkgCache::VerIterator &B) const { return (**this).CompareVer(B); };
128 inline const char *VerStr() const { return (**this).VerStr(); };
129 inline const char *Section() const { return (**this).Section(); };
130 inline const char *Arch() const { return (**this).Arch(); };
131 inline const char *Arch(bool const pseudo) const { return (**this).Arch(pseudo); };
132 inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); };
133 inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); };
134 inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); };
135 inline pkgCache::DepIterator DependsList() const { return (**this).DependsList(); };
136 inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); };
137 inline pkgCache::VerFileIterator FileList() const { return (**this).FileList(); };
138 inline bool Downloadable() const { return (**this).Downloadable(); };
139 inline const char *PriorityType() const { return (**this).PriorityType(); };
140 inline string RelStr() const { return (**this).RelStr(); };
141 inline bool Automatic() const { return (**this).Automatic(); };
142 inline bool Pseudo() const { return (**this).Pseudo(); };
143 inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); };
144 };
145 // 103. set::iterator is required to be modifiable, but this allows modification of keys
146 typedef typename APT::VersionSet::const_iterator iterator;
78c32596 147
856d3b06
DK
148 /** \brief specifies which version(s) will be returned if non is given */
149 enum Version {
150 /** All versions */
151 ALL,
152 /** Candidate and installed version */
153 CANDANDINST,
154 /** Candidate version */
155 CANDIDATE,
156 /** Installed version */
157 INSTALLED,
158 /** Candidate or if non installed version */
159 CANDINST,
160 /** Installed or if non candidate version */
161 INSTCAND,
162 /** Newest version */
163 NEWEST
164 };
165
166 /** \brief returns all versions specified on the commandline
167
168 Get all versions from the commandline, uses given default version if
169 non specifically requested and executes regex's if needed on names.
170 \param Cache the packages and versions are in
171 \param cmdline Command line the versions should be extracted from
172 \param out stream to print various notices to */
173 static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
174 APT::VersionSet::Version const &fallback, std::ostream &out);
175 static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
176 APT::VersionSet::Version const &fallback) {
177 std::ostream out (std::ofstream("/dev/null").rdbuf());
178 return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, out);
179 }
180 static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
181 return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST);
182 }
183 /*}}}*/
184protected: /*{{{*/
185
186 /** \brief returns the candidate version of the package
187
188 \param Cache to be used to query for information
189 \param Pkg we want the candidate version from this package
190 \param AllowError add an error to the stack if not */
191 static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache,
192 pkgCache::PkgIterator const &Pkg, bool const &AllowError = false);
193
194 /** \brief returns the installed version of the package
195
196 \param Cache to be used to query for information
197 \param Pkg we want the installed version from this package
198 \param AllowError add an error to the stack if not */
199 static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache,
200 pkgCache::PkgIterator const &Pkg, bool const &AllowError = false);
201
e1dbde8d 202 /*}}}*/
d4489d49 203}; /*}}}*/
e1dbde8d
DK
204}
205#endif