sl@0
|
1 |
// Copyright David Abrahams 2002.
|
sl@0
|
2 |
// Distributed under the Boost Software License, Version 1.0. (See
|
sl@0
|
3 |
// accompanying file LICENSE_1_0.txt or copy at
|
sl@0
|
4 |
// http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
5 |
#ifndef IMPLICIT_DWA2002326_HPP
|
sl@0
|
6 |
# define IMPLICIT_DWA2002326_HPP
|
sl@0
|
7 |
|
sl@0
|
8 |
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
sl@0
|
9 |
# include <boost/python/converter/registrations.hpp>
|
sl@0
|
10 |
# include <boost/python/converter/registered.hpp>
|
sl@0
|
11 |
|
sl@0
|
12 |
# include <boost/python/extract.hpp>
|
sl@0
|
13 |
|
sl@0
|
14 |
namespace boost { namespace python { namespace converter {
|
sl@0
|
15 |
|
sl@0
|
16 |
template <class Source, class Target>
|
sl@0
|
17 |
struct implicit
|
sl@0
|
18 |
{
|
sl@0
|
19 |
static void* convertible(PyObject* obj)
|
sl@0
|
20 |
{
|
sl@0
|
21 |
// Find a converter which can produce a Source instance from
|
sl@0
|
22 |
// obj. The user has told us that Source can be converted to
|
sl@0
|
23 |
// Target, and instantiating construct() below, ensures that
|
sl@0
|
24 |
// at compile-time.
|
sl@0
|
25 |
return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters)
|
sl@0
|
26 |
? obj : 0;
|
sl@0
|
27 |
}
|
sl@0
|
28 |
|
sl@0
|
29 |
static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes;
|
sl@0
|
32 |
|
sl@0
|
33 |
arg_from_python<Source> get_source(obj);
|
sl@0
|
34 |
bool convertible = get_source.convertible();
|
sl@0
|
35 |
BOOST_ASSERT(convertible);
|
sl@0
|
36 |
|
sl@0
|
37 |
new (storage) Target(get_source());
|
sl@0
|
38 |
|
sl@0
|
39 |
// record successful construction
|
sl@0
|
40 |
data->convertible = storage;
|
sl@0
|
41 |
}
|
sl@0
|
42 |
};
|
sl@0
|
43 |
|
sl@0
|
44 |
}}} // namespace boost::python::converter
|
sl@0
|
45 |
|
sl@0
|
46 |
#endif // IMPLICIT_DWA2002326_HPP
|