aboutsummaryrefslogtreecommitdiff
path: root/paludis/filter.hh
blob: b32027b79bfedca786d69514758320075da4c0d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2008, 2009, 2010, 2011 Ciaran McCreesh
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef PALUDIS_GUARD_PALUDIS_FILTER_HH
#define PALUDIS_GUARD_PALUDIS_FILTER_HH 1

#include <paludis/filter-fwd.hh>
#include <paludis/filter_handler-fwd.hh>
#include <paludis/util/attributes.hh>
#include <paludis/util/pimp.hh>
#include <paludis/util/set-fwd.hh>
#include <paludis/util/fs_path-fwd.hh>
#include <paludis/name-fwd.hh>
#include <paludis/environment-fwd.hh>
#include <paludis/package_id-fwd.hh>
#include <paludis/action-fwd.hh>
#include <paludis/dep_spec-fwd.hh>
#include <paludis/match_package-fwd.hh>
#include <paludis/repository-fwd.hh>
#include <memory>

/** \file
 * Declarations for the Filter class.
 *
 * \ingroup g_selections
 *
 * \section Examples
 *
 * - \ref example_selection.cc "example_selection.cc"
 */

namespace paludis
{
    /**
     * A Filter subclass can be used to further restrict the values picked by a
     * Generator, which when combined together produces a FilteredGenerator
     * which can be passed to a Selection subclass.
     *
     * \ingroup g_selections
     */
    class PALUDIS_VISIBLE Filter
    {
        private:
            Pimp<Filter> _imp;

        protected:
            Filter(const std::shared_ptr<const FilterHandler> &);

        public:
            ///\name Basic operations
            ///\{

            /**
             * Filter subclasses can be copied without losing information.
             */
            Filter(const Filter &);
            Filter & operator= (const Filter &);
            ~Filter();

            ///\}

            /**
             * A Filter can be represented as a string, for use by operator<<.
             */
            std::string as_string() const PALUDIS_ATTRIBUTE((warn_unused_result));

            ///\name For use by Selection
            ///\{

            /**
             * Return any RepositoryContentMayExcludes that are implied by this
             * filter.
             *
             * \since 0.59
             */
            const RepositoryContentMayExcludes may_excludes() const PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * Filter candidate repository names.
             */
            std::shared_ptr<const RepositoryNameSet> repositories(
                    const Environment * const,
                    const std::shared_ptr<const RepositoryNameSet> &) const
                PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * Filter candidate category names.
             */
            std::shared_ptr<const CategoryNamePartSet> categories(
                    const Environment * const,
                    const std::shared_ptr<const RepositoryNameSet> &,
                    const std::shared_ptr<const CategoryNamePartSet> &) const
                PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * Filter candidate package names.
             */
            std::shared_ptr<const QualifiedPackageNameSet> packages(
                    const Environment * const,
                    const std::shared_ptr<const RepositoryNameSet> &,
                    const std::shared_ptr<const QualifiedPackageNameSet> &) const
                PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * Filter candidate PackageID instances.
             */
            std::shared_ptr<const PackageIDSet> ids(
                    const Environment * const,
                    const std::shared_ptr<const PackageIDSet> &) const
                PALUDIS_ATTRIBUTE((warn_unused_result));

            ///\}
    };

    namespace filter
    {
        /**
         * A Filter which accepts all PackageID instances.
         *
         * \ingroup g_selections
         */
        class PALUDIS_VISIBLE All :
            public Filter
        {
            public:
                All();
        };

        /**
         * A Filter which accepts only PackageID instances which support a given
         * Action subclass.
         *
         * \ingroup g_selections
         */
        template <typename>
        class PALUDIS_VISIBLE SupportsAction :
            public Filter
        {
            public:
                SupportsAction();
        };

        /**
         * A Filter which accepts only PackageID instances which are not masked.
         *
         * \ingroup g_selections
         */
        class PALUDIS_VISIBLE NotMasked :
            public Filter
        {
            public:
                NotMasked();
        };

        /**
         * A Filter which accepts only PackageID instances that are installed to
         * a particular root.
         *
         * \ingroup g_selections
         */
        class PALUDIS_VISIBLE InstalledAtRoot :
            public Filter
        {
            public:
                InstalledAtRoot(const FSPath &);
        };

        /**
         * A Filter which accepts only PackageID instances that are installed but
         * not in a particular root.
         *
         * \ingroup g_selections
         */
        class PALUDIS_VISIBLE InstalledNotAtRoot :
            public Filter
        {
            public:
                InstalledNotAtRoot(const FSPath &);
        };

        /**
         * A Filter which accepts only PackageID instances that are installed to
         * the / fs.
         *
         * \ingroup g_selections
         * \since 0.51
         */
        class PALUDIS_VISIBLE InstalledAtSlash :
            public Filter
        {
            public:
                InstalledAtSlash();
        };

        /**
         * A Filter which accepts only PackageID instances that are installed to
         * an fs other than /.
         *
         * \ingroup g_selections
         * \since 0.51
         */
        class PALUDIS_VISIBLE InstalledAtNotSlash :
            public Filter
        {
            public:
                InstalledAtNotSlash();
        };

        /**
         * A Filter which accepts only PackageID instances that are accepted by
         * two different filters.
         *
         * Used internally by FilteredGenerator.
         *
         * \ingroup g_selections
         */
        class PALUDIS_VISIBLE And :
            public Filter
        {
            public:
                And(const Filter &, const Filter &);
        };

        /**
         * A Filter which accepts only PackageID instances that have the same
         * slot as the specified PackageID, or, if the specified PackageID has
         * no slot, that have no slot.
         *
         * \ingroup g_selections
         */
        class PALUDIS_VISIBLE SameSlot :
            public Filter
        {
            public:
                SameSlot(const std::shared_ptr<const PackageID> &);
        };

        /**
         * A Filter which accepts only PackageID instances that have a
         * particular slot.
         *
         * \ingroup g_selections
         */
        class PALUDIS_VISIBLE Slot :
            public Filter
        {
            public:
                Slot(const SlotName &);
        };

        /**
         * A Filter which accepts only PackageID instances that have no slot.
         *
         * \ingroup g_selections
         */
        class PALUDIS_VISIBLE NoSlot :
            public Filter
        {
            public:
                NoSlot();
        };

        /**
         * A Filter which accepts only PackageID instances that match a
         * particular PackageDepSpec.
         *
         * \ingroup g_selections
         */

        class PALUDIS_VISIBLE Matches :
            public Filter
        {
            public:
                /**
                 * \param spec_id The PackageID the spec comes from. May be null. Used
                 * for [use=] style dependencies.
                 *
                 * \since 0.58 takes spec_id
                 */
                Matches(
                        const PackageDepSpec &,
                        const std::shared_ptr<const PackageID> & from_id,
                        const MatchPackageOptions &);
        };
    }

    extern template class Pimp<Filter>;
    extern template class filter::SupportsAction<InstallAction>;
    extern template class filter::SupportsAction<UninstallAction>;
    extern template class filter::SupportsAction<PretendAction>;
    extern template class filter::SupportsAction<ConfigAction>;
    extern template class filter::SupportsAction<FetchAction>;
    extern template class filter::SupportsAction<InfoAction>;
    extern template class filter::SupportsAction<PretendFetchAction>;
}

#endif