]> git.saurik.com Git - apt.git/blob - apt-pkg/cacheset.h
* apt-pkg/cachefile.{cc,h}:
[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 PackageSet : public std::set<pkgCache::PkgIterator> { /*{{{*/
21 /** \class APT::PackageSet
22
23 Simple wrapper around a std::set to provide a similar interface to
24 a set of packages as to the complete set of all packages in the
25 pkgCache. */
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 class VersionSet : public std::set<pkgCache::VerIterator> { /*{{{*/
92 /** \class APT::VersionSet
93
94 Simple wrapper around a std::set to provide a similar interface to
95 a set of versions as to the complete set of all versions in the
96 pkgCache. */
97 public: /*{{{*/
98 /** \brief smell like a pkgCache::VerIterator */
99 class const_iterator : public std::set<pkgCache::VerIterator>::const_iterator {
100 public:
101 const_iterator(std::set<pkgCache::VerIterator>::const_iterator x) :
102 std::set<pkgCache::VerIterator>::const_iterator(x) {}
103
104 operator pkgCache::VerIterator(void) { return **this; }
105
106 inline pkgCache *Cache() const { return (**this).Cache(); };
107 inline unsigned long Index() const {return (**this).Index();};
108 // we have only valid iterators here
109 inline bool end() const { return false; };
110
111 inline pkgCache::Version const * operator->() const {
112 return &***this;
113 };
114
115 inline int CompareVer(const pkgCache::VerIterator &B) const { return (**this).CompareVer(B); };
116 inline const char *VerStr() const { return (**this).VerStr(); };
117 inline const char *Section() const { return (**this).Section(); };
118 inline const char *Arch() const { return (**this).Arch(); };
119 inline const char *Arch(bool const pseudo) const { return (**this).Arch(pseudo); };
120 inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); };
121 inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); };
122 inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); };
123 inline pkgCache::DepIterator DependsList() const { return (**this).DependsList(); };
124 inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); };
125 inline pkgCache::VerFileIterator FileList() const { return (**this).FileList(); };
126 inline bool Downloadable() const { return (**this).Downloadable(); };
127 inline const char *PriorityType() const { return (**this).PriorityType(); };
128 inline string RelStr() const { return (**this).RelStr(); };
129 inline bool Automatic() const { return (**this).Automatic(); };
130 inline bool Pseudo() const { return (**this).Pseudo(); };
131 inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); };
132 };
133 // 103. set::iterator is required to be modifiable, but this allows modification of keys
134 typedef typename APT::VersionSet::const_iterator iterator;
135
136 /*}}}*/
137 }; /*}}}*/
138 }
139 #endif