Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/python/converter/implicit.hpp @ 35

Last change on this file since 35 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.5 KB
Line 
1// Copyright David Abrahams 2002.
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#ifndef IMPLICIT_DWA2002326_HPP
6# define IMPLICIT_DWA2002326_HPP
7
8# include <boost/python/converter/rvalue_from_python_data.hpp>
9# include <boost/python/converter/registrations.hpp>
10# include <boost/python/converter/registered.hpp>
11
12# include <boost/python/extract.hpp>
13
14namespace boost { namespace python { namespace converter { 
15
16template <class Source, class Target>
17struct implicit
18{
19    static void* convertible(PyObject* obj)
20    {
21        // Find a converter which can produce a Source instance from
22        // obj. The user has told us that Source can be converted to
23        // Target, and instantiating construct() below, ensures that
24        // at compile-time.
25        return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters)
26            ? obj : 0;
27    }
28     
29    static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
30    {
31        void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes;
32
33        arg_from_python<Source> get_source(obj);
34        bool convertible = get_source.convertible();
35        BOOST_ASSERT(convertible);
36       
37        new (storage) Target(get_source());
38       
39        // record successful construction
40        data->convertible = storage;
41    }
42};
43
44}}} // namespace boost::python::converter
45
46#endif // IMPLICIT_DWA2002326_HPP
Note: See TracBrowser for help on using the repository browser.