aboutsummaryrefslogtreecommitdiff
path: root/python/slot_requirement.cc
blob: 3317b56e85bca4e9d70923115ab4dc8c3fea426a (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
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 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
 */

#include <python/paludis_python.hh>
#include <python/exception.hh>

#include <paludis/util/make_named_values.hh>
#include <paludis/util/sequence.hh>
#include <paludis/slot_requirement.hh>
#include <paludis/name.hh>
#include <memory>

using namespace paludis;
using namespace paludis::python;
namespace bp = boost::python;

namespace
{
    class SlotRequirementSptrToPythonVisitor
    {
        private:
            const std::shared_ptr<const SlotRequirement> & _m_ptr;

        public:
            boost::python::object obj;

            SlotRequirementSptrToPythonVisitor(const std::shared_ptr<const SlotRequirement> & m_ptr) :
                _m_ptr(m_ptr)
            {
            }

            void visit(const SlotExactPartialRequirement &)
            {
                obj = bp::object(std::static_pointer_cast<const SlotExactPartialRequirement>(_m_ptr));
            }

            void visit(const SlotExactFullRequirement &)
            {
                obj = bp::object(std::static_pointer_cast<const SlotExactFullRequirement>(_m_ptr));
            }

            void visit(const SlotAnyAtAllLockedRequirement &)
            {
                obj = bp::object(std::static_pointer_cast<const SlotAnyAtAllLockedRequirement>(_m_ptr));
            }

            void visit(const SlotAnyPartialLockedRequirement &)
            {
                obj = bp::object(std::static_pointer_cast<const SlotAnyPartialLockedRequirement>(_m_ptr));
            }

            void visit(const SlotAnyUnlockedRequirement &)
            {
                obj = bp::object(std::static_pointer_cast<const SlotAnyUnlockedRequirement>(_m_ptr));
            }

            void visit(const SlotUnknownRewrittenRequirement &)
            {
                obj = bp::object(std::static_pointer_cast<const SlotUnknownRewrittenRequirement>(_m_ptr));
            }
    };

    struct SlotRequirementSptrToPython
    {
        SlotRequirementSptrToPython()
        {
            bp::to_python_converter<std::shared_ptr<const SlotRequirement>, SlotRequirementSptrToPython>();
        }

        static PyObject *
        convert(const std::shared_ptr<const SlotRequirement> & m)
        {
            if (! m)
                return Py_None;

            SlotRequirementSptrToPythonVisitor v(m);
            m->accept(v);
            return bp::incref(v.obj.ptr());
        }
    };
}

void expose_slot_requirement()
{
    SlotRequirementSptrToPython();

    /**
     * SlotRequirement
     */
    bp::class_<SlotRequirement, boost::noncopyable>
        (
         "SlotRequirement",
         "A SlotRequirement represents a PackageDepSpec's slot requirement, "
         "such as ``:3``, ``:*``, ``:=`` or ``:=3``.",
         bp::no_init
        )

        .def("__str__", &SlotRequirement::as_string)
        ;

    /**
     * SlotExactPartialRequirement
     */
    register_shared_ptrs_to_python<SlotExactPartialRequirement>(rsp_const);
    bp::implicitly_convertible<std::shared_ptr<SlotExactPartialRequirement>, std::shared_ptr<SlotRequirement> >();
    bp::class_<SlotExactPartialRequirement, std::shared_ptr<SlotExactPartialRequirement>, bp::bases<SlotRequirement>, boost::noncopyable>
        (
         "SlotExactPartialRequirement",
         "A SlotExactPartialRequirement is a SlotRequirement for exact slot requirements, "
         "such as ``:3`` or ``:=3``.",
         bp::no_init
        )

        .add_property("slot", &SlotExactPartialRequirement::slot,
                "[ro] SlotName\n"
                "The slot in question."
                )
        ;

    /**
     * SlotExactFullRequirement
     */
    register_shared_ptrs_to_python<SlotExactFullRequirement>(rsp_const);
    bp::implicitly_convertible<std::shared_ptr<SlotExactFullRequirement>, std::shared_ptr<SlotRequirement> >();
    bp::class_<SlotExactFullRequirement, std::shared_ptr<SlotExactFullRequirement>, bp::bases<SlotRequirement>, boost::noncopyable>
        (
         "SlotExactFullRequirement",
         "A SlotExactFullRequirement is a SlotRequirement for exact slot requirements, "
         "such as ``:3/3`` or ``:=3/3``.",
         bp::no_init
        )
        ;

    /**
     * SlotAnyAtAllLockedRequirement
     */
    register_shared_ptrs_to_python<SlotAnyAtAllLockedRequirement>(rsp_const);
    bp::implicitly_convertible<std::shared_ptr<SlotAnyAtAllLockedRequirement>, std::shared_ptr<SlotRequirement> >();
    bp::class_<SlotAnyAtAllLockedRequirement, std::shared_ptr<SlotAnyAtAllLockedRequirement>, bp::bases<SlotRequirement>, boost::noncopyable>
        (
         "SlotAnyAtAllLockedRequirement",
         "A SlotAnyAtAllLockedRequirement is a SlotRequirement for ``:=`` slot requirements.",
         bp::no_init
        )
        ;

    /**
     * SlotAnyPartialLockedRequirement
     */
    register_shared_ptrs_to_python<SlotAnyPartialLockedRequirement>(rsp_const);
    bp::implicitly_convertible<std::shared_ptr<SlotAnyPartialLockedRequirement>, std::shared_ptr<SlotRequirement> >();
    bp::class_<SlotAnyPartialLockedRequirement, std::shared_ptr<SlotAnyPartialLockedRequirement>, bp::bases<SlotRequirement>, boost::noncopyable>
        (
         "SlotAnyPartialLockedRequirement",
         "A SlotAnyPartialLockedRequirement is a SlotRequirement for ``:3=`` slot requirements.",
         bp::no_init
        )
        ;

    /**
     * SlotAnyUnlockedRequirement
     */
    register_shared_ptrs_to_python<SlotAnyUnlockedRequirement>(rsp_const);
    bp::implicitly_convertible<std::shared_ptr<SlotAnyUnlockedRequirement>, std::shared_ptr<SlotRequirement> >();
    bp::class_<SlotAnyUnlockedRequirement, std::shared_ptr<SlotAnyUnlockedRequirement>, bp::bases<SlotRequirement>, boost::noncopyable>
        (
         "SlotAnyUnlockedRequirement",
         "A SlotAnyUnlockedRequirement is a SlotRequirement for ``:*`` slot requirements.",
         bp::no_init
        )
        ;

    /**
     * SlotUnknownRewrittenRequirement
     */
    register_shared_ptrs_to_python<SlotUnknownRewrittenRequirement>(rsp_const);
    bp::implicitly_convertible<std::shared_ptr<SlotUnknownRewrittenRequirement>, std::shared_ptr<SlotRequirement> >();
    bp::class_<SlotUnknownRewrittenRequirement, std::shared_ptr<SlotUnknownRewrittenRequirement>, bp::bases<SlotRequirement>, boost::noncopyable>
        (
         "SlotUnknownRewrittenRequirement",
         "A SlotUnknownRewrittenRequirement is a SlotRequirement for the "
         "maybe_original_requirement_if_written() method of ``:3/3.1= slot`` "
         "requirements that do not indicate whether they were originally "
         "of ``:=`` or ``:3=`` type.",
         bp::no_init
        )
        ;
}