• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #include <boost/parameter.hpp>
3 
4 namespace boost { namespace python {
5 
6     BOOST_PARAMETER_TEMPLATE_KEYWORD(class_type)
7     BOOST_PARAMETER_TEMPLATE_KEYWORD(base_list)
8     BOOST_PARAMETER_TEMPLATE_KEYWORD(held_type)
9     BOOST_PARAMETER_TEMPLATE_KEYWORD(copyable)
10 }}
11 
12 namespace boost { namespace python {
13     namespace detail {
14 
15         struct bases_base
16         {
17         };
18     }
19 
20     template <typename A0 = void, typename A1 = void, typename A2 = void>
21     struct bases : detail::bases_base
22     {
23     };
24 }}
25 
26 #include <boost/mpl/bool.hpp>
27 #include <boost/mpl/placeholders.hpp>
28 #include <boost/mpl/if.hpp>
29 #include <boost/mpl/eval_if.hpp>
30 #include <boost/noncopyable.hpp>
31 #include <boost/type_traits/is_same.hpp>
32 #include <boost/type_traits/is_base_of.hpp>
33 #include <boost/type_traits/is_class.hpp>
34 #include <boost/config.hpp>
35 
36 #if !defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) || \
37     !(1 == BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
38 #include <boost/type_traits/is_scalar.hpp>
39 #endif
40 
41 namespace boost { namespace python {
42 
43     typedef boost::parameter::parameters<
44         boost::parameter::required<
45             tag::class_type
46 #if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) && \
47     (1 == BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
48           , boost::mpl::if_<
49                 boost::is_class<boost::mpl::_>
50               , boost::mpl::true_
51               , boost::mpl::false_
52             >
53 #else
54           , boost::mpl::if_<
55                 boost::is_scalar<boost::mpl::_>
56               , boost::mpl::false_
57               , boost::mpl::true_
58             >
59 #endif
60         >
61       , boost::parameter::optional<
62             boost::parameter::deduced<tag::base_list>
63           , boost::mpl::if_<
64                 boost::is_base_of<detail::bases_base,boost::mpl::_>
65               , boost::mpl::true_
66               , boost::mpl::false_
67             >
68         >
69       , boost::parameter::optional<
70             boost::parameter::deduced<tag::held_type>
71           , boost::mpl::eval_if<
72                 boost::is_base_of<detail::bases_base,boost::mpl::_>
73               , boost::mpl::false_
74               , boost::mpl::if_<
75                     boost::is_same<boost::noncopyable,boost::mpl::_>
76                   , boost::mpl::false_
77                   , boost::mpl::true_
78                 >
79             >
80         >
81       , boost::parameter::optional<
82             boost::parameter::deduced<tag::copyable>
83           , boost::mpl::if_<
84                 boost::is_same<boost::noncopyable,boost::mpl::_>
85               , boost::mpl::true_
86               , boost::mpl::false_
87             >
88         >
89     > class_signature;
90 
91     template <
92         typename A0
93       , typename A1 = boost::parameter::void_
94       , typename A2 = boost::parameter::void_
95       , typename A3 = boost::parameter::void_
96     >
97     struct class_
98     {
99         // Create ArgumentPack
100         typedef typename boost::python::class_signature::BOOST_NESTED_TEMPLATE
101         bind<A0,A1,A2,A3>::type args;
102 
103         // Extract first logical parameter.
104         typedef typename boost::parameter::value_type<
105             args,boost::python::tag::class_type
106         >::type class_type;
107 
108         typedef typename boost::parameter::value_type<
109             args,boost::python::tag::base_list,boost::python::bases<>
110         >::type base_list;
111 
112         typedef typename boost::parameter::value_type<
113             args,boost::python::tag::held_type,class_type
114         >::type held_type;
115 
116         typedef typename boost::parameter::value_type<
117             args,boost::python::tag::copyable,void
118         >::type copyable;
119     };
120 }}
121 
122 struct B
123 {
124 };
125 
126 struct D
127 {
128 };
129 
130 typedef boost::python::class_<B,boost::noncopyable> c1;
131 
132 #include <memory>
133 
134 #if defined(BOOST_NO_CXX11_SMART_PTR)
135 typedef boost::python::class_<D,std::auto_ptr<D>,boost::python::bases<B> > c2;
136 #else
137 typedef boost::python::class_<
138     D,std::unique_ptr<D>,boost::python::bases<B>
139 > c2;
140 #endif
141 
142 #include <boost/mpl/assert.hpp>
143 #include <boost/mpl/aux_/test.hpp>
144 
MPL_TEST_CASE()145 MPL_TEST_CASE()
146 {
147     BOOST_MPL_ASSERT((
148         boost::mpl::if_<
149             boost::is_same<c1::class_type,B>
150           , boost::mpl::true_
151           , boost::mpl::false_
152         >::type
153     ));
154     BOOST_MPL_ASSERT((
155         boost::mpl::if_<
156             boost::is_same<c1::base_list,boost::python::bases<> >
157           , boost::mpl::true_
158           , boost::mpl::false_
159         >::type
160     ));
161     BOOST_MPL_ASSERT((
162         boost::mpl::if_<
163             boost::is_same<c1::held_type,B>
164           , boost::mpl::true_
165           , boost::mpl::false_
166         >::type
167     ));
168     BOOST_MPL_ASSERT((
169         boost::mpl::if_<
170             boost::is_same<c1::copyable,boost::noncopyable>
171           , boost::mpl::true_
172           , boost::mpl::false_
173         >::type
174     ));
175     BOOST_MPL_ASSERT((
176         boost::mpl::if_<
177             boost::is_same<c2::class_type,D>
178           , boost::mpl::true_
179           , boost::mpl::false_
180         >::type
181     ));
182     BOOST_MPL_ASSERT((
183         boost::mpl::if_<
184             boost::is_same<c2::base_list,boost::python::bases<B> >
185           , boost::mpl::true_
186           , boost::mpl::false_
187         >::type
188     ));
189 #if defined(BOOST_NO_CXX11_SMART_PTR)
190     BOOST_MPL_ASSERT((
191         boost::mpl::if_<
192             boost::is_same<c2::held_type,std::auto_ptr<D> >
193           , boost::mpl::true_
194           , boost::mpl::false_
195         >::type
196     ));
197 #else
198     BOOST_MPL_ASSERT((
199         boost::mpl::if_<
200             boost::is_same<c2::held_type,std::unique_ptr<D> >
201           , boost::mpl::true_
202           , boost::mpl::false_
203         >::type
204     ));
205 #endif  // BOOST_NO_CXX11_SMART_PTR
206     BOOST_MPL_ASSERT((
207         boost::mpl::if_<
208             boost::is_same<c2::copyable,void>
209           , boost::mpl::true_
210           , boost::mpl::false_
211         >::type
212     ));
213 }
214 
215