1 | // Copyright Gottfried Ganßauge 2003.
|
---|
2 | // Distributed under the Boost Software License, Version 1.0. (See
|
---|
3 | // accompanying file LICENSE_1_0.txt or copy at
|
---|
4 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
5 | /*
|
---|
6 | * Generic Return value converter generator for opaque C++-pointers
|
---|
7 | */
|
---|
8 | # ifndef RETURN_OPAQUE_POINTER_HPP_
|
---|
9 | # define RETURN_OPAQUE_POINTER_HPP_
|
---|
10 |
|
---|
11 | # include <boost/python/detail/prefix.hpp>
|
---|
12 | # include <boost/python/opaque_pointer_converter.hpp>
|
---|
13 | # include <boost/python/detail/indirect_traits.hpp>
|
---|
14 | # include <boost/mpl/if.hpp>
|
---|
15 |
|
---|
16 | namespace boost { namespace python {
|
---|
17 |
|
---|
18 | namespace detail
|
---|
19 | {
|
---|
20 | template <class Pointer>
|
---|
21 | struct opaque_conversion_holder
|
---|
22 | {
|
---|
23 | inline PyObject *operator()(Pointer p) const
|
---|
24 | {
|
---|
25 | static opaque_pointer_converter<Pointer> converter (
|
---|
26 | typeid (Pointer).name());
|
---|
27 |
|
---|
28 | return converter.convert(p);
|
---|
29 | }
|
---|
30 | };
|
---|
31 |
|
---|
32 | template <class R>
|
---|
33 | struct return_opaque_pointer_requires_a_pointer_type
|
---|
34 | # if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
|
---|
35 | {}
|
---|
36 | # endif
|
---|
37 | ;
|
---|
38 | }
|
---|
39 |
|
---|
40 | struct return_opaque_pointer
|
---|
41 | {
|
---|
42 | template <class R>
|
---|
43 | struct apply
|
---|
44 | {
|
---|
45 | BOOST_STATIC_CONSTANT(
|
---|
46 | bool, ok = is_pointer<R>::value);
|
---|
47 |
|
---|
48 | typedef typename mpl::if_c<
|
---|
49 | ok
|
---|
50 | , detail::opaque_conversion_holder<R>
|
---|
51 | , detail::return_opaque_pointer_requires_a_pointer_type<R>
|
---|
52 | >::type type;
|
---|
53 | };
|
---|
54 | };
|
---|
55 | }} // namespace boost::python
|
---|
56 | # endif // RETURN_OPAQUE_POINTER_HPP_
|
---|