aboutsummaryrefslogtreecommitdiff
path: root/paludis/dep_tag.hh
blob: e5ffeadf9111d16ce77d2d66a444f81453b62f76 (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
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2006, 2007, 2008 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_DEP_TAG_HH
#define PALUDIS_GUARD_PALUDIS_DEP_TAG_HH 1

/** \file
 * Declarations for dependency tags.
 *
 * \ingroup g_dep_spec
 *
 * \section Examples
 *
 * - \ref example_dep_tag.cc "example_dep_tag.cc" (for tags)
 * - \ref example_dep_spec.cc "example_dep_spec.cc" (for specifications)
 * - \ref example_dep_label.cc "example_dep_label.cc" (for labels)
 */

#include <paludis/dep_tag-fwd.hh>
#include <paludis/dep_spec-fwd.hh>
#include <paludis/name-fwd.hh>
#include <paludis/package_id-fwd.hh>
#include <paludis/spec_tree-fwd.hh>
#include <paludis/util/instantiation_policy.hh>
#include <paludis/util/simple_visitor.hh>
#include <paludis/util/exception.hh>
#include <paludis/util/named_value.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/operators.hh>
#include <paludis/util/type_list.hh>

#include <string>
#include <tr1/memory>

namespace paludis
{
    namespace n
    {
        struct generation;
        struct tag;
    }

    /**
     * A DepTagCategory is identified by its name and has associated display
     * information for a DepTag's category.
     *
     * It is usually accessed via DepTagCategoryMaker.
     *
     * \see DepTagCategoryMaker
     * \see DepTag
     *
     * \ingroup g_dep_spec
     * \nosubgrouping
     */
    class PALUDIS_VISIBLE DepTagCategory :
        private InstantiationPolicy<DepTagCategory, instantiation_method::NonCopyableTag>
    {
        private:
            bool _visible;
            const std::string _id;
            const std::string _title;
            const std::string _pre_text;
            const std::string _post_text;

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

            DepTagCategory(
                    bool visible,
                    const std::string & id,
                    const std::string & t,
                    const std::string & pre,
                    const std::string & post);

            ///\}

            /**
             * Should we be displayed in a tag category summary?
             */
            bool visible() const;

            /**
             * Fetch our short ID (for example, 'GLSA').
             */
            std::string id() const;

            /**
             * Fetch our title (for example, 'Security advisories'), or an
             * empty string if we're untitled.
             */
            std::string title() const;

            /**
             * Fetch our pre list text, or an empty string.
             */
            std::string pre_text() const;

            /**
             * Fetch our post list text, or an empty string.
             */
            std::string post_text() const;
    };

    /**
     * Factory for accessing DepTagCategory instances.
     *
     * \ingroup g_dep_spec
     * \since 0.30
     */
    class PALUDIS_VISIBLE DepTagCategoryFactory :
        public InstantiationPolicy<DepTagCategoryFactory, instantiation_method::SingletonTag>
    {
        friend class InstantiationPolicy<DepTagCategoryFactory, instantiation_method::SingletonTag>;

        private:
            DepTagCategoryFactory();

        public:
            const std::tr1::shared_ptr<DepTagCategory> create(const std::string &) const
                PALUDIS_ATTRIBUTE((warn_unused_result));
    };

    /**
     * A DepTag can be associated with a PackageDepSpec, and is transferred
     * onto any associated DepListEntry instances.
     *
     * It is used for tagging dep list entries visually, for example to
     * indicate an associated GLSA.
     *
     * \ingroup g_dep_spec
     * \nosubgrouping
     */
    class PALUDIS_VISIBLE DepTag :
        private InstantiationPolicy<DepTag, instantiation_method::NonCopyableTag>,
        public relational_operators::HasRelationalOperators,
        public virtual DeclareAbstractAcceptMethods<DepTag, MakeTypeList<
            GLSADepTag, GeneralSetDepTag, DependencyDepTag, TargetDepTag>::Type>
    {
        protected:
            ///\name Basic operations
            ///\{

            DepTag();

        public:
            virtual ~DepTag();

            ///\}

            /**
             * Fetch our short text (for example, 'GLSA-1234') that is
             * displayed with the dep list entry.
             */
            virtual std::string short_text() const = 0;

            /**
             * Fetch our DepTagCategory's tag.
             */
            virtual std::string category() const = 0;

            ///\name Comparison operators
            ///\{

            bool operator< (const DepTag &) const;
            bool operator== (const DepTag &) const;

            ///\}
    };

    /**
     * DepTag subclass for GLSAs.
     *
     * \ingroup g_dep_spec
     * \nosubgrouping
     */
    class PALUDIS_VISIBLE GLSADepTag :
        public DepTag,
        public ImplementAcceptMethods<DepTag, GLSADepTag>
    {
        private:
            const std::string _id;
            const std::string _glsa_title;
            const FSEntry _glsa_file;

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

            GLSADepTag(const std::string & id, const std::string & glsa_title, const FSEntry&);
            ~GLSADepTag();

            ///\}

            ///\name Content information
            ///\{

            virtual std::string short_text() const;

            virtual std::string category() const;

            /**
             * The full path to the glsa announcement file.
             */
            const FSEntry glsa_file() const;

            /**
             * Fetch our GLSA title (for example, 'Yet another PHP remote access
             * hole').
             */
            std::string glsa_title() const;

            ///\}
    };

    /**
     * DepTag subclass for general sets.
     *
     * \ingroup g_dep_spec
     * \nosubgrouping
     */
    class PALUDIS_VISIBLE GeneralSetDepTag :
        public DepTag,
        public ImplementAcceptMethods<DepTag, GeneralSetDepTag>,
        private PrivateImplementationPattern<GeneralSetDepTag>
    {
        public:
            ///\name Basic operations
            ///\{

            GeneralSetDepTag(const SetName & id, const std::string & source);
            ~GeneralSetDepTag();

            ///\}

            virtual std::string short_text() const;

            virtual std::string category() const;

            /**
             * From which repository or environment did we originate?
             */
            std::string source() const;
    };

    /**
     * DepTag subclass for dependencies.
     *
     * \ingroup g_dep_spec
     * \nosubgrouping
     */
    class PALUDIS_VISIBLE DependencyDepTag :
        public DepTag,
        public ImplementAcceptMethods<DepTag, DependencyDepTag>,
        private PrivateImplementationPattern<DependencyDepTag>
    {
        private:
            void _make_str() const;

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

            DependencyDepTag(const std::tr1::shared_ptr<const PackageID> &, const PackageDepSpec &);

            ~DependencyDepTag();

            ///\}

            virtual std::string short_text() const;

            virtual std::string category() const;

            /**
             * The PackageID that contains our dependency.
             */
            const std::tr1::shared_ptr<const PackageID> package_id() const;

            /**
             * The PackageDepSpec that pulled us in.
             */
            const std::tr1::shared_ptr<const PackageDepSpec> dependency() const;
    };

    /**
     * DepTag subclass for explicit targets.
     *
     * \ingroup g_dep_spec
     * \nosubgrouping
     */
    class PALUDIS_VISIBLE TargetDepTag :
        public DepTag,
        public ImplementAcceptMethods<DepTag, TargetDepTag>
    {
        public:
            ///\name Basic operations
            ///\{

            TargetDepTag();
            ~TargetDepTag();

            ///\}

            virtual std::string short_text() const;
            virtual std::string category() const;
    };

    /**
     * Tags associated with a DepListEntry.
     *
     * The generation key is used internally by DepList. Its value is of no interest
     * to outside clients.
     *
     * \see DepListEntry
     * \ingroup g_dep_list
     * \nosubgrouping
     */
    struct DepTagEntry
    {
        NamedValue<n::generation, long> generation;
        NamedValue<n::tag, std::tr1::shared_ptr<const DepTag> > tag;
    };

    /**
     * Compare two DepListEntry structs by tag only.
     *
     * \see DepTagEntry
     * \ingroup g_dep_list
     * \since 0.34
     */
    struct PALUDIS_VISIBLE DepTagEntryComparator
    {
        bool operator() (const DepTagEntry &, const DepTagEntry &) const PALUDIS_ATTRIBUTE((warn_unused_result));
    };

#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
    extern template class InstantiationPolicy<DepTagCategoryFactory, instantiation_method::SingletonTag>;
    extern template class PrivateImplementationPattern<DependencyDepTag>;
    extern template class PrivateImplementationPattern<GeneralSetDepTag>;
#endif

}

#endif