Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:37

0001 // Copyright David Abrahams 2002.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 #ifndef IMPLICIT_DWA2002326_HPP
0006 # define IMPLICIT_DWA2002326_HPP
0007 
0008 # include <boost/python/converter/rvalue_from_python_data.hpp>
0009 # include <boost/python/converter/registrations.hpp>
0010 # include <boost/python/converter/registered.hpp>
0011 
0012 # include <boost/python/extract.hpp>
0013 
0014 namespace boost { namespace python { namespace converter { 
0015 
0016 template <class Source, class Target>
0017 struct implicit
0018 {
0019     static void* convertible(PyObject* obj)
0020     {
0021         // Find a converter which can produce a Source instance from
0022         // obj. The user has told us that Source can be converted to
0023         // Target, and instantiating construct() below, ensures that
0024         // at compile-time.
0025         return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters)
0026             ? obj : 0;
0027     }
0028       
0029     static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
0030     {
0031         void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes;
0032 
0033         arg_from_python<Source> get_source(obj);
0034         bool convertible = get_source.convertible();
0035         BOOST_VERIFY(convertible);
0036         
0037         new (storage) Target(get_source());
0038         
0039         // record successful construction
0040         data->convertible = storage;
0041     }
0042 };
0043 
0044 }}} // namespace boost::python::converter
0045 
0046 #endif // IMPLICIT_DWA2002326_HPP