]> git.saurik.com Git - apt.git/blob - apt-pkg/packageset.h
* cmdline/apt-cache.cc:
[apt.git] / apt-pkg / packageset.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /** \class APT::PackageSet
4
5 Simple wrapper around a std::set to provide a similar interface to
6 a set of packages as to the complete set of all packages in the
7 pkgCache.
8 */
9 /*}}}*/
10 #ifndef APT_PACKAGESET_H
11 #define APT_PACKAGESET_H
12 // Include Files /*{{{*/
13 #include <iostream>
14 #include <fstream>
15 #include <set>
16 #include <string>
17
18 #include <apt-pkg/pkgcache.h>
19 /*}}}*/
20 namespace APT {
21 class PackageSet : public std::set<pkgCache::PkgIterator> { /*{{{*/
22 public: /*{{{*/
23 /** \brief smell like a pkgCache::PkgIterator */
24 class const_iterator : public std::set<pkgCache::PkgIterator>::const_iterator {
25 public:
26 const_iterator(std::set<pkgCache::PkgIterator>::const_iterator x) :
27 std::set<pkgCache::PkgIterator>::const_iterator(x) {}
28
29 operator pkgCache::PkgIterator(void) { return **this; }
30
31 inline const char *Name() const {return (**this).Name(); }
32 inline std::string FullName(bool const &Pretty) const { return (**this).FullName(Pretty); }
33 inline std::string FullName() const { return (**this).FullName(); }
34 inline const char *Section() const {return (**this).Section(); }
35 inline bool Purge() const {return (**this).Purge(); }
36 inline const char *Arch() const {return (**this).Arch(); }
37 inline pkgCache::GrpIterator Group() const { return (**this).Group(); }
38 inline pkgCache::VerIterator VersionList() const { return (**this).VersionList(); }
39 inline pkgCache::VerIterator CurrentVer() const { return (**this).CurrentVer(); }
40 inline pkgCache::DepIterator RevDependsList() const { return (**this).RevDependsList(); }
41 inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); }
42 inline pkgCache::PkgIterator::OkState State() const { return (**this).State(); }
43 inline const char *CandVersion() const { return (**this).CandVersion(); }
44 inline const char *CurVersion() const { return (**this).CurVersion(); }
45 inline pkgCache *Cache() const { return (**this).Cache(); };
46 inline unsigned long Index() const {return (**this).Index();};
47 // we have only valid iterators here
48 inline bool end() const { return false; };
49
50 friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); }
51
52 inline pkgCache::Package const * operator->() const {
53 return &***this;
54 };
55 };
56 // 103. set::iterator is required to be modifiable, but this allows modification of keys
57 typedef typename APT::PackageSet::const_iterator iterator;
58
59 /** \brief returns all packages in the cache whose name matchs a given pattern
60
61 A simple helper responsible for executing a regular expression on all
62 package names in the cache. Optional it prints a a notice about the
63 packages chosen cause of the given package.
64 \param Cache the packages are in
65 \param pattern regular expression for package names
66 \param out stream to print the notice to */
67 static APT::PackageSet FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out);
68 static APT::PackageSet FromRegEx(pkgCache &Cache, std::string const &pattern) {
69 std::ostream out (std::ofstream("/dev/null").rdbuf());
70 return APT::PackageSet::FromRegEx(Cache, pattern, out);
71 }
72
73 /** \brief returns all packages specified on the commandline
74
75 Get all package names from the commandline and executes regex's if needed.
76 No special package command is supported, just plain names.
77 \param Cache the packages are in
78 \param cmdline Command line the package names should be extracted from
79 \param out stream to print various notices to */
80 static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline, std::ostream &out);
81 static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline) {
82 std::ostream out (std::ofstream("/dev/null").rdbuf());
83 return APT::PackageSet::FromCommandLine(Cache, cmdline, out);
84 }
85
86
87
88 /*}}}*/
89 };
90 /*}}}*/
91 }
92 #endif