]>
git.saurik.com Git - apt.git/blob - apt-pkg/cacheset.h
1 // -*- mode: cpp; mode: fold -*-
4 Wrappers around std::set to have set::iterators which behave
5 similar to the Iterators of the cache structures.
7 Provides also a few helper methods which work with these sets */
10 #define APT_CACHESET_H
11 // Include Files /*{{{*/
17 #include <apt-pkg/cachefile.h>
18 #include <apt-pkg/pkgcache.h>
21 class PackageSet
: public std::set
<pkgCache::PkgIterator
> { /*{{{*/
22 /** \class APT::PackageSet
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
28 /** \brief smell like a pkgCache::PkgIterator */
29 class const_iterator
: public std::set
<pkgCache::PkgIterator
>::const_iterator
{
31 const_iterator(std::set
<pkgCache::PkgIterator
>::const_iterator x
) :
32 std::set
<pkgCache::PkgIterator
>::const_iterator(x
) {}
34 operator pkgCache::PkgIterator(void) { return **this; }
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; };
55 friend std::ostream
& operator<<(std::ostream
& out
, const_iterator i
) { return operator<<(out
, (*i
)); }
57 inline pkgCache::Package
const * operator->() const {
61 // 103. set::iterator is required to be modifiable, but this allows modification of keys
62 typedef typename
APT::PackageSet::const_iterator iterator
;
64 using std::set
<pkgCache::PkgIterator
>::insert
;
65 inline void insert(pkgCache::PkgIterator
const &P
) { if (P
.end() == false) std::set
<pkgCache::PkgIterator
>::insert(P
); };
67 /** \brief returns all packages in the cache whose name matchs a given pattern
69 A simple helper responsible for executing a regular expression on all
70 package names in the cache. Optional it prints a a notice about the
71 packages chosen cause of the given package.
72 \param Cache the packages are in
73 \param pattern regular expression for package names
74 \param out stream to print the notice to */
75 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string pattern
, std::ostream
&out
);
76 static APT::PackageSet
FromRegEx(pkgCacheFile
&Cache
, std::string
const &pattern
) {
77 std::ostream
out (std::ofstream("/dev/null").rdbuf());
78 return APT::PackageSet::FromRegEx(Cache
, pattern
, out
);
81 /** \brief returns all packages specified by a string
83 \param Cache the packages are in
84 \param string String the package name(s) should be extracted from
85 \param out stream to print various notices to */
86 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, std::string
const &string
, std::ostream
&out
);
87 static APT::PackageSet
FromString(pkgCacheFile
&Cache
, std::string
const &string
) {
88 std::ostream
out (std::ofstream("/dev/null").rdbuf());
89 return APT::PackageSet::FromString(Cache
, string
, out
);
92 /** \brief returns all packages specified on the commandline
94 Get all package names from the commandline and executes regex's if needed.
95 No special package command is supported, just plain names.
96 \param Cache the packages are in
97 \param cmdline Command line the package names should be extracted from
98 \param out stream to print various notices to */
99 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
, std::ostream
&out
);
100 static APT::PackageSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
101 std::ostream
out (std::ofstream("/dev/null").rdbuf());
102 return APT::PackageSet::FromCommandLine(Cache
, cmdline
, out
);
106 class VersionSet
: public std::set
<pkgCache::VerIterator
> { /*{{{*/
107 /** \class APT::VersionSet
109 Simple wrapper around a std::set to provide a similar interface to
110 a set of versions as to the complete set of all versions in the
113 /** \brief smell like a pkgCache::VerIterator */
114 class const_iterator
: public std::set
<pkgCache::VerIterator
>::const_iterator
{
116 const_iterator(std::set
<pkgCache::VerIterator
>::const_iterator x
) :
117 std::set
<pkgCache::VerIterator
>::const_iterator(x
) {}
119 operator pkgCache::VerIterator(void) { return **this; }
121 inline pkgCache
*Cache() const { return (**this).Cache(); };
122 inline unsigned long Index() const {return (**this).Index();};
123 // we have only valid iterators here
124 inline bool end() const { return false; };
126 inline pkgCache::Version
const * operator->() const {
130 inline int CompareVer(const pkgCache::VerIterator
&B
) const { return (**this).CompareVer(B
); };
131 inline const char *VerStr() const { return (**this).VerStr(); };
132 inline const char *Section() const { return (**this).Section(); };
133 inline const char *Arch() const { return (**this).Arch(); };
134 inline const char *Arch(bool const pseudo
) const { return (**this).Arch(pseudo
); };
135 inline pkgCache::PkgIterator
ParentPkg() const { return (**this).ParentPkg(); };
136 inline pkgCache::DescIterator
DescriptionList() const { return (**this).DescriptionList(); };
137 inline pkgCache::DescIterator
TranslatedDescription() const { return (**this).TranslatedDescription(); };
138 inline pkgCache::DepIterator
DependsList() const { return (**this).DependsList(); };
139 inline pkgCache::PrvIterator
ProvidesList() const { return (**this).ProvidesList(); };
140 inline pkgCache::VerFileIterator
FileList() const { return (**this).FileList(); };
141 inline bool Downloadable() const { return (**this).Downloadable(); };
142 inline const char *PriorityType() const { return (**this).PriorityType(); };
143 inline string
RelStr() const { return (**this).RelStr(); };
144 inline bool Automatic() const { return (**this).Automatic(); };
145 inline bool Pseudo() const { return (**this).Pseudo(); };
146 inline pkgCache::VerFileIterator
NewestFile() const { return (**this).NewestFile(); };
148 // 103. set::iterator is required to be modifiable, but this allows modification of keys
149 typedef typename
APT::VersionSet::const_iterator iterator
;
151 using std::set
<pkgCache::VerIterator
>::insert
;
152 inline void insert(pkgCache::VerIterator
const &V
) { if (V
.end() == false) std::set
<pkgCache::VerIterator
>::insert(V
); };
154 /** \brief specifies which version(s) will be returned if non is given */
158 /** Candidate and installed version */
160 /** Candidate version */
162 /** Installed version */
164 /** Candidate or if non installed version */
166 /** Installed or if non candidate version */
168 /** Newest version */
172 /** \brief returns all versions specified on the commandline
174 Get all versions from the commandline, uses given default version if
175 non specifically requested and executes regex's if needed on names.
176 \param Cache the packages and versions are in
177 \param cmdline Command line the versions should be extracted from
178 \param out stream to print various notices to */
179 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
180 APT::VersionSet::Version
const &fallback
, std::ostream
&out
);
181 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
,
182 APT::VersionSet::Version
const &fallback
) {
183 std::ostream
out (std::ofstream("/dev/null").rdbuf());
184 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, fallback
, out
);
186 static APT::VersionSet
FromCommandLine(pkgCacheFile
&Cache
, const char **cmdline
) {
187 return APT::VersionSet::FromCommandLine(Cache
, cmdline
, CANDINST
);
192 /** \brief returns the candidate version of the package
194 \param Cache to be used to query for information
195 \param Pkg we want the candidate version from this package
196 \param AllowError add an error to the stack if not */
197 static pkgCache::VerIterator
getCandidateVer(pkgCacheFile
&Cache
,
198 pkgCache::PkgIterator
const &Pkg
, bool const &AllowError
= false);
200 /** \brief returns the installed version of the package
202 \param Cache to be used to query for information
203 \param Pkg we want the installed version from this package
204 \param AllowError add an error to the stack if not */
205 static pkgCache::VerIterator
getInstalledVer(pkgCacheFile
&Cache
,
206 pkgCache::PkgIterator
const &Pkg
, bool const &AllowError
= false);
209 static bool AddSelectedVersion(pkgCacheFile
&Cache
, VersionSet
&verset
,
210 pkgCache::PkgIterator
const &P
, VersionSet::Version
const &fallback
,
211 bool const &AllowError
= false);