1
/* rpackagefilter.h - filters for package listing
3
* Copyright (c) 2000, 2001 Conectiva S/A
5
* Author: Alfredo K. Kojima <kojima@conectiva.com.br>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License as
9
* published by the Free Software Foundation; either version 2 of the
10
* License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24
#ifndef _RPACKAGEFILTER_H_
25
# define _RPACKAGEFILTER_H_
38
class RPackageFilter {
40
virtual const char* type() = 0;
42
virtual bool filter(RPackage *pkg) = 0;
43
virtual void reset() = 0;
45
virtual bool read(Configuration &conf, string key) = 0;
46
virtual bool write(ofstream &out, string pad) = 0;
47
// ~RPackageFilter() = 0;
51
extern const char *RPFSection;
53
class RSectionPackageFilter : public RPackageFilter {
54
vector<string> _groups;
55
bool _inclusive; // include or exclude the packages
58
RSectionPackageFilter() : _inclusive(false) {};
59
inline virtual void reset() { clear(); _inclusive = false; };
61
inline virtual const char* type() { return RPFSection; };
63
void setInclusive(bool flag) { _inclusive = flag; };
66
inline void addSection(string group) { _groups.push_back(group); };
68
string section(int index);
71
virtual bool filter(RPackage *pkg);
72
virtual bool read(Configuration &conf, string key);
73
virtual bool write(ofstream &out, string pad);
77
extern const char *RPFPattern;
79
class RPatternPackageFilter : public RPackageFilter {
87
Replaces, // (or obsoletes)
88
WeakDepends // suggests et al
90
static char *TypeName[];
99
vector<Pattern> _patterns;
102
~RPatternPackageFilter();
104
inline virtual void reset() { clear(); };
106
inline virtual const char *type() { return RPFPattern; };
108
void addPattern(DepType type, string pattern, bool exclusive);
109
inline int count() { return _patterns.size(); };
110
inline void pattern(int index, DepType &type, string &pattern, bool &exclusive) {
111
type = _patterns[index].where;
112
pattern = _patterns[index].pattern;
113
exclusive = _patterns[index].exclusive;
117
virtual bool filter(RPackage *pkg);
118
virtual bool read(Configuration &conf, string key);
119
virtual bool write(ofstream &out, string pad);
123
extern const char *RPFStatus;
125
class RStatusPackageFilter : public RPackageFilter {
129
Upgradable = 1<<1, // installed but upgradable
130
Broken = 1<<2, // installed but dependencies are broken
139
RStatusPackageFilter() : _status(0xffffffff) {};
140
inline virtual void reset() { _status = 0xffffffff; };
142
inline virtual const char *type() { return RPFStatus; };
144
inline void setStatus(int status) { _status = status; };
145
inline int status() { return _status; };
147
virtual bool filter(RPackage *pkg);
148
virtual bool read(Configuration &conf, string key);
149
virtual bool write(ofstream &out, string pad);
153
extern const char *RPFPriority;
155
class RPriorityPackageFilter : public RPackageFilter {
161
inline virtual void reset() { };
163
inline virtual const char *type() { return RPFPriority; };
166
virtual bool filter(RPackage *pkg);
167
virtual bool read(Configuration &conf, string key);
168
virtual bool write(ofstream &out, string pad);
181
bool apply(RPackage *package);
184
RSectionPackageFilter section;
185
RPatternPackageFilter pattern;
186
RStatusPackageFilter status;
187
RPriorityPackageFilter priority;
189
bool read(Configuration &conf, string key);
190
bool write(ofstream &out);
192
RFilter() : preset(false) {};