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