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

#ifndef PALUDIS_GUARD_PALUDIS_MATCH_PACKAGE_HH
#define PALUDIS_GUARD_PALUDIS_MATCH_PACKAGE_HH 1

/** \file
 * Declare the match_package function.
 *
 * Do not merge this file into dep_atom. It will cause all sorts of horrible
 * circular dependency issues. Avoid including this file in headers if at all
 * possible.
 *
 * \ingroup grpmatchpackage
 */

#include <paludis/dep_atom.hh>
#include <paludis/dep_list.hh>
#include <paludis/environment.hh>
#include <paludis/util/attributes.hh>

namespace paludis
{
    /**
     * For internal use by match_package.
     *
     * \ingroup grpmatchpackage
     */
    namespace match_package_internals
    {
        /**
         * Do the match on a PackageDatabaseEntry.
         *
         * \ingroup grpmatchpackage
         */
        bool do_match(
                const Environment * const env,
                const PackageDepAtom * const atom,
                const PackageDatabaseEntry * const entry)
            PALUDIS_ATTRIBUTE((nonnull(1, 2, 3)));

        /**
         * Do the match on a DepListEntry.
         *
         * \ingroup grpmatchpackage
         */
        bool do_match(
                const Environment * const env,
                const PackageDepAtom * const atom,
                const DepListEntry * const entry)
            PALUDIS_ATTRIBUTE((nonnull(2, 3)));

        /**
         * Normalise env type.
         *
         * \ingroup grpmatchpackage
         */
        inline const Environment * sanitise_env(const Environment * env)
        {
            return env;
        }

        /**
         * Normalise DB type.
         *
         * \ingroup grpmatchpackage
         */
        template <typename P1_>
        inline const Environment * sanitise_env(const CountedPtr<const Environment, P1_> env)
        {
            return env.raw_pointer();
        }

        /**
         * Normalise atom type.
         *
         * \ingroup grpmatchpackage
         */
        inline const PackageDepAtom * sanitise_atom(const PackageDepAtom * atom)
        {
            return atom;
        }

        /**
         * Normalise atom type.
         *
         * \ingroup grpmatchpackage
         */
        inline const PackageDepAtom * sanitise_atom(const PackageDepAtom & atom)
        {
            return &atom;
        }

        /**
         * Normalise atom type.
         *
         * \ingroup grpmatchpackage
         */
        template <typename P1_>
        inline const PackageDepAtom * sanitise_atom(const CountedPtr<const PackageDepAtom, P1_> atom)
        {
            return atom.raw_pointer();
        }

        /**
         * Normalise target type.
         *
         * \ingroup grpmatchpackage
         */
        template <typename T_>
        inline const T_ * sanitise_target(const T_ * e)
        {
            return e;
        }

        /**
         * Normalise target type.
         *
         * \ingroup grpmatchpackage
         */
        template <typename T_>
        inline const T_ * sanitise_target(const T_ & e)
        {
            return &e;
        }
    }

    /**
     * Return whether the specified atom matches the specified target.
     *
     * \param env     Some kind of environment
     * \param atom    Some kind of package dep atom
     * \param target  Some kind of target
     *
     * \ingroup grpmatchpackage
     */
    template <typename Env_, typename Atom_, typename Target_>
    bool match_package(
            const Env_ & env,
            const Atom_ & atom,
            const Target_ & target)
    {
        return match_package_internals::do_match(
                match_package_internals::sanitise_env(env),
                match_package_internals::sanitise_atom(atom),
                match_package_internals::sanitise_target(target));
    }
}

#endif