~ubuntu-branches/ubuntu/warty/synaptic/warty

« back to all changes in this revision

Viewing changes to common/rpackagefilter.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2002-04-04 12:23:30 UTC
  • Revision ID: james.westby@ubuntu.com-20020404122330-il87fkpjajirckb2
Tags: upstream-0.16
ImportĀ upstreamĀ versionĀ 0.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* rpackagefilter.h - filters for package listing
 
2
 * 
 
3
 * Copyright (c) 2000, 2001 Conectiva S/A 
 
4
 * 
 
5
 * Author: Alfredo K. Kojima <kojima@conectiva.com.br>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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
 
20
 * USA
 
21
 */
 
22
 
 
23
 
 
24
#ifndef _RPACKAGEFILTER_H_
 
25
# define _RPACKAGEFILTER_H_
 
26
 
 
27
# include <vector>
 
28
# include <string>
 
29
# include <fstream.h>
 
30
 
 
31
# include <regex.h>
 
32
 
 
33
class RPackage;
 
34
 
 
35
class Configuration;
 
36
 
 
37
 
 
38
class RPackageFilter {
 
39
public:
 
40
   virtual const char* type() = 0;
 
41
 
 
42
   virtual bool filter(RPackage *pkg) = 0;
 
43
   virtual void reset() = 0;
 
44
 
 
45
   virtual bool read(Configuration &conf, string key) = 0;
 
46
   virtual bool write(ofstream &out, string pad) = 0;
 
47
   //   ~RPackageFilter() = 0;
 
48
};
 
49
 
 
50
 
 
51
extern const char *RPFSection;
 
52
 
 
53
class RSectionPackageFilter : public RPackageFilter {
 
54
   vector<string> _groups;
 
55
   bool _inclusive; // include or exclude the packages
 
56
   
 
57
public:
 
58
   RSectionPackageFilter() : _inclusive(false) {};
 
59
   inline virtual void reset() { clear(); _inclusive = false; };
 
60
 
 
61
   inline virtual const char* type() { return RPFSection; };
 
62
   
 
63
   void setInclusive(bool flag) { _inclusive = flag; };
 
64
   bool inclusive();
 
65
   
 
66
   inline void addSection(string group) { _groups.push_back(group); };
 
67
   int count();
 
68
   string section(int index);
 
69
   void clear();
 
70
   
 
71
   virtual bool filter(RPackage *pkg);
 
72
   virtual bool read(Configuration &conf, string key);
 
73
   virtual bool write(ofstream &out, string pad);
 
74
};
 
75
 
 
76
 
 
77
extern const char *RPFPattern;
 
78
 
 
79
class RPatternPackageFilter : public RPackageFilter {
 
80
public:
 
81
   enum DepType {
 
82
       Name,
 
83
           Description,
 
84
           Depends,
 
85
           Provides,
 
86
           Conflicts,
 
87
           Replaces, // (or obsoletes)
 
88
           WeakDepends // suggests et al
 
89
   };
 
90
   static char *TypeName[];
 
91
 
 
92
private:
 
93
   struct Pattern {
 
94
       DepType where;
 
95
       string pattern;
 
96
       bool exclusive;
 
97
       regex_t reg;
 
98
   };
 
99
   vector<Pattern> _patterns;
 
100
   
 
101
public:
 
102
   ~RPatternPackageFilter();
 
103
 
 
104
   inline virtual void reset() { clear(); };
 
105
   
 
106
   inline virtual const char *type() { return RPFPattern; };
 
107
   
 
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;
 
114
   };
 
115
   void clear();
 
116
   
 
117
   virtual bool filter(RPackage *pkg);
 
118
   virtual bool read(Configuration &conf, string key);
 
119
   virtual bool write(ofstream &out, string pad);
 
120
};
 
121
 
 
122
 
 
123
extern const char *RPFStatus;
 
124
 
 
125
class RStatusPackageFilter : public RPackageFilter {   
 
126
public:
 
127
   enum Types {
 
128
       Installed = 1<<0,
 
129
           Upgradable = 1<<1, // installed but upgradable
 
130
           Broken = 1<<2, // installed but dependencies are broken
 
131
           NotInstalled = 1<<3,
 
132
           MarkInstall = 1<<4,
 
133
           MarkRemove = 1<<5,
 
134
           MarkKeep = 1<<6
 
135
   };
 
136
private:
 
137
   int _status;
 
138
public:
 
139
   RStatusPackageFilter() : _status(0xffffffff) {};
 
140
   inline virtual void reset() { _status = 0xffffffff; };
 
141
 
 
142
   inline virtual const char *type() { return RPFStatus; };
 
143
   
 
144
   inline void setStatus(int status) { _status = status; };
 
145
   inline int status() { return _status; };
 
146
   
 
147
   virtual bool filter(RPackage *pkg);
 
148
   virtual bool read(Configuration &conf, string key);
 
149
   virtual bool write(ofstream &out, string pad);
 
150
};
 
151
 
 
152
 
 
153
extern const char *RPFPriority;
 
154
 
 
155
class RPriorityPackageFilter : public RPackageFilter {   
 
156
public:
 
157
   
 
158
private:
 
159
   
 
160
public:
 
161
   inline virtual void reset() {  };
 
162
   
 
163
   inline virtual const char *type() { return RPFPriority; };
 
164
   
 
165
   
 
166
   virtual bool filter(RPackage *pkg);
 
167
   virtual bool read(Configuration &conf, string key);
 
168
   virtual bool write(ofstream &out, string pad);
 
169
};
 
170
 
 
171
 
 
172
 
 
173
 
 
174
 
 
175
 
 
176
 
 
177
struct RFilter {
 
178
    string name;
 
179
    bool preset;
 
180
 
 
181
    bool apply(RPackage *package);
 
182
    void reset();
 
183
 
 
184
    RSectionPackageFilter section;
 
185
    RPatternPackageFilter pattern;
 
186
    RStatusPackageFilter status;
 
187
    RPriorityPackageFilter priority;
 
188
 
 
189
    bool read(Configuration &conf, string key);
 
190
    bool write(ofstream &out);
 
191
    
 
192
    RFilter() : preset(false) {};
 
193
};
 
194
 
 
195
 
 
196
#endif
 
197