aboutsummaryrefslogtreecommitdiff
path: root/paludis/dep_atom.hh
blob: 431d1c8ed86c4a361bd29807a01bbbb857591226 (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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
 *
 * 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_DEP_ATOM_HH
#define PALUDIS_GUARD_PALUDIS_DEP_ATOM_HH 1

#include <paludis/dep_tag.hh>
#include <paludis/name.hh>
#include <paludis/util/attributes.hh>
#include <paludis/util/counted_ptr.hh>
#include <paludis/util/instantiation_policy.hh>
#include <paludis/util/visitor.hh>
#include <paludis/version_requirements.hh>
#include <paludis/version_operator.hh>
#include <paludis/version_spec.hh>

#include <libwrapiter/libwrapiter_forward_iterator.hh>

/** \file
 * Declarations for the DepAtom classes.
 *
 * \ingroup grpdepatoms
 */

namespace paludis
{
    class DepAtom;
    class CompositeDepAtom;
    class PackageDepAtom;
    class PlainTextDepAtom;
    class AllDepAtom;
    class AnyDepAtom;
    class UseDepAtom;
    class BlockDepAtom;

    /**
     * Visitor types for a visitor that can visit a DepAtom heirarchy.
     *
     * \ingroup grpdepatoms
     */
    typedef VisitorTypes<PackageDepAtom *, PlainTextDepAtom *, AllDepAtom *, AnyDepAtom *,
            UseDepAtom *, BlockDepAtom *> DepAtomVisitorTypes;

    /**
     * Base class for a dependency atom.
     *
     * \ingroup grpdepatoms
     * \nosubgrouping
     */
    class DepAtom :
        public virtual VisitableInterface<DepAtomVisitorTypes>,
        private InstantiationPolicy<DepAtom, instantiation_method::NonCopyableTag>,
        public InternalCounted<DepAtom>
    {
        protected:
            DepAtom();

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

            virtual ~DepAtom();

            ///\}

            ///\name Upcasts
            ///\{

            /**
             * Return us as a UseDepAtom, or 0 if we are not a
             * UseDepAtom.
             */
            virtual const UseDepAtom * as_use_dep_atom() const;

            /**
             * Return us as a PackageDepAtom, or 0 if we are not a
             * UseDepAtom.
             */
            virtual const PackageDepAtom * as_package_dep_atom() const;

            ///\}
    };

    /**
     * Class for dependency atoms that have a number of child dependency
     * atoms.
     *
     * \ingroup grpdepatoms
     * \nosubgrouping
     */
    class CompositeDepAtom :
        public DepAtom,
        private PrivateImplementationPattern<CompositeDepAtom>
    {
        protected:
            ///\name Basic operations
            ///\{

            CompositeDepAtom();

            ///\}

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

            ~CompositeDepAtom();

            ///\}

            ///\name Modify our children
            ///\{

            /**
             * Append a child to our collection.
             */
            virtual void add_child(DepAtom::ConstPointer);

            ///\}

            ///\name Iterate over our children
            ///\{

            typedef libwrapiter::ForwardIterator<CompositeDepAtom, const DepAtom::ConstPointer> Iterator;

            Iterator begin() const;

            Iterator end() const;

            ///\name Pointer types
            ///\{
            typedef CountedPtr<CompositeDepAtom, count_policy::InternalCountTag> Pointer;

            typedef CountedPtr<const CompositeDepAtom, count_policy::InternalCountTag> ConstPointer;
            ///\}
    };

    /**
     * Represents a "|| ( )" dependency block.
     *
     * \ingroup grpdepatoms
     * \nosubgrouping
     */
    class AnyDepAtom :
        public CompositeDepAtom,
        public Visitable<AnyDepAtom, DepAtomVisitorTypes>
    {
        public:
            ///\name Basic operations
            ///\{

            AnyDepAtom();

            ///\}
    };

    /**
     * Represents a ( first second third ) or top level group of dependency
     * atoms.
     *
     * \ingroup grpdepatoms
     * \nosubgrouping
     */
    class AllDepAtom :
        public CompositeDepAtom,
        public Visitable<AllDepAtom, DepAtomVisitorTypes>
    {
        public:
            ///\name Basic operations
            ///\{

            AllDepAtom();

            ///\}
    };

    /**
     * Represents a use? ( ) dependency atom.
     *
     * \ingroup grpdepatoms
     * \nosubgrouping
     */
    class UseDepAtom :
        public CompositeDepAtom,
        public Visitable<UseDepAtom, DepAtomVisitorTypes>
    {
        private:
            const UseFlagName _flag;
            const bool _inverse;

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

            UseDepAtom(const UseFlagName &, bool);

            ///\}

            /**
             * Fetch our use flag name.
             */
            const UseFlagName & flag() const
            {
                return _flag;
            }

            /**
             * Fetch whether we are a ! flag.
             */
            bool inverse() const
            {
                return _inverse;
            }

            virtual const UseDepAtom * as_use_dep_atom() const;

            /**
             * A non-constant smart pointer to ourself.
             */
            typedef CountedPtr<UseDepAtom, count_policy::InternalCountTag> Pointer;

            /**
             * A constant smart pointer to ourself.
             */
            typedef CountedPtr<const UseDepAtom, count_policy::InternalCountTag> ConstPointer;
    };

    /**
     * A StringDepAtom represents a non-composite dep atom with an associated
     * piece of text.
     *
     * \ingroup grpdepatoms
     * \nosubgrouping
     */
    class StringDepAtom :
        public DepAtom
    {
        private:
            const std::string _str;

        protected:
            ///\name Basic operations
            ///\{

            StringDepAtom(const std::string &);

            ~StringDepAtom();

            ///\}

        public:
            /**
             * Fetch our text.
             */
            const std::string & text() const
            {
                return _str;
            }
    };

    /**
     * A selection of USE flag requirements.
     *
     * \ingroup grpdepatoms
     * \nosubgrouping
     */
    class UseRequirements :
        public InternalCounted<UseRequirements>,
        private PrivateImplementationPattern<UseRequirements>
    {
        public:
            ///\name Basic operations
            ///\{

            UseRequirements();
            ~UseRequirements();

            ///\}

            ///\name Iterate over our USE requirements
            ///\{

            typedef libwrapiter::ForwardIterator<UseRequirements,
                    const std::pair<const UseFlagName, UseFlagState> > Iterator;

            Iterator begin() const;
            Iterator end() const;

            ///\}

            /// Find the requirement for a particular USE flag.
            Iterator find(const UseFlagName & u) const;

            /// Insert a new requirement.
            bool insert(const UseFlagName & u, UseFlagState s);

            /// What state is desired for a particular use flag?
            UseFlagState state(const UseFlagName &) const;
    };

    /**
     * A PackageDepAtom represents a package name (for example,
     * 'app-editors/vim'), possibly with associated version and SLOT
     * restrictions.
     *
     * \ingroup grpdepatoms
     * \nosubgrouping
     */
    class PackageDepAtom :
        public StringDepAtom,
        public Visitable<PackageDepAtom, DepAtomVisitorTypes>
    {
        private:
            QualifiedPackageName _package;
            VersionRequirements::Pointer _version_requirements;
            VersionRequirementsMode _version_requirements_mode;
            CountedPtr<SlotName, count_policy::ExternalCountTag> _slot;
            CountedPtr<RepositoryName, count_policy::ExternalCountTag> _repository;
            UseRequirements::Pointer _use_requirements;
            DepTag::ConstPointer _tag;

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

            /**
             * Constructor, no version or SLOT restrictions.
             */
            PackageDepAtom(const QualifiedPackageName & package);

            /**
             * Constructor, parse restrictions ourself.
             */
            PackageDepAtom(const std::string &);

            /**
             * Copy constructor.
             */
            PackageDepAtom(const PackageDepAtom &);

            ~PackageDepAtom();

            ///\}

            /**
             * Fetch the package name.
             */
            const QualifiedPackageName & package() const
            {
                return _package;
            }

            /**
             * Fetch the version requirements (may be a zero pointer).
             */
            VersionRequirements::ConstPointer version_requirements_ptr() const
            {
                return _version_requirements;
            }

            /**
             * Fetch the version requirements mode.
             */
            VersionRequirementsMode version_requirements_mode() const
            {
                return _version_requirements_mode;
            }

            /**
             * Fetch the slot name (may be a zero pointer).
             */
            CountedPtr<SlotName, count_policy::ExternalCountTag> slot_ptr() const
            {
                return _slot;
            }

            /**
             * Fetch the repo name (may be a zero pointer).
             */
            CountedPtr<RepositoryName, count_policy::ExternalCountTag> repository_ptr() const
            {
                return _repository;
            }

            /**
             * Fetch the use requirements (may be a zero pointer).
             */
            UseRequirements::ConstPointer use_requirements_ptr() const
            {
                return _use_requirements;
            }

            ///\name Pointer types
            ///\{

            /**
             * A non-constant smart pointer to ourself.
             */
            typedef CountedPtr<PackageDepAtom, count_policy::InternalCountTag> Pointer;

            /**
             * A constant smart pointer to ourself.
             */
            typedef CountedPtr<const PackageDepAtom, count_policy::InternalCountTag> ConstPointer;

            ///\}

            /**
             * Fetch our tag.
             */
            DepTag::ConstPointer tag() const
            {
                return _tag;
            }

            /**
             * Set our tag.
             */
            void set_tag(const DepTag::ConstPointer & s)
            {
                _tag = s;
            }

            /**
             * Fetch a copy of ourself without the USE requirements.
             */
            Pointer without_use_requirements() const;

            virtual const PackageDepAtom * as_package_dep_atom() const;
    };

    /**
     * A PlainTextDepAtom represents a plain text entry (for example,
     * a URI in SRC_URI).
     *
     * \ingroup grpdepatoms
     * \nosubgrouping
     */
    class PlainTextDepAtom :
        public StringDepAtom,
        public Visitable<PlainTextDepAtom, DepAtomVisitorTypes>
    {
        public:
            ///\name Basic operations
            ///\{

            PlainTextDepAtom(const std::string &);

            ///\}

            ///\name Pointer types
            ///\{

            /**
             * A non-constant smart pointer to ourself.
             */
            typedef CountedPtr<PlainTextDepAtom, count_policy::InternalCountTag> Pointer;

            /**
             * A constant smart pointer to ourself.
             */
            typedef CountedPtr<const PlainTextDepAtom, count_policy::InternalCountTag> ConstPointer;

            ///\}
    };

    /**
     * A PlainTextDepAtom can be written to an ostream.
     *
     * \ingroup grpdepatoms
     */
    std::ostream & operator<< (std::ostream &, const PlainTextDepAtom &);

    /**
     * Thrown if an invalid package dep atom specification is encountered.
     *
     * \ingroup grpexceptions
     * \ingroup grpdepatoms
     * \nosubgrouping
     */
    class PackageDepAtomError :
        public Exception
    {
        public:
            ///\name Basic operations
            ///\{

            PackageDepAtomError(const std::string & msg) throw ();

            ///\}
    };

    /**
     * A PackageDepAtom can be written to an ostream.
     *
     * \ingroup grpdepatoms
     */
    std::ostream & operator<< (std::ostream &, const PackageDepAtom &);

    /**
     * A BlockDepAtom represents a block on a package name (for example,
     * 'app-editors/vim'), possibly with associated version and SLOT
     * restrictions.
     *
     * \ingroup grpdepatoms
     * \nosubgrouping
     */
    class BlockDepAtom :
        public StringDepAtom,
        public Visitable<BlockDepAtom, DepAtomVisitorTypes>
    {
        private:
            PackageDepAtom::ConstPointer _atom;

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

            /**
             * Constructor, with blocking atom.
             */
            BlockDepAtom(PackageDepAtom::ConstPointer atom);

            ///\}

            /**
             * Fetch the atom we're blocking.
             */
            PackageDepAtom::ConstPointer blocked_atom() const
            {
                return _atom;
            }

            ///\name Pointer operations
            ///\{

            /**
             * A non-constant smart pointer to ourself.
             */
            typedef CountedPtr<BlockDepAtom, count_policy::InternalCountTag> Pointer;

            /**
             * A constant smart pointer to ourself.
             */
            typedef CountedPtr<const BlockDepAtom, count_policy::InternalCountTag> ConstPointer;

            ///\}
    };

}

#endif