]> git.saurik.com Git - apt.git/blob - apt-pkg/packageset.h
move regex magic from apt-get to new FromRegEx method
[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
48 friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); }
49
50 inline pkgCache::PkgIterator const * operator->() const {
51 return &**this;
52 };
53 };
54 // 103. set::iterator is required to be modifiable, but this allows modification of keys
55 typedef typename APT::PackageSet::const_iterator iterator;
56
57 /** \brief returns all packages in the cache whose name matchs a given pattern
58
59 A simple helper responsible for executing a regular expression on all
60 package names in the cache. Optional it prints a a notice about the
61 packages chosen cause of the given package.
62 \param Cache the packages are in
63 \param pattern regular expression for package names
64 \param out stream to print the notice to */
65 static APT::PackageSet FromRegEx(pkgCache &Cache, const char *pattern, std::ostream &out);
66 static APT::PackageSet FromRegEx(pkgCache &Cache, const char *pattern) {
67 std::ostream out (std::ofstream("/dev/null").rdbuf());
68 return APT::PackageSet::FromRegEx(Cache, pattern, out);
69 }
70
71 /*}}}*/
72 };
73 /*}}}*/
74 }
75 #endif