os/ossrv/ossrv_pub/boost_apis/boost/python/converter/implicit.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/converter/implicit.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,46 @@
     1.4 +// Copyright David Abrahams 2002.
     1.5 +// Distributed under the Boost Software License, Version 1.0. (See
     1.6 +// accompanying file LICENSE_1_0.txt or copy at
     1.7 +// http://www.boost.org/LICENSE_1_0.txt)
     1.8 +#ifndef IMPLICIT_DWA2002326_HPP
     1.9 +# define IMPLICIT_DWA2002326_HPP
    1.10 +
    1.11 +# include <boost/python/converter/rvalue_from_python_data.hpp>
    1.12 +# include <boost/python/converter/registrations.hpp>
    1.13 +# include <boost/python/converter/registered.hpp>
    1.14 +
    1.15 +# include <boost/python/extract.hpp>
    1.16 +
    1.17 +namespace boost { namespace python { namespace converter { 
    1.18 +
    1.19 +template <class Source, class Target>
    1.20 +struct implicit
    1.21 +{
    1.22 +    static void* convertible(PyObject* obj)
    1.23 +    {
    1.24 +        // Find a converter which can produce a Source instance from
    1.25 +        // obj. The user has told us that Source can be converted to
    1.26 +        // Target, and instantiating construct() below, ensures that
    1.27 +        // at compile-time.
    1.28 +        return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters)
    1.29 +            ? obj : 0;
    1.30 +    }
    1.31 +      
    1.32 +    static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
    1.33 +    {
    1.34 +        void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes;
    1.35 +
    1.36 +        arg_from_python<Source> get_source(obj);
    1.37 +        bool convertible = get_source.convertible();
    1.38 +        BOOST_ASSERT(convertible);
    1.39 +        
    1.40 +        new (storage) Target(get_source());
    1.41 +        
    1.42 +        // record successful construction
    1.43 +        data->convertible = storage;
    1.44 +    }
    1.45 +};
    1.46 +
    1.47 +}}} // namespace boost::python::converter
    1.48 +
    1.49 +#endif // IMPLICIT_DWA2002326_HPP