aboutsummaryrefslogtreecommitdiff
path: root/paludis/choice.hh
blob: d745931ed481722f306a1af9a4b9c6205d206ae0 (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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/* 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_CHOICE_HH
#define PALUDIS_GUARD_PALUDIS_CHOICE_HH 1

#include <paludis/choice-fwd.hh>
#include <paludis/permitted_choice_value_parameter_values-fwd.hh>
#include <paludis/util/attributes.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/pimp.hh>
#include <paludis/util/exception.hh>
#include <paludis/util/named_value.hh>
#include <paludis/util/wrapped_value.hh>
#include <paludis/util/set.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/wrapped_output_iterator.hh>
#include <memory>
#include <string>

/** \file
 * Declarations for choice-related classes.
 *
 * \ingroup g_choices
 * \since 0.32
 *
 * \section Examples
 *
 * - None at this time.
 */

namespace paludis
{
    namespace n
    {
        typedef Name<struct name_consider_added_or_changed> consider_added_or_changed;
        typedef Name<struct name_contains_every_value> contains_every_value;
        typedef Name<struct name_hidden> hidden;
        typedef Name<struct name_hide_description> hide_description;
        typedef Name<struct name_human_name> human_name;
        typedef Name<struct name_prefix> prefix;
        typedef Name<struct name_raw_name> raw_name;
        typedef Name<struct name_show_with_no_prefix> show_with_no_prefix;
    }

    /**
     * Thrown if a ChoicePrefixName is given an invalid value.
     *
     * \since 0.32
     * \ingroup g_choices
     * \ingroup g_exceptions
     */
    class PALUDIS_VISIBLE ChoicePrefixNameError :
        public NameError
    {
        public:
            ChoicePrefixNameError(const std::string &) noexcept;
    };

    /**
     * Thrown if a ChoiceNameWithPrefix is given an invalid value.
     *
     * \since 0.32
     * \ingroup g_choices
     * \ingroup g_exceptions
     */
    class PALUDIS_VISIBLE ChoiceNameWithPrefixError :
        public NameError
    {
        public:
            ChoiceNameWithPrefixError(const std::string &) noexcept;
    };

    /**
     * Thrown if a UnprefixedChoiceName is given an invalid value.
     *
     * \since 0.32
     * \ingroup g_choices
     * \ingroup g_exceptions
     */
    class PALUDIS_VISIBLE UnprefixedChoiceNameError :
        public NameError
    {
        public:
            UnprefixedChoiceNameError(const std::string &) noexcept;
    };

    template <>
    struct WrappedValueTraits<ChoicePrefixNameTag>
    {
        typedef std::string UnderlyingType;
        typedef void ValidationParamsType;
        typedef ChoicePrefixNameError ExceptionType;

        static bool validate(const std::string &) PALUDIS_ATTRIBUTE((warn_unused_result));
    };

    extern template class PALUDIS_VISIBLE WrappedValue<ChoicePrefixNameTag>;

    template <>
    struct WrappedValueTraits<UnprefixedChoiceNameTag>
    {
        typedef std::string UnderlyingType;
        typedef void ValidationParamsType;
        typedef UnprefixedChoiceNameError ExceptionType;

        static bool validate(const std::string &) PALUDIS_ATTRIBUTE((warn_unused_result));
    };

    extern template class PALUDIS_VISIBLE WrappedValue<UnprefixedChoiceNameTag>;

    template <>
    struct WrappedValueTraits<ChoiceNameWithPrefixTag>
    {
        typedef std::string UnderlyingType;
        typedef void ValidationParamsType;
        typedef ChoiceNameWithPrefixError ExceptionType;

        static bool validate(const std::string &) PALUDIS_ATTRIBUTE((warn_unused_result));
    };

    extern template class PALUDIS_VISIBLE WrappedValue<ChoiceNameWithPrefixTag>;

    /**
     * Choices holds a collection of configurable values for a PackageID.
     *
     * A PackageID may have a choices_key holding a Choices object. This Choices object
     * will hold a number of Choice objects. Examples of things held by Choice objects for
     * ebuilds include USE, USE_EXPAND values (linguas, video_cards and so on), ARCH and
     * build_options.
     *
     * \ingroup g_choices
     * \since 0.32
     */
    class PALUDIS_VISIBLE Choices
    {
        private:
            Pimp<Choices> _imp;

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

            Choices();
            ~Choices();

            ///\}

            /**
             * Add a new Choice to our collection.
             */
            void add(const std::shared_ptr<const Choice> &);

            ///\name Iterate over Choice children
            ///\{

            struct ConstIteratorTag;
            typedef WrappedForwardIterator<ConstIteratorTag, const std::shared_ptr<const Choice> > ConstIterator;
            ConstIterator begin() const PALUDIS_ATTRIBUTE((warn_unused_result));
            ConstIterator end() const PALUDIS_ATTRIBUTE((warn_unused_result));

            ///\since 0.44
            ConstIterator find(const ChoicePrefixName &) const PALUDIS_ATTRIBUTE((warn_unused_result));

            ///\}

            /**
             * Find a ChoiceValue that has a particular prefix and name.
             *
             * Returns a zero pointer for no match.
             *
             * This is a convenient way of getting a particular use flag's details. Calling this
             * method with, say, "nls" or "ruby" will get the value for that flag without having
             * to hunt around in all the subkeys manually. Prefixes work too, e.g. "linguas_en" for
             * 0-based EAPIs or "linguas:en" for exheres EAPIs.
             */
            const std::shared_ptr<const ChoiceValue> find_by_name_with_prefix(
                    const ChoiceNameWithPrefix &) const PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * Do we have a Choice subkey with contains_every_value true and a prefix matching
             * this name?
             *
             * 0-based EAPIs don't require things like userland_GNU in IUSE. So if you're looking
             * for a flag and don't find it, check this method before issuing a QA notice.
             */
            bool has_matching_contains_every_value_prefix(const ChoiceNameWithPrefix &) const PALUDIS_ATTRIBUTE((warn_unused_result));
    };

    /**
     * Named parameters for Choice::Choice.
     *
     * \since 0.38
     * \ingroup g_choices
     */
    struct ChoiceParams
    {
        NamedValue<n::consider_added_or_changed, bool> consider_added_or_changed;
        NamedValue<n::contains_every_value, bool> contains_every_value;
        NamedValue<n::hidden, bool> hidden;
        NamedValue<n::hide_description, bool> hide_description;
        NamedValue<n::human_name, std::string> human_name;
        NamedValue<n::prefix, ChoicePrefixName> prefix;
        NamedValue<n::raw_name, std::string> raw_name;
        NamedValue<n::show_with_no_prefix, bool> show_with_no_prefix;
    };

    /**
     * An individual choice in a Choices collection.
     *
     * Examples of a choice include USE, individual USE_EXPAND values (linguas, video_cards etc)
     * and build_options.
     *
     * \ingroup g_choices
     * \since 0.32
     */
    class PALUDIS_VISIBLE Choice
    {
        private:
            Pimp<Choice> _imp;

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

            ///\since 0.38
            Choice(const ChoiceParams &);
            ~Choice();

            ///\}

            /**
             * Add a new ChoiceValue.
             */
            void add(const std::shared_ptr<const ChoiceValue> &);

            ///\name Properties
            ///\{

            /**
             * Our raw name, for example 'USE' or 'LINGUAS'.
             */
            const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * A human-readable name (often the same as raw_name).
             */
            const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * The prefix for our ChoiceValue children.
             *
             * An empty string for USE and ARCH, 'linguas' for LINGUAS etc.
             */
            const ChoicePrefixName prefix() const PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * If true, pretend that we contain every possible value and that any value not listed
             * as a child exists and is not enabled.
             *
             * For pesky 0-based EAPIs that don't require things like userland_GNU in IUSE, and that
             * don't have a comprehensive list of possible values.
             */
            bool contains_every_value() const PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * If true, this option should not usually be shown visually to a user.
             */
            bool hidden() const PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * If true, this option should not have a description be shown
             * visually to the user.
             */
            bool hide_description() const PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * If true, hint that we're better not displaying our prefix to the user.
             *
             * This is used by --pretend --install and --query to avoid showing a Use:
             * prefix before a list of use flag names.
             */
            bool show_with_no_prefix() const PALUDIS_ATTRIBUTE((warn_unused_result));

            /**
             * If false, do not consider flags in this section for 'added' or 'changed'
             * detection.
             *
             * Used by build_options.
             */
            bool consider_added_or_changed() const PALUDIS_ATTRIBUTE((warn_unused_result));

            ///\}

            ///\name Iterate over ChoiceValue children
            ///\{

            struct ConstIteratorTag;
            typedef WrappedForwardIterator<ConstIteratorTag, const std::shared_ptr<const ChoiceValue> > ConstIterator;
            ConstIterator begin() const PALUDIS_ATTRIBUTE((warn_unused_result));
            ConstIterator end() const PALUDIS_ATTRIBUTE((warn_unused_result));

            ///\}
    };

    /**
     * An individial Value in a ChoiceValue.
     *
     * For example, the 'nls' flag in 'USE'.
     *
     * Some choice values have an associated parameter. For example,
     * build_options:jobs=4.
     *
     * \ingroup g_choices
     * \since 0.32
     */
    class PALUDIS_VISIBLE ChoiceValue
    {
        public:
            ///\name Basic operations
            ///\{

            virtual ~ChoiceValue() = 0;

            ///\}

            ///\name Properties
            ///\{

            /**
             * Our name, without an prefix (for example, 'nls' or 'en').
             */
            virtual const UnprefixedChoiceName unprefixed_name() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;

            /**
             * Our name, with prefix if there is one (for example, 'nls' or 'linguas_en').
             */
            virtual const ChoiceNameWithPrefix name_with_prefix() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;

            /**
             * Is this flag enabled?
             */
            virtual bool enabled() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;

            /**
             * Would this flag be enabled by default (i.e. before
             * considering any overrides from the Environment)?
             */
            virtual bool enabled_by_default() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;

            /**
             * Does this flag have to be explicitly accepted when doing matching?
             */
            virtual bool presumed() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;

            /**
             * Is this flag locked (forced or masked)?
             */
            virtual bool locked() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;

            /**
             * The flag's description, or an empty string.
             */
            virtual const std::string description() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;

            /**
             * The origin of this choice.
             *
             * \since 0.66
             *
             * Use this to avoid showing things like LINGUAS values that aren't listed
             * in IUSE but that end up as a ChoiceValue anyway.
             */
            virtual ChoiceOrigin origin() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;

            /**
             * This flag's parameter, or an empty string if it doesn't have one.
             *
             * \since 0.40
             */
            virtual const std::string parameter() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;

            /**
             * Permitted values for this flag's parameter, or null if there is no parameter.
             *
             * \since 0.59
             */
            virtual const std::shared_ptr<const PermittedChoiceValueParameterValues> permitted_parameter_values() const
                PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;

            ///\}
    };

    extern template class Pimp<Choices>;
    extern template class Pimp<Choice>;

    extern template class PALUDIS_VISIBLE Set<UnprefixedChoiceName>;
    extern template class PALUDIS_VISIBLE WrappedForwardIterator<Set<UnprefixedChoiceName>::ConstIteratorTag, const UnprefixedChoiceName>;
    extern template class PALUDIS_VISIBLE WrappedOutputIterator<Set<UnprefixedChoiceName>::InserterTag, UnprefixedChoiceName>;

    extern template class PALUDIS_VISIBLE WrappedForwardIterator<Choices::ConstIteratorTag, const std::shared_ptr<const Choice> >;
    extern template class PALUDIS_VISIBLE WrappedForwardIterator<Choice::ConstIteratorTag, const std::shared_ptr<const ChoiceValue> >;
}

#endif