mirror of
https://github.com/boostorg/python.git
synced 2026-01-24 18:12:43 +00:00
This commit was manufactured by cvs2svn to create branch 'mpl_v2'.
[SVN r15247]
This commit is contained in:
103
include/boost/python/args.hpp
Normal file
103
include/boost/python/args.hpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ARGS_DWA2002323_HPP
|
||||
# define ARGS_DWA2002323_HPP
|
||||
# include <boost/config.hpp>
|
||||
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
|
||||
# include <boost/mpl/type_list.hpp>
|
||||
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
enum no_init_t { no_init };
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class Args>
|
||||
struct args_base {};
|
||||
}
|
||||
}}
|
||||
|
||||
# if !defined(__EDG_VERSION__) || __EDG_VERSION__ > 245
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
// A type list for specifying arguments
|
||||
template < BOOST_PYTHON_ENUM_WITH_DEFAULT(BOOST_PYTHON_MAX_ARITY, typename A, boost::mpl::null_argument) >
|
||||
struct args : detail::args_base<args<BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, A)> >
|
||||
, boost::mpl::type_list< BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, A) >::type
|
||||
{};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
# else // slow template instantiators need this other version with
|
||||
// explicit specializations of mpl::size<> and
|
||||
// mpl::at<>. Eventually, however, inheritance from mpl::list
|
||||
// *should* be eliminated and the two versions unified, just in
|
||||
// order to get true arity independence
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template < BOOST_PYTHON_ENUM_WITH_DEFAULT(BOOST_PYTHON_MAX_ARITY, typename A, boost::mpl::null_argument) >
|
||||
struct args : detail::args_base<args<BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, A)> >
|
||||
{};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
namespace boost { namespace mpl {
|
||||
|
||||
template <class T> struct size;
|
||||
template <long N, class Seq> struct at;
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/args.hpp>, 1))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY - 1, <boost/python/args.hpp>, 2))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
|
||||
}} // namespace boost::mpl
|
||||
|
||||
# endif // __EDG_VERSION__
|
||||
|
||||
# endif // ARGS_DWA2002323_HPP
|
||||
|
||||
/* ---------- size ---------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
|
||||
# line BOOST_PP_LINE(__LINE__, args.hpp(size))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template <BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
struct size<boost::python::args<BOOST_PYTHON_UNARY_ENUM(N, A)> >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(long, value = N);
|
||||
};
|
||||
|
||||
# undef N
|
||||
|
||||
/* ---------- at ---------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
|
||||
# line BOOST_PP_LINE(__LINE__, args.hpp(at))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template <BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, class A)>
|
||||
struct at<N, boost::python::args<BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, A)> >
|
||||
{
|
||||
typedef BOOST_PP_CAT(A, N) type;
|
||||
};
|
||||
|
||||
# undef N
|
||||
|
||||
#endif
|
||||
101
include/boost/python/back_reference.hpp
Normal file
101
include/boost/python/back_reference.hpp
Normal file
@@ -0,0 +1,101 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef BACK_REFERENCE_DWA2002510_HPP
|
||||
# define BACK_REFERENCE_DWA2002510_HPP
|
||||
|
||||
# include <boost/python/object_fwd.hpp>
|
||||
# include <boost/python/detail/dependent.hpp>
|
||||
# include <boost/python/detail/raw_pyobject.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T>
|
||||
struct back_reference
|
||||
{
|
||||
private: // types
|
||||
typedef typename detail::dependent<object,T>::type source_t;
|
||||
public:
|
||||
typedef T type;
|
||||
|
||||
back_reference(PyObject*, T);
|
||||
source_t const& source() const;
|
||||
T get() const;
|
||||
private:
|
||||
source_t m_source;
|
||||
T m_value;
|
||||
};
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template<typename T>
|
||||
class is_back_reference
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class is_back_reference<back_reference<T> >
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
# else // no partial specialization
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#include <boost/type.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
typedef char (&yes_back_reference_t)[1];
|
||||
typedef char (&no_back_reference_t)[2];
|
||||
|
||||
no_back_reference_t is_back_reference_test(...);
|
||||
|
||||
template<typename T>
|
||||
yes_back_reference_t is_back_reference_test(boost::type< back_reference<T> >);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class is_back_reference
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
sizeof(detail::is_back_reference_test(boost::type<T>()))
|
||||
== sizeof(detail::yes_back_reference_t)));
|
||||
};
|
||||
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
template <class T>
|
||||
back_reference<T>::back_reference(PyObject* p, T x)
|
||||
: m_source(detail::borrowed_reference(p))
|
||||
, m_value(x)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
typename back_reference<T>::source_t const& back_reference<T>::source() const
|
||||
{
|
||||
return m_source;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T back_reference<T>::get() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // BACK_REFERENCE_DWA2002510_HPP
|
||||
20
include/boost/python/borrowed.hpp
Executable file
20
include/boost/python/borrowed.hpp
Executable file
@@ -0,0 +1,20 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef BORROWED_DWA2002614_HPP
|
||||
# define BORROWED_DWA2002614_HPP
|
||||
# include <boost/python/detail/borrowed_ptr.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T>
|
||||
inline python::detail::borrowed<T>* borrowed(T* p)
|
||||
{
|
||||
return (detail::borrowed<T>*)p;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // BORROWED_DWA2002614_HPP
|
||||
64
include/boost/python/call.hpp
Normal file
64
include/boost/python/call.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# ifndef CALL_DWA2002411_HPP
|
||||
# define CALL_DWA2002411_HPP
|
||||
|
||||
# include <boost/type.hpp>
|
||||
|
||||
# include <boost/python/converter/arg_to_python.hpp>
|
||||
# include <boost/python/converter/return_from_python.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/python/detail/void_return.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
# define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(z, n, _) \
|
||||
, converter::arg_to_python<A##n>(a##n).get()
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/call.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
# endif // CALL_DWA2002411_HPP
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
# line BOOST_PP_LINE(__LINE__, call.hpp)
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template <
|
||||
class R
|
||||
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)
|
||||
>
|
||||
typename detail::returnable<R>::type
|
||||
call(PyObject* callable
|
||||
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, const& a)
|
||||
, boost::type<R>* = 0
|
||||
)
|
||||
{
|
||||
converter::return_from_python<R> converter;
|
||||
return converter(
|
||||
PyEval_CallFunction(
|
||||
callable
|
||||
, const_cast<char*>("(" BOOST_PP_REPEAT(N, BOOST_PYTHON_FIXED, "O") ")")
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil)
|
||||
));
|
||||
}
|
||||
|
||||
# undef N
|
||||
|
||||
#endif
|
||||
64
include/boost/python/call_method.hpp
Normal file
64
include/boost/python/call_method.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
# ifndef CALL_METHOD_DWA2002411_HPP
|
||||
# define CALL_METHOD_DWA2002411_HPP
|
||||
|
||||
# include <boost/type.hpp>
|
||||
|
||||
# include <boost/python/converter/arg_to_python.hpp>
|
||||
# include <boost/python/converter/return_from_python.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/python/detail/void_return.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
# define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(z, n, _) \
|
||||
, converter::arg_to_python<A##n>(a##n).get()
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/call_method.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
# endif // CALL_METHOD_DWA2002411_HPP
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
# line BOOST_PP_LINE(__LINE__, call_method.hpp)
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template <
|
||||
class R
|
||||
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)
|
||||
>
|
||||
typename detail::returnable<R>::type
|
||||
call_method(PyObject* self, char const* name
|
||||
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, const& a)
|
||||
, boost::type<R>* = 0
|
||||
)
|
||||
{
|
||||
converter::return_from_python<R> converter;
|
||||
return converter(
|
||||
PyEval_CallMethod(
|
||||
self
|
||||
, const_cast<char*>(name)
|
||||
, const_cast<char*>("(" BOOST_PP_REPEAT(N, BOOST_PYTHON_FIXED, "O") ")")
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil)
|
||||
));
|
||||
}
|
||||
|
||||
# undef N
|
||||
|
||||
#endif // BOOST_PP_IS_ITERATING
|
||||
106
include/boost/python/cast.hpp
Executable file
106
include/boost/python/cast.hpp
Executable file
@@ -0,0 +1,106 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CAST_DWA200269_HPP
|
||||
# define CAST_DWA200269_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/python/base_type_traits.hpp>
|
||||
# include <boost/python/detail/convertible.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class Source, class Target> inline Target* upcast_impl(Source*, Target*);
|
||||
|
||||
template <class Source, class Target>
|
||||
inline Target* upcast(Source* p, yes_convertible, no_convertible, Target*)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
template <class Source, class Target>
|
||||
inline Target* upcast(Source* p, no_convertible, no_convertible, Target*)
|
||||
{
|
||||
typedef typename base_type_traits<Source>::type base;
|
||||
|
||||
return detail::upcast_impl((base*)p, (Target*)0);
|
||||
}
|
||||
|
||||
template <bool is_same = true>
|
||||
struct upcaster
|
||||
{
|
||||
template <class T>
|
||||
static inline T* execute(T* x, T*) { return x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct upcaster<false>
|
||||
{
|
||||
template <class Source, class Target>
|
||||
static inline Target* execute(Source* x, Target*)
|
||||
{
|
||||
return detail::upcast(
|
||||
x, detail::convertible<Target*>::check(x)
|
||||
, detail::convertible<Source*>::check((Target*)0)
|
||||
, (Target*)0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class Target, class Source>
|
||||
inline Target* downcast(Source* p, yes_convertible)
|
||||
{
|
||||
return static_cast<Target*>(p);
|
||||
}
|
||||
|
||||
template <class Target, class Source>
|
||||
inline Target* downcast(Source* p, no_convertible, boost::type<Target>* = 0)
|
||||
{
|
||||
typedef typename base_type_traits<Source>::type base;
|
||||
return (Target*)detail::downcast<base>(p, convertible<Source*>::check((base*)0));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void assert_castable(boost::type<T>* = 0)
|
||||
{
|
||||
typedef char must_be_a_complete_type[sizeof(T)];
|
||||
}
|
||||
|
||||
template <class Source, class Target>
|
||||
inline Target* upcast_impl(Source* x, Target*)
|
||||
{
|
||||
typedef typename add_cv<Source>::type src_t;
|
||||
typedef typename add_cv<Target>::type target_t;
|
||||
static bool const same = is_same<src_t,target_t>::value;
|
||||
|
||||
return detail::upcaster<same>::execute(x, (Target*)0);
|
||||
}
|
||||
}
|
||||
|
||||
template <class Target, class Source>
|
||||
inline Target* upcast(Source* x, Target* = 0)
|
||||
{
|
||||
detail::assert_castable<Source>();
|
||||
detail::assert_castable<Target>();
|
||||
return detail::upcast_impl(x, (Target*)0);
|
||||
|
||||
}
|
||||
|
||||
template <class Target, class Source>
|
||||
inline Target* downcast(Source* x, Target* = 0)
|
||||
{
|
||||
detail::assert_castable<Source>();
|
||||
detail::assert_castable<Target>();
|
||||
return detail::downcast<Target>(x, detail::convertible<Source*>::check((Target*)0));
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CAST_DWA200269_HPP
|
||||
495
include/boost/python/class.hpp
Normal file
495
include/boost/python/class.hpp
Normal file
@@ -0,0 +1,495 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CLASS_DWA200216_HPP
|
||||
# define CLASS_DWA200216_HPP
|
||||
|
||||
# include <boost/python/class_fwd.hpp>
|
||||
# include <boost/python/object/class.hpp>
|
||||
# include <boost/python/bases.hpp>
|
||||
# include <boost/python/args.hpp>
|
||||
|
||||
# include <boost/python/object.hpp>
|
||||
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/detail/member_function_cast.hpp>
|
||||
# include <boost/python/object/class_converters.hpp>
|
||||
# include <boost/type_traits/ice.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/mpl/size.hpp>
|
||||
# include <boost/mpl/for_each.hpp>
|
||||
# include <boost/mpl/bool_t.hpp>
|
||||
# include <boost/python/object/select_holder.hpp>
|
||||
# include <boost/python/object/class_wrapper.hpp>
|
||||
# include <boost/python/object/make_instance.hpp>
|
||||
# include <boost/python/data_members.hpp>
|
||||
# include <boost/utility.hpp>
|
||||
# include <boost/python/detail/operator_id.hpp>
|
||||
# include <boost/python/object/pickle_support.hpp>
|
||||
# include <boost/python/make_function.hpp>
|
||||
# include <boost/python/object/add_to_namespace.hpp>
|
||||
# include <boost/python/detail/def_helper.hpp>
|
||||
# include <boost/python/detail/force_instantiate.hpp>
|
||||
# include <boost/python/detail/defaults_def.hpp>
|
||||
# include <boost/python/signature.hpp>
|
||||
# include <boost/python/init.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct write_type_id;
|
||||
|
||||
template <class T, class Prev = detail::not_specified>
|
||||
struct select_held_type;
|
||||
|
||||
template <class T1, class T2, class T3>
|
||||
struct has_noncopyable;
|
||||
|
||||
template <detail::operator_id, class L, class R>
|
||||
struct operator_;
|
||||
|
||||
// Register a to_python converter for a class T, depending on the
|
||||
// type of the first (tag) argument. The 2nd argument is a pointer
|
||||
// to the type of holder that must be created. The 3rd argument is a
|
||||
// reference to the Python type object to be created.
|
||||
template <class T, class SelectHolder>
|
||||
static inline void register_copy_constructor(mpl::bool_t<true> const&, SelectHolder const& , T* = 0)
|
||||
{
|
||||
typedef typename SelectHolder::type holder;
|
||||
force_instantiate(objects::class_wrapper<T,holder, objects::make_instance<T,holder> >());
|
||||
SelectHolder::register_();
|
||||
}
|
||||
|
||||
// Tag dispatched to have no effect.
|
||||
template <class T, class SelectHolder>
|
||||
static inline void register_copy_constructor(mpl::bool_t<false> const&, SelectHolder const&, T* = 0)
|
||||
{
|
||||
SelectHolder::register_();
|
||||
}
|
||||
|
||||
template <class T> int assert_default_constructible(T const&);
|
||||
}
|
||||
|
||||
//
|
||||
// class_<T,Bases,HolderGenerator>
|
||||
//
|
||||
// This is the primary mechanism through which users will expose
|
||||
// C++ classes to Python. The three template arguments are:
|
||||
//
|
||||
template <
|
||||
class T // class being wrapped
|
||||
, class X1 // = detail::not_specified
|
||||
, class X2 // = detail::not_specified
|
||||
, class X3 // = detail::not_specified
|
||||
>
|
||||
class class_ : public objects::class_base
|
||||
{
|
||||
private: // types
|
||||
typedef objects::class_base base;
|
||||
|
||||
typedef class_<T,X1,X2,X3> self;
|
||||
BOOST_STATIC_CONSTANT(bool, is_copyable = (!detail::has_noncopyable<X1,X2,X3>::value));
|
||||
|
||||
typedef typename detail::select_held_type<
|
||||
X1, typename detail::select_held_type<
|
||||
X2, typename detail::select_held_type<
|
||||
X3
|
||||
>::type>::type>::type held_type;
|
||||
|
||||
typedef objects::select_holder<T,held_type> holder_selector;
|
||||
|
||||
typedef typename detail::select_bases<X1
|
||||
, typename detail::select_bases<X2
|
||||
, typename boost::python::detail::select_bases<X3>::type
|
||||
>::type
|
||||
>::type bases;
|
||||
|
||||
// A helper class which will contain an array of id objects to be
|
||||
// passed to the base class constructor
|
||||
struct id_vector
|
||||
{
|
||||
id_vector()
|
||||
{
|
||||
// Stick the derived class id into the first element of the array
|
||||
ids[0] = type_id<T>();
|
||||
|
||||
// Write the rest of the elements into succeeding positions.
|
||||
type_info* p = ids + 1;
|
||||
mpl::for_each<bases, void, detail::write_type_id>::execute(&p);
|
||||
}
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
std::size_t, size = mpl::size<bases>::value + 1);
|
||||
type_info ids[size];
|
||||
};
|
||||
friend struct id_vector;
|
||||
|
||||
public:
|
||||
// Automatically derive the class name - only works on some
|
||||
// compilers because type_info::name is sometimes mangled (gcc)
|
||||
class_(); // With default-constructor init function
|
||||
class_(no_init_t); // With no init function
|
||||
|
||||
// Construct with the class name, with or without docstring, and default init() function
|
||||
class_(char const* name, char const* doc = 0);
|
||||
|
||||
// Construct with class name, no docstring, and no init() function
|
||||
class_(char const* name, no_init_t);
|
||||
|
||||
// Construct with class name, docstring, and no init() function
|
||||
class_(char const* name, char const* doc, no_init_t);
|
||||
|
||||
template <class InitArgs>
|
||||
inline class_(char const* name, detail::args_base<InitArgs> const&)
|
||||
: base(name, id_vector::size, id_vector().ids)
|
||||
{
|
||||
this->register_();
|
||||
this->def_init(InitArgs());
|
||||
this->set_instance_size(holder_selector::additional_size());
|
||||
}
|
||||
|
||||
|
||||
template <class InitArgs>
|
||||
inline class_(char const* name, char const* doc, detail::args_base<InitArgs> const&, char const* initdoc = 0)
|
||||
: base(name, id_vector::size, id_vector().ids, doc)
|
||||
{
|
||||
this->register_();
|
||||
this->def_init(InitArgs(), initdoc);
|
||||
this->set_instance_size(holder_selector::additional_size());
|
||||
}
|
||||
|
||||
// Wrap a member function or a non-member function which can take
|
||||
// a T, T cv&, or T cv* as its first parameter, or a callable
|
||||
// python object.
|
||||
template <class F>
|
||||
self& def(char const* name, F f)
|
||||
{
|
||||
this->def_impl(name, f, default_call_policies(), 0, &f);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_ARITY, class T)>
|
||||
self& def(init<BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_ARITY, T)> const& i)
|
||||
{
|
||||
define_init(*this, i, default_call_policies(), 0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class CallPolicyOrDoc, BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_ARITY, class T)>
|
||||
self& def(
|
||||
init<BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_ARITY, T)> const& i,
|
||||
CallPolicyOrDoc const& policy_or_doc,
|
||||
char const* doc = 0)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc> helper;
|
||||
define_init(*this, i,
|
||||
helper::get_policy(policy_or_doc),
|
||||
helper::get_doc(policy_or_doc, doc));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Arg1T, class Arg2T>
|
||||
self& def(char const* name, Arg1T arg1, Arg2T const& arg2)
|
||||
{
|
||||
// The arguments may be:
|
||||
// arg1: function or signature
|
||||
// arg2: policy or docstring or stubs
|
||||
|
||||
dispatch_def(&arg2, name, arg1, arg2, (char*)0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Arg1T, class Arg2T, class Arg3T>
|
||||
self& def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3)
|
||||
{
|
||||
// The arguments may be:
|
||||
// arg1: function or signature
|
||||
// arg2: policy or docstring or stubs
|
||||
// arg3: policy or docstring
|
||||
|
||||
dispatch_def(&arg2, name, arg1, arg2, arg3);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Arg1T, class Arg2T, class Arg3T>
|
||||
self& def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3, char const* doc)
|
||||
{
|
||||
// The arguments are definitely:
|
||||
// arg1: signature
|
||||
// arg2: stubs
|
||||
// arg3: policy
|
||||
|
||||
dispatch_def(&arg2, name, arg1, arg2, arg3, doc);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <detail::operator_id id, class L, class R>
|
||||
self& def(detail::operator_<id,L,R> const& op)
|
||||
{
|
||||
typedef detail::operator_<id,L,R> op_t;
|
||||
return this->def(op.name(), &op_t::template apply<T>::execute);
|
||||
}
|
||||
|
||||
// Define the constructor with the given Args, which should be an
|
||||
// MPL sequence of types.
|
||||
template <class Args>
|
||||
self& def_init(Args const&)
|
||||
{
|
||||
return this->def("__init__",
|
||||
python::make_constructor<Args>(
|
||||
// Using runtime type selection works around a CWPro7 bug.
|
||||
holder_selector::execute((held_type*)0).get()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
template <class Args, class CallPolicyOrDoc>
|
||||
self& def_init(Args const&, CallPolicyOrDoc const& policy_or_doc, char const* doc = 0)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc> helper;
|
||||
|
||||
return this->def(
|
||||
"__init__",
|
||||
python::make_constructor<Args>(
|
||||
helper::get_policy(policy_or_doc)
|
||||
// Using runtime type selection works around a CWPro7 bug.
|
||||
, holder_selector::execute((held_type*)0).get()
|
||||
)
|
||||
, helper::get_doc(policy_or_doc, doc)
|
||||
);
|
||||
}
|
||||
|
||||
// Define the default constructor.
|
||||
self& def_init()
|
||||
{
|
||||
this->def_init(mpl::type_list<>::type());
|
||||
return *this;
|
||||
}
|
||||
|
||||
//
|
||||
// Data member access
|
||||
//
|
||||
template <class D>
|
||||
self& def_readonly(char const* name, D T::*pm)
|
||||
{
|
||||
this->add_property(name, make_getter(pm));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class D>
|
||||
self& def_readwrite(char const* name, D T::*pm)
|
||||
{
|
||||
return this->add_property(name, make_getter(pm), make_setter(pm));
|
||||
}
|
||||
|
||||
// Property creation
|
||||
template <class Get>
|
||||
self& add_property(char const* name, Get const& fget)
|
||||
{
|
||||
base::add_property(name, object(fget));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Get, class Set>
|
||||
self& add_property(char const* name, Get const& fget, Set const& fset)
|
||||
{
|
||||
base::add_property(name, object(fget), object(fset));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
self& setattr(char const* name, U const& x)
|
||||
{
|
||||
this->base::setattr(name, object(x));
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Pickle support
|
||||
template <typename PickleSuiteType>
|
||||
self& def_pickle(PickleSuiteType const& x)
|
||||
{
|
||||
error_messages::must_be_derived_from_pickle_suite(x);
|
||||
detail::pickle_suite_finalize<PickleSuiteType>::register_(
|
||||
*this,
|
||||
&PickleSuiteType::getinitargs,
|
||||
&PickleSuiteType::getstate,
|
||||
&PickleSuiteType::setstate,
|
||||
PickleSuiteType::getstate_manages_dict());
|
||||
return *this;
|
||||
}
|
||||
|
||||
private: // helper functions
|
||||
|
||||
template <class Fn, class Policies>
|
||||
inline void def_impl(char const* name, Fn fn, Policies const& policies
|
||||
, char const* doc, ...)
|
||||
{
|
||||
objects::add_to_namespace(
|
||||
*this, name,
|
||||
make_function(
|
||||
// This bit of nastiness casts F to a member function of T if possible.
|
||||
detail::member_function_cast<T,Fn>::stage1(fn).stage2((T*)0).stage3(fn)
|
||||
, policies)
|
||||
, doc);
|
||||
}
|
||||
|
||||
template <class F>
|
||||
inline void def_impl(char const* name, F f, default_call_policies const&
|
||||
, char const* doc, object const*)
|
||||
{
|
||||
objects::add_to_namespace(*this, name, f, doc);
|
||||
}
|
||||
|
||||
inline void register_() const;
|
||||
|
||||
template <class Fn, class CallPolicyOrDoc>
|
||||
void dispatch_def(
|
||||
void const*,
|
||||
char const* name,
|
||||
Fn fn,
|
||||
CallPolicyOrDoc const& policy_or_doc,
|
||||
char const* doc)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc> helper;
|
||||
|
||||
this->def_impl(
|
||||
name, fn, helper::get_policy(policy_or_doc),
|
||||
helper::get_doc(policy_or_doc, doc), &fn);
|
||||
|
||||
}
|
||||
|
||||
template <class StubsT, class SigT, class CallPolicyOrDoc>
|
||||
void dispatch_def(
|
||||
detail::func_stubs_base const*,
|
||||
char const* name,
|
||||
SigT sig,
|
||||
StubsT const& stubs,
|
||||
CallPolicyOrDoc const& policy_or_doc,
|
||||
char const* doc = 0)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc> helper;
|
||||
|
||||
// convert sig to a type_list (see detail::get_signature in signature.hpp)
|
||||
// before calling detail::define_with_defaults.
|
||||
detail::define_with_defaults(
|
||||
name, stubs, helper::get_policy(policy_or_doc),
|
||||
*this, detail::get_signature(sig),
|
||||
helper::get_doc(policy_or_doc, doc));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
// register converters
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline void class_<T,X1,X2,X3>::register_() const
|
||||
{
|
||||
objects::register_class_from_python<T,bases>();
|
||||
|
||||
detail::register_copy_constructor<T>(
|
||||
mpl::bool_t<is_copyable>()
|
||||
, holder_selector::execute((held_type*)0)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline class_<T,X1,X2,X3>::class_()
|
||||
: base(typeid(T).name(), id_vector::size, id_vector().ids)
|
||||
{
|
||||
this->register_();
|
||||
detail::force_instantiate(sizeof(detail::assert_default_constructible(T())));
|
||||
this->def_init();
|
||||
this->set_instance_size(holder_selector::additional_size());
|
||||
}
|
||||
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline class_<T,X1,X2,X3>::class_(no_init_t)
|
||||
: base(typeid(T).name(), id_vector::size, id_vector().ids)
|
||||
{
|
||||
this->register_();
|
||||
this->def_no_init();
|
||||
}
|
||||
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc)
|
||||
: base(name, id_vector::size, id_vector().ids, doc)
|
||||
{
|
||||
this->register_();
|
||||
detail::force_instantiate(sizeof(detail::assert_default_constructible(T())));
|
||||
this->def_init();
|
||||
this->set_instance_size(holder_selector::additional_size());
|
||||
}
|
||||
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline class_<T,X1,X2,X3>::class_(char const* name, no_init_t)
|
||||
: base(name, id_vector::size, id_vector().ids)
|
||||
{
|
||||
this->register_();
|
||||
this->def_no_init();
|
||||
}
|
||||
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc, no_init_t)
|
||||
: base(name, id_vector::size, id_vector().ids, doc)
|
||||
{
|
||||
this->register_();
|
||||
this->def_no_init();
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// This is an mpl BinaryMetaFunction object with a runtime behavior,
|
||||
// which is to write the id of the type which is passed as its 2nd
|
||||
// compile-time argument into the iterator pointed to by its runtime
|
||||
// argument
|
||||
struct write_type_id
|
||||
{
|
||||
// The first argument is Ignored because mpl::for_each is still
|
||||
// currently an accumulate (reduce) implementation.
|
||||
template <class Ignored, class T> struct apply
|
||||
{
|
||||
// also an artifact of accumulate-based for_each
|
||||
typedef void type;
|
||||
|
||||
// Here's the runtime behavior
|
||||
static void execute(type_info** p)
|
||||
{
|
||||
*(*p)++ = type_id<T>();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <class T1, class T2, class T3>
|
||||
struct has_noncopyable
|
||||
: type_traits::ice_or<
|
||||
is_same<T1,noncopyable>::value
|
||||
, is_same<T2,noncopyable>::value
|
||||
, is_same<T3,noncopyable>::value>
|
||||
{};
|
||||
|
||||
|
||||
template <class T, class Prev>
|
||||
struct select_held_type
|
||||
: mpl::select_type<
|
||||
type_traits::ice_or<
|
||||
specifies_bases<T>::value
|
||||
, is_same<T,noncopyable>::value
|
||||
>::value
|
||||
, Prev
|
||||
, T
|
||||
>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CLASS_DWA200216_HPP
|
||||
336
include/boost/python/converter/arg_from_python.hpp
Executable file
336
include/boost/python/converter/arg_from_python.hpp
Executable file
@@ -0,0 +1,336 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ARG_FROM_PYTHON_DWA2002127_HPP
|
||||
# define ARG_FROM_PYTHON_DWA2002127_HPP
|
||||
|
||||
# include <boost/python/converter/from_python.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
# include <boost/python/converter/registered_pointee.hpp>
|
||||
# include <boost/python/detail/void_ptr.hpp>
|
||||
# include <boost/python/back_reference.hpp>
|
||||
# include <boost/python/detail/referent_storage.hpp>
|
||||
# include <boost/python/converter/obj_mgr_arg_from_python.hpp>
|
||||
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <class T> struct arg_from_python;
|
||||
}}
|
||||
|
||||
// This header defines Python->C++ function argument converters,
|
||||
// parametrized on the argument type.
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
//
|
||||
// lvalue converters
|
||||
//
|
||||
// These require that an lvalue of the type U is stored somewhere in
|
||||
// the Python object being converted.
|
||||
|
||||
// Used when T == U*const&
|
||||
template <class T>
|
||||
struct pointer_cref_arg_from_python
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
pointer_cref_arg_from_python(PyObject*);
|
||||
T operator()(PyObject*) const;
|
||||
bool convertible() const;
|
||||
|
||||
private: // storage for a U*
|
||||
// needed because not all compilers will let us declare U* as the
|
||||
// return type of operator() -- we return U*const& instead
|
||||
typename python::detail::referent_storage<T>::type m_result;
|
||||
};
|
||||
|
||||
// Base class for pointer and reference converters
|
||||
struct arg_lvalue_from_python_base
|
||||
{
|
||||
public: // member functions
|
||||
arg_lvalue_from_python_base(void* result);
|
||||
bool convertible() const;
|
||||
|
||||
protected: // member functions
|
||||
void*const& result() const;
|
||||
|
||||
private: // data members
|
||||
void* m_result;
|
||||
};
|
||||
|
||||
// Used when T == U*
|
||||
template <class T>
|
||||
struct pointer_arg_from_python : arg_lvalue_from_python_base
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
pointer_arg_from_python(PyObject*);
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
// Used when T == U& and (T != V const& or T == W volatile&)
|
||||
template <class T>
|
||||
struct reference_arg_from_python : arg_lvalue_from_python_base
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
reference_arg_from_python(PyObject*);
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
// ===================
|
||||
|
||||
//
|
||||
// rvalue converters
|
||||
//
|
||||
// These require only that an object of type T can be created from
|
||||
// the given Python object, but not that the T object exist
|
||||
// somewhere in storage.
|
||||
//
|
||||
|
||||
// Used when T is a plain value (non-pointer, non-reference) type or
|
||||
// a (non-volatile) const reference to a plain value type.
|
||||
template <class T>
|
||||
struct arg_rvalue_from_python
|
||||
{
|
||||
typedef typename boost::add_reference<
|
||||
typename boost::add_const<T>::type
|
||||
>::type result_type;
|
||||
|
||||
arg_rvalue_from_python(PyObject*);
|
||||
bool convertible() const;
|
||||
|
||||
result_type operator()(PyObject*);
|
||||
|
||||
private:
|
||||
rvalue_from_python_data<result_type> m_data;
|
||||
};
|
||||
|
||||
|
||||
// ==================
|
||||
|
||||
// Converts to a (PyObject*,T) bundle, for when you need a reference
|
||||
// back to the Python object
|
||||
template <class T>
|
||||
struct back_reference_arg_from_python
|
||||
: boost::python::arg_from_python<typename T::type>
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
back_reference_arg_from_python(PyObject*);
|
||||
T operator()(PyObject*);
|
||||
private:
|
||||
typedef boost::python::arg_from_python<typename T::type> base;
|
||||
};
|
||||
|
||||
|
||||
// ==================
|
||||
|
||||
// This metafunction selects the appropriate arg_from_python converter
|
||||
// type for an argument of type T.
|
||||
template <class T>
|
||||
struct select_arg_from_python
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, obj_mgr = is_object_manager<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, obj_mgr_ref = is_reference_to_object_manager<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr = is_pointer<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr_cref
|
||||
= boost::python::detail::is_reference_to_pointer<T>::value
|
||||
&& boost::python::detail::is_reference_to_const<T>::value
|
||||
&& !boost::python::detail::is_reference_to_volatile<T>::value);
|
||||
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ref =
|
||||
boost::python::detail::is_reference_to_non_const<T>::value
|
||||
|| boost::python::detail::is_reference_to_volatile<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, back_ref =
|
||||
boost::python::is_back_reference<T>::value);
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
obj_mgr
|
||||
, object_manager_value_arg_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
obj_mgr_ref
|
||||
, object_manager_ref_arg_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
ptr
|
||||
, pointer_arg_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
ptr_cref
|
||||
, pointer_cref_arg_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
ref
|
||||
, reference_arg_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
back_ref
|
||||
, back_reference_arg_from_python<T>
|
||||
, arg_rvalue_from_python<T>
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
// ==================
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
|
||||
// arg_lvalue_from_python_base
|
||||
//
|
||||
inline arg_lvalue_from_python_base::arg_lvalue_from_python_base(void* result)
|
||||
: m_result(result)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool arg_lvalue_from_python_base::convertible() const
|
||||
{
|
||||
return m_result != 0;
|
||||
}
|
||||
|
||||
inline void*const& arg_lvalue_from_python_base::result() const
|
||||
{
|
||||
return m_result;
|
||||
}
|
||||
|
||||
// pointer_cref_arg_from_python
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
// null_ptr_reference -- a function returning a reference to a null
|
||||
// pointer of type U. Needed so that extractors for T*const& can
|
||||
// convert Python's None.
|
||||
template <class T>
|
||||
struct null_ptr_owner
|
||||
{
|
||||
static T value;
|
||||
};
|
||||
template <class T> T null_ptr_owner<T>::value = 0;
|
||||
|
||||
template <class U>
|
||||
inline U& null_ptr_reference(U&(*)())
|
||||
{
|
||||
return null_ptr_owner<U>::value;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline pointer_cref_arg_from_python<T>::pointer_cref_arg_from_python(PyObject* p)
|
||||
{
|
||||
// T == U*const&: store a U* in the m_result storage. Nonzero
|
||||
// indicates success. If find returns nonzero, it's a pointer to
|
||||
// a U object.
|
||||
python::detail::write_void_ptr_reference(
|
||||
m_result.bytes
|
||||
, p == Py_None ? p : converter::get_lvalue_from_python(p, registered_pointee<T>::converters)
|
||||
, (T(*)())0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool pointer_cref_arg_from_python<T>::convertible() const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0) != 0;
|
||||
}
|
||||
template <class T>
|
||||
inline T pointer_cref_arg_from_python<T>::operator()(PyObject* p) const
|
||||
{
|
||||
return (p == Py_None) // None ==> 0
|
||||
? detail::null_ptr_reference((T(*)())0)
|
||||
// Otherwise, return a U*const& to the m_result storage.
|
||||
: python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0);
|
||||
}
|
||||
|
||||
// pointer_arg_from_python
|
||||
//
|
||||
template <class T>
|
||||
inline pointer_arg_from_python<T>::pointer_arg_from_python(PyObject* p)
|
||||
: arg_lvalue_from_python_base(
|
||||
p == Py_None ? p : converter::get_lvalue_from_python(p, registered_pointee<T>::converters))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T pointer_arg_from_python<T>::operator()(PyObject* p) const
|
||||
{
|
||||
return (p == Py_None) ? 0 : T(result());
|
||||
}
|
||||
|
||||
// reference_arg_from_python
|
||||
//
|
||||
template <class T>
|
||||
inline reference_arg_from_python<T>::reference_arg_from_python(PyObject* p)
|
||||
: arg_lvalue_from_python_base(converter::get_lvalue_from_python(p,registered<T>::converters))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T reference_arg_from_python<T>::operator()(PyObject*) const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(result(), (T(*)())0);
|
||||
}
|
||||
|
||||
|
||||
// arg_rvalue_from_python
|
||||
//
|
||||
template <class T>
|
||||
inline arg_rvalue_from_python<T>::arg_rvalue_from_python(PyObject* obj)
|
||||
: m_data(converter::rvalue_from_python_stage1(obj, registered<T>::converters))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool arg_rvalue_from_python<T>::convertible() const
|
||||
{
|
||||
return m_data.stage1.convertible != 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typename arg_rvalue_from_python<T>::result_type
|
||||
arg_rvalue_from_python<T>::operator()(PyObject* p)
|
||||
{
|
||||
if (m_data.stage1.construct != 0)
|
||||
m_data.stage1.construct(p, &m_data.stage1);
|
||||
|
||||
return python::detail::void_ptr_to_reference(m_data.stage1.convertible, (result_type(*)())0);
|
||||
}
|
||||
|
||||
// back_reference_arg_from_python
|
||||
//
|
||||
template <class T>
|
||||
back_reference_arg_from_python<T>::back_reference_arg_from_python(PyObject* x)
|
||||
: base(x)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T
|
||||
back_reference_arg_from_python<T>::operator()(PyObject* x)
|
||||
{
|
||||
return T(x, base::operator()(x));
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // ARG_FROM_PYTHON_DWA2002127_HPP
|
||||
247
include/boost/python/converter/arg_to_python.hpp
Executable file
247
include/boost/python/converter/arg_to_python.hpp
Executable file
@@ -0,0 +1,247 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ARG_TO_PYTHON_DWA200265_HPP
|
||||
# define ARG_TO_PYTHON_DWA200265_HPP
|
||||
|
||||
# include <boost/python/ptr.hpp>
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
# include <boost/python/converter/registered_pointee.hpp>
|
||||
# include <boost/python/converter/arg_to_python_base.hpp>
|
||||
# include <boost/python/to_python_indirect.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/type_traits/function_traits.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/python/detail/convertible.hpp>
|
||||
# include <boost/python/detail/string_literal.hpp>
|
||||
# include <boost/python/base_type_traits.hpp>
|
||||
// Bring in specializations
|
||||
# include <boost/python/converter/builtin_converters.hpp>
|
||||
# include <boost/python/tag.hpp>
|
||||
# include <boost/python/object/function_handle.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class T> struct is_object_manager;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
BOOST_PYTHON_DECL void throw_no_class_registered();
|
||||
|
||||
template <class T>
|
||||
struct function_arg_to_python : handle<>
|
||||
{
|
||||
function_arg_to_python(T const& x);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct reference_arg_to_python : handle<>
|
||||
{
|
||||
reference_arg_to_python(T& x);
|
||||
private:
|
||||
static PyObject* get_object(T& x);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct value_arg_to_python : arg_to_python_base
|
||||
{
|
||||
// Throw an exception if the conversion can't succeed
|
||||
value_arg_to_python(T const&);
|
||||
};
|
||||
|
||||
template <class Ptr>
|
||||
struct pointer_deep_arg_to_python : arg_to_python_base
|
||||
{
|
||||
// Throw an exception if the conversion can't succeed
|
||||
pointer_deep_arg_to_python(Ptr);
|
||||
};
|
||||
|
||||
template <class Ptr>
|
||||
struct pointer_shallow_arg_to_python : handle<>
|
||||
{
|
||||
// Throw an exception if the conversion can't succeed
|
||||
pointer_shallow_arg_to_python(Ptr);
|
||||
private:
|
||||
static PyObject* get_object(Ptr p);
|
||||
};
|
||||
|
||||
// Convert types that manage a Python object to_python
|
||||
template <class T>
|
||||
struct object_manager_arg_to_python
|
||||
{
|
||||
object_manager_arg_to_python(T const& x) : m_src(x) {}
|
||||
|
||||
PyObject* get() const
|
||||
{
|
||||
return python::upcast<PyObject>(get_managed_object(m_src, tag));
|
||||
}
|
||||
|
||||
private:
|
||||
T const& m_src;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct select_arg_to_python
|
||||
{
|
||||
// Special handling for char const[N]; interpret them as char
|
||||
// const* for the sake of conversion
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, is_string = python::detail::is_string_literal<T const>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, function = is_function<T>::value | python::detail::is_pointer_to_function<T>::value | is_member_function_pointer<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, manager = is_object_manager<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr = is_pointer<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ref_wrapper = is_reference_wrapper<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr_wrapper = is_pointer_wrapper<T>::value);
|
||||
|
||||
typedef typename unwrap_reference<T>::type unwrapped_referent;
|
||||
typedef typename unwrap_pointer<T>::type unwrapped_ptr;
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
is_string
|
||||
, arg_to_python<char const*>
|
||||
, typename mpl::select_type<
|
||||
function
|
||||
, function_arg_to_python<T>
|
||||
, typename mpl::select_type<
|
||||
manager
|
||||
, object_manager_arg_to_python<T>
|
||||
, typename mpl::select_type<
|
||||
ptr
|
||||
, pointer_deep_arg_to_python<T>
|
||||
, typename mpl::select_type<
|
||||
ptr_wrapper
|
||||
, pointer_shallow_arg_to_python<unwrapped_ptr>
|
||||
, typename mpl::select_type<
|
||||
ref_wrapper
|
||||
, reference_arg_to_python<unwrapped_referent>
|
||||
, value_arg_to_python<T>
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct arg_to_python
|
||||
: detail::select_arg_to_python<T>::type
|
||||
{
|
||||
typedef typename detail::select_arg_to_python<T>::type base;
|
||||
public: // member functions
|
||||
// Throw an exception if the conversion can't succeed
|
||||
arg_to_python(T const& x);
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
// reject_raw_object_ptr -- cause a compile-time error if the user
|
||||
// should pass a raw Python object pointer
|
||||
using python::detail::yes_convertible;
|
||||
using python::detail::no_convertible;
|
||||
using python::detail::unspecialized;
|
||||
|
||||
template <class T> struct cannot_convert_raw_PyObject;
|
||||
|
||||
template <class T, class Convertibility>
|
||||
struct reject_raw_object_helper
|
||||
{
|
||||
static void error(Convertibility)
|
||||
{
|
||||
cannot_convert_raw_PyObject<T*>::to_python_use_handle_instead();
|
||||
}
|
||||
static void error(...) {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline void reject_raw_object_ptr(T*)
|
||||
{
|
||||
reject_raw_object_helper<T,yes_convertible>::error(
|
||||
python::detail::convertible<PyObject const volatile*>::check((T*)0));
|
||||
|
||||
typedef typename remove_cv<T>::type value_type;
|
||||
|
||||
reject_raw_object_helper<T,no_convertible>::error(
|
||||
python::detail::convertible<unspecialized*>::check(
|
||||
(base_type_traits<value_type>*)0
|
||||
));
|
||||
}
|
||||
// ---------
|
||||
|
||||
template <class T>
|
||||
inline function_arg_to_python<T>::function_arg_to_python(T const& x)
|
||||
: handle<>(python::objects::make_function_handle(x))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline value_arg_to_python<T>::value_arg_to_python(T const& x)
|
||||
: arg_to_python_base(&x, registered<T>::converters)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
inline pointer_deep_arg_to_python<Ptr>::pointer_deep_arg_to_python(Ptr x)
|
||||
: arg_to_python_base(x, registered_pointee<Ptr>::converters)
|
||||
{
|
||||
detail::reject_raw_object_ptr((Ptr)0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline PyObject* reference_arg_to_python<T>::get_object(T& x)
|
||||
{
|
||||
to_python_indirect<T&,python::detail::make_reference_holder> convert;
|
||||
if (!convert.convertible())
|
||||
throw_no_class_registered();
|
||||
return convert(x);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline reference_arg_to_python<T>::reference_arg_to_python(T& x)
|
||||
: handle<>(reference_arg_to_python<T>::get_object(x))
|
||||
{
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
inline pointer_shallow_arg_to_python<Ptr>::pointer_shallow_arg_to_python(Ptr x)
|
||||
: handle<>(pointer_shallow_arg_to_python<Ptr>::get_object(x))
|
||||
{
|
||||
detail::reject_raw_object_ptr((Ptr)0);
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
inline PyObject* pointer_shallow_arg_to_python<Ptr>::get_object(Ptr x)
|
||||
{
|
||||
to_python_indirect<Ptr,python::detail::make_reference_holder> convert;
|
||||
if (!convert.convertible())
|
||||
throw_no_class_registered();
|
||||
return x ? convert(x) : python::detail::none();
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline arg_to_python<T>::arg_to_python(T const& x)
|
||||
: base(x)
|
||||
{}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // ARG_TO_PYTHON_DWA200265_HPP
|
||||
35
include/boost/python/converter/arg_to_python_base.hpp
Executable file
35
include/boost/python/converter/arg_to_python_base.hpp
Executable file
@@ -0,0 +1,35 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ARG_TO_PYTHON_BASE_DWA200237_HPP
|
||||
# define ARG_TO_PYTHON_BASE_DWA200237_HPP
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/handle.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct registration;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct BOOST_PYTHON_DECL arg_to_python_base
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC <= 1300 || _MSC_FULL_VER > 13102179
|
||||
: handle<>
|
||||
# endif
|
||||
{
|
||||
arg_to_python_base(void const volatile* source, registration const&);
|
||||
# if defined(BOOST_MSVC) && BOOST_MSVC > 1300 && _MSC_FULL_VER <= 13102179
|
||||
PyObject* get() const { return m_ptr.get(); }
|
||||
PyObject* release() { return m_ptr.release(); }
|
||||
private:
|
||||
handle<> m_ptr;
|
||||
# endif
|
||||
};
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // ARG_TO_PYTHON_BASE_DWA200237_HPP
|
||||
123
include/boost/python/converter/builtin_converters.hpp
Normal file
123
include/boost/python/converter/builtin_converters.hpp
Normal file
@@ -0,0 +1,123 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef BUILTIN_CONVERTERS_DWA2002124_HPP
|
||||
# define BUILTIN_CONVERTERS_DWA2002124_HPP
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/none.hpp>
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <string>
|
||||
# include <complex>
|
||||
|
||||
// Since all we can use to decide how to convert an object to_python
|
||||
// is its C++ type, there can be only one such converter for each
|
||||
// type. Therefore, for built-in conversions we can bypass registry
|
||||
// lookups using explicit specializations of arg_to_python and
|
||||
// result_to_python.
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace converter
|
||||
{
|
||||
template <class T> struct arg_to_python;
|
||||
BOOST_PYTHON_DECL PyObject* do_return_to_python(char);
|
||||
BOOST_PYTHON_DECL PyObject* do_return_to_python(char const*);
|
||||
BOOST_PYTHON_DECL PyObject* do_return_to_python(PyObject*);
|
||||
BOOST_PYTHON_DECL PyObject* do_arg_to_python(PyObject*);
|
||||
}
|
||||
|
||||
// Provide specializations of to_python_value
|
||||
template <class T> struct to_python_value;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// Since there's no registry lookup, always report the existence of
|
||||
// a converter.
|
||||
struct builtin_to_python
|
||||
{
|
||||
static bool convertible() { return true; }
|
||||
};
|
||||
}
|
||||
|
||||
// Use expr to create the PyObject corresponding to x
|
||||
# define BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
template <> struct to_python_value<T&> \
|
||||
: detail::builtin_to_python \
|
||||
{ \
|
||||
inline PyObject* operator()(T const& x) const \
|
||||
{ \
|
||||
return (expr); \
|
||||
} \
|
||||
}; \
|
||||
template <> struct to_python_value<T const&> \
|
||||
: detail::builtin_to_python \
|
||||
{ \
|
||||
inline PyObject* operator()(T const& x) const \
|
||||
{ \
|
||||
return (expr); \
|
||||
} \
|
||||
};
|
||||
|
||||
# define BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
namespace converter \
|
||||
{ \
|
||||
template <> struct arg_to_python< T > \
|
||||
: handle<> \
|
||||
{ \
|
||||
arg_to_python(T const& x) \
|
||||
: python::handle<>(expr) {} \
|
||||
}; \
|
||||
}
|
||||
|
||||
// Specialize argument and return value converters for T using expr
|
||||
# define BOOST_PYTHON_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE(T,expr) \
|
||||
BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE(T,expr)
|
||||
|
||||
// Specialize converters for signed and unsigned T to Python Int
|
||||
# define BOOST_PYTHON_TO_INT(T) \
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed T, PyInt_FromLong(x)) \
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned T, PyInt_FromLong(x))
|
||||
|
||||
// Bool is not signed.
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, PyInt_FromLong(x))
|
||||
|
||||
// note: handles signed char and unsigned char, but not char (see below)
|
||||
BOOST_PYTHON_TO_INT(char)
|
||||
|
||||
BOOST_PYTHON_TO_INT(short)
|
||||
BOOST_PYTHON_TO_INT(int)
|
||||
BOOST_PYTHON_TO_INT(long)
|
||||
|
||||
// using Python's macro instead of Boost's - we don't seem to get the
|
||||
// config right all the time.
|
||||
# ifdef HAVE_LONG_LONG
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed LONG_LONG, PyLong_FromLongLong(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned LONG_LONG, PyLong_FromUnsignedLongLong(x))
|
||||
# endif
|
||||
|
||||
# undef BOOST_TO_PYTHON_INT
|
||||
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_return_to_python(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_return_to_python(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, PyString_FromString(x.c_str()))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(float, PyFloat_FromDouble(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(double, PyFloat_FromDouble(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(long double, PyFloat_FromDouble(x))
|
||||
BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE(PyObject*, converter::do_return_to_python(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<float>, PyComplex_FromDoubles(x.real(), x.imag()))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<double>, PyComplex_FromDoubles(x.real(), x.imag()))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex<long double>, PyComplex_FromDoubles(x.real(), x.imag()))
|
||||
|
||||
namespace converter
|
||||
{
|
||||
|
||||
void initialize_builtin_converters();
|
||||
|
||||
}
|
||||
|
||||
}} // namespace boost::python::converter
|
||||
|
||||
#endif // BUILTIN_CONVERTERS_DWA2002124_HPP
|
||||
18
include/boost/python/converter/constructor_function.hpp
Normal file
18
include/boost/python/converter/constructor_function.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CONSTRUCTOR_FUNCTION_DWA200278_HPP
|
||||
# define CONSTRUCTOR_FUNCTION_DWA200278_HPP
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// Declares the type of functions used to construct C++ objects for
|
||||
// rvalue from_python conversions.
|
||||
struct rvalue_from_python_stage1_data;
|
||||
typedef void (*constructor_function)(PyObject* source, rvalue_from_python_stage1_data*);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // CONSTRUCTOR_FUNCTION_DWA200278_HPP
|
||||
15
include/boost/python/converter/convertible_function.hpp
Normal file
15
include/boost/python/converter/convertible_function.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CONVERTIBLE_FUNCTION_DWA200278_HPP
|
||||
# define CONVERTIBLE_FUNCTION_DWA200278_HPP
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
typedef void* (*convertible_function)(PyObject*);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // CONVERTIBLE_FUNCTION_DWA200278_HPP
|
||||
43
include/boost/python/converter/from_python.hpp
Normal file
43
include/boost/python/converter/from_python.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FIND_FROM_PYTHON_DWA2002223_HPP
|
||||
# define FIND_FROM_PYTHON_DWA2002223_HPP
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct registration;
|
||||
struct rvalue_from_python_chain;
|
||||
|
||||
BOOST_PYTHON_DECL void* get_lvalue_from_python(
|
||||
PyObject* source, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL rvalue_from_python_chain const* implicit_conversion_chain(
|
||||
PyObject* source, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL rvalue_from_python_stage1_data rvalue_from_python_stage1(
|
||||
PyObject* source, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL void* rvalue_from_python_stage2(
|
||||
PyObject* source, rvalue_from_python_stage1_data&, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL void* rvalue_result_from_python(
|
||||
PyObject*, rvalue_from_python_stage1_data&);
|
||||
|
||||
BOOST_PYTHON_DECL void* reference_result_from_python(PyObject*, registration const&);
|
||||
BOOST_PYTHON_DECL void* pointer_result_from_python(PyObject*, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL void void_result_from_python(PyObject*);
|
||||
|
||||
BOOST_PYTHON_DECL void throw_no_pointer_from_python(PyObject*, registration const&);
|
||||
BOOST_PYTHON_DECL void throw_no_reference_from_python(PyObject*, registration const&);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // FIND_FROM_PYTHON_DWA2002223_HPP
|
||||
57
include/boost/python/converter/implicit.hpp
Normal file
57
include/boost/python/converter/implicit.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef IMPLICIT_DWA2002326_HPP
|
||||
# define IMPLICIT_DWA2002326_HPP
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
# include <boost/python/converter/registrations.hpp>
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class Source, class Target>
|
||||
struct implicit
|
||||
{
|
||||
static void* convertible(PyObject* obj)
|
||||
{
|
||||
// Find a converter chain which can produce a Source instance
|
||||
// from obj. The user has told us that Source can be converted
|
||||
// to Target, and instantiating construct() below, ensures
|
||||
// that at compile-time.
|
||||
return const_cast<rvalue_from_python_chain*>(
|
||||
converter::implicit_conversion_chain(obj, registered<Source>::converters));
|
||||
}
|
||||
|
||||
static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
|
||||
{
|
||||
// This is the chain we got from the convertible step
|
||||
rvalue_from_python_chain const* chain
|
||||
= static_cast<rvalue_from_python_chain*>(data->convertible);
|
||||
|
||||
// Call the convertible function again
|
||||
rvalue_from_python_data<Source> intermediate_data(chain->convertible(obj));
|
||||
|
||||
// Use the result to construct the source type if the first
|
||||
// converter was an rvalue converter.
|
||||
if (chain->construct != 0)
|
||||
chain->construct(obj, &intermediate_data.stage1);
|
||||
|
||||
void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes;
|
||||
# if !defined(BOOST_MSVC) || _MSC_FULL_VER != 13012108 // vc7.01 alpha workaround
|
||||
new (storage) Target(*static_cast<Source*>(intermediate_data.stage1.convertible));
|
||||
# else
|
||||
Target x(*static_cast<Source*>(intermediate_data.stage1.convertible));
|
||||
new (storage) Target(x);
|
||||
# endif
|
||||
|
||||
// record successful construction
|
||||
data->convertible = storage;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // IMPLICIT_DWA2002326_HPP
|
||||
116
include/boost/python/converter/obj_mgr_arg_from_python.hpp
Normal file
116
include/boost/python/converter/obj_mgr_arg_from_python.hpp
Normal file
@@ -0,0 +1,116 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef OBJ_MGR_ARG_FROM_PYTHON_DWA2002628_HPP
|
||||
# define OBJ_MGR_ARG_FROM_PYTHON_DWA2002628_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/referent_storage.hpp>
|
||||
# include <boost/python/detail/destroy.hpp>
|
||||
# include <boost/python/detail/construct.hpp>
|
||||
# include <boost/python/converter/object_manager.hpp>
|
||||
# include <boost/python/detail/raw_pyobject.hpp>
|
||||
# include <boost/python/tag.hpp>
|
||||
|
||||
//
|
||||
// arg_from_python converters for Python type wrappers, to be used as
|
||||
// base classes for specializations.
|
||||
//
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class T>
|
||||
struct object_manager_value_arg_from_python
|
||||
{
|
||||
typedef T result_type;
|
||||
|
||||
object_manager_value_arg_from_python(PyObject*);
|
||||
bool convertible() const;
|
||||
T operator()(PyObject*) const;
|
||||
private:
|
||||
PyObject* m_source;
|
||||
};
|
||||
|
||||
// Used for converting reference-to-object-manager arguments from
|
||||
// python. The process used here is a little bit odd. Upon
|
||||
// construction, we build the object manager object in the m_result
|
||||
// object, *forcing* it to accept the source Python object by casting
|
||||
// its pointer to detail::borrowed_reference. This is supposed to
|
||||
// bypass any type checking of the source object. The convertible
|
||||
// check then extracts the owned object and checks it. If the check
|
||||
// fails, nothing else in the program ever gets to touch this strange
|
||||
// "forced" object.
|
||||
template <class Ref>
|
||||
struct object_manager_ref_arg_from_python
|
||||
{
|
||||
typedef Ref result_type;
|
||||
|
||||
object_manager_ref_arg_from_python(PyObject*);
|
||||
bool convertible() const;
|
||||
Ref operator()(PyObject*) const;
|
||||
~object_manager_ref_arg_from_python();
|
||||
private:
|
||||
typename python::detail::referent_storage<Ref>::type m_result;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
|
||||
template <class T>
|
||||
inline object_manager_value_arg_from_python<T>::object_manager_value_arg_from_python(PyObject* x)
|
||||
: m_source(x)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool object_manager_value_arg_from_python<T>::convertible() const
|
||||
{
|
||||
return object_manager_traits<T>::check(m_source);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T object_manager_value_arg_from_python<T>::operator()(PyObject* x) const
|
||||
{
|
||||
return T(python::detail::borrowed_reference(x));
|
||||
}
|
||||
|
||||
template <class Ref>
|
||||
inline object_manager_ref_arg_from_python<Ref>::object_manager_ref_arg_from_python(PyObject* x)
|
||||
{
|
||||
python::detail::construct_referent<Ref>(&m_result.bytes, python::detail::borrowed_reference(x));
|
||||
}
|
||||
|
||||
template <class Ref>
|
||||
inline object_manager_ref_arg_from_python<Ref>::~object_manager_ref_arg_from_python()
|
||||
{
|
||||
python::detail::destroy_referent<Ref>(this->m_result.bytes);
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
inline bool object_manager_ref_check(T const& x)
|
||||
{
|
||||
return object_manager_traits<T>::check(get_managed_object(x, tag));
|
||||
}
|
||||
}
|
||||
|
||||
template <class Ref>
|
||||
inline bool object_manager_ref_arg_from_python<Ref>::convertible() const
|
||||
{
|
||||
return detail::object_manager_ref_check(
|
||||
python::detail::void_ptr_to_reference(this->m_result.bytes, (Ref(*)())0));
|
||||
}
|
||||
|
||||
template <class Ref>
|
||||
inline Ref object_manager_ref_arg_from_python<Ref>::operator()(PyObject*) const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(
|
||||
this->m_result.bytes, (Ref(*)())0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // OBJ_MGR_ARG_FROM_PYTHON_DWA2002628_HPP
|
||||
232
include/boost/python/converter/object_manager.hpp
Executable file
232
include/boost/python/converter/object_manager.hpp
Executable file
@@ -0,0 +1,232 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef OBJECT_MANAGER_DWA2002614_HPP
|
||||
# define OBJECT_MANAGER_DWA2002614_HPP
|
||||
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/python/cast.hpp>
|
||||
# include <boost/python/converter/pyobject_traits.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
|
||||
// Facilities for dealing with types which always manage Python
|
||||
// objects. Some examples are object, list, str, et. al. Different
|
||||
// to_python/from_python conversion rules apply here because in
|
||||
// contrast to other types which are typically embedded inside a
|
||||
// Python object, these are wrapped around a Python object. For most
|
||||
// object managers T, a C++ non-const T reference argument does not
|
||||
// imply the existence of a T lvalue embedded in the corresponding
|
||||
// Python argument, since mutating member functions on T actually only
|
||||
// modify the held Python object.
|
||||
//
|
||||
// handle<T> is an object manager, though strictly speaking it should
|
||||
// not be. In other words, even though mutating member functions of
|
||||
// hanlde<T> actually modify the handle<T> and not the T object,
|
||||
// handle<T>& arguments of wrapped functions will bind to "rvalues"
|
||||
// wrapping the actual Python argument, just as with other object
|
||||
// manager classes. Making an exception for handle<T> is simply not
|
||||
// worth the trouble.
|
||||
//
|
||||
// borrowed<T> cv* is an object manager so that we can use the general
|
||||
// to_python mechanisms to convert raw Python object pointers to
|
||||
// python, without the usual semantic problems of using raw pointers.
|
||||
|
||||
|
||||
// Object Manager Concept requirements:
|
||||
//
|
||||
// T is an Object Manager
|
||||
// p is a PyObject*
|
||||
// x is a T
|
||||
//
|
||||
// * object_manager_traits<T>::is_specialized == true
|
||||
//
|
||||
// * T(detail::borrowed_reference(p))
|
||||
// Manages p without checking its type
|
||||
//
|
||||
// * get_managed_object(x, boost::python::tag)
|
||||
// Convertible to PyObject*
|
||||
//
|
||||
// Additional requirements if T can be converted from_python:
|
||||
//
|
||||
// * T(object_manager_traits<T>::adopt(p))
|
||||
// steals a reference to p, or throws a TypeError exception if
|
||||
// p doesn't have an appropriate type. May assume p is non-null
|
||||
//
|
||||
// * X::check(p)
|
||||
// convertible to bool. True iff T(X::construct(p)) will not
|
||||
// throw.
|
||||
|
||||
// Forward declarations
|
||||
//
|
||||
namespace boost { namespace python
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
class object;
|
||||
}
|
||||
}}
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
|
||||
// Specializations for handle<T>
|
||||
template <class T>
|
||||
struct handle_object_manager_traits
|
||||
: pyobject_traits<typename T::element_type>
|
||||
{
|
||||
private:
|
||||
typedef pyobject_traits<typename T::element_type> base;
|
||||
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, is_specialized = true);
|
||||
|
||||
// Initialize with a null_ok pointer for efficiency, bypassing the
|
||||
// null check since the source is always non-null.
|
||||
static null_ok<typename T::element_type>* adopt(PyObject* p)
|
||||
{
|
||||
return python::allow_null(base::checked_downcast(p));
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct default_object_manager_traits
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, is_specialized = python::detail::is_borrowed_ptr<T>::value
|
||||
);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct object_manager_traits
|
||||
: mpl::select_type<
|
||||
is_handle<T>::value
|
||||
, handle_object_manager_traits<T>
|
||||
, default_object_manager_traits<T>
|
||||
>::type
|
||||
{
|
||||
};
|
||||
|
||||
//
|
||||
// Traits for detecting whether a type is an object manager or a
|
||||
// (cv-qualified) reference to an object manager.
|
||||
//
|
||||
|
||||
template <class T>
|
||||
struct is_object_manager
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = object_manager_traits<T>::is_specialized);
|
||||
};
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager<T&>
|
||||
: is_object_manager<T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager<T const&>
|
||||
: is_object_manager<T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager<T volatile&>
|
||||
: is_object_manager<T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager<T const volatile&>
|
||||
: is_object_manager<T>
|
||||
{
|
||||
};
|
||||
# else
|
||||
|
||||
namespace detail
|
||||
{
|
||||
typedef char (&yes_reference_to_object_manager)[1];
|
||||
typedef char (&no_reference_to_object_manager)[2];
|
||||
|
||||
// A number of nastinesses go on here in order to work around MSVC6
|
||||
// bugs.
|
||||
template <class T>
|
||||
struct is_object_manager_help
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_object_manager<T>::value
|
||||
, yes_reference_to_object_manager
|
||||
, no_reference_to_object_manager
|
||||
>::type type;
|
||||
|
||||
// If we just use the type instead of the result of calling this
|
||||
// function, VC6 will ICE.
|
||||
static type call();
|
||||
};
|
||||
|
||||
// A set of overloads for each cv-qualification. The same argument
|
||||
// is passed twice: the first one is used to unwind the cv*, and the
|
||||
// second one is used to avoid relying on partial ordering for
|
||||
// overload resolution.
|
||||
template <class U>
|
||||
typename is_object_manager_help<U>
|
||||
is_object_manager_helper(U*, void*);
|
||||
|
||||
template <class U>
|
||||
typename is_object_manager_help<U>
|
||||
is_object_manager_helper(U const*, void const*);
|
||||
|
||||
template <class U>
|
||||
typename is_object_manager_help<U>
|
||||
is_object_manager_helper(U volatile*, void volatile*);
|
||||
|
||||
template <class U>
|
||||
typename is_object_manager_help<U>
|
||||
is_object_manager_helper(U const volatile*, void const volatile*);
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager_nonref
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager_ref
|
||||
{
|
||||
static T sample_object;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (sizeof(is_object_manager_helper(&sample_object, &sample_object).call())
|
||||
== sizeof(detail::yes_reference_to_object_manager)
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_object_manager
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_reference<T>::value
|
||||
, detail::is_reference_to_object_manager_ref<T>
|
||||
, detail::is_reference_to_object_manager_nonref<T>
|
||||
> chooser;
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, value = chooser::type::value);
|
||||
};
|
||||
# endif
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // OBJECT_MANAGER_DWA2002614_HPP
|
||||
42
include/boost/python/converter/pyobject_traits.hpp
Normal file
42
include/boost/python/converter/pyobject_traits.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef PYOBJECT_TRAITS_DWA2002720_HPP
|
||||
# define PYOBJECT_TRAITS_DWA2002720_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/converter/pyobject_type.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class> struct pyobject_traits;
|
||||
|
||||
template <>
|
||||
struct pyobject_traits<PyObject>
|
||||
{
|
||||
// All objects are convertible to PyObject
|
||||
static bool check(PyObject*) { return true; }
|
||||
static PyObject* checked_downcast(PyObject* x) { return x; }
|
||||
};
|
||||
|
||||
//
|
||||
// Specializations
|
||||
//
|
||||
|
||||
# define BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(T) \
|
||||
template <> struct pyobject_traits<Py##T##Object> \
|
||||
: pyobject_type<Py##T##Object, &Py##T##_Type> {}
|
||||
|
||||
// This is not an exhaustive list; should be expanded.
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Type);
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(List);
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Int);
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Long);
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Dict);
|
||||
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Tuple);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // PYOBJECT_TRAITS_DWA2002720_HPP
|
||||
36
include/boost/python/converter/pyobject_type.hpp
Normal file
36
include/boost/python/converter/pyobject_type.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef PYOBJECT_TYPE_DWA2002720_HPP
|
||||
# define PYOBJECT_TYPE_DWA2002720_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/cast.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
BOOST_PYTHON_DECL PyObject* checked_downcast_impl(PyObject*, PyTypeObject*);
|
||||
|
||||
// Used as a base class for specializations which need to provide
|
||||
// Python type checking capability.
|
||||
template <class Object, PyTypeObject* pytype>
|
||||
struct pyobject_type
|
||||
{
|
||||
static bool check(PyObject* x)
|
||||
{
|
||||
return ::PyObject_IsInstance(x, (PyObject*)pytype);
|
||||
}
|
||||
|
||||
static Object* checked_downcast(PyObject* x)
|
||||
{
|
||||
return python::downcast<Object>(
|
||||
(checked_downcast_impl)(x, pytype)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // PYOBJECT_TYPE_DWA2002720_HPP
|
||||
99
include/boost/python/converter/pytype_arg_from_python.hpp
Normal file
99
include/boost/python/converter/pytype_arg_from_python.hpp
Normal file
@@ -0,0 +1,99 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP
|
||||
# define PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
|
||||
//
|
||||
// arg_from_python converters for Python type wrappers, to be used as
|
||||
// base classes for specializations.
|
||||
//
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <PyTypeObject* python_type>
|
||||
struct pytype_arg_from_python
|
||||
{
|
||||
pytype_arg_from_python(PyObject*);
|
||||
bool convertible() const;
|
||||
private:
|
||||
PyObject* m_src;
|
||||
};
|
||||
|
||||
// rvalue converter base
|
||||
template <class Wrapper, PyTypeObject* python_type>
|
||||
struct pytype_wrapper_value_arg_from_python
|
||||
: pytype_arg_from_python<python_type>
|
||||
{
|
||||
typedef Wrapper result_type;
|
||||
|
||||
pytype_wrapper_value_arg_from_python(PyObject*);
|
||||
Wrapper operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
// Special case for Wrapper& - must store an lvalue internally. This
|
||||
// OK because the entire state of the object is actually in the Python
|
||||
// object.
|
||||
template <class Wrapper, PyTypeObject* python_type>
|
||||
struct pytype_wrapper_ref_arg_from_python
|
||||
: pytype_arg_from_python<python_type>
|
||||
{
|
||||
typedef Wrapper& result_type;
|
||||
|
||||
pytype_wrapper_ref_arg_from_python(PyObject*);
|
||||
Wrapper& operator()(PyObject*) const;
|
||||
private:
|
||||
mutable Wrapper m_result;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
|
||||
template <PyTypeObject* python_type>
|
||||
inline pytype_arg_from_python<python_type>::pytype_arg_from_python(PyObject* x)
|
||||
: m_src(x)
|
||||
{
|
||||
}
|
||||
|
||||
template <PyTypeObject* python_type>
|
||||
inline bool pytype_arg_from_python<python_type>::convertible() const
|
||||
{
|
||||
return PyObject_IsInstance(m_src, (PyObject*)python_type);
|
||||
}
|
||||
|
||||
template <class Wrapper, PyTypeObject* python_type>
|
||||
pytype_wrapper_value_arg_from_python<Wrapper,python_type>::pytype_wrapper_value_arg_from_python(
|
||||
PyObject* p)
|
||||
: pytype_arg_from_python<python_type>(p)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Wrapper, PyTypeObject* python_type>
|
||||
Wrapper pytype_wrapper_value_arg_from_python<Wrapper,python_type>::operator()(
|
||||
PyObject* x) const
|
||||
{
|
||||
return Wrapper(python::detail::borrowed_reference(x));
|
||||
}
|
||||
|
||||
template <class Wrapper, PyTypeObject* python_type>
|
||||
pytype_wrapper_ref_arg_from_python<Wrapper,python_type>::pytype_wrapper_ref_arg_from_python(
|
||||
PyObject* p)
|
||||
: pytype_arg_from_python<python_type>(p)
|
||||
, m_result(python::detail::borrowed_reference(p))
|
||||
{
|
||||
}
|
||||
|
||||
template <class Wrapper, PyTypeObject* python_type>
|
||||
Wrapper& pytype_wrapper_ref_arg_from_python<Wrapper,python_type>::operator()(
|
||||
PyObject* x) const
|
||||
{
|
||||
return m_result;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP
|
||||
43
include/boost/python/converter/pytype_object_mgr_traits.hpp
Normal file
43
include/boost/python/converter/pytype_object_mgr_traits.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP
|
||||
# define PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP
|
||||
|
||||
# include <boost/python/detail/raw_pyobject.hpp>
|
||||
# include <boost/python/cast.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/converter/pyobject_type.hpp>
|
||||
# include <boost/python/errors.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// Provide a forward declaration as a convenience for clients, who all
|
||||
// need it.
|
||||
template <class T> struct object_manager_traits;
|
||||
|
||||
// Derive specializations of object_manager_traits from this class
|
||||
// when T is an object manager for a particular Python type hierarchy.
|
||||
//
|
||||
template <PyTypeObject* pytype, class T>
|
||||
struct pytype_object_manager_traits
|
||||
: pyobject_type<T, pytype> // provides check()
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, is_specialized = true);
|
||||
static inline python::detail::new_reference adopt(PyObject*);
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
template <PyTypeObject* pytype, class T>
|
||||
inline python::detail::new_reference pytype_object_manager_traits<pytype,T>::adopt(PyObject* x)
|
||||
{
|
||||
return python::detail::new_reference(python::pytype_check(pytype, x));
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP
|
||||
54
include/boost/python/converter/registered.hpp
Normal file
54
include/boost/python/converter/registered.hpp
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTERED_DWA2002710_HPP
|
||||
# define REGISTERED_DWA2002710_HPP
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/registrations.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct registration;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct registered_base
|
||||
{
|
||||
static registration const& converters;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct registered
|
||||
: detail::registered_base<
|
||||
typename add_reference<
|
||||
typename add_cv<T>::type
|
||||
>::type
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
// collapses a few more types to the same static instance
|
||||
template <class T>
|
||||
struct registered<T&> : registered<T> {};
|
||||
# endif
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
registration const& registered_base<T>::converters
|
||||
= registry::lookup(type_id<T>());
|
||||
}
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTERED_DWA2002710_HPP
|
||||
63
include/boost/python/converter/registered_pointee.hpp
Normal file
63
include/boost/python/converter/registered_pointee.hpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTERED_POINTEE_DWA2002710_HPP
|
||||
# define REGISTERED_POINTEE_DWA2002710_HPP
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
# include <boost/python/converter/pointer_type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct registration;
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T>
|
||||
struct registered_pointee
|
||||
: registered<
|
||||
typename remove_pointer<
|
||||
typename remove_cv<
|
||||
typename remove_reference<T>::type
|
||||
>::type
|
||||
>::type
|
||||
>
|
||||
{
|
||||
};
|
||||
# else
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct registered_pointee_base
|
||||
{
|
||||
static registration const& converters;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct registered_pointee
|
||||
: detail::registered_pointee_base<
|
||||
typename add_reference<
|
||||
typename add_cv<T>::type
|
||||
>::type
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
registration const& registered_pointee_base<T>::converters
|
||||
= registry::lookup(pointer_type_id<T>());
|
||||
}
|
||||
|
||||
# endif
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTERED_POINTEE_DWA2002710_HPP
|
||||
67
include/boost/python/converter/registrations.hpp
Normal file
67
include/boost/python/converter/registrations.hpp
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTRATIONS_DWA2002223_HPP
|
||||
# define REGISTRATIONS_DWA2002223_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/converter/convertible_function.hpp>
|
||||
# include <boost/python/converter/constructor_function.hpp>
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct lvalue_from_python_chain
|
||||
{
|
||||
convertible_function convert;
|
||||
lvalue_from_python_chain* next;
|
||||
};
|
||||
|
||||
struct rvalue_from_python_chain
|
||||
{
|
||||
convertible_function convertible;
|
||||
constructor_function construct;
|
||||
rvalue_from_python_chain* next;
|
||||
};
|
||||
|
||||
struct registration
|
||||
{
|
||||
explicit registration(type_info);
|
||||
|
||||
const python::type_info target_type;
|
||||
|
||||
// The chain of eligible from_python converters when an lvalue is required
|
||||
lvalue_from_python_chain* lvalue_chain;
|
||||
|
||||
// The chain of eligible from_python converters when an rvalue is acceptable
|
||||
rvalue_from_python_chain* rvalue_chain;
|
||||
|
||||
// The unique to_python converter for the associated C++ type.
|
||||
to_python_function_t to_python;
|
||||
|
||||
// The class object associated with this type
|
||||
PyTypeObject* class_object;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
inline registration::registration(type_info target_type)
|
||||
: target_type(target_type)
|
||||
, lvalue_chain(0)
|
||||
, rvalue_chain(0)
|
||||
, to_python(0)
|
||||
, class_object(0)
|
||||
{}
|
||||
|
||||
inline bool operator<(registration const& lhs, registration const& rhs)
|
||||
{
|
||||
return lhs.target_type < rhs.target_type;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTRATIONS_DWA2002223_HPP
|
||||
52
include/boost/python/converter/registry.hpp
Normal file
52
include/boost/python/converter/registry.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTRY_DWA20011127_HPP
|
||||
# define REGISTRY_DWA20011127_HPP
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
# include <boost/python/converter/constructor_function.hpp>
|
||||
# include <boost/python/converter/convertible_function.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct registration;
|
||||
|
||||
// This namespace acts as a sort of singleton
|
||||
namespace registry
|
||||
{
|
||||
// Get the registration corresponding to the type, creating it if neccessary
|
||||
BOOST_PYTHON_DECL registration const& lookup(type_info);
|
||||
|
||||
// Return a pointer to the corresponding registration, if one exists
|
||||
BOOST_PYTHON_DECL registration const* query(type_info);
|
||||
|
||||
BOOST_PYTHON_DECL void insert(to_python_function_t, type_info);
|
||||
|
||||
// Insert an lvalue from_python converter
|
||||
BOOST_PYTHON_DECL void insert(void* (*convert)(PyObject*), type_info);
|
||||
|
||||
// Insert an rvalue from_python converter
|
||||
BOOST_PYTHON_DECL void insert(
|
||||
convertible_function
|
||||
, constructor_function
|
||||
, type_info
|
||||
);
|
||||
|
||||
// Insert an rvalue from_python converter at the tail of the
|
||||
// chain. Used for implicit conversions
|
||||
BOOST_PYTHON_DECL void push_back(
|
||||
convertible_function
|
||||
, constructor_function
|
||||
, type_info
|
||||
);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTRY_DWA20011127_HPP
|
||||
151
include/boost/python/converter/return_from_python.hpp
Executable file
151
include/boost/python/converter/return_from_python.hpp
Executable file
@@ -0,0 +1,151 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef RETURN_FROM_PYTHON_DWA200265_HPP
|
||||
# define RETURN_FROM_PYTHON_DWA200265_HPP
|
||||
|
||||
# include <boost/python/converter/from_python.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
# include <boost/python/converter/registered_pointee.hpp>
|
||||
# include <boost/python/detail/void_ptr.hpp>
|
||||
# include <boost/call_traits.hpp>
|
||||
# include <boost/python/detail/void_return.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class T> struct is_object_manager;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
struct return_pointer_from_python
|
||||
{
|
||||
typedef T result_type;
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct return_reference_from_python
|
||||
{
|
||||
typedef T result_type;
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct return_rvalue_from_python
|
||||
{
|
||||
typedef typename call_traits<T>::param_type result_type;
|
||||
return_rvalue_from_python();
|
||||
result_type operator()(PyObject*);
|
||||
private:
|
||||
rvalue_from_python_data<T> m_data;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct return_object_manager_from_python
|
||||
{
|
||||
typedef T result_type;
|
||||
result_type operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct select_return_from_python
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, obj_mgr = is_object_manager<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr = is_pointer<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ref = is_reference<T>::value);
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
obj_mgr
|
||||
, return_object_manager_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
ptr
|
||||
, return_pointer_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
ref
|
||||
, return_reference_from_python<T>
|
||||
, return_rvalue_from_python<T>
|
||||
>::type
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct return_from_python
|
||||
: detail::select_return_from_python<T>::type
|
||||
{
|
||||
};
|
||||
|
||||
// Specialization as a convenience for call and call_method
|
||||
template <>
|
||||
struct return_from_python<void>
|
||||
{
|
||||
typedef python::detail::returnable<void>::type result_type;
|
||||
|
||||
result_type operator()(PyObject* x) const
|
||||
{
|
||||
(void_result_from_python)(x);
|
||||
# ifdef BOOST_NO_VOID_RETURNS
|
||||
return result_type();
|
||||
# endif
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Implementations
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
inline return_rvalue_from_python<T>::return_rvalue_from_python()
|
||||
: m_data(
|
||||
const_cast<registration*>(®istered<T>::converters)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typename return_rvalue_from_python<T>::result_type
|
||||
return_rvalue_from_python<T>::operator()(PyObject* obj)
|
||||
{
|
||||
return *(T*)
|
||||
(rvalue_result_from_python)(obj, m_data.stage1);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T return_reference_from_python<T>::operator()(PyObject* obj) const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(
|
||||
(reference_result_from_python)(obj, registered<T>::converters)
|
||||
, (T(*)())0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T return_pointer_from_python<T>::operator()(PyObject* obj) const
|
||||
{
|
||||
return T(
|
||||
(pointer_result_from_python)(obj, registered_pointee<T>::converters)
|
||||
);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T return_object_manager_from_python<T>::operator()(PyObject* obj) const
|
||||
{
|
||||
return T(
|
||||
object_manager_traits<T>::adopt(obj)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // RETURN_FROM_PYTHON_DWA200265_HPP
|
||||
138
include/boost/python/converter/rvalue_from_python_data.hpp
Normal file
138
include/boost/python/converter/rvalue_from_python_data.hpp
Normal file
@@ -0,0 +1,138 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FROM_PYTHON_AUX_DATA_DWA2002128_HPP
|
||||
# define FROM_PYTHON_AUX_DATA_DWA2002128_HPP
|
||||
|
||||
# include <boost/python/converter/constructor_function.hpp>
|
||||
# include <boost/python/detail/referent_storage.hpp>
|
||||
# include <boost/python/detail/destroy.hpp>
|
||||
# include <boost/static_assert.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
// Data management for potential rvalue conversions from Python to C++
|
||||
// types. When a client requests a conversion to T* or T&, we
|
||||
// generally require that an object of type T exists in the source
|
||||
// Python object, and the code here does not apply**. This implements
|
||||
// conversions which may create new temporaries of type T. The classic
|
||||
// example is a conversion which converts a Python tuple to a
|
||||
// std::vector. Since no std::vector lvalue exists in the Python
|
||||
// object -- it must be created "on-the-fly" by the converter, and
|
||||
// which must manage the lifetime of the created object.
|
||||
//
|
||||
// Note that the client is not precluded from using a registered
|
||||
// lvalue conversion to T in this case. In other words, we will
|
||||
// happily accept a Python object which /does/ contain a std::vector
|
||||
// lvalue, provided an appropriate converter is registered. So, while
|
||||
// this is an rvalue conversion from the client's point-of-view, the
|
||||
// converter registry may serve up lvalue or rvalue conversions for
|
||||
// the target type.
|
||||
//
|
||||
// ** C++ argument from_python conversions to T const& are an
|
||||
// exception to the rule for references: since in C++, const
|
||||
// references can bind to temporary rvalues, we allow rvalue
|
||||
// converters to be chosen when the target type is T const& for some
|
||||
// T.
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// Conversions begin by filling in and returning a copy of this
|
||||
// structure. The process looks up a converter in the rvalue converter
|
||||
// registry for the target type. It calls the convertible() function
|
||||
// of each registered converter, passing the source PyObject* as an
|
||||
// argument, until a non-null result is returned. This result goes in
|
||||
// the convertible field, and the converter's construct() function is
|
||||
// stored in the construct field.
|
||||
//
|
||||
// If no appropriate converter is found, conversion fails and the
|
||||
// convertible field is null. When used in argument conversion for
|
||||
// wrapped C++ functions, it causes overload resolution to reject the
|
||||
// current function but not to fail completely. If an exception is
|
||||
// thrown, overload resolution stops and the exception propagates back
|
||||
// through the caller.
|
||||
//
|
||||
// If an lvalue converter is matched, its convertible() function is
|
||||
// expected to return a pointer to the stored T object; its
|
||||
// construct() function will be NULL. The convertible() function of
|
||||
// rvalue converters may return any non-singular pointer; the actual
|
||||
// target object will only be available once the converter's
|
||||
// construct() function is called.
|
||||
struct rvalue_from_python_stage1_data
|
||||
{
|
||||
void* convertible;
|
||||
constructor_function construct;
|
||||
};
|
||||
|
||||
// Augments rvalue_from_python_stage1_data by adding storage for
|
||||
// constructing an object of remove_reference<T>::type. The
|
||||
// construct() function of rvalue converters (stored in m_construct
|
||||
// above) will cast the rvalue_from_python_stage1_data to an
|
||||
// appropriate instantiation of this template in order to access that
|
||||
// storage.
|
||||
template <class T>
|
||||
struct rvalue_from_python_storage
|
||||
{
|
||||
rvalue_from_python_stage1_data stage1;
|
||||
|
||||
// Storage for the result, in case an rvalue must be constructed
|
||||
typename python::detail::referent_storage<
|
||||
typename add_reference<T>::type
|
||||
>::type storage;
|
||||
};
|
||||
|
||||
// Augments rvalue_from_python_storage<T> with a destructor. If
|
||||
// stage1.convertible == storage.bytes, it indicates that an object of
|
||||
// remove_reference<T>::type has been constructed in storage and
|
||||
// should will be destroyed in ~rvalue_from_python_data(). It is
|
||||
// crucial that successful rvalue conversions establish this equality
|
||||
// and that unsuccessful ones do not.
|
||||
template <class T>
|
||||
struct rvalue_from_python_data : rvalue_from_python_storage<T>
|
||||
{
|
||||
# if (!defined(__MWERKS__) || __MWERKS__ >= 0x3000) \
|
||||
&& (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 245) \
|
||||
&& (!defined(__DECCXX_VER) || __DECCXX_VER > 60590014)
|
||||
// This must always be a POD struct with m_data its first member.
|
||||
BOOST_STATIC_ASSERT(offsetof(rvalue_from_python_storage<T>,stage1) == 0);
|
||||
# endif
|
||||
|
||||
// The usual constructor
|
||||
rvalue_from_python_data(rvalue_from_python_stage1_data const&);
|
||||
|
||||
// This constructor just sets m_convertible -- used by
|
||||
// implicitly_convertible<> to perform the final step of the
|
||||
// conversion, where the construct() function is already known.
|
||||
rvalue_from_python_data(void* convertible);
|
||||
|
||||
// Destroys any object constructed in the storage.
|
||||
~rvalue_from_python_data();
|
||||
private:
|
||||
typedef typename add_reference<typename add_cv<T>::type>::type ref_type;
|
||||
};
|
||||
|
||||
//
|
||||
// Implementataions
|
||||
//
|
||||
template <class T>
|
||||
inline rvalue_from_python_data<T>::rvalue_from_python_data(rvalue_from_python_stage1_data const& stage1)
|
||||
{
|
||||
this->stage1 = stage1;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline rvalue_from_python_data<T>::rvalue_from_python_data(void* convertible)
|
||||
{
|
||||
this->stage1.convertible = convertible;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline rvalue_from_python_data<T>::~rvalue_from_python_data()
|
||||
{
|
||||
if (this->stage1.convertible == this->storage.bytes)
|
||||
python::detail::destroy_referent<ref_type>(this->storage.bytes);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // FROM_PYTHON_AUX_DATA_DWA2002128_HPP
|
||||
111
include/boost/python/data_members.hpp
Normal file
111
include/boost/python/data_members.hpp
Normal file
@@ -0,0 +1,111 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DATA_MEMBERS_DWA2002328_HPP
|
||||
# define DATA_MEMBERS_DWA2002328_HPP
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/return_value_policy.hpp>
|
||||
# include <boost/python/copy_non_const_reference.hpp>
|
||||
# include <boost/python/object/function_object.hpp>
|
||||
# include <boost/python/arg_from_python.hpp>
|
||||
# include <boost/bind.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class Data, class Class, class Policies>
|
||||
struct member
|
||||
{
|
||||
static PyObject* get(Data Class::*pm, PyObject* args_, PyObject*, Policies const& policies)
|
||||
{
|
||||
arg_from_python<Class*> c0(PyTuple_GET_ITEM(args_, 0));
|
||||
if (!c0.convertible()) return 0;
|
||||
|
||||
// find the result converter
|
||||
typedef typename Policies::result_converter result_converter;
|
||||
typedef typename boost::add_reference<Data>::type source;
|
||||
typename mpl::apply1<result_converter,source>::type cr;
|
||||
if (!cr.convertible()) return 0;
|
||||
|
||||
if (!policies.precall(args_)) return 0;
|
||||
|
||||
PyObject* result = cr( (c0(PyTuple_GET_ITEM(args_, 0)))->*pm );
|
||||
|
||||
return policies.postcall(args_, result);
|
||||
}
|
||||
|
||||
static PyObject* set(Data Class::*pm, PyObject* args_, PyObject*, Policies const& policies)
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
arg_from_python<Class*> c0(PyTuple_GET_ITEM(args_, 0));
|
||||
if (!c0.convertible()) return 0;
|
||||
|
||||
typedef typename add_const<Data>::type target1;
|
||||
typedef typename add_reference<target1>::type target;
|
||||
arg_from_python<target> c1(PyTuple_GET_ITEM(args_, 1));
|
||||
|
||||
if (!c1.convertible()) return 0;
|
||||
|
||||
if (!policies.precall(args_)) return 0;
|
||||
|
||||
(c0(PyTuple_GET_ITEM(args_, 0)))->*pm = c1(PyTuple_GET_ITEM(args_, 1));
|
||||
|
||||
return policies.postcall(args_, detail::none());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template <class C, class D>
|
||||
object make_getter(D C::*pm)
|
||||
{
|
||||
typedef return_value_policy<copy_non_const_reference> default_policy;
|
||||
|
||||
return objects::function_object(
|
||||
::boost::bind(
|
||||
&detail::member<D,C,default_policy>::get, pm, _1, _2
|
||||
, default_policy())
|
||||
, 1);
|
||||
|
||||
}
|
||||
|
||||
template <class C, class D, class Policies>
|
||||
object make_getter(D C::*pm, Policies const& policies)
|
||||
{
|
||||
return objects::function_object(
|
||||
::boost::bind(
|
||||
&detail::member<D,C,Policies>::get, pm, _1, _2
|
||||
, policies)
|
||||
, 1);
|
||||
}
|
||||
|
||||
template <class C, class D>
|
||||
object make_setter(D C::*pm)
|
||||
{
|
||||
return objects::function_object(
|
||||
::boost::bind(
|
||||
&detail::member<D,C,default_call_policies>::set, pm, _1, _2
|
||||
, default_call_policies())
|
||||
, 2);
|
||||
}
|
||||
|
||||
template <class C, class D, class Policies>
|
||||
object make_setter(D C::*pm, Policies const& policies)
|
||||
{
|
||||
return objects::function_object(
|
||||
::boost::bind(
|
||||
&detail::member<D,C,Policies>::set, pm, _1, _2
|
||||
, policies)
|
||||
, 2);
|
||||
}
|
||||
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // DATA_MEMBERS_DWA2002328_HPP
|
||||
100
include/boost/python/def.hpp
Normal file
100
include/boost/python/def.hpp
Normal file
@@ -0,0 +1,100 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DEF_DWA200292_HPP
|
||||
# define DEF_DWA200292_HPP
|
||||
|
||||
# include <boost/python/object_fwd.hpp>
|
||||
# include <boost/python/make_function.hpp>
|
||||
# include <boost/python/detail/def_helper.hpp>
|
||||
# include <boost/python/detail/defaults_def.hpp>
|
||||
# include <boost/python/scope.hpp>
|
||||
# include <boost/python/signature.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
void BOOST_PYTHON_DECL scope_setattr_doc(char const* name, object const& obj, char const* doc);
|
||||
|
||||
template <class Fn, class CallPolicyOrDoc>
|
||||
void
|
||||
dispatch_def(
|
||||
void const*,
|
||||
char const* name,
|
||||
Fn fn,
|
||||
CallPolicyOrDoc const& policy_or_doc,
|
||||
char const* doc)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc> helper;
|
||||
|
||||
detail::scope_setattr_doc(
|
||||
name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)),
|
||||
helper::get_doc(policy_or_doc, doc));
|
||||
}
|
||||
|
||||
template <class StubsT, class SigT, class CallPolicyOrDoc>
|
||||
void dispatch_def(
|
||||
detail::func_stubs_base const*,
|
||||
char const* name,
|
||||
SigT sig,
|
||||
StubsT const& stubs,
|
||||
CallPolicyOrDoc const& policy_or_doc,
|
||||
char const* doc = 0)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc> helper;
|
||||
|
||||
// convert sig to a type_list (see detail::get_signature in signature.hpp)
|
||||
// before calling detail::define_with_defaults.
|
||||
|
||||
scope current;
|
||||
detail::define_with_defaults(
|
||||
name, stubs, helper::get_policy(policy_or_doc),
|
||||
current, detail::get_signature(sig),
|
||||
helper::get_doc(policy_or_doc, doc));
|
||||
}
|
||||
}
|
||||
|
||||
template <class Fn>
|
||||
void def(char const* name, Fn fn)
|
||||
{
|
||||
detail::scope_setattr_doc(name, boost::python::make_function(fn), 0);
|
||||
}
|
||||
|
||||
template <class Arg1T, class Arg2T>
|
||||
void def(char const* name, Arg1T arg1, Arg2T const& arg2)
|
||||
{
|
||||
// The arguments may be:
|
||||
// arg1: function or signature
|
||||
// arg2: policy or docstring or stubs
|
||||
|
||||
detail::dispatch_def(&arg2, name, arg1, arg2, (char*)0);
|
||||
}
|
||||
|
||||
template <class Arg1T, class Arg2T, class Arg3T>
|
||||
void def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3)
|
||||
{
|
||||
// The arguments may be:
|
||||
// arg1: function or signature
|
||||
// arg2: policy or docstring or stubs
|
||||
// arg3: policy or docstring
|
||||
|
||||
detail::dispatch_def(&arg2, name, arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
template <class Arg1T, class Arg2T, class Arg3T>
|
||||
void def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3, char const* doc)
|
||||
{
|
||||
// The arguments are definitely:
|
||||
// arg1: signature
|
||||
// arg2: stubs
|
||||
// arg3: policy
|
||||
|
||||
detail::dispatch_def(&arg2, name, arg1, arg2, arg3, doc);
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // DEF_DWA200292_HPP
|
||||
24
include/boost/python/detail/aix_init_module.hpp
Normal file
24
include/boost/python/detail/aix_init_module.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef AIX_INIT_MODULE_DWA2002529_HPP
|
||||
# define AIX_INIT_MODULE_DWA2002529_HPP
|
||||
# ifdef _AIX
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <cstdio>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
extern "C"
|
||||
{
|
||||
typedef PyObject* (*so_load_function)(char*,char*,FILE*);
|
||||
}
|
||||
|
||||
void aix_init_module(so_load_function, char const* name, void (*init_module)());
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
# endif
|
||||
|
||||
#endif // AIX_INIT_MODULE_DWA2002529_HPP
|
||||
14
include/boost/python/detail/api_placeholder.hpp
Normal file
14
include/boost/python/detail/api_placeholder.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef BOOST_PYTHON_API_PLACE_HOLDER_HPP
|
||||
#define BOOST_PYTHON_API_PLACE_HOLDER_HPP
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
inline long len(object const& obj)
|
||||
{
|
||||
long result = PyObject_Length(obj.ptr());
|
||||
if (PyErr_Occurred()) throw_error_already_set();
|
||||
return result;
|
||||
}
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // BOOST_PYTHON_API_PLACE_HOLDER_HPP
|
||||
127
include/boost/python/detail/arg_tuple_size.hpp
Normal file
127
include/boost/python/detail/arg_tuple_size.hpp
Normal file
@@ -0,0 +1,127 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
//
|
||||
// This work was funded in part by Lawrence Berkeley National Labs
|
||||
//
|
||||
// This file generated for 5-argument member functions and 6-argument free
|
||||
// functions by gen_arg_tuple_size.python
|
||||
|
||||
#ifndef ARG_TUPLE_SIZE_DWA20011201_HPP
|
||||
# define ARG_TUPLE_SIZE_DWA20011201_HPP
|
||||
|
||||
# include <boost/config.hpp>
|
||||
|
||||
# include <boost/python/detail/char_array.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
// Computes (at compile-time) the number of elements that a Python
|
||||
// argument tuple must have in order to be passed to a wrapped C++
|
||||
// (member) function of the given type.
|
||||
template <class F> struct arg_tuple_size;
|
||||
|
||||
// We will use the "sizeof() trick" to work around the lack of
|
||||
// partial specialization in MSVC6 and its broken-ness in borland.
|
||||
// See http://opensource.adobe.com or
|
||||
// http://groups.yahoo.com/group/boost/message/5441 for
|
||||
// more examples
|
||||
|
||||
// The following helper functions are never actually called, since
|
||||
// they are only used within a sizeof() expression, but the type of
|
||||
// their return value is used to discriminate between various free
|
||||
// and member function pointers at compile-time.
|
||||
|
||||
// Specializations for function pointers
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/arg_tuple_size.hpp>, BOOST_PYTHON_FUNCTION_POINTER))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
// Specializations for member function pointers
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, BOOST_PYTHON_CV_COUNT - 1, <boost/python/detail/arg_tuple_size.hpp>, BOOST_PYTHON_POINTER_TO_MEMBER))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
|
||||
template <class F>
|
||||
struct arg_tuple_size
|
||||
{
|
||||
// The sizeof() magic happens here
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value
|
||||
= sizeof(arg_tuple_size_helper(F(0)).elements) - 1);
|
||||
};
|
||||
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // ARG_TUPLE_SIZE_DWA20011201_HPP
|
||||
|
||||
// --------------- function pointers --------------- //
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER
|
||||
# line BOOST_PP_LINE(__LINE__, arg_tuple_size.hpp(function pointers))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
|
||||
template <class R BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
struct arg_tuple_size<R (*)(BOOST_PYTHON_UNARY_ENUM(N, A))>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = N);
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
template<class R BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
char_array<N> arg_tuple_size_helper(
|
||||
R (*)(BOOST_PYTHON_UNARY_ENUM(N, A)));
|
||||
|
||||
# endif // !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
|
||||
# undef N
|
||||
|
||||
// --------------- pointers-to-members --------------- //
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_POINTER_TO_MEMBER
|
||||
// Outer iteration over cv-qualifications
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_2 \
|
||||
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/arg_tuple_size.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 2 && BOOST_PP_RELATIVE_FLAGS(1) == BOOST_PYTHON_POINTER_TO_MEMBER
|
||||
# line BOOST_PP_LINE(__LINE__, arg_tuple_size.hpp(pointers-to-members))
|
||||
// Inner iteration over arities
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1))
|
||||
|
||||
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
|
||||
template <class R, class T BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
struct arg_tuple_size<R (T::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = N + 1U);
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
template <class R, class T BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
char_array<N + 1> arg_tuple_size_helper(
|
||||
R (T::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q);
|
||||
|
||||
# endif // !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
|
||||
# undef Q
|
||||
# undef N
|
||||
|
||||
#endif // !defined(BOOST_PP_IS_ITERATING)
|
||||
112
include/boost/python/detail/borrowed_ptr.hpp
Executable file
112
include/boost/python/detail/borrowed_ptr.hpp
Executable file
@@ -0,0 +1,112 @@
|
||||
#ifndef BORROWED_PTR_DWA20020601_HPP
|
||||
# define BORROWED_PTR_DWA20020601_HPP
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/tag.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template<class T> class borrowed
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
# if !defined(__MWERKS__) || __MWERKS__ > 0x3000
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr<borrowed<T>*>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr<borrowed<T> const*>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr<borrowed<T> volatile*>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr<borrowed<T> const volatile*>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
# else
|
||||
template<typename T>
|
||||
struct is_borrowed
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
template<typename T>
|
||||
struct is_borrowed<borrowed<T> >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
template<typename T>
|
||||
struct is_borrowed_ptr<T*>
|
||||
: is_borrowed<typename remove_cv<T>::type>
|
||||
{
|
||||
};
|
||||
# endif
|
||||
|
||||
# else // no partial specialization
|
||||
|
||||
typedef char (&yes_borrowed_ptr_t)[1];
|
||||
typedef char (&no_borrowed_ptr_t)[2];
|
||||
|
||||
no_borrowed_ptr_t is_borrowed_ptr_test(...);
|
||||
|
||||
template <class T>
|
||||
typename mpl::select_type<
|
||||
is_pointer<T>::value
|
||||
, T
|
||||
, int
|
||||
>::type
|
||||
is_borrowed_ptr_test1(boost::type<T>);
|
||||
|
||||
template<typename T>
|
||||
yes_borrowed_ptr_t is_borrowed_ptr_test(borrowed<T> const volatile*);
|
||||
|
||||
template<typename T>
|
||||
class is_borrowed_ptr
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
sizeof(detail::is_borrowed_ptr_test(is_borrowed_ptr_test1(boost::type<T>())))
|
||||
== sizeof(detail::yes_borrowed_ptr_t)));
|
||||
};
|
||||
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T* get_managed_object(detail::borrowed<T> const volatile* p, tag_t)
|
||||
{
|
||||
return (T*)p;
|
||||
}
|
||||
|
||||
}} // namespace boost::python::detail
|
||||
|
||||
#endif // #ifndef BORROWED_PTR_DWA20020601_HPP
|
||||
107
include/boost/python/detail/caller.hpp
Normal file
107
include/boost/python/detail/caller.hpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
//
|
||||
// The author gratefully acknowleges the support of Dragon Systems, Inc., in
|
||||
// producing this work.
|
||||
//
|
||||
// This file generated for 10-argument member functions and 11-argument free
|
||||
// functions by gen_caller.python
|
||||
|
||||
# ifndef CALLER_DWA20011214_HPP
|
||||
# define CALLER_DWA20011214_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/returning.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
|
||||
# // temp: include <boost/mpl/select_type.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <class T> struct to_python;
|
||||
}}
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct caller
|
||||
{
|
||||
typedef PyObject* result_type;
|
||||
|
||||
// function pointers
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/caller.hpp>, BOOST_PYTHON_FUNCTION_POINTER))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
// pointers-to-members
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, 3, <boost/python/detail/caller.hpp>, BOOST_PYTHON_POINTER_TO_MEMBER))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
# endif // CALLER_DWA20011214_HPP
|
||||
|
||||
/* ---------- function pointers --------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER
|
||||
# line BOOST_PP_LINE(__LINE__, detail/caller.hpp(function pointers))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template <
|
||||
class P, class R
|
||||
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)
|
||||
>
|
||||
PyObject* operator()(
|
||||
R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A))
|
||||
, PyObject* args
|
||||
, PyObject* keywords
|
||||
, P const& policies) const
|
||||
{
|
||||
return returning<R>::call(pf, args, keywords, &policies);
|
||||
}
|
||||
|
||||
# undef N
|
||||
|
||||
/* ---------- pointers-to-members ---------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_POINTER_TO_MEMBER
|
||||
// outer over cv-qualifiers
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/caller.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 2
|
||||
// inner over arities
|
||||
|
||||
#define N BOOST_PP_ITERATION()
|
||||
#define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1))
|
||||
|
||||
template <
|
||||
class P, class R, class T
|
||||
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)
|
||||
>
|
||||
PyObject* operator()(
|
||||
R (T::*pmf)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q
|
||||
, PyObject* args, PyObject* keywords
|
||||
, P const& policies
|
||||
) const
|
||||
{
|
||||
return returning<R>::call(pmf, args, keywords, &policies);
|
||||
}
|
||||
|
||||
#undef N
|
||||
#undef Q
|
||||
|
||||
#endif
|
||||
43
include/boost/python/detail/construct.hpp
Normal file
43
include/boost/python/detail/construct.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CONSTRUCT_REFERENCE_DWA2002716_HPP
|
||||
# define CONSTRUCT_REFERENCE_DWA2002716_HPP
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <class T, class Arg>
|
||||
void construct_pointee(void* storage, Arg& x
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
|
||||
, T const volatile*
|
||||
# else
|
||||
, T const*
|
||||
# endif
|
||||
)
|
||||
{
|
||||
new (storage) T(x);
|
||||
}
|
||||
|
||||
template <class T, class Arg>
|
||||
void construct_referent_impl(void* storage, Arg& x, T&(*)())
|
||||
{
|
||||
construct_pointee(storage, x, (T*)0);
|
||||
}
|
||||
|
||||
template <class T, class Arg>
|
||||
void construct_referent(void* storage, Arg const& x, T(*tag)() = 0)
|
||||
{
|
||||
construct_referent_impl(storage, x, tag);
|
||||
}
|
||||
|
||||
template <class T, class Arg>
|
||||
void construct_referent(void* storage, Arg& x, T(*tag)() = 0)
|
||||
{
|
||||
construct_referent_impl(storage, x, tag);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // CONSTRUCT_REFERENCE_DWA2002716_HPP
|
||||
77
include/boost/python/detail/decorated_type_id.hpp
Executable file
77
include/boost/python/detail/decorated_type_id.hpp
Executable file
@@ -0,0 +1,77 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DECORATED_TYPE_ID_DWA2002517_HPP
|
||||
# define DECORATED_TYPE_ID_DWA2002517_HPP
|
||||
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct decorated_type_info : totally_ordered<decorated_type_info>
|
||||
{
|
||||
enum decoration { const_ = 0x1, volatile_ = 0x2, reference = 0x4 };
|
||||
|
||||
decorated_type_info(type_info, decoration = decoration());
|
||||
|
||||
inline bool operator<(decorated_type_info const& rhs) const;
|
||||
inline bool operator==(decorated_type_info const& rhs) const;
|
||||
|
||||
friend BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, decorated_type_info const&);
|
||||
|
||||
operator type_info const&() const;
|
||||
private: // type
|
||||
typedef type_info base_id_t;
|
||||
|
||||
private: // data members
|
||||
decoration m_decoration;
|
||||
base_id_t m_base_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline decorated_type_info decorated_type_id(boost::type<T>* = 0)
|
||||
{
|
||||
return decorated_type_info(
|
||||
type_id<T>()
|
||||
, decorated_type_info::decoration(
|
||||
(is_const<T>::value || python::detail::is_reference_to_const<T>::value
|
||||
? decorated_type_info::const_ : 0)
|
||||
| (is_volatile<T>::value || python::detail::is_reference_to_volatile<T>::value
|
||||
? decorated_type_info::volatile_ : 0)
|
||||
| (is_reference<T>::value ? decorated_type_info::reference : 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
inline decorated_type_info::decorated_type_info(type_info base_t, decoration decoration)
|
||||
: m_decoration(decoration)
|
||||
, m_base_type(base_t)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool decorated_type_info::operator<(decorated_type_info const& rhs) const
|
||||
{
|
||||
return m_decoration < rhs.m_decoration
|
||||
|| m_decoration == rhs.m_decoration
|
||||
&& m_base_type < rhs.m_base_type;
|
||||
}
|
||||
|
||||
inline bool decorated_type_info::operator==(decorated_type_info const& rhs) const
|
||||
{
|
||||
return m_decoration == rhs.m_decoration && m_base_type == rhs.m_base_type;
|
||||
}
|
||||
|
||||
inline decorated_type_info::operator type_info const&() const
|
||||
{
|
||||
return m_base_type;
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, decorated_type_info const&);
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // DECORATED_TYPE_ID_DWA2002517_HPP
|
||||
61
include/boost/python/detail/def_helper.hpp
Normal file
61
include/boost/python/detail/def_helper.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DEF_HELPER_DWA200287_HPP
|
||||
# define DEF_HELPER_DWA200287_HPP
|
||||
|
||||
# include <boost/type_traits/ice.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/python/detail/string_literal.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
//
|
||||
// def_helper<T> --
|
||||
//
|
||||
// A helper for def() functions which determines how to interpret
|
||||
// an argument of type T which could be either CallPolicies or a
|
||||
// string literal representing a docstring.
|
||||
//
|
||||
// Generates two static functions:
|
||||
//
|
||||
// get_policy(x), where x is of type T, returns a policies
|
||||
// object: either a reference to x or default_call_policies()
|
||||
// if x is a string literal.
|
||||
//
|
||||
// get_doc(x, s), where s convertible to char const*, returns x
|
||||
// if x is a string literal, s otherwise.
|
||||
|
||||
template <bool is_string = false>
|
||||
struct def_helper_impl
|
||||
{
|
||||
template <class P>
|
||||
static P const& get_policy(P const& x) { return x; }
|
||||
|
||||
template <class P>
|
||||
static char const* get_doc(P const&, char const* doc) { return doc; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct def_helper_impl<true>
|
||||
{
|
||||
static python::default_call_policies get_policy(char const*) { return default_call_policies(); }
|
||||
static char const* get_doc(char const* doc, char const*) { return doc; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct def_helper
|
||||
: def_helper_impl<
|
||||
type_traits::ice_or<
|
||||
is_string_literal<T const>::value
|
||||
, is_same<T, char const*>::value
|
||||
, is_same<T, char*>::value
|
||||
>::value
|
||||
>
|
||||
{};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // DEF_HELPER_DWA200287_HPP
|
||||
253
include/boost/python/detail/defaults_def.hpp
Normal file
253
include/boost/python/detail/defaults_def.hpp
Normal file
@@ -0,0 +1,253 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
#ifndef DEFAULTS_DEF_JDG20020811_HPP
|
||||
#define DEFAULTS_DEF_JDG20020811_HPP
|
||||
|
||||
#include <boost/python/detail/defaults_gen.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/mpl/int_t.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/preprocessor/iterate.hpp>
|
||||
#include <boost/python/detail/type_list_utils.hpp>
|
||||
#include <boost/python/class_fwd.hpp>
|
||||
#include <boost/python/object/function.hpp>
|
||||
#include <boost/python/scope.hpp>
|
||||
#include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace python {
|
||||
|
||||
struct module;
|
||||
|
||||
namespace objects
|
||||
{
|
||||
struct class_base;
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <class Func, class CallPolicies, class NameSpaceT>
|
||||
static void name_space_def(
|
||||
NameSpaceT& name_space,
|
||||
char const* name,
|
||||
Func f,
|
||||
CallPolicies const& policies,
|
||||
char const* doc,
|
||||
objects::class_base*
|
||||
)
|
||||
{
|
||||
name_space.def(
|
||||
name, f, policies, doc);
|
||||
}
|
||||
|
||||
template <class Func, class CallPolicies>
|
||||
static void name_space_def(
|
||||
object& name_space,
|
||||
char const* name,
|
||||
Func f,
|
||||
CallPolicies const& policies,
|
||||
char const* doc,
|
||||
...
|
||||
)
|
||||
{
|
||||
scope within(name_space);
|
||||
|
||||
def(name, f, policies, doc);
|
||||
}
|
||||
|
||||
// For backward compatibility
|
||||
template <class Func, class CallPolicies, class NameSpaceT>
|
||||
static void name_space_def(
|
||||
NameSpaceT& name_space,
|
||||
char const* name,
|
||||
Func f,
|
||||
CallPolicies const& policies,
|
||||
char const* doc,
|
||||
module*
|
||||
)
|
||||
{
|
||||
name_space.def(
|
||||
name, f, policies, doc);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// This Boost PP code generates expansions for
|
||||
//
|
||||
// template <typename StubsT, typename NameSpaceT>
|
||||
// inline void
|
||||
// define_stub_function(
|
||||
// char const* name, StubsT s, NameSpaceT& name_space, boost::mpl::int_t<N>)
|
||||
// {
|
||||
// name_space.def(name, &StubsT::func_N);
|
||||
// }
|
||||
//
|
||||
// where N runs from 0 to BOOST_PYTHON_MAX_ARITY
|
||||
//
|
||||
// The set of overloaded functions (define_stub_function) expects:
|
||||
//
|
||||
// 1. char const* name: function name that will be visible to python
|
||||
// 2. StubsT: a function stubs struct (see defaults_gen.hpp)
|
||||
// 3. NameSpaceT& name_space: a python::class_ or python::module instance
|
||||
// 4. int_t<N>: the Nth overloaded function (StubsT::func_N)
|
||||
// (see defaults_gen.hpp)
|
||||
// 5. char const* name: doc string
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int N>
|
||||
struct define_stub_function {};
|
||||
|
||||
#define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/defaults_def.hpp>))
|
||||
|
||||
#include BOOST_PP_ITERATE()
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// define_with_defaults_helper<N>
|
||||
//
|
||||
// This helper template struct does the actual recursive definition.
|
||||
// There's a generic version define_with_defaults_helper<N> and a
|
||||
// terminal case define_with_defaults_helper<0>. The struct and its
|
||||
// specialization has a sole static member function def that expects:
|
||||
//
|
||||
// 1. char const* name: function name that will be visible to python
|
||||
// 2. StubsT: a function stubs struct (see defaults_gen.hpp)
|
||||
// 3. NameSpaceT& name_space: a python::class_ or python::module instance
|
||||
// 4. char const* name: doc string
|
||||
//
|
||||
// The def static member function calls a corresponding
|
||||
// define_stub_function<N>. The general case recursively calls
|
||||
// define_with_defaults_helper<N-1>::def until it reaches the
|
||||
// terminal case case define_with_defaults_helper<0>.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int N>
|
||||
struct define_with_defaults_helper {
|
||||
|
||||
template <class StubsT, class CallPolicies, class NameSpaceT>
|
||||
static void
|
||||
def(
|
||||
char const* name,
|
||||
StubsT stubs,
|
||||
CallPolicies const& policies,
|
||||
NameSpaceT& name_space,
|
||||
char const* doc)
|
||||
{
|
||||
// define the NTH stub function of stubs
|
||||
define_stub_function<N>::define(name, stubs, policies, name_space, doc);
|
||||
// call the next define_with_defaults_helper
|
||||
define_with_defaults_helper<N-1>::def(name, stubs, policies, name_space, doc);
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
template <>
|
||||
struct define_with_defaults_helper<0> {
|
||||
|
||||
template <class StubsT, class CallPolicies, class NameSpaceT>
|
||||
static void
|
||||
def(
|
||||
char const* name,
|
||||
StubsT stubs,
|
||||
CallPolicies const& policies,
|
||||
NameSpaceT& name_space,
|
||||
char const* doc)
|
||||
{
|
||||
// define the Oth stub function of stubs
|
||||
define_stub_function<0>::define(name, stubs, policies, name_space, doc);
|
||||
// return
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// define_with_defaults
|
||||
//
|
||||
// 1. char const* name: function name that will be visible to python
|
||||
// 2. StubsT: a function stubs struct (see defaults_gen.hpp)
|
||||
// 3. CallPolicies& policies: Call policies
|
||||
// 4. NameSpaceT& name_space: a python::class_ or python::module instance
|
||||
// 5. SigT sig: Function signature typelist (see defaults_gen.hpp)
|
||||
// 6. char const* name: doc string
|
||||
//
|
||||
// This is the main entry point. This function recursively defines all
|
||||
// stub functions of StubT (see defaults_gen.hpp) in NameSpaceT name_space which
|
||||
// can be either a python::class_ or a python::module. The sig argument
|
||||
// is a typelist that specifies the return type, the class (for member
|
||||
// functions, and the arguments. Here are some SigT examples:
|
||||
//
|
||||
// int foo(int) mpl::type_list<int, int>
|
||||
// void bar(int, int) mpl::type_list<void, int, int>
|
||||
// void C::foo(int) mpl::type_list<void, C, int>
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <class StubsT, class CallPolicies, class NameSpaceT, class SigT>
|
||||
inline void
|
||||
define_with_defaults(
|
||||
char const* name,
|
||||
StubsT,
|
||||
CallPolicies const& policies,
|
||||
NameSpaceT& name_space,
|
||||
SigT sig,
|
||||
char const* doc)
|
||||
{
|
||||
typedef typename boost::python::detail::type_at<0, SigT>::type nth_type;
|
||||
typedef typename StubsT::v_type v_type;
|
||||
typedef typename StubsT::nv_type nv_type;
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
boost::is_same<void, nth_type>::value
|
||||
, v_type
|
||||
, nv_type
|
||||
>::type stubs_type;
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
(stubs_type::max_args) <=
|
||||
boost::python::detail::type_list_size<SigT>::value);
|
||||
|
||||
typedef typename stubs_type::template gen<SigT> gen_type;
|
||||
define_with_defaults_helper<stubs_type::n_funcs-1>::def
|
||||
(name, gen_type(), policies, name_space, doc);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#endif // DEFAULTS_DEF_JDG20020811_HPP
|
||||
|
||||
#else // defined(BOOST_PP_IS_ITERATING)
|
||||
// PP vertical iteration code
|
||||
|
||||
|
||||
template <>
|
||||
struct define_stub_function<BOOST_PP_ITERATION()> {
|
||||
template <class StubsT, class CallPolicies, class NameSpaceT>
|
||||
static void define(
|
||||
char const* name,
|
||||
StubsT,
|
||||
CallPolicies const& policies,
|
||||
NameSpaceT& name_space,
|
||||
char const* doc
|
||||
)
|
||||
{
|
||||
detail::name_space_def(name_space,
|
||||
name,
|
||||
&StubsT::BOOST_PP_CAT(func_, BOOST_PP_ITERATION()),
|
||||
policies,
|
||||
doc, &name_space);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(BOOST_PP_IS_ITERATING)
|
||||
287
include/boost/python/detail/defaults_gen.hpp
Normal file
287
include/boost/python/detail/defaults_gen.hpp
Normal file
@@ -0,0 +1,287 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef DEFAULTS_GEN_JDG20020807_HPP
|
||||
#define DEFAULTS_GEN_JDG20020807_HPP
|
||||
|
||||
#include <boost/python/detail/preprocessor.hpp>
|
||||
#include <boost/preprocessor/repeat.hpp>
|
||||
#include <boost/preprocessor/enum.hpp>
|
||||
#include <boost/preprocessor/enum_params.hpp>
|
||||
#include <boost/preprocessor/tuple.hpp>
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <boost/preprocessor/arithmetic/sub.hpp>
|
||||
#include <boost/preprocessor/arithmetic/add.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/preprocessor/inc.hpp>
|
||||
#include <boost/preprocessor/empty.hpp>
|
||||
#include <boost/preprocessor/comma_if.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/python/detail/type_list_utils.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// func_stubs_base is used as a base class for all function stubs.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
struct func_stubs_base {};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define BPL_IMPL_TYPEDEF_GEN(z, INDEX, DATA) \
|
||||
typedef typename boost::python::detail::type_at \
|
||||
< \
|
||||
BOOST_PP_ADD(INDEX, DATA), \
|
||||
SigT \
|
||||
>::type BOOST_PP_CAT(T, INDEX); \
|
||||
|
||||
#define BPL_IMPL_FUNC_WRAPPER_GEN(z, index, DATA) \
|
||||
static RT BOOST_PP_CAT(func_, index) ( \
|
||||
BOOST_PYTHON_BINARY_ENUM( \
|
||||
BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), T, arg) \
|
||||
) \
|
||||
{ \
|
||||
BOOST_PP_TUPLE_ELEM(3, 2, DATA) \
|
||||
BOOST_PP_TUPLE_ELEM(3, 0, DATA) \
|
||||
( \
|
||||
BOOST_PP_ENUM_PARAMS( \
|
||||
BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), \
|
||||
arg \
|
||||
) \
|
||||
); \
|
||||
}
|
||||
|
||||
#define BPL_IMPL_GEN_FUNCTION(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS, RETURN) \
|
||||
struct FSTUBS_NAME { \
|
||||
\
|
||||
BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(N_DFLTS)); \
|
||||
BOOST_STATIC_CONSTANT(int, max_args = n_funcs); \
|
||||
\
|
||||
template <typename SigT> \
|
||||
struct gen { \
|
||||
\
|
||||
typedef typename boost::python::detail::type_at<0, SigT>::type RT; \
|
||||
\
|
||||
BOOST_PP_REPEAT_2ND \
|
||||
( \
|
||||
N_ARGS, \
|
||||
BPL_IMPL_TYPEDEF_GEN, \
|
||||
1 \
|
||||
) \
|
||||
\
|
||||
BOOST_PP_REPEAT_2ND \
|
||||
( \
|
||||
BOOST_PP_INC(N_DFLTS), \
|
||||
BPL_IMPL_FUNC_WRAPPER_GEN, \
|
||||
(FNAME, BOOST_PP_SUB(N_ARGS, N_DFLTS), RETURN) \
|
||||
) \
|
||||
}; \
|
||||
}; \
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define BPL_IMPL_MEM_FUNC_WRAPPER_GEN(z, index, DATA) \
|
||||
static RT BOOST_PP_CAT(func_, index) ( \
|
||||
ClassT& obj BOOST_PP_COMMA_IF( \
|
||||
BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(3, 1, DATA), index)) \
|
||||
BOOST_PYTHON_BINARY_ENUM( \
|
||||
BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), T, arg) \
|
||||
) \
|
||||
{ \
|
||||
BOOST_PP_TUPLE_ELEM(3, 2, DATA) obj.BOOST_PP_TUPLE_ELEM(3, 0, DATA)( \
|
||||
BOOST_PP_ENUM_PARAMS( \
|
||||
BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), arg \
|
||||
) \
|
||||
); \
|
||||
}
|
||||
|
||||
#define BPL_IMPL_GEN_MEM_FUNCTION(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS, RETURN) \
|
||||
struct FSTUBS_NAME { \
|
||||
\
|
||||
BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(N_DFLTS)); \
|
||||
BOOST_STATIC_CONSTANT(int, max_args = n_funcs + 1); \
|
||||
\
|
||||
template <typename SigT> \
|
||||
struct gen { \
|
||||
\
|
||||
typedef typename boost::python::detail::type_at<0, SigT>::type RT; \
|
||||
typedef typename boost::python::detail::type_at<1, SigT>::type ClassT; \
|
||||
\
|
||||
BOOST_PP_REPEAT_2ND \
|
||||
( \
|
||||
N_ARGS, \
|
||||
BPL_IMPL_TYPEDEF_GEN, \
|
||||
2 \
|
||||
) \
|
||||
\
|
||||
BOOST_PP_REPEAT_2ND \
|
||||
( \
|
||||
BOOST_PP_INC(N_DFLTS), \
|
||||
BPL_IMPL_MEM_FUNC_WRAPPER_GEN, \
|
||||
(FNAME, BOOST_PP_SUB(N_ARGS, N_DFLTS), RETURN) \
|
||||
) \
|
||||
}; \
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#if defined(BOOST_MSVC)
|
||||
|
||||
#define BPL_IMPL_GEN_FUNCTION_STUB(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS) \
|
||||
BPL_IMPL_GEN_FUNCTION \
|
||||
(FNAME, BOOST_PP_CAT(FSTUBS_NAME, _NV), N_ARGS, N_DFLTS, return) \
|
||||
BPL_IMPL_GEN_FUNCTION \
|
||||
(FNAME, BOOST_PP_CAT(FSTUBS_NAME, _V), N_ARGS, N_DFLTS, ;) \
|
||||
struct FSTUBS_NAME \
|
||||
: public boost::python::detail::func_stubs_base { \
|
||||
\
|
||||
typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(FSTUBS_NAME, _V) v_type; \
|
||||
}; \
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define BPL_IMPL_GEN_MEM_FUNCTION_STUB(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS) \
|
||||
BPL_IMPL_GEN_MEM_FUNCTION \
|
||||
(FNAME, BOOST_PP_CAT(FSTUBS_NAME, _NV), N_ARGS, N_DFLTS, return) \
|
||||
BPL_IMPL_GEN_MEM_FUNCTION \
|
||||
(FNAME, BOOST_PP_CAT(FSTUBS_NAME, _V), N_ARGS, N_DFLTS, ;) \
|
||||
struct FSTUBS_NAME \
|
||||
: public boost::python::detail::func_stubs_base { \
|
||||
\
|
||||
typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(FSTUBS_NAME, _V) v_type; \
|
||||
}; \
|
||||
|
||||
#else
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define BPL_IMPL_GEN_FUNCTION_STUB(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS) \
|
||||
BPL_IMPL_GEN_FUNCTION \
|
||||
(FNAME, BOOST_PP_CAT(FSTUBS_NAME, _NV), N_ARGS, N_DFLTS, return) \
|
||||
struct FSTUBS_NAME \
|
||||
: public boost::python::detail::func_stubs_base { \
|
||||
\
|
||||
typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) v_type; \
|
||||
}; \
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define BPL_IMPL_GEN_MEM_FUNCTION_STUB(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS) \
|
||||
BPL_IMPL_GEN_MEM_FUNCTION \
|
||||
(FNAME, BOOST_PP_CAT(FSTUBS_NAME, _NV), N_ARGS, N_DFLTS, return) \
|
||||
struct FSTUBS_NAME \
|
||||
: public boost::python::detail::func_stubs_base { \
|
||||
\
|
||||
typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) nv_type; \
|
||||
typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) v_type; \
|
||||
}; \
|
||||
|
||||
#endif // defined(BOOST_MSVC)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// MAIN MACROS
|
||||
//
|
||||
// Given GENERATOR_NAME, FNAME, MIN_ARGS and MAX_ARGS, These macros
|
||||
// generate function stubs that forward to a function or member function
|
||||
// named FNAME. MAX_ARGS is the arity of the function or member function
|
||||
// FNAME. FNAME can have default arguments. MIN_ARGS is the minimum
|
||||
// arity that FNAME can accept.
|
||||
//
|
||||
// There are two versions:
|
||||
//
|
||||
// 1. BOOST_PYTHON_FUNCTION_OVERLOADS for free functions
|
||||
// 2. BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS for member functions.
|
||||
//
|
||||
// For instance, given a function:
|
||||
//
|
||||
// int
|
||||
// foo(int a, char b = 1, unsigned c = 2, double d = 3)
|
||||
// {
|
||||
// return a + b + c + int(d);
|
||||
// }
|
||||
//
|
||||
// The macro invocation:
|
||||
//
|
||||
// BOOST_PYTHON_FUNCTION_OVERLOADS(foo_stubs, foo, 1, 4)
|
||||
//
|
||||
// Generates this code:
|
||||
//
|
||||
// struct foo_stubs_NV {
|
||||
//
|
||||
// static const int n_funcs = 4;
|
||||
// static const int max_args = n_funcs;
|
||||
//
|
||||
// template <typename SigT>
|
||||
// struct gen {
|
||||
//
|
||||
// typedef typename mpl::at<0, SigT>::type RT;
|
||||
// typedef typename mpl::at<1, SigT>::type T0;
|
||||
// typedef typename mpl::at<2, SigT>::type T1;
|
||||
// typedef typename mpl::at<3, SigT>::type T2;
|
||||
// typedef typename mpl::at<4, SigT>::type T3;
|
||||
//
|
||||
// static RT func_0(T0 arg0)
|
||||
// { return foo(arg0); }
|
||||
//
|
||||
// static RT func_1(T0 arg0, T1 arg1)
|
||||
// { return foo(arg0, arg1); }
|
||||
//
|
||||
// static RT func_2(T0 arg0, T1 arg1, T2 arg2)
|
||||
// { return foo(arg0, arg1, arg2); }
|
||||
//
|
||||
// static RT func_3(T0 arg0, T1 arg1, T2 arg2, T3 arg3)
|
||||
// { return foo(arg0, arg1, arg2, arg3); }
|
||||
// };
|
||||
// };
|
||||
//
|
||||
// struct foo_stubs
|
||||
// : public boost::python::detail::func_stubs_base {
|
||||
//
|
||||
// typedef foo_stubs_NV nv_type;
|
||||
// typedef foo_stubs_NV v_type;
|
||||
// };
|
||||
//
|
||||
// The typedefs nv_type and v_type are used to handle compilers that
|
||||
// do not support void returns. The example above typedefs nv_type
|
||||
// and v_type to foo_stubs_NV. On compilers that do not support
|
||||
// void returns, there are two versions: foo_stubs_NV and foo_stubs_V.
|
||||
// The "V" version is almost identical to the "NV" version except
|
||||
// for the return type (void) and the lack of the return keyword.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define BOOST_PYTHON_FUNCTION_OVERLOADS(GENERATOR_NAME, FNAME, MIN_ARGS, MAX_ARGS) \
|
||||
BPL_IMPL_GEN_FUNCTION_STUB \
|
||||
( \
|
||||
FNAME, \
|
||||
GENERATOR_NAME, \
|
||||
MAX_ARGS, \
|
||||
BOOST_PP_SUB(MAX_ARGS, MIN_ARGS) \
|
||||
)
|
||||
|
||||
#define BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(GENERATOR_NAME, FNAME, MIN_ARGS, MAX_ARGS) \
|
||||
BPL_IMPL_GEN_MEM_FUNCTION_STUB \
|
||||
( \
|
||||
FNAME, \
|
||||
GENERATOR_NAME, \
|
||||
MAX_ARGS, \
|
||||
BOOST_PP_SUB(MAX_ARGS, MIN_ARGS) \
|
||||
)
|
||||
|
||||
// deprecated macro names (to be removed)
|
||||
#define BOOST_PYTHON_FUNCTION_GENERATOR BOOST_PYTHON_FUNCTION_OVERLOADS
|
||||
#define BOOST_PYTHON_MEM_FUN_GENERATOR BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#endif // DEFAULTS_GEN_JDG20020807_HPP
|
||||
|
||||
|
||||
28
include/boost/python/detail/dependent.hpp
Normal file
28
include/boost/python/detail/dependent.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DEPENDENT_DWA200286_HPP
|
||||
# define DEPENDENT_DWA200286_HPP
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
// A way to turn a concrete type T into a type dependent on U. This
|
||||
// keeps conforming compilers (those implementing proper 2-phase
|
||||
// name lookup for templates) from complaining about incomplete
|
||||
// types in situations where it would otherwise be inconvenient or
|
||||
// impossible to re-order code so that all types are defined in time.
|
||||
|
||||
// One such use is when we must return an incomplete T from a member
|
||||
// function template (which must be defined in the class body to
|
||||
// keep MSVC happy).
|
||||
template <class T, class U>
|
||||
struct dependent
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // DEPENDENT_DWA200286_HPP
|
||||
83
include/boost/python/detail/destroy.hpp
Normal file
83
include/boost/python/detail/destroy.hpp
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DESTROY_DWA2002221_HPP
|
||||
# define DESTROY_DWA2002221_HPP
|
||||
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <bool array, bool trivial_destructor> struct value_destroyer;
|
||||
|
||||
template <>
|
||||
struct value_destroyer<false,false>
|
||||
{
|
||||
template <class T>
|
||||
static void execute(T const volatile* p)
|
||||
{
|
||||
p->T::~T();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct value_destroyer<true,false>
|
||||
{
|
||||
template <class A, class T>
|
||||
static void execute(A*, T const volatile* const first)
|
||||
{
|
||||
for (T const volatile* p = first; p != first + sizeof(A)/sizeof(T); ++p)
|
||||
value_destroyer<
|
||||
boost::is_array<T>::value
|
||||
,boost::has_trivial_destructor<T>::value
|
||||
>::execute(p);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void execute(T const volatile* p)
|
||||
{
|
||||
execute(p, *p);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct value_destroyer<true,true>
|
||||
{
|
||||
template <class T>
|
||||
static void execute(T const volatile* p)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct value_destroyer<false,true>
|
||||
{
|
||||
template <class T>
|
||||
static void execute(T const volatile* p)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline void destroy_referent_impl(void* p, T& (*)())
|
||||
{
|
||||
// note: cv-qualification needed for MSVC6
|
||||
// must come *before* T for metrowerks
|
||||
value_destroyer<
|
||||
(boost::is_array<T>::value)
|
||||
, (boost::has_trivial_destructor<T>::value)
|
||||
>::execute((const volatile T*)p);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void destroy_referent(void* p, T(*)() = 0)
|
||||
{
|
||||
destroy_referent_impl(p, (T(*)())0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // DESTROY_DWA2002221_HPP
|
||||
48
include/boost/python/detail/exception_handler.hpp
Normal file
48
include/boost/python/detail/exception_handler.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef EXCEPTION_HANDLER_DWA2002810_HPP
|
||||
# define EXCEPTION_HANDLER_DWA2002810_HPP
|
||||
|
||||
# include <boost/function/function0.hpp>
|
||||
# include <boost/function/function2.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct BOOST_PYTHON_DECL exception_handler;
|
||||
|
||||
typedef function2<bool, exception_handler const&, function0<void> const&> handler_function;
|
||||
|
||||
struct BOOST_PYTHON_DECL exception_handler
|
||||
{
|
||||
private: // types
|
||||
|
||||
public:
|
||||
explicit exception_handler(handler_function const& impl);
|
||||
|
||||
inline bool handle(function0<void> const& f) const;
|
||||
|
||||
bool operator()(function0<void> const& f) const;
|
||||
|
||||
static exception_handler* chain;
|
||||
|
||||
private:
|
||||
static exception_handler* tail;
|
||||
|
||||
handler_function m_impl;
|
||||
exception_handler* m_next;
|
||||
};
|
||||
|
||||
|
||||
inline bool exception_handler::handle(function0<void> const& f) const
|
||||
{
|
||||
return this->m_impl(*this, f);
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL void register_exception_handler(handler_function const& f);
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // EXCEPTION_HANDLER_DWA2002810_HPP
|
||||
33
include/boost/python/detail/force_instantiate.hpp
Executable file
33
include/boost/python/detail/force_instantiate.hpp
Executable file
@@ -0,0 +1,33 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FORCE_INSTANTIATE_DWA200265_HPP
|
||||
# define FORCE_INSTANTIATE_DWA200265_HPP
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
// Allows us to force the argument to be instantiated without
|
||||
// incurring unused variable warnings
|
||||
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC == 1200 || _MSC_FULL_VER > 13102196
|
||||
|
||||
template <class T>
|
||||
inline void force_instantiate(T const&) {}
|
||||
|
||||
# else
|
||||
|
||||
# pragma optimize("g", off)
|
||||
inline void force_instantiate_impl(...) {}
|
||||
# pragma optimize("", on)
|
||||
template <class T>
|
||||
inline void force_instantiate(T const& x)
|
||||
{
|
||||
detail::force_instantiate_impl(&x);
|
||||
}
|
||||
# endif
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // FORCE_INSTANTIATE_DWA200265_HPP
|
||||
389
include/boost/python/detail/indirect_traits.hpp
Normal file
389
include/boost/python/detail/indirect_traits.hpp
Normal file
@@ -0,0 +1,389 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef INDIRECT_TRAITS_DWA2002131_HPP
|
||||
# define INDIRECT_TRAITS_DWA2002131_HPP
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/type_traits/function_traits.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T>
|
||||
struct is_reference_to_const
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_const<T const&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
# if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
|
||||
template<class T>
|
||||
struct is_reference_to_const<T const volatile&>
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
# endif
|
||||
|
||||
# if 0 // Corresponding code doesn't work on MSVC yet
|
||||
template <class T>
|
||||
struct is_reference_to_function
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_function<T&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_function<T const&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_function<T volatile&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_function<T const volatile&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
|
||||
};
|
||||
# endif
|
||||
|
||||
template <class T>
|
||||
struct is_pointer_to_function
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_pointer_to_function<T*>
|
||||
{
|
||||
// There's no such thing as a pointer-to-cv-function, so we don't need specializations for those
|
||||
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_non_const
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
::boost::type_traits::ice_and<
|
||||
::boost::is_reference<T>::value
|
||||
, ::boost::type_traits::ice_not<
|
||||
::boost::python::detail::is_reference_to_const<T>::value>::value
|
||||
>::value)
|
||||
);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_volatile
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_volatile<T volatile&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
# if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
|
||||
template <class T>
|
||||
struct is_reference_to_volatile<T const volatile&>
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
# endif
|
||||
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer<T*&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer<T* const&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer<T* volatile&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer<T* const volatile&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_class
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (boost::type_traits::ice_and<
|
||||
is_reference<T>::value
|
||||
, is_class<
|
||||
typename remove_cv<
|
||||
typename remove_reference<T>::type
|
||||
>::type
|
||||
>::value
|
||||
>::value)
|
||||
);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_pointer_to_class
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (boost::type_traits::ice_and<
|
||||
is_pointer<T>::value
|
||||
, is_class<
|
||||
typename remove_cv<
|
||||
typename remove_pointer<T>::type
|
||||
>::type
|
||||
>::value
|
||||
>::value)
|
||||
);
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
typedef char (&inner_yes_type)[3];
|
||||
typedef char (&inner_no_type)[2];
|
||||
typedef char (&outer_no_type)[1];
|
||||
|
||||
template <typename V>
|
||||
struct is_const_help
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_const<V>::value
|
||||
, inner_yes_type
|
||||
, inner_no_type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
struct is_volatile_help
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_volatile<V>::value
|
||||
, inner_yes_type
|
||||
, inner_no_type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
struct is_pointer_help
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_pointer<V>::value
|
||||
, inner_yes_type
|
||||
, inner_no_type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
struct is_class_help
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_class<V>::value
|
||||
, inner_yes_type
|
||||
, inner_no_type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
# if 0 // doesn't seem to work yet
|
||||
template <class T>
|
||||
struct is_reference_to_function
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= sizeof(::boost::detail::is_function_tester(t)) == sizeof(::boost::type_traits::yes_type));
|
||||
# endif
|
||||
|
||||
template <class T>
|
||||
struct is_pointer_to_function
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= sizeof(::boost::detail::is_function_tester(t)) == sizeof(::boost::type_traits::yes_type));
|
||||
};
|
||||
|
||||
struct false_helper1
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
typename is_const_help<V>::type reference_to_const_helper(V&);
|
||||
outer_no_type
|
||||
reference_to_const_helper(...);
|
||||
|
||||
template <bool ref = true>
|
||||
struct is_reference_to_const_helper1
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= sizeof(reference_to_const_helper(t)) == sizeof(inner_yes_type));
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct is_reference_to_const_helper1<false> : false_helper1
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_const
|
||||
: is_reference_to_const_helper1<is_reference<T>::value>::template apply<T>
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <bool ref = true>
|
||||
struct is_reference_to_non_const_helper1
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= sizeof(reference_to_const_helper(t)) == sizeof(inner_no_type));
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct is_reference_to_non_const_helper1<false> : false_helper1
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_non_const
|
||||
: is_reference_to_non_const_helper1<is_reference<T>::value>::template apply<T>
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
template <typename V>
|
||||
typename is_volatile_help<V>::type reference_to_volatile_helper(V&);
|
||||
outer_no_type
|
||||
reference_to_volatile_helper(...);
|
||||
|
||||
template <bool ref = true>
|
||||
struct is_reference_to_volatile_helper1
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= sizeof(reference_to_volatile_helper(t)) == sizeof(inner_yes_type));
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct is_reference_to_volatile_helper1<false> : false_helper1
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_volatile
|
||||
: is_reference_to_volatile_helper1<is_reference<T>::value>::template apply<T>
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
template <typename V>
|
||||
typename is_pointer_help<V>::type reference_to_pointer_helper(V&);
|
||||
outer_no_type reference_to_pointer_helper(...);
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_pointer
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (is_reference<T>::value
|
||||
&& sizeof(reference_to_pointer_helper(t)) == sizeof(inner_yes_type))
|
||||
);
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
typename is_class_help<V>::type reference_to_class_helper(V const volatile&);
|
||||
outer_no_type reference_to_class_helper(...);
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_class
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (is_reference<T>::value
|
||||
&& sizeof(reference_to_class_helper(t)) == sizeof(inner_yes_type))
|
||||
);
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
typename is_class_help<V>::type pointer_to_class_helper(V const volatile*);
|
||||
outer_no_type pointer_to_class_helper(...);
|
||||
|
||||
template <class T>
|
||||
struct is_pointer_to_class
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (is_pointer<T>::value
|
||||
&& sizeof(pointer_to_class_helper(t)) == sizeof(inner_yes_type))
|
||||
);
|
||||
};
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // INDIRECT_TRAITS_DWA2002131_HPP
|
||||
31
include/boost/python/detail/make_tuple.hpp
Normal file
31
include/boost/python/detail/make_tuple.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
# // Copyright David Abrahams 2002. Permission to copy, use,
|
||||
# // modify, sell and distribute this software is granted provided this
|
||||
# // copyright notice appears in all copies. This software is provided
|
||||
# // "as is" without express or implied warranty, and with no claim as
|
||||
# // to its suitability for any purpose.
|
||||
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
# error Boost.Python - do not include this file!
|
||||
#endif
|
||||
|
||||
#define N BOOST_PP_ITERATION()
|
||||
|
||||
#define BOOST_PYTHON_MAKE_TUPLE_ARG(z, N, ignored) \
|
||||
PyTuple_SET_ITEM( \
|
||||
result.ptr() \
|
||||
, N \
|
||||
, python::incref(python::object(a##N).ptr()) \
|
||||
);
|
||||
|
||||
template <BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
tuple
|
||||
make_tuple(BOOST_PYTHON_BINARY_ENUM(N, A, const& a))
|
||||
{
|
||||
tuple result((detail::new_reference)::PyTuple_New(N));
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_MAKE_TUPLE_ARG, _)
|
||||
return result;
|
||||
}
|
||||
|
||||
#undef BOOST_PYTHON_MAKE_TUPLE_ARG
|
||||
|
||||
#undef N
|
||||
113
include/boost/python/detail/member_function_cast.hpp
Normal file
113
include/boost/python/detail/member_function_cast.hpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# ifndef MEMBER_FUNCTION_CAST_DWA2002311_HPP
|
||||
# define MEMBER_FUNCTION_CAST_DWA2002311_HPP
|
||||
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <class S, class FT>
|
||||
struct cast_helper
|
||||
{
|
||||
struct yes_helper
|
||||
{
|
||||
static FT stage3(FT x) { return x; }
|
||||
};
|
||||
|
||||
struct no_helper
|
||||
{
|
||||
template <class T>
|
||||
static T stage3(T x) { return x; }
|
||||
};
|
||||
|
||||
static yes_helper stage2(S*) { return yes_helper(); }
|
||||
static no_helper stage2(void*) { return no_helper(); }
|
||||
};
|
||||
|
||||
struct non_member_function_cast_impl
|
||||
{
|
||||
template <class T>
|
||||
static non_member_function_cast_impl stage1(T) { return non_member_function_cast_impl(); }
|
||||
|
||||
template <class T>
|
||||
static non_member_function_cast_impl stage2(T) { return non_member_function_cast_impl(); }
|
||||
|
||||
template <class T>
|
||||
T stage3(T x) { return x; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct member_function_cast_impl
|
||||
{
|
||||
# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
template <class U>
|
||||
static non_member_function_cast_impl stage1(U)
|
||||
{
|
||||
return non_member_function_cast_impl();
|
||||
}
|
||||
# endif
|
||||
|
||||
// Member functions
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 3, <boost/python/detail/member_function_cast.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
};
|
||||
|
||||
template <class T, class SF>
|
||||
struct member_function_cast
|
||||
# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
: member_function_cast_impl<T>
|
||||
# else
|
||||
: mpl::select_type<
|
||||
is_member_function_pointer<SF>::value
|
||||
, member_function_cast_impl<T>
|
||||
, non_member_function_cast_impl
|
||||
>::type
|
||||
# endif
|
||||
{
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
# endif // MEMBER_FUNCTION_CAST_DWA2002311_HPP
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
// outer over cv-qualifiers
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/member_function_cast.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 2
|
||||
# line BOOST_PP_LINE(__LINE__, member_function_cast.hpp)
|
||||
// inner over arities
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1))
|
||||
|
||||
template <
|
||||
class S, class R
|
||||
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)
|
||||
>
|
||||
static cast_helper<S, R (T::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q>
|
||||
stage1(R (S::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q)
|
||||
{
|
||||
return cast_helper<S, R (T::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q>();
|
||||
}
|
||||
|
||||
# undef N
|
||||
# undef Q
|
||||
|
||||
#endif
|
||||
45
include/boost/python/detail/module_base.hpp
Normal file
45
include/boost/python/detail/module_base.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MODULE_BASE_DWA2002227_HPP
|
||||
# define MODULE_BASE_DWA2002227_HPP
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/python/object_fwd.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
class BOOST_PYTHON_DECL module_base
|
||||
{
|
||||
public:
|
||||
// Create a module. REQUIRES: only one module is created per module.
|
||||
module_base(char const* name, char const* doc = 0);
|
||||
~module_base();
|
||||
|
||||
// Add elements to the module
|
||||
void add(type_handle const&); // just use the type's name
|
||||
|
||||
// Return a reference to the Python module object being built
|
||||
inline handle<> object() const;
|
||||
|
||||
protected:
|
||||
void setattr_doc(const char* name, python::object const&, char const* doc);
|
||||
|
||||
private:
|
||||
handle<> m_module;
|
||||
static PyMethodDef initial_methods[1];
|
||||
};
|
||||
|
||||
//
|
||||
// inline implementations
|
||||
//
|
||||
inline handle<> module_base::object() const
|
||||
{
|
||||
return m_module;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // MODULE_BASE_DWA2002227_HPP
|
||||
51
include/boost/python/detail/module_info.hpp
Normal file
51
include/boost/python/detail/module_info.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright David Hawkes 2002.
|
||||
// Permission is hereby granted to copy, use and modify this software
|
||||
// for any purpose, including commercial distribution, provided this
|
||||
// copyright notice is not removed. No warranty WHATSOEVER is provided with this
|
||||
// software. Any user(s) accepts this software "as is" and as such they will not
|
||||
// bind the author(s) to any claim of suitabilty for any purpose.
|
||||
|
||||
#ifndef MODULE_INFO
|
||||
# define MODULE_INFO
|
||||
|
||||
#include <boost/python/object.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
class module_info
|
||||
{
|
||||
public:
|
||||
module_info(const char *name)
|
||||
{
|
||||
m_module_name = name;
|
||||
}
|
||||
void set_module(object const& m)
|
||||
{
|
||||
if(!m_primary_module)
|
||||
m_primary_module = m;
|
||||
}
|
||||
object const& get_module() const
|
||||
{
|
||||
return m_primary_module;
|
||||
}
|
||||
void set_prior_module(object const& m)
|
||||
{
|
||||
m_prior_module = m;
|
||||
}
|
||||
object const& get_prior_module() const
|
||||
{
|
||||
return m_prior_module;
|
||||
}
|
||||
const char* get_module_name() const
|
||||
{
|
||||
return m_module_name;
|
||||
}
|
||||
private:
|
||||
object m_primary_module;
|
||||
object m_prior_module;
|
||||
const char* m_module_name;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif // MODULE_INFO
|
||||
53
include/boost/python/detail/module_init.hpp
Normal file
53
include/boost/python/detail/module_init.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifdef BOOST_PYTHON_V2
|
||||
# error obsolete
|
||||
#endif
|
||||
#ifndef MODULE_INIT_DWA2002529_HPP
|
||||
# define MODULE_INIT_DWA2002529_HPP
|
||||
|
||||
# ifndef BOOST_PYTHON_MODULE_INIT
|
||||
|
||||
# if defined(_WIN32) || defined(__CYGWIN__)
|
||||
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void init_module_##name(); \
|
||||
extern "C" __declspec(dllexport) void init##name() \
|
||||
{ \
|
||||
boost::python::handle_exception(&init_module_##name); \
|
||||
} \
|
||||
void init_module_##name()
|
||||
|
||||
# elif defined(_AIX)
|
||||
|
||||
# include <boost/python/detail/aix_init_module.hpp>
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void init_module_##name(); \
|
||||
extern "C" \
|
||||
{ \
|
||||
extern PyObject* _PyImport_LoadDynamicModule(char*, char*, FILE *); \
|
||||
void init##name() \
|
||||
{ \
|
||||
boost::python::detail::aix_init_module(_PyImport_LoadDynamicModule, &init_module_##name); \
|
||||
} \
|
||||
} \
|
||||
void init_module_##name()
|
||||
|
||||
# else
|
||||
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void init_module_##name(); \
|
||||
extern "C" void init##name() \
|
||||
{ \
|
||||
boost::python::handle_exception(&init_module_##name); \
|
||||
} \
|
||||
void init_module_##name()
|
||||
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
#endif // MODULE_INIT_DWA2002529_HPP
|
||||
63
include/boost/python/detail/preprocessor.hpp
Normal file
63
include/boost/python/detail/preprocessor.hpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef PREPROCESSOR_DWA200247_HPP
|
||||
# define PREPROCESSOR_DWA200247_HPP
|
||||
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
# include <boost/preprocessor/tuple/elem.hpp>
|
||||
|
||||
// stuff that should be in the preprocessor library
|
||||
|
||||
# define BOOST_PYTHON_APPLY(x) BOOST_PP_CAT(BOOST_PYTHON_APPLY_, x)
|
||||
|
||||
# define BOOST_PYTHON_APPLY_BOOST_PYTHON_ITEM(v) v
|
||||
# define BOOST_PYTHON_APPLY_BOOST_PYTHON_NIL
|
||||
|
||||
// cv-qualifiers
|
||||
|
||||
# if !defined(__MWERKS__) || __MWERKS__ > 0x2407
|
||||
# define BOOST_PYTHON_CV_COUNT 4
|
||||
# else
|
||||
# define BOOST_PYTHON_CV_COUNT 1
|
||||
# endif
|
||||
|
||||
# ifndef BOOST_PYTHON_MAX_ARITY
|
||||
# define BOOST_PYTHON_MAX_ARITY 15
|
||||
# endif
|
||||
|
||||
# define BOOST_PYTHON_CV_QUALIFIER(i) \
|
||||
BOOST_PYTHON_APPLY( \
|
||||
BOOST_PP_TUPLE_ELEM(4, i, BOOST_PYTHON_CV_QUALIFIER_I) \
|
||||
)
|
||||
|
||||
# define BOOST_PYTHON_CV_QUALIFIER_I \
|
||||
( \
|
||||
BOOST_PYTHON_NIL, \
|
||||
BOOST_PYTHON_ITEM(const), \
|
||||
BOOST_PYTHON_ITEM(volatile), \
|
||||
BOOST_PYTHON_ITEM(const volatile) \
|
||||
)
|
||||
|
||||
// enumerators
|
||||
# define BOOST_PYTHON_UNARY_ENUM(c, text) BOOST_PP_REPEAT(c, BOOST_PYTHON_UNARY_ENUM_I, text)
|
||||
# define BOOST_PYTHON_UNARY_ENUM_I(z, n, text) BOOST_PP_COMMA_IF(n) text ## n
|
||||
|
||||
# define BOOST_PYTHON_BINARY_ENUM(c, a, b) BOOST_PP_REPEAT(c, BOOST_PYTHON_BINARY_ENUM_I, (a, b))
|
||||
# define BOOST_PYTHON_BINARY_ENUM_I(z, n, _) BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, _), n) BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, _), n)
|
||||
|
||||
# define BOOST_PYTHON_ENUM_WITH_DEFAULT(c, text, def) BOOST_PP_REPEAT(c, BOOST_PYTHON_ENUM_WITH_DEFAULT_I, (text, def))
|
||||
# define BOOST_PYTHON_ENUM_WITH_DEFAULT_I(z, n, _) BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, _), n) = BOOST_PP_TUPLE_ELEM(2, 1, _)
|
||||
|
||||
// fixed text (no commas)
|
||||
# define BOOST_PYTHON_FIXED(z, n, text) text
|
||||
|
||||
// flags
|
||||
# define BOOST_PYTHON_FUNCTION_POINTER 0x0001
|
||||
# define BOOST_PYTHON_POINTER_TO_MEMBER 0x0002
|
||||
|
||||
#endif // PREPROCESSOR_DWA200247_HPP
|
||||
140
include/boost/python/detail/python22_fixed.h
Normal file
140
include/boost/python/detail/python22_fixed.h
Normal file
@@ -0,0 +1,140 @@
|
||||
// Copy of Python 2.2/2.2.1 Python.h .
|
||||
// Changes marked with "Boost.Python modification"
|
||||
#ifndef Py_PYTHON_H
|
||||
#define Py_PYTHON_H
|
||||
/* Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" { */
|
||||
|
||||
|
||||
/* Enable compiler features; switching on C lib defines doesn't work
|
||||
here, because the symbols haven't necessarily been defined yet. */
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
/* Forcing SUSv2 compatibility still produces problems on some
|
||||
platforms, True64 and SGI IRIX begin two of them, so for now the
|
||||
define is switched off. */
|
||||
#if 0
|
||||
#ifndef _XOPEN_SOURCE
|
||||
# define _XOPEN_SOURCE 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Include nearly all Python header files */
|
||||
|
||||
#include "patchlevel.h"
|
||||
#include "pyconfig.h"
|
||||
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
/* pyconfig.h may or may not define DL_IMPORT */
|
||||
#ifndef DL_IMPORT /* declarations for DLL import/export */
|
||||
#define DL_IMPORT(RTYPE) RTYPE
|
||||
#endif
|
||||
#ifndef DL_EXPORT /* declarations for DLL import/export */
|
||||
#define DL_EXPORT(RTYPE) RTYPE
|
||||
#endif
|
||||
|
||||
#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)
|
||||
#define _SGI_MP_SOURCE
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#ifndef NULL
|
||||
# error "Python.h requires that stdio.h define NULL."
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#if PY_MICRO_VERSION == 1 // Boost.Python modification: emulate Python 2.2
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#endif // Boost.Python modification: emulate Python 2.2
|
||||
|
||||
/* CAUTION: Build setups should ensure that NDEBUG is defined on the
|
||||
* compiler command line when building Python in release mode; else
|
||||
* assert() calls won't be removed.
|
||||
*/
|
||||
#include <assert.h>
|
||||
|
||||
#include "pyport.h"
|
||||
|
||||
#include "pymem.h"
|
||||
|
||||
#include "object.h"
|
||||
#include "objimpl.h"
|
||||
|
||||
#include "pydebug.h"
|
||||
|
||||
#include "unicodeobject.h"
|
||||
#include "intobject.h"
|
||||
#include "longobject.h"
|
||||
#include "floatobject.h"
|
||||
#ifndef WITHOUT_COMPLEX
|
||||
#include "complexobject.h"
|
||||
#endif
|
||||
#include "rangeobject.h"
|
||||
#include "stringobject.h"
|
||||
#include "bufferobject.h"
|
||||
#include "tupleobject.h"
|
||||
#include "listobject.h"
|
||||
#include "dictobject.h"
|
||||
#include "methodobject.h"
|
||||
#include "moduleobject.h"
|
||||
#include "funcobject.h"
|
||||
#include "classobject.h"
|
||||
#include "fileobject.h"
|
||||
#include "cobject.h"
|
||||
#include "traceback.h"
|
||||
#include "sliceobject.h"
|
||||
#include "cellobject.h"
|
||||
extern "C" { // Boost.Python modification: provide missing extern "C"
|
||||
#include "iterobject.h"
|
||||
#include "descrobject.h"
|
||||
} // Boost.Python modification: provide missing extern "C"
|
||||
#include "weakrefobject.h"
|
||||
|
||||
#include "codecs.h"
|
||||
#include "pyerrors.h"
|
||||
|
||||
#include "pystate.h"
|
||||
|
||||
#include "modsupport.h"
|
||||
#include "pythonrun.h"
|
||||
#include "ceval.h"
|
||||
#include "sysmodule.h"
|
||||
#include "intrcheck.h"
|
||||
#include "import.h"
|
||||
|
||||
#include "abstract.h"
|
||||
|
||||
#define PyArg_GetInt(v, a) PyArg_Parse((v), "i", (a))
|
||||
#define PyArg_NoArgs(v) PyArg_Parse(v, "")
|
||||
|
||||
/* Convert a possibly signed character to a nonnegative int */
|
||||
/* XXX This assumes characters are 8 bits wide */
|
||||
#ifdef __CHAR_UNSIGNED__
|
||||
#define Py_CHARMASK(c) (c)
|
||||
#else
|
||||
#define Py_CHARMASK(c) ((c) & 0xff)
|
||||
#endif
|
||||
|
||||
#include "pyfpe.h"
|
||||
|
||||
/* These definitions must match corresponding definitions in graminit.h.
|
||||
There's code in compile.c that checks that they are the same. */
|
||||
#define Py_single_input 256
|
||||
#define Py_file_input 257
|
||||
#define Py_eval_input 258
|
||||
|
||||
#ifdef HAVE_PTH
|
||||
/* GNU pth user-space thread support */
|
||||
#include <pth.h>
|
||||
#endif
|
||||
#endif /* !Py_PYTHON_H */
|
||||
33
include/boost/python/detail/raw_pyobject.hpp
Normal file
33
include/boost/python/detail/raw_pyobject.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef RAW_PYOBJECT_DWA2002628_HPP
|
||||
# define RAW_PYOBJECT_DWA2002628_HPP
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
//
|
||||
// Define some types which we can use to get around the vagaries of
|
||||
// PyObject*. We will use these to initialize object instances, and
|
||||
// keep them in namespace detail to make sure they stay out of the
|
||||
// hands of users. That is much simpler than trying to grant
|
||||
// friendship to all the appropriate parties.
|
||||
//
|
||||
|
||||
// New references are normally checked for null
|
||||
struct new_reference_t;
|
||||
typedef new_reference_t* new_reference;
|
||||
|
||||
// Borrowed references are assumed to be non-null
|
||||
struct borrowed_reference_t;
|
||||
typedef borrowed_reference_t* borrowed_reference;
|
||||
|
||||
// New references which aren't checked for null
|
||||
struct new_non_null_reference_t;
|
||||
typedef new_non_null_reference_t* new_non_null_reference;
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // RAW_PYOBJECT_DWA2002628_HPP
|
||||
75
include/boost/python/detail/referent_storage.hpp
Normal file
75
include/boost/python/detail/referent_storage.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REFERENT_STORAGE_DWA200278_HPP
|
||||
# define REFERENT_STORAGE_DWA200278_HPP
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct alignment_dummy;
|
||||
typedef void (*function_ptr)();
|
||||
typedef int (alignment_dummy::*member_ptr);
|
||||
typedef int (alignment_dummy::*member_function_ptr)();
|
||||
|
||||
# define BOOST_PYTHON_ALIGNER(T, n) \
|
||||
typename mpl::select_type< \
|
||||
sizeof(T) <= size, T, char>::type t##n
|
||||
|
||||
// Storage for size bytes, aligned to all fundamental types no larger than size
|
||||
template <std::size_t size>
|
||||
union aligned_storage
|
||||
{
|
||||
BOOST_PYTHON_ALIGNER(char, 0);
|
||||
BOOST_PYTHON_ALIGNER(short, 1);
|
||||
BOOST_PYTHON_ALIGNER(int, 2);
|
||||
BOOST_PYTHON_ALIGNER(long, 3);
|
||||
BOOST_PYTHON_ALIGNER(float, 4);
|
||||
BOOST_PYTHON_ALIGNER(double, 5);
|
||||
BOOST_PYTHON_ALIGNER(long double, 6);
|
||||
BOOST_PYTHON_ALIGNER(void*, 7);
|
||||
BOOST_PYTHON_ALIGNER(function_ptr, 8);
|
||||
BOOST_PYTHON_ALIGNER(member_ptr, 9);
|
||||
BOOST_PYTHON_ALIGNER(member_function_ptr, 10);
|
||||
char bytes[size];
|
||||
};
|
||||
|
||||
# undef BOOST_PYTHON_ALIGNER
|
||||
|
||||
// Compute the size of T's referent. We wouldn't need this at all,
|
||||
// but sizeof() is broken in CodeWarriors <= 8.0
|
||||
template <class T> struct referent_size;
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
template <class T>
|
||||
struct referent_size<T&>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
std::size_t, value = sizeof(T));
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
template <class T> struct referent_size
|
||||
{
|
||||
static T f();
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(f()));
|
||||
};
|
||||
|
||||
# endif
|
||||
|
||||
// A metafunction returning a POD type which can store U, where T ==
|
||||
// U&. If T is not a reference type, returns a POD which can store T.
|
||||
template <class T>
|
||||
struct referent_storage
|
||||
{
|
||||
typedef aligned_storage<referent_size<T>::value> type;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // REFERENT_STORAGE_DWA200278_HPP
|
||||
124
include/boost/python/detail/result.hpp
Executable file
124
include/boost/python/detail/result.hpp
Executable file
@@ -0,0 +1,124 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# ifndef RESULT_DWA2002521_HPP
|
||||
# define RESULT_DWA2002521_HPP
|
||||
|
||||
# include <boost/type.hpp>
|
||||
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
// Defines a family of overloaded function which, given x, a function
|
||||
// pointer, member [function] pointer, or an AdaptableFunction object,
|
||||
// returns a pointer to type<R>*, where R is the result type of
|
||||
// invoking the result of bind(x).
|
||||
//
|
||||
// In order to work around bugs in deficient compilers, if x might be
|
||||
// an AdaptableFunction object, you must pass OL as a second argument
|
||||
// to get this to work portably.
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/result.hpp>, BOOST_PYTHON_FUNCTION_POINTER))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, BOOST_PYTHON_CV_COUNT - 1, <boost/python/detail/result.hpp>, BOOST_PYTHON_POINTER_TO_MEMBER))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
template <class R, class T>
|
||||
boost::type<R>* result(R (T::*), int = 0) { return 0; }
|
||||
|
||||
# if (defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140) \
|
||||
|| (defined(__GNUC__) && __GNUC__ < 3) \
|
||||
|| (defined(__MWERKS__) && __MWERKS__ < 0x3000)
|
||||
// This code actually works on all implementations, but why use it when we don't have to?
|
||||
template <class T>
|
||||
struct get_result_type
|
||||
{
|
||||
typedef boost::type<typename T::result_type> type;
|
||||
};
|
||||
|
||||
struct void_type
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct result_result
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_class<T>::value
|
||||
, get_result_type<T>
|
||||
, void_type
|
||||
>::type t1;
|
||||
|
||||
typedef typename t1::type* type;
|
||||
};
|
||||
|
||||
template <class X>
|
||||
typename result_result<X>::type
|
||||
result(X const&, short) { return 0; }
|
||||
|
||||
# else // Simpler code for more-capable compilers
|
||||
template <class X>
|
||||
boost::type<typename X::result_type>*
|
||||
result(X const&, short = 0) { return 0; }
|
||||
|
||||
# endif
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
# endif // RESULT_DWA2002521_HPP
|
||||
|
||||
/* --------------- function pointers --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER
|
||||
# line BOOST_PP_LINE(__LINE__, result.hpp(function pointers))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template <class R BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
boost::type<R>* result(R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A)), int = 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
# undef N
|
||||
|
||||
/* --------------- pointers-to-members --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_POINTER_TO_MEMBER
|
||||
// Outer over cv-qualifiers
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/result.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 2
|
||||
# line BOOST_PP_LINE(__LINE__, result.hpp(pointers-to-members))
|
||||
// Inner over arities
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1))
|
||||
|
||||
template <class R, class T BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
boost::type<R>* result(R (T::*pmf)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q, int = 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
# undef N
|
||||
# undef Q
|
||||
|
||||
#endif
|
||||
215
include/boost/python/detail/returning.hpp
Normal file
215
include/boost/python/detail/returning.hpp
Normal file
@@ -0,0 +1,215 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// (C) Copyright David Abrahams 2001,2002. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
//
|
||||
// This work was funded in part by Lawrence Berkeley National Labs
|
||||
//
|
||||
// This file generated for 5-argument member functions and 6-argument free
|
||||
// functions by gen_returning.py
|
||||
|
||||
# ifndef RETURNING_DWA20011201_HPP
|
||||
# define RETURNING_DWA20011201_HPP
|
||||
|
||||
# include <boost/config.hpp>
|
||||
|
||||
# include <boost/python/arg_from_python.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/none.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/inc.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
# include <boost/mpl/apply.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
# define BOOST_PYTHON_RETURNING_NON_VOID 0x0004
|
||||
# define BOOST_PYTHON_RETURNING_VOID 0x0008
|
||||
|
||||
template <class R>
|
||||
struct returning
|
||||
{
|
||||
// Specializations for function pointers
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/returning.hpp>, \
|
||||
BOOST_PYTHON_FUNCTION_POINTER | BOOST_PYTHON_RETURNING_NON_VOID))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
// Specializations for member function pointers
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, 3, <boost/python/detail/returning.hpp>, \
|
||||
BOOST_PYTHON_POINTER_TO_MEMBER | BOOST_PYTHON_RETURNING_NON_VOID))
|
||||
# include BOOST_PP_ITERATE()
|
||||
};
|
||||
|
||||
template <>
|
||||
struct returning<void>
|
||||
{
|
||||
typedef void R;
|
||||
// Specializations for function pointers
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/returning.hpp>, \
|
||||
BOOST_PYTHON_FUNCTION_POINTER | BOOST_PYTHON_RETURNING_VOID))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
// Specializations for member function pointers
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, 3, <boost/python/detail/returning.hpp>, \
|
||||
BOOST_PYTHON_POINTER_TO_MEMBER | BOOST_PYTHON_RETURNING_VOID))
|
||||
# include BOOST_PP_ITERATE()
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
# undef BOOST_PYTHON_RETURNING_NON_VOID
|
||||
# undef BOOST_PYTHON_RETURNING_VOID
|
||||
|
||||
# endif // RETURNING_DWA20011201_HPP
|
||||
|
||||
// --------------- function pointers --------------- //
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && (BOOST_PP_ITERATION_FLAGS() & BOOST_PYTHON_FUNCTION_POINTER)
|
||||
# line BOOST_PP_LINE(__LINE__, returning.hpp(function pointers))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
# define BOOST_PYTHON_CALL_ARGS(z, n, _) \
|
||||
BOOST_PP_COMMA_IF(n) c##n(PyTuple_GET_ITEM(args_, n))
|
||||
|
||||
# define BOOST_PYTHON_CHECK_CONVERSION(z, n, _) \
|
||||
arg_from_python<A##n> c##n(PyTuple_GET_ITEM(args_, n)); \
|
||||
if (!c##n.convertible()) \
|
||||
return 0;
|
||||
|
||||
# if (BOOST_PP_ITERATION_FLAGS() & BOOST_PYTHON_RETURNING_NON_VOID)
|
||||
|
||||
template<class P BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
static PyObject* call(
|
||||
R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A))
|
||||
, PyObject* args_
|
||||
, PyObject*, P const* policies)
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_CHECK_CONVERSION, nil)
|
||||
|
||||
// find the result converter
|
||||
typedef typename P::result_converter result_converter;
|
||||
typename mpl::apply1<result_converter, R>::type cr;
|
||||
if (!cr.convertible() || !policies->precall(args_))
|
||||
return 0;
|
||||
PyObject* result = cr(
|
||||
(*pf)(BOOST_PP_REPEAT(N, BOOST_PYTHON_CALL_ARGS, nil))
|
||||
);
|
||||
return policies->postcall(args_, result);
|
||||
}
|
||||
# elif (BOOST_PP_ITERATION_FLAGS() & BOOST_PYTHON_RETURNING_VOID)
|
||||
|
||||
template<class P BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
static PyObject* call(
|
||||
R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A))
|
||||
, PyObject* args_
|
||||
, PyObject*, P const* policies)
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_CHECK_CONVERSION, nil)
|
||||
|
||||
if (!policies->precall(args_))
|
||||
return 0;
|
||||
(*pf)(BOOST_PP_REPEAT(N, BOOST_PYTHON_CALL_ARGS, nil));
|
||||
return policies->postcall(args_, detail::none());
|
||||
}
|
||||
# endif // returning void / non-void
|
||||
|
||||
# undef N
|
||||
# undef BOOST_PYTHON_CALL_ARGS
|
||||
# undef BOOST_PYTHON_CHECK_CONVERSION
|
||||
|
||||
// --------------- pointers to members --------------- //
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && (BOOST_PP_ITERATION_FLAGS() & BOOST_PYTHON_POINTER_TO_MEMBER)
|
||||
|
||||
// Outer iteration over cv-qualifications
|
||||
# define BOOST_PP_ITERATION_PARAMS_2 \
|
||||
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/returning.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 2 && BOOST_PP_RELATIVE_FLAGS(1) & BOOST_PYTHON_POINTER_TO_MEMBER
|
||||
# line BOOST_PP_LINE(__LINE__, returning.hpp(pointers-to-members))
|
||||
|
||||
// Inner iteration over arities
|
||||
# define N BOOST_PP_ITERATION()
|
||||
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1))
|
||||
|
||||
# define BOOST_PYTHON_CALL_ARGS(z, n, _) \
|
||||
BOOST_PP_COMMA_IF(n) c##n(PyTuple_GET_ITEM(args_, BOOST_PP_INC(n)))
|
||||
|
||||
# define BOOST_PYTHON_CHECK_CONVERSION(z, n, _) \
|
||||
arg_from_python<A##n> c##n(PyTuple_GET_ITEM(args_, BOOST_PP_INC(n))); \
|
||||
if (!c##n.convertible()) \
|
||||
return 0;
|
||||
|
||||
# if (BOOST_PP_RELATIVE_FLAGS(1) & BOOST_PYTHON_RETURNING_NON_VOID)
|
||||
|
||||
template<class P, class T BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
static PyObject* call(
|
||||
R (T::*pmf)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q
|
||||
, PyObject* args_
|
||||
, PyObject*, P const* policies)
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
// self is special
|
||||
arg_from_python<T&> ct(PyTuple_GET_ITEM(args_, 0));
|
||||
if (!ct.convertible())
|
||||
return 0;
|
||||
|
||||
// unroll a loop for the rest of them
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_CHECK_CONVERSION, nil)
|
||||
|
||||
// find the result converter
|
||||
typedef typename P::result_converter result_converter;
|
||||
typename mpl::apply1<result_converter, R>::type cr;
|
||||
if (!cr.convertible() || !policies->precall(args_))
|
||||
return 0;
|
||||
PyObject* result = cr(
|
||||
((ct(PyTuple_GET_ITEM(args_, 0))).*pmf)(
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_CALL_ARGS, nil))
|
||||
);
|
||||
return policies->postcall(args_, result);
|
||||
}
|
||||
# elif (BOOST_PP_RELATIVE_FLAGS(1) & BOOST_PYTHON_RETURNING_VOID)
|
||||
|
||||
template<class P, class T BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
static PyObject* call(
|
||||
R (T::*pmf)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q
|
||||
, PyObject* args_
|
||||
, PyObject*, P const* policies)
|
||||
{
|
||||
// check that each of the arguments is convertible
|
||||
// self is special
|
||||
arg_from_python<T&> ct(PyTuple_GET_ITEM(args_, 0));
|
||||
if (!ct.convertible())
|
||||
return 0;
|
||||
|
||||
// unroll a loop for the rest of them
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_CHECK_CONVERSION, nil)
|
||||
|
||||
if (!policies->precall(args_))
|
||||
return 0;
|
||||
|
||||
((ct(PyTuple_GET_ITEM(args_, 0))).*pmf)(
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_CALL_ARGS, nil));
|
||||
return policies->postcall(args_, detail::none());
|
||||
}
|
||||
# endif
|
||||
|
||||
# undef N
|
||||
# undef Q
|
||||
# undef BOOST_PYTHON_CALL_ARGS
|
||||
# undef BOOST_PYTHON_CHECK_CONVERSION
|
||||
|
||||
#endif
|
||||
90
include/boost/python/detail/string_literal.hpp
Normal file
90
include/boost/python/detail/string_literal.hpp
Normal file
@@ -0,0 +1,90 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef STRING_LITERAL_DWA2002629_HPP
|
||||
# define STRING_LITERAL_DWA2002629_HPP
|
||||
|
||||
# include <cstddef>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/type_traits/array_traits.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T>
|
||||
struct is_string_literal
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
# if !defined(__MWERKS__) || __MWERKS__ > 0x2407
|
||||
template <std::size_t n>
|
||||
struct is_string_literal<char const[n]>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
# if (defined(__DECCXX_VER) && __DECCXX_VER <= 60590014) \
|
||||
|| (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
|
||||
// This compiler mistakenly gets the type of string literals as char*
|
||||
// instead of char[NN].
|
||||
template <>
|
||||
struct is_string_literal<char* const>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
# endif
|
||||
|
||||
# else
|
||||
|
||||
// CWPro7 has trouble with the array type deduction above
|
||||
template <class T, std::size_t n>
|
||||
struct is_string_literal<T[n]>
|
||||
: is_same<T, char const>
|
||||
{
|
||||
};
|
||||
# endif
|
||||
# else
|
||||
template <bool is_array = true>
|
||||
struct string_literal_helper
|
||||
{
|
||||
typedef char (&yes_string_literal)[1];
|
||||
typedef char (&no_string_literal)[2];
|
||||
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef apply<T> self;
|
||||
static T x;
|
||||
static yes_string_literal check(char const*);
|
||||
static no_string_literal check(char*);
|
||||
static no_string_literal check(void const volatile*);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = sizeof(self::check(x)) == sizeof(yes_string_literal));
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct string_literal_helper<false>
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_string_literal
|
||||
: string_literal_helper<is_array<T>::value>::apply<T>
|
||||
{
|
||||
};
|
||||
# endif
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // STRING_LITERAL_DWA2002629_HPP
|
||||
75
include/boost/python/detail/target.hpp
Normal file
75
include/boost/python/detail/target.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# ifndef TARGET_DWA2002521_HPP
|
||||
# define TARGET_DWA2002521_HPP
|
||||
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
|
||||
# include <boost/type.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/target.hpp>, BOOST_PYTHON_FUNCTION_POINTER))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(4, (0, BOOST_PYTHON_CV_COUNT - 1, <boost/python/detail/target.hpp>, BOOST_PYTHON_POINTER_TO_MEMBER))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
template <class R, class T>
|
||||
boost::type<T*>* target(R (T::*)) { return 0; }
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
# endif // TARGET_DWA2002521_HPP
|
||||
|
||||
/* --------------- function pointers --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER
|
||||
# line BOOST_PP_LINE(__LINE__, target.hpp(function_pointers))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template <class R BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
boost::type<BOOST_PP_IF(N, A0, void)>* target(R (*)(BOOST_PYTHON_UNARY_ENUM(N, A)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
# undef N
|
||||
|
||||
/* --------------- pointers-to-members --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_POINTER_TO_MEMBER
|
||||
// Outer over cv-qualifiers
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/target.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 2
|
||||
# line BOOST_PP_LINE(__LINE__, target.hpp(pointers-to-members))
|
||||
// Inner over arities
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1))
|
||||
|
||||
template <class R, class T BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
boost::type<T Q*>* target(R (T::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
# undef N
|
||||
# undef Q
|
||||
|
||||
#endif
|
||||
45
include/boost/python/detail/translate_exception.hpp
Normal file
45
include/boost/python/detail/translate_exception.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef TRANSLATE_EXCEPTION_DWA2002810_HPP
|
||||
# define TRANSLATE_EXCEPTION_DWA2002810_HPP
|
||||
|
||||
# include <boost/python/detail/exception_handler.hpp>
|
||||
# include <boost/function/function0.hpp>
|
||||
# include <boost/call_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
// A ternary function object used to translate C++ exceptions of type
|
||||
// ExceptionType into Python exceptions by invoking an object of type
|
||||
// Translate. Typically the translate function will be curried with
|
||||
// boost::bind().
|
||||
template <class ExceptionType, class Translate>
|
||||
struct translate_exception
|
||||
{
|
||||
typedef typename add_reference<
|
||||
typename add_const<ExceptionType>::type
|
||||
>::type exception_cref;
|
||||
|
||||
inline bool operator()(
|
||||
exception_handler const& handler
|
||||
, function0<void> const& f
|
||||
, typename call_traits<Translate>::param_type translate) const
|
||||
{
|
||||
try
|
||||
{
|
||||
return handler(f);
|
||||
}
|
||||
catch(exception_cref e)
|
||||
{
|
||||
translate(e);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // TRANSLATE_EXCEPTION_DWA2002810_HPP
|
||||
116
include/boost/python/detail/type_list_utils.hpp
Normal file
116
include/boost/python/detail/type_list_utils.hpp
Normal file
@@ -0,0 +1,116 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
#ifndef TYPE_LIST_UTILS_JDG20020826_HPP
|
||||
#define TYPE_LIST_UTILS_JDG20020826_HPP
|
||||
|
||||
# include <boost/mpl/at.hpp>
|
||||
# include <boost/mpl/size.hpp>
|
||||
//# include <boost/mpl/pop_front.hpp>
|
||||
//# include <boost/mpl/pop_back.hpp>
|
||||
|
||||
# include <boost/preprocessor/enum_params.hpp>
|
||||
# include <boost/preprocessor/enum_shifted_params.hpp>
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/dec.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
# include <boost/mpl/type_list.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
# if (!defined(__EDG_VERSION__) || __EDG_VERSION__ > 245) \
|
||||
&& (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600)
|
||||
|
||||
template <int N, class L>
|
||||
struct type_at : public boost::mpl::at<N, L> {};
|
||||
|
||||
template <class L>
|
||||
struct type_list_size : public boost::mpl::size<L> {};
|
||||
|
||||
// template <class L>
|
||||
// struct pop_front : public boost::mpl::pop_front<L> {};
|
||||
//
|
||||
// template <class L>
|
||||
// struct pop_back : public boost::mpl::pop_back<L> {};
|
||||
|
||||
# else
|
||||
|
||||
template <int N, class L>
|
||||
struct type_at {};
|
||||
|
||||
template <class L>
|
||||
struct type_list_size {};
|
||||
|
||||
// template <class L>
|
||||
// struct pop_front {};
|
||||
//
|
||||
// template <class L>
|
||||
// struct pop_back {};
|
||||
|
||||
// template <class L, class T>
|
||||
// struct push_back {};
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/type_list_utils.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# endif
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // TYPE_LIST_UTILS_JDG20020826_HPP
|
||||
|
||||
#else // defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
# if (N < BOOST_PYTHON_MAX_ARITY-1)
|
||||
|
||||
template <BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_ARITY, class A)>
|
||||
struct type_at<N, boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_ARITY, A)> >
|
||||
{
|
||||
typedef BOOST_PP_CAT(A, N) type;
|
||||
};
|
||||
|
||||
// template <BOOST_PP_ENUM_PARAMS(N, class A) BOOST_PP_COMMA_IF(N) class T>
|
||||
// struct push_back<boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(N, A)>, T>
|
||||
// {
|
||||
// typedef boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(N, A) BOOST_PP_COMMA_IF(N) T> sequence;
|
||||
// };
|
||||
|
||||
# if (N > 0)
|
||||
|
||||
// template <BOOST_PP_ENUM_PARAMS(N, class A)>
|
||||
// struct pop_front<boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(N, A)> >
|
||||
// {
|
||||
// typedef boost::mpl::type_list<BOOST_PP_ENUM_SHIFTED_PARAMS(N, A)> sequence;
|
||||
// };
|
||||
//
|
||||
// template <BOOST_PP_ENUM_PARAMS(N, class A)>
|
||||
// struct pop_back<boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(N, A)> >
|
||||
// {
|
||||
// typedef boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(N), A)> sequence;
|
||||
// };
|
||||
|
||||
# endif
|
||||
# endif
|
||||
|
||||
template <BOOST_PP_ENUM_PARAMS(N, class A)>
|
||||
struct type_list_size<boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(N, A)> >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(long, value = N);
|
||||
};
|
||||
|
||||
# undef N
|
||||
|
||||
#endif // !defined(BOOST_PP_IS_ITERATING)
|
||||
43
include/boost/python/detail/void_return.hpp
Normal file
43
include/boost/python/detail/void_return.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef VOID_RETURN_DWA200274_HPP
|
||||
# define VOID_RETURN_DWA200274_HPP
|
||||
|
||||
# include <boost/config.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct void_return
|
||||
{
|
||||
void_return() {}
|
||||
private:
|
||||
void operator=(void_return const&);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct returnable
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
# ifdef BOOST_NO_VOID_RETURNS
|
||||
template <>
|
||||
struct returnable<void>
|
||||
{
|
||||
typedef void_return type;
|
||||
};
|
||||
|
||||
# ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
|
||||
template <> struct returnable<const void> : returnable<void> {};
|
||||
template <> struct returnable<volatile void> : returnable<void> {};
|
||||
template <> struct returnable<const volatile void> : returnable<void> {};
|
||||
# endif
|
||||
|
||||
# endif // BOOST_NO_VOID_RETURNS
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // VOID_RETURN_DWA200274_HPP
|
||||
153
include/boost/python/detail/wrap_python.hpp
Normal file
153
include/boost/python/detail/wrap_python.hpp
Normal file
@@ -0,0 +1,153 @@
|
||||
// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
//
|
||||
// The author gratefully acknowleges the support of Dragon Systems, Inc., in
|
||||
// producing this work.
|
||||
|
||||
// This file serves as a wrapper around <Python.h> which allows it to be
|
||||
// compiled with GCC 2.95.2 under Win32 and which disables the default MSVC
|
||||
// behavior so that a program may be compiled in debug mode without requiring a
|
||||
// special debugging build of the Python library.
|
||||
|
||||
|
||||
// To use the Python debugging library, #define BOOST_DEBUG_PYTHON on the
|
||||
// compiler command-line.
|
||||
|
||||
// Revision History:
|
||||
// 05 Mar 01 Suppress warnings under Cygwin with Python 2.0 (Dave Abrahams)
|
||||
// 04 Mar 01 Rolled in some changes from the Dragon fork (Dave Abrahams)
|
||||
// 01 Mar 01 define PyObject_INIT() for Python 1.x (Dave Abrahams)
|
||||
|
||||
//
|
||||
// Python's LongObject.h helpfully #defines ULONGLONG_MAX for us,
|
||||
// which confuses Boost's config
|
||||
//
|
||||
#include <limits.h>
|
||||
#ifndef ULONG_MAX
|
||||
# define BOOST_PYTHON_ULONG_MAX_UNDEFINED
|
||||
#endif
|
||||
#ifndef LONGLONG_MAX
|
||||
# define BOOST_PYTHON_LONGLONG_MAX_UNDEFINED
|
||||
#endif
|
||||
#ifndef ULONGLONG_MAX
|
||||
# define BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED
|
||||
#endif
|
||||
|
||||
//
|
||||
// Get ahold of Python's version number
|
||||
//
|
||||
#include <patchlevel.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
# ifndef BOOST_DEBUG_PYTHON
|
||||
# undef _DEBUG // Don't let Python force the debug library just because we're debugging.
|
||||
# define DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H
|
||||
# endif
|
||||
#endif
|
||||
|
||||
//
|
||||
// Some things we need in order to get Python.h to work with compilers other
|
||||
// than MSVC on Win32
|
||||
//
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
# if defined(__GNUC__) && defined(__CYGWIN__)
|
||||
|
||||
# define SIZEOF_LONG 4
|
||||
|
||||
# if PY_MAJOR_VERSION < 2 || PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 2
|
||||
|
||||
typedef int pid_t;
|
||||
|
||||
# define WORD_BIT 32
|
||||
# define hypot _hypot
|
||||
# include <stdio.h>
|
||||
|
||||
# if PY_MAJOR_VERSION < 2
|
||||
# define HAVE_CLOCK
|
||||
# define HAVE_STRFTIME
|
||||
# define HAVE_STRERROR
|
||||
# endif
|
||||
|
||||
# define NT_THREADS
|
||||
|
||||
# ifndef NETSCAPE_PI
|
||||
# define USE_SOCKET
|
||||
# endif
|
||||
|
||||
# ifdef USE_DL_IMPORT
|
||||
# define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
|
||||
# endif
|
||||
|
||||
# ifdef USE_DL_EXPORT
|
||||
# define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
|
||||
# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
|
||||
# endif
|
||||
|
||||
# define HAVE_LONG_LONG 1
|
||||
# define LONG_LONG long long
|
||||
# endif
|
||||
|
||||
# elif defined(__MWERKS__)
|
||||
|
||||
# ifndef _MSC_VER
|
||||
# define PY_MSC_VER_DEFINED_FROM_WRAP_PYTHON_H 1
|
||||
# define _MSC_VER 900
|
||||
# endif
|
||||
|
||||
# if PY_MAJOR_VERSION < 2 || PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 2
|
||||
# include <config.h>
|
||||
# else
|
||||
# include <pyconfig.h>
|
||||
# endif
|
||||
# undef hypot // undo the evil #define left by Python.
|
||||
|
||||
# elif defined(__BORLANDC__)
|
||||
# if PY_MAJOR_VERSION < 2 || PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 2
|
||||
# include <config.h>
|
||||
# else
|
||||
# include <pyconfig.h>
|
||||
# endif
|
||||
# undef HAVE_HYPOT
|
||||
# define HAVE_HYPOT 1
|
||||
# endif
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#ifdef BOOST_PYTHON_ULONG_MAX_UNDEFINED
|
||||
# undef ULONG_MAX
|
||||
# undef BOOST_PYTHON_ULONG_MAX_UNDEFINED
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_PYTHON_LONGLONG_MAX_UNDEFINED
|
||||
# undef LONGLONG_MAX
|
||||
# undef BOOST_PYTHON_LONGLONG_MAX_UNDEFINED
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED
|
||||
# undef ULONGLONG_MAX
|
||||
# undef BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED
|
||||
#endif
|
||||
|
||||
#ifdef PY_MSC_VER_DEFINED_FROM_WRAP_PYTHON_H
|
||||
# undef _MSC_VER
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H
|
||||
# undef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H
|
||||
# define _DEBUG
|
||||
#endif
|
||||
|
||||
#if !defined(PY_MAJOR_VERSION) || PY_MAJOR_VERSION < 2
|
||||
# define PyObject_INIT(op, typeobj) \
|
||||
( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
|
||||
#endif
|
||||
|
||||
#ifdef __MWERKS__
|
||||
# pragma warn_possunwant off
|
||||
#elif _MSC_VER
|
||||
# pragma warning(disable:4786)
|
||||
#endif
|
||||
130
include/boost/python/dict.hpp
Normal file
130
include/boost/python/dict.hpp
Normal file
@@ -0,0 +1,130 @@
|
||||
#ifndef DICT_20020706_HPP
|
||||
#define DICT_20020706_HPP
|
||||
|
||||
#include <boost/python/object.hpp>
|
||||
#include <boost/python/list.hpp>
|
||||
#include <boost/python/tuple.hpp>
|
||||
#include <boost/python/converter/pytype_object_mgr_traits.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
class dict : public object
|
||||
{
|
||||
public:
|
||||
// dict() -> new empty dictionary.
|
||||
// dict(mapping) -> new dictionary initialized from a mapping object's
|
||||
// (key, value) pairs.
|
||||
// dict(seq) -> new dictionary initialized as if via:
|
||||
BOOST_PYTHON_DECL dict(); // new dict
|
||||
explicit BOOST_PYTHON_DECL dict(object_cref data);
|
||||
|
||||
template <class T>
|
||||
explicit dict(T const& data)
|
||||
: object(dict::call(object(data)))
|
||||
{
|
||||
}
|
||||
|
||||
// D.clear() -> None. Remove all items from D.
|
||||
BOOST_PYTHON_DECL void clear();
|
||||
|
||||
// D.copy() -> a shallow copy of D
|
||||
BOOST_PYTHON_DECL dict copy();
|
||||
|
||||
// D.get(k[,d]) -> D[k] if D.has_key(k), else d. d defaults to None.
|
||||
BOOST_PYTHON_DECL object get(object_cref k) const;
|
||||
|
||||
template<class T>
|
||||
object get(T const& k) const
|
||||
{
|
||||
return this->get(object(k));
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL object get(object_cref k, object_cref d) const;
|
||||
|
||||
template<class T1, class T2>
|
||||
object get(T1 const& k, T2 const& d) const
|
||||
{
|
||||
return this->get(object(k),object(d));
|
||||
}
|
||||
|
||||
// D.has_key(k) -> 1 if D has a key k, else 0
|
||||
BOOST_PYTHON_DECL bool has_key(object_cref k) const;
|
||||
|
||||
template<class T>
|
||||
bool has_key(T const& k) const
|
||||
{
|
||||
return this->has_key(object(k));
|
||||
}
|
||||
|
||||
// D.items() -> list of D's (key, value) pairs, as 2-tuples
|
||||
BOOST_PYTHON_DECL list items() const;
|
||||
|
||||
// D.iteritems() -> an iterator over the (key, value) items of D
|
||||
BOOST_PYTHON_DECL object iteritems() const;
|
||||
|
||||
// D.iterkeys() -> an iterator over the keys of D
|
||||
BOOST_PYTHON_DECL object iterkeys() const;
|
||||
|
||||
// D.itervalues() -> an iterator over the values of D
|
||||
BOOST_PYTHON_DECL object itervalues() const;
|
||||
|
||||
// D.keys() -> list of D's keys
|
||||
BOOST_PYTHON_DECL list keys() const;
|
||||
|
||||
// D.popitem() -> (k, v), remove and return some (key, value) pair as a
|
||||
// 2-tuple; but raise KeyError if D is empty
|
||||
BOOST_PYTHON_DECL tuple popitem();
|
||||
|
||||
// D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if not D.has_key(k)
|
||||
BOOST_PYTHON_DECL object setdefault(object_cref k);
|
||||
|
||||
template<class T>
|
||||
object setdefault(T const& k)
|
||||
{
|
||||
return this->setdefault(object(k));
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL object setdefault(object_cref k, object_cref d);
|
||||
|
||||
template<class T1, class T2>
|
||||
object setdefault(T1 const& k, T2 const& d)
|
||||
{
|
||||
return this->setdefault(object(k),object(d));
|
||||
}
|
||||
|
||||
// D.update(E) -> None. Update D from E: for k in E.keys(): D[k] = E[k]
|
||||
BOOST_PYTHON_DECL void update(object_cref E);
|
||||
|
||||
template<class T>
|
||||
void update(T const& E)
|
||||
{
|
||||
this->update(object(E));
|
||||
}
|
||||
|
||||
// D.values() -> list of D's values
|
||||
BOOST_PYTHON_DECL list values() const;
|
||||
|
||||
public: // implementation detail -- for internal use only
|
||||
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict)
|
||||
|
||||
private:
|
||||
static BOOST_PYTHON_DECL detail::new_reference call(object const&);
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Converter Specializations
|
||||
//
|
||||
namespace converter
|
||||
{
|
||||
template <>
|
||||
struct object_manager_traits<dict>
|
||||
: pytype_object_manager_traits<&PyDict_Type,dict>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif
|
||||
|
||||
76
include/boost/python/enum.hpp
Normal file
76
include/boost/python/enum.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ENUM_DWA200298_HPP
|
||||
# define ENUM_DWA200298_HPP
|
||||
|
||||
# include <boost/python/object/enum_base.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T>
|
||||
struct enum_ : public objects::enum_base
|
||||
{
|
||||
enum_(char const* name);
|
||||
inline enum_<T>& value(char const* name, T);
|
||||
|
||||
private:
|
||||
static PyObject* to_python(void const* x);
|
||||
static void* convertible(PyObject* obj);
|
||||
static void construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline enum_<T>::enum_(char const* name)
|
||||
: enum_base(
|
||||
name
|
||||
, &enum_<T>::to_python
|
||||
, &enum_<T>::convertible
|
||||
, &enum_<T>::construct
|
||||
, type_id<T>())
|
||||
{
|
||||
}
|
||||
|
||||
// This is the conversion function that gets registered for converting
|
||||
template <class T>
|
||||
PyObject* enum_<T>::to_python(void const* x)
|
||||
{
|
||||
return enum_base::to_python(
|
||||
converter::registered<T>::converters.class_object
|
||||
, static_cast<long>(*(T const*)x));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void* enum_<T>::convertible(PyObject* obj)
|
||||
{
|
||||
return PyObject_IsInstance(
|
||||
obj
|
||||
, upcast<PyObject>(
|
||||
converter::registered<T>::converters.class_object))
|
||||
|
||||
? obj : 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void enum_<T>::construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data)
|
||||
{
|
||||
T x = static_cast<T>(PyInt_AS_LONG(obj));
|
||||
void* const storage = ((converter::rvalue_from_python_storage<T>*)data)->storage.bytes;
|
||||
new (storage) T(x);
|
||||
data->convertible = storage;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline enum_<T>& enum_<T>::value(char const* name, T x)
|
||||
{
|
||||
this->add_value(name, static_cast<long>(x));
|
||||
return *this;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // ENUM_DWA200298_HPP
|
||||
57
include/boost/python/errors.hpp
Normal file
57
include/boost/python/errors.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
//
|
||||
// The author gratefully acknowleges the support of Dragon Systems, Inc., in
|
||||
// producing this work.
|
||||
|
||||
#ifndef ERRORS_DWA052500_H_
|
||||
# define ERRORS_DWA052500_H_
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/function/function0.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
struct BOOST_PYTHON_DECL error_already_set {};
|
||||
struct BOOST_PYTHON_DECL argument_error : error_already_set {};
|
||||
|
||||
// Handles exceptions caught just before returning to Python code.
|
||||
// Returns true iff an exception was caught.
|
||||
BOOST_PYTHON_DECL bool handle_exception_impl(function0<void>);
|
||||
|
||||
template <class T>
|
||||
bool handle_exception(T f)
|
||||
{
|
||||
return handle_exception_impl(function0<void>(boost::ref(f)));
|
||||
}
|
||||
|
||||
namespace detail { inline void rethrow() { throw; } }
|
||||
|
||||
inline void handle_exception()
|
||||
{
|
||||
handle_exception(detail::rethrow);
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL void throw_argument_error();
|
||||
BOOST_PYTHON_DECL void throw_error_already_set();
|
||||
|
||||
template <class T>
|
||||
inline T* expect_non_null(T* x)
|
||||
{
|
||||
if (x == 0)
|
||||
throw_error_already_set();
|
||||
return x;
|
||||
}
|
||||
|
||||
# ifdef BOOST_PYTHON_V2
|
||||
// Return source if it is an instance of pytype; throw an appropriate
|
||||
// exception otherwise.
|
||||
BOOST_PYTHON_DECL PyObject* pytype_check(PyTypeObject* pytype, PyObject* source);
|
||||
# endif
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // ERRORS_DWA052500_H_
|
||||
25
include/boost/python/exception_translator.hpp
Normal file
25
include/boost/python/exception_translator.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef EXCEPTION_TRANSLATOR_DWA2002810_HPP
|
||||
# define EXCEPTION_TRANSLATOR_DWA2002810_HPP
|
||||
# include <boost/python/detail/translate_exception.hpp>
|
||||
# include <boost/python/detail/exception_handler.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/bind.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class ExceptionType, class Translate>
|
||||
void register_exception_translator(Translate const& translate, boost::type<ExceptionType>* = 0)
|
||||
{
|
||||
detail::register_exception_handler(
|
||||
bind<bool>(detail::translate_exception<ExceptionType,Translate>(), _1, _2, translate)
|
||||
);
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // EXCEPTION_TRANSLATOR_DWA2002810_HPP
|
||||
240
include/boost/python/extract.hpp
Normal file
240
include/boost/python/extract.hpp
Normal file
@@ -0,0 +1,240 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef EXTRACT_DWA200265_HPP
|
||||
# define EXTRACT_DWA200265_HPP
|
||||
|
||||
# include <boost/python/converter/object_manager.hpp>
|
||||
# include <boost/python/converter/from_python.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_data.hpp>
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
# include <boost/python/converter/registered_pointee.hpp>
|
||||
# include <boost/python/detail/void_ptr.hpp>
|
||||
# include <boost/call_traits.hpp>
|
||||
# include <boost/python/detail/void_return.hpp>
|
||||
# include <boost/python/object_core.hpp>
|
||||
# include <boost/python/refcount.hpp>
|
||||
# include <boost/utility.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace converter
|
||||
{
|
||||
template <class Ptr>
|
||||
struct extract_pointer
|
||||
{
|
||||
typedef Ptr result_type;
|
||||
extract_pointer(PyObject*);
|
||||
|
||||
bool check() const;
|
||||
Ptr operator()() const;
|
||||
|
||||
private:
|
||||
PyObject* m_source;
|
||||
void* m_result;
|
||||
};
|
||||
|
||||
template <class Ref>
|
||||
struct extract_reference
|
||||
{
|
||||
typedef Ref result_type;
|
||||
extract_reference(PyObject*);
|
||||
|
||||
bool check() const;
|
||||
Ref operator()() const;
|
||||
|
||||
private:
|
||||
PyObject* m_source;
|
||||
void* m_result;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct extract_rvalue : private noncopyable
|
||||
{
|
||||
typedef typename call_traits<T>::param_type result_type;
|
||||
extract_rvalue(PyObject*);
|
||||
|
||||
bool check() const;
|
||||
result_type operator()() const;
|
||||
private:
|
||||
PyObject* m_source;
|
||||
mutable rvalue_from_python_data<T> m_data;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct extract_object_manager
|
||||
{
|
||||
typedef T result_type;
|
||||
extract_object_manager(PyObject*);
|
||||
|
||||
bool check() const;
|
||||
result_type operator()() const;
|
||||
private:
|
||||
PyObject* m_source;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct select_extract
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, obj_mgr = is_object_manager<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ptr = is_pointer<T>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, ref = is_reference<T>::value);
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
obj_mgr
|
||||
, extract_object_manager<T>
|
||||
, typename mpl::select_type<
|
||||
ptr
|
||||
, extract_pointer<T>
|
||||
, typename mpl::select_type<
|
||||
ref
|
||||
, extract_reference<T>
|
||||
, extract_rvalue<T>
|
||||
>::type
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct extract
|
||||
: converter::select_extract<T>::type
|
||||
{
|
||||
private:
|
||||
typedef typename converter::select_extract<T>::type base;
|
||||
public:
|
||||
typedef typename base::result_type result_type;
|
||||
|
||||
operator result_type() const
|
||||
{
|
||||
return (*this)();
|
||||
}
|
||||
|
||||
extract(PyObject*);
|
||||
extract(object const&);
|
||||
};
|
||||
|
||||
//
|
||||
// Implementations
|
||||
//
|
||||
template <class T>
|
||||
inline extract<T>::extract(PyObject* o)
|
||||
: base(o)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline extract<T>::extract(object const& o)
|
||||
: base(o.ptr())
|
||||
{
|
||||
}
|
||||
|
||||
namespace converter
|
||||
{
|
||||
template <class T>
|
||||
inline extract_rvalue<T>::extract_rvalue(PyObject* x)
|
||||
: m_source(x)
|
||||
, m_data(
|
||||
(rvalue_from_python_stage1)(x, registered<T>::converters)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool
|
||||
extract_rvalue<T>::check() const
|
||||
{
|
||||
return m_data.stage1.convertible;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typename extract_rvalue<T>::result_type
|
||||
extract_rvalue<T>::operator()() const
|
||||
{
|
||||
return *(T*)(
|
||||
// Only do the stage2 conversion once
|
||||
m_data.stage1.convertible == m_data.storage.bytes
|
||||
? m_data.storage.bytes
|
||||
: (rvalue_from_python_stage2)(m_source, m_data.stage1, registered<T>::converters)
|
||||
);
|
||||
}
|
||||
|
||||
template <class Ref>
|
||||
inline extract_reference<Ref>::extract_reference(PyObject* obj)
|
||||
: m_source(obj)
|
||||
, m_result(
|
||||
(get_lvalue_from_python)(obj, registered<Ref>::converters)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Ref>
|
||||
inline bool extract_reference<Ref>::check() const
|
||||
{
|
||||
return m_result != 0;
|
||||
}
|
||||
|
||||
template <class Ref>
|
||||
inline Ref extract_reference<Ref>::operator()() const
|
||||
{
|
||||
if (m_result == 0)
|
||||
(throw_no_reference_from_python)(m_source, registered<Ref>::converters);
|
||||
|
||||
return python::detail::void_ptr_to_reference(m_result, (Ref(*)())0);
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
inline extract_pointer<Ptr>::extract_pointer(PyObject* obj)
|
||||
: m_source(obj)
|
||||
, m_result(
|
||||
obj == Py_None ? 0 : (get_lvalue_from_python)(obj, registered_pointee<Ptr>::converters)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
inline bool extract_pointer<Ptr>::check() const
|
||||
{
|
||||
return m_source == Py_None || m_result != 0;
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
inline Ptr extract_pointer<Ptr>::operator()() const
|
||||
{
|
||||
if (m_result == 0 && m_source != Py_None)
|
||||
(throw_no_pointer_from_python)(m_source, registered_pointee<Ptr>::converters);
|
||||
|
||||
return Ptr(m_result);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline extract_object_manager<T>::extract_object_manager(PyObject* obj)
|
||||
: m_source(obj)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool extract_object_manager<T>::check() const
|
||||
{
|
||||
return object_manager_traits<T>::check(m_source);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T extract_object_manager<T>::operator()() const
|
||||
{
|
||||
return T(
|
||||
object_manager_traits<T>::adopt(python::incref(m_source))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace boost::python::converter
|
||||
|
||||
#endif // EXTRACT_DWA200265_HPP
|
||||
241
include/boost/python/handle.hpp
Executable file
241
include/boost/python/handle.hpp
Executable file
@@ -0,0 +1,241 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef HANDLE_DWA200269_HPP
|
||||
# define HANDLE_DWA200269_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/cast.hpp>
|
||||
# include <boost/python/errors.hpp>
|
||||
# include <boost/python/borrowed.hpp>
|
||||
# include <boost/python/handle_fwd.hpp>
|
||||
# include <boost/python/refcount.hpp>
|
||||
# include <boost/python/tag.hpp>
|
||||
# include <boost/python/detail/raw_pyobject.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T> struct null_ok;
|
||||
|
||||
template <class T>
|
||||
inline null_ok<T>* allow_null(T* p)
|
||||
{
|
||||
return (null_ok<T>*)p;
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T>
|
||||
inline T* manage_ptr(detail::borrowed<null_ok<T> >* p, int)
|
||||
{
|
||||
return python::xincref((T*)p);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T* manage_ptr(null_ok<detail::borrowed<T> >* p, int)
|
||||
{
|
||||
return python::xincref((T*)p);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T* manage_ptr(detail::borrowed<T>* p, long)
|
||||
{
|
||||
return python::incref(expect_non_null((T*)p));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T* manage_ptr(null_ok<T>* p, long)
|
||||
{
|
||||
return (T*)p;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T* manage_ptr(T* p, ...)
|
||||
{
|
||||
return expect_non_null(p);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
class handle
|
||||
{
|
||||
typedef T* (handle::* bool_type )() const;
|
||||
|
||||
public: // types
|
||||
typedef T element_type;
|
||||
|
||||
public: // member functions
|
||||
handle();
|
||||
~handle();
|
||||
|
||||
template <class Y>
|
||||
explicit handle(Y* p)
|
||||
: m_p(
|
||||
python::upcast<T>(
|
||||
detail::manage_ptr(p, 0)
|
||||
)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
handle& operator=(handle const& r);
|
||||
|
||||
#if !defined(BOOST_MSVC) || (BOOST_MSVC > 1200)
|
||||
|
||||
template<typename Y>
|
||||
handle& operator=(handle<Y> const & r) // never throws
|
||||
{
|
||||
python::xdecref(m_p);
|
||||
m_p = python::xincref(python::upcast<T>(r.get()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <typename Y>
|
||||
handle(handle<Y> const& r)
|
||||
: m_p(python::xincref(python::upcast<T>(r.get())))
|
||||
{
|
||||
}
|
||||
|
||||
handle(handle const& r)
|
||||
: m_p(python::xincref(r.m_p))
|
||||
{
|
||||
}
|
||||
|
||||
T* operator-> () const;
|
||||
T& operator* () const;
|
||||
T* get() const;
|
||||
T* release();
|
||||
|
||||
operator bool_type() const // never throws
|
||||
{
|
||||
return m_p ? &handle<T>::get : 0;
|
||||
}
|
||||
bool operator! () const; // never throws
|
||||
|
||||
public: // implementation details -- do not touch
|
||||
// Defining this in the class body suppresses a VC7 link failure
|
||||
inline handle(detail::borrowed_reference x)
|
||||
: m_p(
|
||||
python::incref(
|
||||
downcast<T>((PyObject*)x)
|
||||
))
|
||||
{
|
||||
}
|
||||
|
||||
private: // data members
|
||||
T* m_p;
|
||||
};
|
||||
|
||||
typedef handle<PyTypeObject> type_handle;
|
||||
|
||||
//
|
||||
// Compile-time introspection
|
||||
//
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template<typename T>
|
||||
class is_handle
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class is_handle<handle<T> >
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
# else
|
||||
namespace detail
|
||||
{
|
||||
typedef char (&yes_handle_t)[1];
|
||||
typedef char (&no_handle_t)[2];
|
||||
|
||||
no_handle_t is_handle_test(...);
|
||||
|
||||
template<typename T>
|
||||
yes_handle_t is_handle_test(boost::type< handle<T> >);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class is_handle
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
sizeof(detail::is_handle_test(boost::type<T>()))
|
||||
== sizeof(detail::yes_handle_t)));
|
||||
};
|
||||
# endif
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
template <class T>
|
||||
inline handle<T>::handle()
|
||||
: m_p(0)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline handle<T>::~handle()
|
||||
{
|
||||
python::xdecref(m_p);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline handle<T>& handle<T>::operator=(handle<T> const& r)
|
||||
{
|
||||
python::xdecref(m_p);
|
||||
m_p = python::xincref(r.m_p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T* handle<T>::operator->() const
|
||||
{
|
||||
return m_p;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T& handle<T>::operator*() const
|
||||
{
|
||||
return *m_p;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T* handle<T>::get() const
|
||||
{
|
||||
return m_p;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool handle<T>::operator!() const
|
||||
{
|
||||
return m_p == 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T* handle<T>::release()
|
||||
{
|
||||
T* result = m_p;
|
||||
m_p = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Because get_managed_object must return a non-null PyObject*, we
|
||||
// return Py_None if the handle is null.
|
||||
template <class T>
|
||||
inline PyObject* get_managed_object(handle<T> const& h, tag_t)
|
||||
{
|
||||
return h.get() ? python::upcast<PyObject>(h.get()) : Py_None;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
|
||||
#endif // HANDLE_DWA200269_HPP
|
||||
431
include/boost/python/init.hpp
Normal file
431
include/boost/python/init.hpp
Normal file
@@ -0,0 +1,431 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef INIT_JDG20020820_HPP
|
||||
#define INIT_JDG20020820_HPP
|
||||
|
||||
#include <boost/mpl/type_list.hpp>
|
||||
#include <boost/mpl/for_each.hpp>
|
||||
#include <boost/mpl/select_type.hpp>
|
||||
#include <boost/mpl/at.hpp>
|
||||
#include <boost/mpl/size.hpp>
|
||||
#include <boost/mpl/pop_front.hpp>
|
||||
#include <boost/mpl/pop_back.hpp>
|
||||
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/preprocessor/enum_params_with_a_default.hpp>
|
||||
#include <boost/preprocessor/enum_params.hpp>
|
||||
#include <boost/preprocessor/repeat.hpp>
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <boost/preprocessor/inc.hpp>
|
||||
#include <boost/preprocessor/dec.hpp>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define BOOST_PYTHON_TEMPLATE_TYPES_WITH_DEFAULT \
|
||||
BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT \
|
||||
( \
|
||||
BOOST_PYTHON_MAX_ARITY, \
|
||||
class T, \
|
||||
boost::mpl::null_argument \
|
||||
) \
|
||||
|
||||
#define BOOST_PYTHON_TEMPLATE_TYPES \
|
||||
BOOST_PP_ENUM_PARAMS \
|
||||
( \
|
||||
BOOST_PYTHON_MAX_ARITY, \
|
||||
class T \
|
||||
) \
|
||||
|
||||
#define BOOST_PYTHON_TEMPLATE_ARGS \
|
||||
BOOST_PP_ENUM_PARAMS \
|
||||
( \
|
||||
BOOST_PYTHON_MAX_ARITY, \
|
||||
T \
|
||||
) \
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <BOOST_PYTHON_TEMPLATE_TYPES_WITH_DEFAULT>
|
||||
struct init; // forward declaration
|
||||
|
||||
///////////////////////////////////////
|
||||
template <BOOST_PYTHON_TEMPLATE_TYPES_WITH_DEFAULT>
|
||||
struct optional; // forward declaration
|
||||
|
||||
namespace detail {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// is_nil<T>::value
|
||||
//
|
||||
// This metaprogram checks if T is nil
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <class T>
|
||||
struct is_nil : public boost::is_same<T, boost::mpl::null_argument> {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// is_optional<T>::value
|
||||
//
|
||||
// This metaprogram checks if T is an optional
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
|
||||
template <class T>
|
||||
struct is_optional {
|
||||
|
||||
private:
|
||||
|
||||
template <BOOST_PYTHON_TEMPLATE_TYPES>
|
||||
static boost::type_traits::yes_type f(optional<BOOST_PYTHON_TEMPLATE_ARGS>);
|
||||
static boost::type_traits::no_type f(...);
|
||||
static T t();
|
||||
|
||||
public:
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value =
|
||||
sizeof(f(t())) == sizeof(::boost::type_traits::yes_type));
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
#else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
|
||||
template <class T>
|
||||
struct is_optional {
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <BOOST_PYTHON_TEMPLATE_TYPES>
|
||||
struct is_optional<optional<BOOST_PYTHON_TEMPLATE_ARGS> > {
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
#endif // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// append_to_init<ListT, T> [ and helpers ]
|
||||
//
|
||||
// A metaprogram appends T to the initializer type list
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct append_to_init_helper1 {
|
||||
|
||||
// Case 1: default case, just push T to the back of ListT
|
||||
|
||||
template <class ListT, class T>
|
||||
struct apply {
|
||||
|
||||
typedef typename boost::mpl::push_back<ListT, T>::sequence sequence;
|
||||
};
|
||||
};
|
||||
|
||||
struct append_to_init_helper2 {
|
||||
|
||||
template <class ListT, class T>
|
||||
struct apply {
|
||||
|
||||
// Case 2: optional case, T is an optional, append all
|
||||
// the contents of the optional T into back of ListT
|
||||
|
||||
typedef typename boost::mpl::for_each
|
||||
<
|
||||
typename T::sequence,
|
||||
ListT,
|
||||
boost::mpl::push_back<boost::mpl::_1, boost::mpl::_2>
|
||||
>::state sequence;
|
||||
};
|
||||
};
|
||||
|
||||
struct append_to_init_helper3 {
|
||||
|
||||
// Case 3: nil case, we found a nil, do nothing
|
||||
|
||||
template <class ListT, class T>
|
||||
struct apply {
|
||||
|
||||
typedef ListT sequence;
|
||||
};
|
||||
};
|
||||
|
||||
template <class ListT, class T>
|
||||
struct append_to_init {
|
||||
|
||||
typedef typename boost::mpl::select_type
|
||||
<
|
||||
is_optional<T>::value, // if
|
||||
append_to_init_helper2, // then
|
||||
typename boost::mpl::select_type // else
|
||||
<
|
||||
is_nil<T>::value, // if
|
||||
append_to_init_helper3, // then
|
||||
append_to_init_helper1 // else
|
||||
>::type
|
||||
>::type helper;
|
||||
|
||||
typedef typename helper::template apply<ListT, T>::sequence sequence;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// check_init_params [ and helpers ]
|
||||
//
|
||||
// Check the init template parameters. Detect illegal
|
||||
// arguments such as:
|
||||
//
|
||||
// init<int, optional<char, long>, int> // BAD trailing int
|
||||
// init<optional<char, long>, optional<char> > // BAD optional used twice
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <int N>
|
||||
struct check_init_params_helper {
|
||||
|
||||
template <class ListT>
|
||||
struct apply {
|
||||
|
||||
// case where size of sequence is not zero
|
||||
|
||||
typedef typename boost::mpl::pop_front<ListT>::sequence rest;
|
||||
|
||||
enum {
|
||||
|
||||
// if first is optional then there must be no more
|
||||
// elements to its right. if not then recurse and check
|
||||
// the rest of the type list
|
||||
|
||||
first_is_optional =
|
||||
is_optional<typename boost::mpl::at<0, ListT>::type>::value,
|
||||
size_of_rest = boost::mpl::size<rest>::value,
|
||||
rest_is_nil = (size_of_rest == 0),
|
||||
is_ok = first_is_optional ? rest_is_nil :
|
||||
check_init_params_helper<size_of_rest>
|
||||
::template apply<rest>::is_ok
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct check_init_params_helper<0> {
|
||||
|
||||
// case where size of sequence is zero
|
||||
|
||||
template <class ListT>
|
||||
struct apply {
|
||||
|
||||
enum { is_ok = true };
|
||||
};
|
||||
};
|
||||
|
||||
struct init_base {};
|
||||
|
||||
template <BOOST_PYTHON_TEMPLATE_TYPES>
|
||||
struct check_init_params : init_base {
|
||||
|
||||
typedef boost::mpl::type_list<BOOST_PYTHON_TEMPLATE_ARGS> params;
|
||||
|
||||
BOOST_STATIC_ASSERT
|
||||
(
|
||||
check_init_params_helper<boost::mpl::size<params>::value>
|
||||
::template apply<params>::is_ok
|
||||
);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// count_optional_types [ and helpers ]
|
||||
//
|
||||
// count_optional_types<T0..TN>::value computes the number of
|
||||
// optional types (see init and optional below). For example:
|
||||
//
|
||||
// init<int, string, optional<char, long, double> >::value == 3
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <class T>
|
||||
struct count_optionals1 {
|
||||
|
||||
BOOST_STATIC_CONSTANT(int, value = 0);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct count_optionals2 {
|
||||
|
||||
BOOST_STATIC_CONSTANT(
|
||||
int, value = boost::mpl::size<typename T::sequence>::value + 1);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct count_optionals
|
||||
: boost::mpl::select_type
|
||||
<
|
||||
is_optional<T>::value, // if
|
||||
count_optionals2<T>, // then
|
||||
count_optionals1<T> // else
|
||||
>::type
|
||||
{
|
||||
};
|
||||
|
||||
template <BOOST_PYTHON_TEMPLATE_TYPES>
|
||||
struct count_optional_types {
|
||||
|
||||
BOOST_STATIC_CONSTANT(int, value =
|
||||
count_optionals<T0>::value +
|
||||
count_optionals<T1>::value +
|
||||
count_optionals<T2>::value
|
||||
);
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// init
|
||||
//
|
||||
// init<T0...TN>::sequence returns a typelist. One of T0..TN
|
||||
// mat be an optional<...> see below. There should be only one
|
||||
// optional in the input types and an optional should be the
|
||||
// last in the list.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define BOOST_PYTHON_APPEND_TO_INIT(z, INDEX, D) \
|
||||
typedef typename detail::append_to_init \
|
||||
< \
|
||||
BOOST_PP_CAT(l, INDEX), \
|
||||
BOOST_PP_CAT(T, BOOST_PP_INC(INDEX)) \
|
||||
>::sequence BOOST_PP_CAT(l, BOOST_PP_INC(INDEX)); \
|
||||
|
||||
|
||||
template <BOOST_PYTHON_TEMPLATE_TYPES>
|
||||
struct init : detail::check_init_params<BOOST_PYTHON_TEMPLATE_ARGS>
|
||||
{
|
||||
typedef boost::mpl::type_list<T0> l0;
|
||||
BOOST_PP_REPEAT
|
||||
(BOOST_PP_DEC(BOOST_PYTHON_MAX_ARITY), BOOST_PYTHON_APPEND_TO_INIT, 0)
|
||||
|
||||
typedef BOOST_PP_CAT(l, BOOST_PP_DEC(BOOST_PYTHON_MAX_ARITY)) sequence;
|
||||
|
||||
BOOST_STATIC_CONSTANT(int, n_arguments = boost::mpl::size<sequence>::value);
|
||||
|
||||
BOOST_STATIC_CONSTANT(int, n_defaults =
|
||||
(detail::count_optional_types<BOOST_PYTHON_TEMPLATE_ARGS>::value)
|
||||
);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// optional
|
||||
//
|
||||
// optional<T0...TN>::sequence returns a typelist.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <BOOST_PYTHON_TEMPLATE_TYPES>
|
||||
struct optional {
|
||||
|
||||
typedef boost::mpl::type_list<BOOST_PYTHON_TEMPLATE_ARGS> sequence;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// define_class_init_helper<N>::apply
|
||||
//
|
||||
// General case
|
||||
//
|
||||
// Accepts a class_ and an arguments list. Defines a constructor
|
||||
// for the class given the arguments and recursively calls
|
||||
// define_class_init_helper<N-1>::apply with one less arguments (the
|
||||
// rightmost argument is shaved off)
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int N>
|
||||
struct define_class_init_helper {
|
||||
|
||||
template <class ClassT, class CallPoliciesT, class ArgsT>
|
||||
static void apply(ClassT& cl, CallPoliciesT const& policies, ArgsT const& args, char const* doc)
|
||||
{
|
||||
cl.def_init(args, policies, doc);
|
||||
typename boost::mpl::pop_back<ArgsT>::sequence next;
|
||||
define_class_init_helper<N-1>::apply(cl, policies, next, doc);
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// define_class_init_helper<0>::apply
|
||||
//
|
||||
// Terminal case
|
||||
//
|
||||
// Accepts a class_ and an arguments list. Defines a constructor
|
||||
// for the class given the arguments.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
struct define_class_init_helper<0> {
|
||||
|
||||
template <class ClassT, class CallPoliciesT, class ArgsT>
|
||||
static void apply(ClassT& cl, CallPoliciesT const& policies, ArgsT const& args, char const* doc)
|
||||
{
|
||||
cl.def_init(args, policies, doc);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// define_init
|
||||
//
|
||||
// Accepts a class_ and an init-list. Defines a set of constructors for
|
||||
// the class given the arguments. The init list (see init above) has
|
||||
// n_defaults (number of default arguments and n_arguments (number of
|
||||
// actual arguments). This function defines n_defaults + 1 constructors
|
||||
// for the class. Each constructor after the first has one less argument
|
||||
// to its right. Example:
|
||||
//
|
||||
// init<int, default<char, long, double>
|
||||
//
|
||||
// Defines:
|
||||
//
|
||||
// __init__(int, char, long, double)
|
||||
// __init__(int, char, long)
|
||||
// __init__(int, char)
|
||||
// __init__(int)
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <class ClassT, class CallPoliciesT, class InitT>
|
||||
void
|
||||
define_init(ClassT& cl, InitT const& i, CallPoliciesT const& policies, char const* doc)
|
||||
{
|
||||
typedef typename InitT::sequence args_t;
|
||||
detail::define_class_init_helper<InitT::n_defaults>::apply(cl, policies, args_t(), doc);
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#undef BOOST_PYTHON_TEMPLATE_TYPES_WITH_DEFAULT
|
||||
#undef BOOST_PYTHON_TEMPLATE_TYPES
|
||||
#undef BOOST_PYTHON_TEMPLATE_ARGS
|
||||
#undef BOOST_PYTHON_IS_OPTIONAL_VALUE
|
||||
#undef BOOST_PYTHON_APPEND_TO_INIT
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#endif // INIT_JDG20020820_HPP
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
57
include/boost/python/instance_holder.hpp
Executable file
57
include/boost/python/instance_holder.hpp
Executable file
@@ -0,0 +1,57 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef INSTANCE_HOLDER_DWA2002517_HPP
|
||||
# define INSTANCE_HOLDER_DWA2002517_HPP
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/utility.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
// Base class for all holders
|
||||
struct BOOST_PYTHON_DECL instance_holder : private noncopyable
|
||||
{
|
||||
public:
|
||||
instance_holder();
|
||||
virtual ~instance_holder();
|
||||
|
||||
// return the next holder in a chain
|
||||
instance_holder* next() const;
|
||||
|
||||
virtual void* holds(type_info) = 0;
|
||||
|
||||
void install(PyObject* inst) throw();
|
||||
|
||||
// These functions should probably be located elsewhere.
|
||||
|
||||
// Allocate storage for an object of the given size at the given
|
||||
// offset in the Python instance<> object if bytes are available
|
||||
// there. Otherwise allocate size bytes of heap memory.
|
||||
static void* allocate(PyObject*, std::size_t offset, std::size_t size);
|
||||
|
||||
// Deallocate storage from the heap if it was not carved out of
|
||||
// the given Python object by allocate(), above.
|
||||
static void deallocate(PyObject*, void* storage) throw();
|
||||
private:
|
||||
instance_holder* m_next;
|
||||
};
|
||||
|
||||
// This macro is needed for implementation of derived holders
|
||||
# define BOOST_PYTHON_UNFORWARD(N,ignored) (typename unforward<A##N>::type)(a##N)
|
||||
|
||||
//
|
||||
// implementation
|
||||
//
|
||||
inline instance_holder* instance_holder::next() const
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // INSTANCE_HOLDER_DWA2002517_HPP
|
||||
115
include/boost/python/iterator.hpp
Normal file
115
include/boost/python/iterator.hpp
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ITERATOR_DWA2002512_HPP
|
||||
# define ITERATOR_DWA2002512_HPP
|
||||
|
||||
# include <boost/python/detail/target.hpp>
|
||||
# include <boost/python/object/iterator.hpp>
|
||||
# include <boost/python/object_core.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// Adds an additional layer of binding to
|
||||
// objects::make_iterator(...), which allows us to pass member
|
||||
// function and member data pointers.
|
||||
template <class NextPolicies, class Target, class Accessor1, class Accessor2>
|
||||
inline object make_iterator(
|
||||
Accessor1 get_start, Accessor2 get_finish, boost::type<Target>* target = 0, NextPolicies* = 0)
|
||||
{
|
||||
return objects::make_iterator_function<NextPolicies,Target>(
|
||||
boost::protect(boost::bind(get_start, _1))
|
||||
, boost::protect(boost::bind(get_finish, _1))
|
||||
);
|
||||
}
|
||||
|
||||
// Guts of template class iterators<>, below.
|
||||
template <bool const_ = false>
|
||||
struct iterators_impl
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename T::iterator iterator;
|
||||
static iterator begin(T& x) { return x.begin(); }
|
||||
static iterator end(T& x) { return x.end(); }
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct iterators_impl<true>
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename T::const_iterator iterator;
|
||||
static iterator begin(T& x) { return x.begin(); }
|
||||
static iterator end(T& x) { return x.end(); }
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// An "ordinary function generator" which contains static begin(x) and
|
||||
// end(x) functions that invoke T::begin() and T::end(), respectively.
|
||||
template <class T>
|
||||
struct iterators
|
||||
: detail::iterators_impl<
|
||||
boost::is_const<T>::value
|
||||
>::template apply<T>
|
||||
{
|
||||
};
|
||||
|
||||
// Create an iterator-building function which uses the given
|
||||
// accessors. Deduce the Target type from the accessors. The iterator
|
||||
// returns copies of the inderlying elements.
|
||||
template <class Accessor1, class Accessor2>
|
||||
object range(Accessor1 start, Accessor2 finish)
|
||||
{
|
||||
return detail::make_iterator<objects::default_iterator_call_policies>(
|
||||
start, finish
|
||||
, detail::target(start));
|
||||
}
|
||||
|
||||
// Create an iterator-building function which uses the given accessors
|
||||
// and next() policies. Deduce the Target type.
|
||||
template <class NextPolicies, class Accessor1, class Accessor2>
|
||||
object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0)
|
||||
{
|
||||
return detail::make_iterator<NextPolicies>(start, finish, detail::target(start));
|
||||
}
|
||||
|
||||
// Create an iterator-building function which uses the given accessors
|
||||
// and next() policies, operating on the given Target type
|
||||
template <class NextPolicies, class Target, class Accessor1, class Accessor2>
|
||||
object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0, boost::type<Target>* = 0)
|
||||
{
|
||||
typedef typename add_reference<Target>::type target;
|
||||
return detail::make_iterator<NextPolicies, target>(start, finish);
|
||||
}
|
||||
|
||||
// A Python callable object which produces an iterator traversing
|
||||
// [x.begin(), x.end()), where x is an instance of the Container
|
||||
// type. NextPolicies are used as the CallPolicies for the iterator's
|
||||
// next() function.
|
||||
template <class Container
|
||||
, class NextPolicies = objects::default_iterator_call_policies>
|
||||
struct iterator : object
|
||||
{
|
||||
iterator()
|
||||
: object(
|
||||
python::range<NextPolicies>(
|
||||
&iterators<Container>::begin, &iterators<Container>::end
|
||||
))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // ITERATOR_DWA2002512_HPP
|
||||
117
include/boost/python/list.hpp
Normal file
117
include/boost/python/list.hpp
Normal file
@@ -0,0 +1,117 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef LIST_DWA2002627_HPP
|
||||
# define LIST_DWA2002627_HPP
|
||||
|
||||
# include <boost/python/object.hpp>
|
||||
# include <boost/python/converter/pytype_object_mgr_traits.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
class list : public object
|
||||
{
|
||||
public:
|
||||
BOOST_PYTHON_DECL list(); // new list
|
||||
explicit BOOST_PYTHON_DECL list(object_cref sequence); // new list initialized from sequence's items
|
||||
|
||||
template <class T>
|
||||
explicit list(T const& sequence)
|
||||
: object(list::call(object(sequence)))
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL void append(object_cref); // append object to end
|
||||
|
||||
template <class T>
|
||||
void append(T const& x)
|
||||
{
|
||||
this->append(object(x));
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL long count(object_cref value) const; // return number of occurrences of value
|
||||
|
||||
template <class T>
|
||||
long count(T const& value) const
|
||||
{
|
||||
return this->count(object(value));
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL void extend(object_cref sequence); // extend list by appending sequence elements
|
||||
|
||||
template <class T>
|
||||
void extend(T const& x)
|
||||
{
|
||||
this->extend(object(x));
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL long index(object_cref value) const; // return index of first occurrence of value
|
||||
|
||||
template <class T>
|
||||
long index(T const& x) const
|
||||
{
|
||||
return this->index(object(x));
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL void insert(int index, object_cref); // insert object before index
|
||||
BOOST_PYTHON_DECL void insert(object const& index, object_cref);
|
||||
|
||||
template <class T>
|
||||
void insert(int index, T const& x) // insert object before index
|
||||
{
|
||||
this->insert(index, object(x));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void insert(object const& index, T const& x) // insert object before index
|
||||
{
|
||||
this->insert(index, object(x));
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL object pop(); // remove and return item at index (default last)
|
||||
BOOST_PYTHON_DECL object pop(long index);
|
||||
BOOST_PYTHON_DECL object pop(object const& index);
|
||||
|
||||
BOOST_PYTHON_DECL void remove(object_cref value); // remove first occurrence of value
|
||||
|
||||
template <class T>
|
||||
void remove(T const& value)
|
||||
{
|
||||
this->remove(object(value));
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL void reverse(); // reverse *IN PLACE*
|
||||
|
||||
BOOST_PYTHON_DECL void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
|
||||
BOOST_PYTHON_DECL void sort(object_cref cmpfunc);
|
||||
|
||||
template <class T>
|
||||
void sort(T const& value)
|
||||
{
|
||||
this->sort(object(value));
|
||||
}
|
||||
|
||||
public: // implementation detail -- for internal use only
|
||||
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list)
|
||||
|
||||
private:
|
||||
static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&);
|
||||
};
|
||||
|
||||
//
|
||||
// Converter Specializations
|
||||
//
|
||||
namespace converter
|
||||
{
|
||||
template <>
|
||||
struct object_manager_traits<list>
|
||||
: pytype_object_manager_traits<&PyList_Type,list>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // LIST_DWA2002627_HPP
|
||||
55
include/boost/python/long.hpp
Normal file
55
include/boost/python/long.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef LONG_DWA2002627_HPP
|
||||
# define LONG_DWA2002627_HPP
|
||||
|
||||
# include <boost/python/object.hpp>
|
||||
# include <boost/python/converter/pytype_object_mgr_traits.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
class long_ : public object
|
||||
{
|
||||
public:
|
||||
BOOST_PYTHON_DECL long_(); // new long_
|
||||
explicit BOOST_PYTHON_DECL long_(object_cref rhs);
|
||||
|
||||
template <class T>
|
||||
explicit long_(T const& rhs)
|
||||
: object(long_::call(object(rhs)))
|
||||
{
|
||||
}
|
||||
|
||||
explicit BOOST_PYTHON_DECL long_(object_cref rhs, object_cref base);
|
||||
|
||||
template <class T, class U>
|
||||
explicit long_(T const& rhs, U const& base)
|
||||
: object(long_::call(object(rhs), object(base)))
|
||||
{
|
||||
}
|
||||
public: // implementation detail -- for internal use only
|
||||
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(long_)
|
||||
|
||||
private:
|
||||
static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&);
|
||||
static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&, object const&);
|
||||
};
|
||||
|
||||
//
|
||||
// Converter Specializations
|
||||
//
|
||||
namespace converter
|
||||
{
|
||||
template <>
|
||||
struct object_manager_traits<long_>
|
||||
: pytype_object_manager_traits<&PyLong_Type,long_>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // LONG_DWA2002627_HPP
|
||||
64
include/boost/python/make_function.hpp
Normal file
64
include/boost/python/make_function.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MAKE_FUNCTION_DWA20011221_HPP
|
||||
# define MAKE_FUNCTION_DWA20011221_HPP
|
||||
|
||||
# include <boost/python/object/function_object.hpp>
|
||||
# include <boost/python/object/make_holder.hpp>
|
||||
# include <boost/python/detail/caller.hpp>
|
||||
# include <boost/python/detail/arg_tuple_size.hpp>
|
||||
# include <boost/mpl/size.hpp>
|
||||
# include <boost/bind.hpp>
|
||||
# include <boost/python/default_call_policies.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class F>
|
||||
object make_function(F f)
|
||||
{
|
||||
return objects::function_object(
|
||||
::boost::bind<PyObject*>(detail::caller(), f, _1, _2, default_call_policies())
|
||||
, detail::arg_tuple_size<F>::value);
|
||||
}
|
||||
|
||||
template <class F, class Policies>
|
||||
object make_function(F f, Policies const& policies)
|
||||
{
|
||||
return objects::function_object(
|
||||
::boost::bind<PyObject*>(detail::caller(), f, _1, _2, policies)
|
||||
, detail::arg_tuple_size<F>::value);
|
||||
}
|
||||
|
||||
template <class ArgList, class HolderGenerator>
|
||||
object make_constructor(HolderGenerator* = 0, ArgList* = 0)
|
||||
{
|
||||
enum { nargs = mpl::size<ArgList>::value };
|
||||
|
||||
return objects::function_object(
|
||||
::boost::bind<PyObject*>(
|
||||
detail::caller()
|
||||
, objects::make_holder<nargs>
|
||||
::template apply<HolderGenerator,ArgList>::execute
|
||||
, _1, _2, default_call_policies())
|
||||
, nargs + 1);
|
||||
}
|
||||
|
||||
template <class ArgList, class HolderGenerator, class Policies>
|
||||
object make_constructor(Policies const& policies, HolderGenerator* = 0, ArgList* = 0)
|
||||
{
|
||||
enum { nargs = mpl::size<ArgList>::value };
|
||||
|
||||
return objects::function_object(
|
||||
::boost::bind<PyObject*>(detail::caller(),
|
||||
objects::make_holder<nargs>
|
||||
::template apply<HolderGenerator,ArgList>::execute
|
||||
, _1, _2, policies)
|
||||
, nargs + 1);
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // MAKE_FUNCTION_DWA20011221_HPP
|
||||
109
include/boost/python/module.hpp
Normal file
109
include/boost/python/module.hpp
Normal file
@@ -0,0 +1,109 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MODULE_DWA2001128_HPP
|
||||
# define MODULE_DWA2001128_HPP
|
||||
|
||||
# include <boost/python/errors.hpp>
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/make_function.hpp>
|
||||
# include <boost/python/class_fwd.hpp>
|
||||
# include <boost/python/detail/module_base.hpp>
|
||||
# include <boost/python/module_init.hpp>
|
||||
# include <boost/python/object_core.hpp>
|
||||
# include <boost/python/detail/def_helper.hpp>
|
||||
# include <boost/python/detail/defaults_def.hpp>
|
||||
# include <boost/python/signature.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
class module : public detail::module_base
|
||||
{
|
||||
public:
|
||||
typedef detail::module_base base;
|
||||
|
||||
module(char const* name, char const* doc = 0)
|
||||
: base(name, doc) {}
|
||||
|
||||
// Add elements to the module
|
||||
template <class T>
|
||||
module& setattr(const char* name, T const& x)
|
||||
{
|
||||
this->base::setattr_doc(name, python::object(x), 0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
module& add(type_handle x); // just use the type's name
|
||||
|
||||
template <class T1, class T2 , class T3, class T4>
|
||||
module& add(class_<T1,T2,T3,T4> const& c)
|
||||
{
|
||||
// Soon to disappear...
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Fn>
|
||||
module& def(char const* name, Fn fn)
|
||||
{
|
||||
this->setattr_doc(
|
||||
name, boost::python::make_function(fn), 0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Arg1T, class Arg2T>
|
||||
module& def(char const* name, Arg1T arg1, Arg2T const& arg2, char const* doc = 0)
|
||||
{
|
||||
dispatch_def(name, arg1, arg2, doc, &arg2);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template <class Fn, class CallPolicyOrDoc>
|
||||
void
|
||||
dispatch_def(
|
||||
char const* name,
|
||||
Fn fn,
|
||||
CallPolicyOrDoc const& policy_or_doc,
|
||||
char const* doc,
|
||||
void const*)
|
||||
{
|
||||
typedef detail::def_helper<CallPolicyOrDoc> helper;
|
||||
|
||||
this->setattr_doc(
|
||||
name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)),
|
||||
helper::get_doc(policy_or_doc, doc));
|
||||
}
|
||||
|
||||
template <typename StubsT, typename SigT>
|
||||
void
|
||||
dispatch_def(
|
||||
char const* name,
|
||||
SigT sig,
|
||||
StubsT const& stubs,
|
||||
char const* doc,
|
||||
detail::func_stubs_base const*)
|
||||
{
|
||||
// convert sig to a type_list (see detail::get_signature in signature.hpp)
|
||||
// before calling detail::define_with_defaults.
|
||||
detail::define_with_defaults(
|
||||
name, stubs, default_call_policies(),
|
||||
*this, detail::get_signature(sig), doc);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// inline implementations
|
||||
//
|
||||
inline module& module::add(type_handle x)
|
||||
{
|
||||
this->base::add(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // MODULE_DWA20011221_HPP
|
||||
61
include/boost/python/module_init.hpp
Normal file
61
include/boost/python/module_init.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MODULE_INIT_DWA20020722_HPP
|
||||
# define MODULE_INIT_DWA20020722_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/config.hpp>
|
||||
|
||||
# ifndef BOOST_PYTHON_MODULE_INIT
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
BOOST_PYTHON_DECL void init_module(char const* name, void(*)());
|
||||
|
||||
}}}
|
||||
|
||||
# if defined(_WIN32) || defined(__CYGWIN__)
|
||||
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void init_module_##name(); \
|
||||
extern "C" __declspec(dllexport) void init##name() \
|
||||
{ \
|
||||
boost::python::detail::init_module( \
|
||||
#name,&init_module_##name); \
|
||||
} \
|
||||
void init_module_##name()
|
||||
|
||||
# elif defined(_AIX)
|
||||
|
||||
# include <boost/python/detail/aix_init_module.hpp>
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void init_module_##name(); \
|
||||
extern "C" \
|
||||
{ \
|
||||
extern PyObject* _PyImport_LoadDynamicModule(char*, char*, FILE *); \
|
||||
void init##name() \
|
||||
{ \
|
||||
boost::python::detail::aix_init_module( \
|
||||
_PyImport_LoadDynamicModule, #name, &init_module_##name); \
|
||||
} \
|
||||
} \
|
||||
void init_module_##name()
|
||||
|
||||
# else
|
||||
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void init_module_##name(); \
|
||||
extern "C" void init##name() \
|
||||
{ \
|
||||
boost::python::detail::init_module(#name, &init_module_##name); \
|
||||
} \
|
||||
void init_module_##name()
|
||||
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
#endif // MODULE_INIT_DWA20020722_HPP
|
||||
23
include/boost/python/object.hpp
Executable file
23
include/boost/python/object.hpp
Executable file
@@ -0,0 +1,23 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef OBJECT_DWA2002612_HPP
|
||||
# define OBJECT_DWA2002612_HPP
|
||||
|
||||
# include <boost/python/object_core.hpp>
|
||||
# include <boost/python/object_attributes.hpp>
|
||||
# include <boost/python/object_items.hpp>
|
||||
# include <boost/python/object_slices.hpp>
|
||||
# include <boost/python/object_operators.hpp>
|
||||
# include <boost/python/converter/arg_to_python.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
class type_; // XXX temporary work-around
|
||||
class string;
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // OBJECT_DWA2002612_HPP
|
||||
24
include/boost/python/object/add_to_namespace.hpp
Normal file
24
include/boost/python/object/add_to_namespace.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ADD_TO_NAMESPACE_DWA200286_HPP
|
||||
# define ADD_TO_NAMESPACE_DWA200286_HPP
|
||||
|
||||
# include <boost/python/object_fwd.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
//
|
||||
// A setattr that's "smart" about function overloading (and docstrings).
|
||||
//
|
||||
BOOST_PYTHON_DECL void add_to_namespace(
|
||||
object const& name_space, char const* name, object const& attribute);
|
||||
|
||||
BOOST_PYTHON_DECL void add_to_namespace(
|
||||
object const& name_space, char const* name, object const& attribute, char const* doc);
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // ADD_TO_NAMESPACE_DWA200286_HPP
|
||||
52
include/boost/python/object/class.hpp
Normal file
52
include/boost/python/object/class.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CLASS_DWA20011214_HPP
|
||||
# define CLASS_DWA20011214_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/utility.hpp>
|
||||
# include <boost/python/instance_holder.hpp>
|
||||
# include <boost/python/object_core.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace objects {
|
||||
|
||||
struct BOOST_PYTHON_DECL class_base : python::api::object
|
||||
{
|
||||
// constructor
|
||||
class_base(
|
||||
char const* name // The name of the class
|
||||
|
||||
, std::size_t num_types // A list of class_ids. The first is the type
|
||||
, type_info const*const types // this is wrapping. The rest are the types of
|
||||
// any bases.
|
||||
|
||||
, char const* doc = 0 // Docstring, if any.
|
||||
);
|
||||
|
||||
// Retrieve the underlying object
|
||||
void add_property(char const* name, object const& fget);
|
||||
void add_property(char const* name, object const& fget, object const& fset);
|
||||
void setattr(char const* name, object const&);
|
||||
void enable_pickling(bool getstate_manages_dict);
|
||||
|
||||
// Set a special attribute in the class which tells Boost.Python
|
||||
// to allocate extra bytes for embedded C++ objects in Python
|
||||
// instances.
|
||||
void set_instance_size(std::size_t bytes);
|
||||
|
||||
// Set an __init__ function which throws an appropriate exception
|
||||
// for abstract classes.
|
||||
void def_no_init();
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // CLASS_DWA20011214_HPP
|
||||
20
include/boost/python/object/class_detail.hpp
Normal file
20
include/boost/python/object/class_detail.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CLASS_DETAIL_DWA200295_HPP
|
||||
# define CLASS_DETAIL_DWA200295_HPP
|
||||
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
BOOST_PYTHON_DECL type_handle registered_class_object(type_info id);
|
||||
BOOST_PYTHON_DECL type_handle class_metatype();
|
||||
BOOST_PYTHON_DECL type_handle class_type();
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // CLASS_DETAIL_DWA200295_HPP
|
||||
29
include/boost/python/object/class_wrapper.hpp
Normal file
29
include/boost/python/object/class_wrapper.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef CLASS_WRAPPER_DWA20011221_HPP
|
||||
# define CLASS_WRAPPER_DWA20011221_HPP
|
||||
|
||||
# include <boost/python/to_python_converter.hpp>
|
||||
# include <boost/ref.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
// Used to convert objects of type Src to wrapped C++ classes by
|
||||
// building a new instance object and installing a Holder constructed
|
||||
// from the Src object.
|
||||
template <class Src, class Holder, class MakeInstance>
|
||||
struct class_wrapper
|
||||
: to_python_converter<Src,class_wrapper<Src,Holder,MakeInstance> >
|
||||
{
|
||||
static PyObject* convert(Src const& x)
|
||||
{
|
||||
return MakeInstance::execute(cref(x));
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // CLASS_WRAPPER_DWA20011221_HPP
|
||||
34
include/boost/python/object/enum_base.hpp
Normal file
34
include/boost/python/object/enum_base.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ENUM_BASE_DWA200298_HPP
|
||||
# define ENUM_BASE_DWA200298_HPP
|
||||
|
||||
# include <boost/python/object_core.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
# include <boost/python/converter/convertible_function.hpp>
|
||||
# include <boost/python/converter/constructor_function.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
struct BOOST_PYTHON_DECL enum_base : python::api::object
|
||||
{
|
||||
protected:
|
||||
enum_base(
|
||||
char const* name
|
||||
, converter::to_python_function_t
|
||||
, converter::convertible_function
|
||||
, converter::constructor_function
|
||||
, type_info);
|
||||
|
||||
void add_value(char const* name, long value);
|
||||
|
||||
static PyObject* to_python(PyTypeObject* type, long x);
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // ENUM_BASE_DWA200298_HPP
|
||||
72
include/boost/python/object/function.hpp
Normal file
72
include/boost/python/object/function.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FUNCTION_DWA20011214_HPP
|
||||
# define FUNCTION_DWA20011214_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/function/function2.hpp>
|
||||
# include <boost/python/object_core.hpp>
|
||||
# include <boost/python/object/py_function.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
struct BOOST_PYTHON_DECL function : PyObject
|
||||
{
|
||||
function(py_function const&, unsigned min_args, unsigned max_args = 0);
|
||||
~function();
|
||||
|
||||
PyObject* call(PyObject*, PyObject*) const;
|
||||
|
||||
// Add an attribute to the name_space with the given name. If it is
|
||||
// a function object (this class), and an existing function is
|
||||
// already there, add it as an overload.
|
||||
static void add_to_namespace(
|
||||
object const& name_space, char const* name, object const& attribute);
|
||||
|
||||
static void add_to_namespace(
|
||||
object const& name_space, char const* name, object const& attribute, char const* doc);
|
||||
|
||||
object const& doc() const;
|
||||
void doc(object const& x);
|
||||
|
||||
object const& name() const;
|
||||
|
||||
private: // helper functions
|
||||
void argument_error(PyObject* args, PyObject* keywords) const;
|
||||
void add_overload(handle<function> const&);
|
||||
|
||||
private: // data members
|
||||
py_function m_fn;
|
||||
unsigned m_min_args;
|
||||
unsigned m_max_args;
|
||||
handle<function> m_overloads;
|
||||
object m_name;
|
||||
object m_doc;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
inline object const& function::doc() const
|
||||
{
|
||||
return this->m_doc;
|
||||
}
|
||||
|
||||
inline void function::doc(object const& x)
|
||||
{
|
||||
this->m_doc = x;
|
||||
}
|
||||
|
||||
inline object const& function::name() const
|
||||
{
|
||||
return this->m_name;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // FUNCTION_DWA20011214_HPP
|
||||
40
include/boost/python/object/function_handle.hpp
Normal file
40
include/boost/python/object/function_handle.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FUNCTION_HANDLE_DWA2002725_HPP
|
||||
# define FUNCTION_HANDLE_DWA2002725_HPP
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/python/detail/caller.hpp>
|
||||
# include <boost/python/detail/arg_tuple_size.hpp>
|
||||
# include <boost/python/default_call_policies.hpp>
|
||||
# include <boost/python/object/py_function.hpp>
|
||||
# include <boost/bind.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
BOOST_PYTHON_DECL handle<> function_handle_impl(py_function const& f, unsigned min_args, unsigned max_args = 0);
|
||||
|
||||
// Just like function_object, but returns a handle<> instead. Using
|
||||
// this for arg_to_python<> allows us to break a circular dependency
|
||||
// between object and arg_to_python.
|
||||
template <class F>
|
||||
inline handle<> function_handle(F const& f, unsigned min_args, unsigned max_args = 0)
|
||||
{
|
||||
return objects::function_handle_impl(objects::py_function(f), min_args, max_args);
|
||||
}
|
||||
|
||||
// Just like make_function, but returns a handle<> intead. Same
|
||||
// reasoning as above.
|
||||
template <class F>
|
||||
handle<> make_function_handle(F f)
|
||||
{
|
||||
return objects::function_handle(
|
||||
::boost::bind<PyObject*>(python::detail::caller(), f, _1, _2, default_call_policies())
|
||||
, python::detail::arg_tuple_size<F>::value);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // FUNCTION_HANDLE_DWA2002725_HPP
|
||||
24
include/boost/python/object/function_object.hpp
Normal file
24
include/boost/python/object/function_object.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FUNCTION_OBJECT_DWA2002725_HPP
|
||||
# define FUNCTION_OBJECT_DWA2002725_HPP
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/function/function2.hpp>
|
||||
# include <boost/python/object_core.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
BOOST_PYTHON_DECL api::object function_object_impl(boost::function2<PyObject*, PyObject*, PyObject*> const& f, unsigned min_args, unsigned max_args = 0);
|
||||
|
||||
template <class F>
|
||||
inline object function_object(F const& f, unsigned min_args, unsigned max_args = 0)
|
||||
{
|
||||
return objects::function_object_impl(boost::function2<PyObject*, PyObject*, PyObject*>(f), min_args, max_args);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // FUNCTION_OBJECT_DWA2002725_HPP
|
||||
50
include/boost/python/object/instance.hpp
Normal file
50
include/boost/python/object/instance.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef INSTANCE_DWA200295_HPP
|
||||
# define INSTANCE_DWA200295_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/type_traits/alignment_traits.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
namespace boost { namespace python
|
||||
{
|
||||
struct instance_holder;
|
||||
}} // namespace boost::python
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
// Each extension instance will be one of these
|
||||
template <class Data = char>
|
||||
struct instance
|
||||
{
|
||||
PyObject_VAR_HEAD
|
||||
PyObject* dict;
|
||||
PyObject* weakrefs;
|
||||
instance_holder* objects;
|
||||
|
||||
BOOST_STATIC_CONSTANT(std::size_t, alignment = alignment_of<Data>::value);
|
||||
typedef typename type_with_alignment<alignment>::type align_t;
|
||||
|
||||
union
|
||||
{
|
||||
align_t align;
|
||||
char bytes[sizeof(Data)];
|
||||
} storage;
|
||||
};
|
||||
|
||||
template <class Data>
|
||||
struct additional_instance_size
|
||||
{
|
||||
typedef instance<Data> instance_data;
|
||||
typedef instance<char> instance_char;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
std::size_t, value = sizeof(instance_data) - offsetof(instance_char,storage));
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // INSTANCE_DWA200295_HPP
|
||||
217
include/boost/python/object/iterator.hpp
Normal file
217
include/boost/python/object/iterator.hpp
Normal file
@@ -0,0 +1,217 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ITERATOR_DWA2002510_HPP
|
||||
# define ITERATOR_DWA2002510_HPP
|
||||
|
||||
# include <boost/python/object/iterator_core.hpp>
|
||||
# include <boost/python/class_fwd.hpp>
|
||||
# include <boost/python/object/class_detail.hpp>
|
||||
# include <boost/python/return_value_policy.hpp>
|
||||
# include <boost/python/copy_const_reference.hpp>
|
||||
# include <boost/python/object/function_object.hpp>
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/python/arg_from_python.hpp>
|
||||
# include <boost/mpl/apply.hpp>
|
||||
# include <boost/bind.hpp>
|
||||
# include <boost/bind/protect.hpp>
|
||||
# include <boost/python/detail/raw_pyobject.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
// CallPolicies for the next() method of iterators. We don't want
|
||||
// users to have to explicitly specify that the references returned by
|
||||
// iterators are copied, so we just replace the result_converter from
|
||||
// the default_iterator_call_policies with a permissive one which
|
||||
// always copies the result.
|
||||
struct default_iterator_call_policies
|
||||
: default_call_policies
|
||||
{
|
||||
struct result_converter
|
||||
{
|
||||
template <class R>
|
||||
struct apply
|
||||
{
|
||||
typedef to_python_value<R> type;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// Instantiations of these are wrapped to produce Python iterators.
|
||||
template <class NextPolicies, class Iterator>
|
||||
struct iterator_range
|
||||
{
|
||||
iterator_range(object sequence, Iterator start, Iterator finish);
|
||||
|
||||
object m_sequence; // Keeps the sequence alive while iterating.
|
||||
Iterator m_start;
|
||||
Iterator m_finish;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// Guts of the iterator's next() function. We can't just wrap an
|
||||
// ordinary function because we don't neccessarily know the result
|
||||
// type of dereferencing the iterator. This also saves us from
|
||||
// throwing C++ exceptions to indicate end-of-sequence.
|
||||
template <class Iterator, class Policies>
|
||||
struct iterator_next
|
||||
{
|
||||
static PyObject* execute(PyObject* args_, PyObject* kw, Policies const& policies)
|
||||
{
|
||||
typedef iterator_range<Policies,Iterator> range_;
|
||||
|
||||
PyObject* py_self = PyTuple_GET_ITEM(args_, 0);
|
||||
arg_from_python<range_*> c0(py_self);
|
||||
range_* self = c0(py_self);
|
||||
|
||||
// Done iterating?
|
||||
if (self->m_start == self->m_finish)
|
||||
{
|
||||
objects::set_stop_iteration_error();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// note: precall happens before we can check for the result
|
||||
// converter in this case, to ensure it happens before the
|
||||
// iterator is dereferenced. However, the arity is 1 so
|
||||
// there's not much risk that this will amount to anything.
|
||||
if (!policies.precall(args_)) return 0;
|
||||
|
||||
PyObject* result = iterator_next::convert_result(*self->m_start);
|
||||
++self->m_start;
|
||||
|
||||
return policies.postcall(args_, result);
|
||||
}
|
||||
private:
|
||||
// Convert the result of dereferencing the iterator. Dispatched
|
||||
// here because we can't neccessarily get the value_type of the
|
||||
// iterator without PTS. This way, we deduce the value type by
|
||||
// dereferencing.
|
||||
template <class ValueType>
|
||||
static PyObject* convert_result(ValueType& x)
|
||||
{
|
||||
typedef typename Policies::result_converter result_converter;
|
||||
typename mpl::apply1<result_converter,ValueType&>::type cr;
|
||||
if (!cr.convertible()) return 0;
|
||||
|
||||
return cr(x);
|
||||
}
|
||||
template <class ValueType>
|
||||
static PyObject* convert_result(ValueType const& x)
|
||||
{
|
||||
typedef typename Policies::result_converter result_converter;
|
||||
typename mpl::apply1<result_converter,ValueType const&>::type cr;
|
||||
if (!cr.convertible()) return 0;
|
||||
|
||||
return cr(x);
|
||||
}
|
||||
};
|
||||
|
||||
// Get a Python class which contains the given iterator and
|
||||
// policies, creating it if neccessary. Requires: NextPolicies is
|
||||
// default-constructible.
|
||||
template <class Iterator, class NextPolicies>
|
||||
object demand_iterator_class(char const* name, Iterator* = 0, NextPolicies const& policies = NextPolicies())
|
||||
{
|
||||
typedef iterator_range<NextPolicies,Iterator> range_;
|
||||
|
||||
// Check the registry. If one is already registered, return it.
|
||||
handle<> class_obj(
|
||||
objects::registered_class_object(python::type_id<range_>()));
|
||||
|
||||
if (class_obj.get() != 0)
|
||||
return object(class_obj);
|
||||
|
||||
// Make a callable object which can be used as the iterator's next() function.
|
||||
object next_function =
|
||||
objects::function_object(
|
||||
bind(&detail::iterator_next<Iterator,NextPolicies>::execute, _1, _2, policies)
|
||||
, 1);
|
||||
|
||||
return class_<range_>(name, no_init)
|
||||
.def("__iter__", identity_function())
|
||||
.setattr("next", next_function)
|
||||
;
|
||||
}
|
||||
|
||||
// This class template acts as a generator for an ordinary function
|
||||
// which builds a Python iterator.
|
||||
template <class Target, class Iterator
|
||||
, class Accessor1, class Accessor2
|
||||
, class NextPolicies
|
||||
>
|
||||
struct make_iterator_help
|
||||
{
|
||||
// Extract an object x of the Target type from the first Python
|
||||
// argument, and invoke get_start(x)/get_finish(x) to produce
|
||||
// iterators, which are used to construct a new iterator_range<>
|
||||
// object that gets wrapped into a Python iterator.
|
||||
static PyObject* create(
|
||||
Accessor1 const& get_start, Accessor2 const& get_finish
|
||||
, PyObject* args_, PyObject* /*kw*/)
|
||||
{
|
||||
// Make sure the Python class is instantiated.
|
||||
demand_iterator_class<Iterator,NextPolicies>("iterator");
|
||||
|
||||
to_python_value<iterator_range<NextPolicies,Iterator> > cr;
|
||||
|
||||
// This check is probably redundant, since we ensure the
|
||||
// type is registered above.
|
||||
if (!cr.convertible())
|
||||
return 0;
|
||||
|
||||
// Extract x from the first argument
|
||||
PyObject* arg0 = PyTuple_GET_ITEM(args_, 0);
|
||||
arg_from_python<Target> c0(arg0);
|
||||
if (!c0.convertible()) return 0;
|
||||
typename arg_from_python<Target>::result_type x = c0(arg0);
|
||||
|
||||
// Build and convert the iterator_range<>.
|
||||
return cr(
|
||||
iterator_range<NextPolicies,Iterator>(
|
||||
object((python::detail::borrowed_reference)arg0)
|
||||
, get_start(x), get_finish(x)));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Create a Python callable object which accepts a single argument
|
||||
// convertible to the C++ Target type and returns a Python
|
||||
// iterator. The Python iterator uses get_start(x) and get_finish(x)
|
||||
// (where x is an instance of Target) to produce begin and end
|
||||
// iterators for the range, and an instance of NextPolicies is used as
|
||||
// CallPolicies for the Python iterator's next() function.
|
||||
template <class NextPolicies, class Target, class Accessor1, class Accessor2>
|
||||
inline object make_iterator_function(
|
||||
Accessor1 const& get_start, Accessor2 const& get_finish
|
||||
, boost::type<Target>* = 0, NextPolicies* = 0)
|
||||
{
|
||||
typedef typename Accessor1::result_type result_type;
|
||||
|
||||
return
|
||||
objects::function_object(
|
||||
boost::bind(
|
||||
&detail::make_iterator_help<
|
||||
Target,result_type,Accessor1,Accessor2,NextPolicies
|
||||
>::create
|
||||
, get_start, get_finish, _1, _2)
|
||||
, 1 );
|
||||
}
|
||||
|
||||
//
|
||||
// implementation
|
||||
//
|
||||
template <class NextPolicies, class Iterator>
|
||||
inline iterator_range<NextPolicies,Iterator>::iterator_range(
|
||||
object sequence, Iterator start, Iterator finish)
|
||||
: m_sequence(sequence), m_start(start), m_finish(finish)
|
||||
{
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // ITERATOR_DWA2002510_HPP
|
||||
19
include/boost/python/object/iterator_core.hpp
Normal file
19
include/boost/python/object/iterator_core.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef ITERATOR_CORE_DWA2002512_HPP
|
||||
# define ITERATOR_CORE_DWA2002512_HPP
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/object_fwd.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
BOOST_PYTHON_DECL object const& identity_function();
|
||||
BOOST_PYTHON_DECL void set_stop_iteration_error();
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // ITERATOR_CORE_DWA2002512_HPP
|
||||
81
include/boost/python/object/make_holder.hpp
Normal file
81
include/boost/python/object/make_holder.hpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# ifndef MAKE_HOLDER_DWA20011215_HPP
|
||||
# define MAKE_HOLDER_DWA20011215_HPP
|
||||
|
||||
# include <boost/python/object/instance.hpp>
|
||||
|
||||
# include <boost/python/object/forward.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
|
||||
# include <boost/mpl/at.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
# include <cstddef>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
template <int nargs> struct make_holder;
|
||||
|
||||
# define BOOST_PYTHON_FORWARD_ARG(z, index, _) \
|
||||
typedef typename mpl::at<index,ArgList>::type t##index; \
|
||||
typedef typename forward<t##index>::type f##index;
|
||||
|
||||
# define BOOST_PYTHON_DO_FORWARD_ARG(z, index, _) , f##index(a##index)
|
||||
|
||||
// specializations...
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/make_holder.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# undef BOOST_PYTHON_FORWARD_ARG
|
||||
# undef BOOST_PYTHON_DO_FORWARD_ARG
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
# endif // MAKE_HOLDER_DWA20011215_HPP
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
# line BOOST_PP_LINE(__LINE__, make_holder.hpp)
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template <>
|
||||
struct make_holder<N>
|
||||
{
|
||||
template <class Holder, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_FORWARD_ARG, nil)
|
||||
static void execute(
|
||||
PyObject* p
|
||||
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, t, a))
|
||||
{
|
||||
typedef instance<Holder> instance_t;
|
||||
|
||||
void* memory = Holder::allocate(p, offsetof(instance_t, storage), sizeof(Holder));
|
||||
try {
|
||||
(new (memory) Holder(
|
||||
p BOOST_PP_REPEAT(N, BOOST_PYTHON_DO_FORWARD_ARG, nil)))->install(p);
|
||||
}
|
||||
catch(...) {
|
||||
Holder::deallocate(p, memory);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
# undef N
|
||||
|
||||
#endif
|
||||
72
include/boost/python/object/make_instance.hpp
Normal file
72
include/boost/python/object/make_instance.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef MAKE_INSTANCE_DWA200296_HPP
|
||||
# define MAKE_INSTANCE_DWA200296_HPP
|
||||
|
||||
# include <boost/python/object/instance.hpp>
|
||||
# include <boost/python/converter/registered.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
template <class T, class Holder>
|
||||
struct make_instance
|
||||
{
|
||||
typedef objects::instance<Holder> instance_t;
|
||||
|
||||
template <class Arg>
|
||||
static PyObject* execute(Arg& x)
|
||||
{
|
||||
BOOST_STATIC_ASSERT(is_class<T>::value);
|
||||
PyTypeObject* type = converter::registered<T>::converters.class_object;
|
||||
|
||||
PyObject* raw_result = type->tp_alloc(
|
||||
type, objects::additional_instance_size<Holder>::value);
|
||||
|
||||
if (raw_result != 0)
|
||||
{
|
||||
instance_t* result = (instance_t*)raw_result;
|
||||
try
|
||||
{
|
||||
// construct the new C++ object and install the pointer
|
||||
// in the Python object.
|
||||
construct(result, x)->install(raw_result);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
Py_DECREF(raw_result); // reclaim the Python object
|
||||
throw;
|
||||
}
|
||||
|
||||
// Note the position of the internally-stored Holder,
|
||||
// for the sake of destruction
|
||||
result->ob_size = offsetof(instance_t, storage);
|
||||
}
|
||||
return raw_result;
|
||||
}
|
||||
|
||||
private:
|
||||
// Kind of a hack to support code re-use. The first form is used
|
||||
// to construct holders around pointers or smart pointers. The
|
||||
// second form is used to construct holders around by-value
|
||||
// returns. We have to pass a pointer to the owning Python object
|
||||
// to the second form in order to make it forward the 2nd argument
|
||||
// on to the constructor of its embedded T object.
|
||||
template <class Arg>
|
||||
static Holder* construct(instance_t* result, Arg& x)
|
||||
{
|
||||
return new ((void*)&result->storage) Holder(x);
|
||||
}
|
||||
|
||||
static Holder* construct(instance_t* result, reference_wrapper<T const> x)
|
||||
{
|
||||
return new ((void*)&result->storage) Holder((PyObject*)result, x);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // MAKE_INSTANCE_DWA200296_HPP
|
||||
123
include/boost/python/object/pickle_support.hpp
Normal file
123
include/boost/python/object/pickle_support.hpp
Normal file
@@ -0,0 +1,123 @@
|
||||
// (C) Copyright R.W. Grosse-Kunstleve 2002.
|
||||
// Permission to copy, use, modify, sell and distribute this software
|
||||
// is granted provided this copyright notice appears in all copies. This
|
||||
// software is provided "as is" without express or implied warranty, and
|
||||
// with no claim as to its suitability for any purpose.
|
||||
#ifndef BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP
|
||||
#define BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace api
|
||||
{
|
||||
class object;
|
||||
}
|
||||
using api::object;
|
||||
class tuple;
|
||||
|
||||
BOOST_PYTHON_DECL object const& make_instance_reduce_function();
|
||||
|
||||
struct pickle_suite;
|
||||
|
||||
namespace error_messages {
|
||||
|
||||
template <class T>
|
||||
struct missing_pickle_suite_function_or_incorrect_signature {};
|
||||
|
||||
inline void must_be_derived_from_pickle_suite(pickle_suite const&) {}
|
||||
}
|
||||
|
||||
namespace detail { struct pickle_suite_registration; }
|
||||
|
||||
struct pickle_suite
|
||||
{
|
||||
private:
|
||||
struct inaccessible {};
|
||||
friend struct detail::pickle_suite_registration;
|
||||
public:
|
||||
static inaccessible* getinitargs() { return 0; }
|
||||
static inaccessible* getstate() { return 0; }
|
||||
static inaccessible* setstate() { return 0; }
|
||||
static bool getstate_manages_dict() { return false; }
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct pickle_suite_registration
|
||||
{
|
||||
typedef pickle_suite::inaccessible inaccessible;
|
||||
|
||||
template <class Class_, class Tgetinitargs>
|
||||
static
|
||||
void
|
||||
register_(
|
||||
Class_& cl,
|
||||
tuple (*getinitargs_fn)(Tgetinitargs),
|
||||
inaccessible* (*getstate_fn)(),
|
||||
inaccessible* (*setstate_fn)(),
|
||||
bool)
|
||||
{
|
||||
cl.enable_pickling(false);
|
||||
cl.def("__getinitargs__", getinitargs_fn);
|
||||
}
|
||||
|
||||
template <class Class_,
|
||||
class Rgetstate, class Tgetstate,
|
||||
class Tsetstate, class Ttuple>
|
||||
static
|
||||
void
|
||||
register_(
|
||||
Class_& cl,
|
||||
inaccessible* (*getinitargs_fn)(),
|
||||
Rgetstate (*getstate_fn)(Tgetstate),
|
||||
void (*setstate_fn)(Tsetstate, Ttuple),
|
||||
bool getstate_manages_dict)
|
||||
{
|
||||
cl.enable_pickling(getstate_manages_dict);
|
||||
cl.def("__getstate__", getstate_fn);
|
||||
cl.def("__setstate__", setstate_fn);
|
||||
}
|
||||
|
||||
template <class Class_,
|
||||
class Tgetinitargs,
|
||||
class Rgetstate, class Tgetstate,
|
||||
class Tsetstate, class Ttuple>
|
||||
static
|
||||
void
|
||||
register_(
|
||||
Class_& cl,
|
||||
tuple (*getinitargs_fn)(Tgetinitargs),
|
||||
Rgetstate (*getstate_fn)(Tgetstate),
|
||||
void (*setstate_fn)(Tsetstate, Ttuple),
|
||||
bool getstate_manages_dict)
|
||||
{
|
||||
cl.enable_pickling(getstate_manages_dict);
|
||||
cl.def("__getinitargs__", getinitargs_fn);
|
||||
cl.def("__getstate__", getstate_fn);
|
||||
cl.def("__setstate__", setstate_fn);
|
||||
}
|
||||
|
||||
template <class Class_>
|
||||
static
|
||||
void
|
||||
register_(
|
||||
Class_&,
|
||||
...)
|
||||
{
|
||||
typedef typename
|
||||
error_messages::missing_pickle_suite_function_or_incorrect_signature<
|
||||
Class_>::error_type error_type;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename PickleSuiteType>
|
||||
struct pickle_suite_finalize
|
||||
: PickleSuiteType,
|
||||
pickle_suite_registration
|
||||
{};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP
|
||||
158
include/boost/python/object/pointer_holder.hpp
Normal file
158
include/boost/python/object/pointer_holder.hpp
Normal file
@@ -0,0 +1,158 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# ifndef POINTER_HOLDER_DWA20011215_HPP
|
||||
# define POINTER_HOLDER_DWA20011215_HPP
|
||||
|
||||
# include <boost/type.hpp>
|
||||
|
||||
# include <boost/python/instance_holder.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/object/inheritance.hpp>
|
||||
# include <boost/python/object/find_instance.hpp>
|
||||
# include <boost/python/object/forward.hpp>
|
||||
# include <boost/python/object/class_wrapper.hpp>
|
||||
# include <boost/python/pointee.hpp>
|
||||
# include <boost/python/detail/force_instantiate.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/mpl/apply.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
# define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) (typename unforward<A##n>::type)(a##n)
|
||||
|
||||
template <class Pointer, class Value>
|
||||
struct pointer_holder : instance_holder
|
||||
{
|
||||
typedef Value value_type;
|
||||
|
||||
pointer_holder(Pointer);
|
||||
|
||||
// Forward construction to the held object
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/pointer_holder.hpp>, 1))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
private: // types
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(type_info);
|
||||
|
||||
private: // data members
|
||||
Pointer m_p;
|
||||
};
|
||||
|
||||
template <class Pointer, class Value>
|
||||
struct pointer_holder_back_reference : instance_holder
|
||||
{
|
||||
private:
|
||||
typedef typename python::pointee<Pointer>::type held_type;
|
||||
public:
|
||||
typedef Value value_type;
|
||||
|
||||
// Not sure about this one -- can it work? The source object
|
||||
// undoubtedly does not carry the correct back reference pointer.
|
||||
pointer_holder_back_reference(Pointer);
|
||||
|
||||
// Forward construction to the held object
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/pointer_holder.hpp>, 2))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(type_info);
|
||||
|
||||
private: // data members
|
||||
Pointer m_p;
|
||||
};
|
||||
|
||||
# undef BOOST_PYTHON_UNFORWARD_LOCAL
|
||||
|
||||
template <class Pointer, class Value>
|
||||
inline pointer_holder<Pointer,Value>::pointer_holder(Pointer p)
|
||||
: m_p(p)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Pointer, class Value>
|
||||
inline pointer_holder_back_reference<Pointer,Value>::pointer_holder_back_reference(Pointer p)
|
||||
: m_p(p)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Pointer, class Value>
|
||||
void* pointer_holder<Pointer, Value>::holds(type_info dst_t)
|
||||
{
|
||||
if (dst_t == python::type_id<Pointer>())
|
||||
return &this->m_p;
|
||||
|
||||
type_info src_t = python::type_id<Value>();
|
||||
return src_t == dst_t ? &*this->m_p
|
||||
: find_dynamic_type(&*this->m_p, src_t, dst_t);
|
||||
}
|
||||
|
||||
template <class Pointer, class Value>
|
||||
void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t)
|
||||
{
|
||||
if (dst_t == python::type_id<Pointer>())
|
||||
return &this->m_p;
|
||||
|
||||
if (dst_t == python::type_id<held_type>())
|
||||
return &*this->m_p;
|
||||
|
||||
type_info src_t = python::type_id<Value>();
|
||||
Value* p = &*this->m_p;
|
||||
return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
# endif // POINTER_HOLDER_DWA20011215_HPP
|
||||
|
||||
/* --------------- pointer_holder --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
|
||||
# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp)
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
# if (N != 0)
|
||||
template< BOOST_PYTHON_UNARY_ENUM(N, class A) >
|
||||
# endif
|
||||
pointer_holder(PyObject* BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a))
|
||||
: m_p(new Value(
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
|
||||
))
|
||||
{}
|
||||
|
||||
# undef N
|
||||
|
||||
/* --------------- pointer_holder_back_reference --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
|
||||
# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp(pointer_holder_back_reference))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
# if (N != 0)
|
||||
template < BOOST_PYTHON_UNARY_ENUM(N, class A) >
|
||||
# endif
|
||||
pointer_holder_back_reference(
|
||||
PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a))
|
||||
: m_p(new held_type(
|
||||
p BOOST_PP_COMMA_IF(N) BOOST_PP_REPEAT(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
|
||||
))
|
||||
{}
|
||||
|
||||
# undef N
|
||||
|
||||
#endif
|
||||
22
include/boost/python/object/py_function.hpp
Normal file
22
include/boost/python/object/py_function.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef PY_FUNCTION_DWA200286_HPP
|
||||
# define PY_FUNCTION_DWA200286_HPP
|
||||
# include <boost/function/function2.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
// This type is used as a "generalized Python callback", wrapping the
|
||||
// function signature:
|
||||
//
|
||||
// PyObject* (PyObject* args, PyObject* keywords)
|
||||
//
|
||||
// We use boost::function to avoid generating lots of virtual tables
|
||||
typedef boost::function2<PyObject*, PyObject*, PyObject*> py_function;
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // PY_FUNCTION_DWA200286_HPP
|
||||
148
include/boost/python/object/select_holder.hpp
Normal file
148
include/boost/python/object/select_holder.hpp
Normal file
@@ -0,0 +1,148 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef SELECT_HOLDER_DWA2002322_HPP
|
||||
# define SELECT_HOLDER_DWA2002322_HPP
|
||||
|
||||
# include <boost/python/has_back_reference.hpp>
|
||||
# include <boost/python/detail/not_specified.hpp>
|
||||
# include <boost/python/pointee.hpp>
|
||||
# include <boost/python/object/value_holder.hpp>
|
||||
# include <boost/python/object/pointer_holder.hpp>
|
||||
# include <boost/python/object/find_instance.hpp>
|
||||
# include <boost/python/object/make_instance.hpp>
|
||||
# include <boost/python/object/instance.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/type_traits/alignment_traits.hpp>
|
||||
# include <boost/mpl/bool_t.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T, class Held>
|
||||
struct select_value_holder
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, selector = (!is_same<T,Held>::value) | has_back_reference<T>::value);
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
selector
|
||||
, value_holder_back_reference<T,Held>
|
||||
, value_holder<T>
|
||||
>::type type;
|
||||
|
||||
static inline void register_()
|
||||
{
|
||||
select_value_holder::register_(mpl::bool_t<selector>());
|
||||
}
|
||||
|
||||
static type* get() { return 0; }
|
||||
|
||||
private:
|
||||
static inline void register_(mpl::bool_t<true>)
|
||||
{
|
||||
python::detail::force_instantiate(instance_finder<Held>::registration);
|
||||
}
|
||||
|
||||
static inline void register_(mpl::bool_t<false>)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <class T,class Ptr>
|
||||
struct select_pointer_holder
|
||||
{
|
||||
typedef typename python::pointee<Ptr>::type pointee;
|
||||
BOOST_STATIC_CONSTANT(bool, selector = (!is_same<T,pointee>::value) | has_back_reference<T>::value);
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
selector
|
||||
, pointer_holder_back_reference<Ptr,T>
|
||||
, pointer_holder<Ptr,T>
|
||||
>::type type;
|
||||
|
||||
static inline void register_()
|
||||
{
|
||||
select_pointer_holder::register_(mpl::bool_t<selector>());
|
||||
}
|
||||
|
||||
static type* get() { return 0; }
|
||||
|
||||
private:
|
||||
static inline void register_(mpl::bool_t<true>)
|
||||
{
|
||||
// not implemented at least until we solve the back
|
||||
// reference issue mentioned in pointer_holder.hpp.
|
||||
//
|
||||
// python::detail::force_instantiate(
|
||||
// class_wrapper<Pointer,pointer_holder_back_reference<Pointer,Value> >());
|
||||
|
||||
python::detail::force_instantiate(instance_finder<Ptr>::registration);
|
||||
python::detail::force_instantiate(instance_finder<pointee>::registration);
|
||||
}
|
||||
|
||||
struct construct_from_pointer
|
||||
{
|
||||
static type* execute(PyObject*, Ptr x)
|
||||
{
|
||||
return new type(x);
|
||||
}
|
||||
};
|
||||
|
||||
static inline void register_(mpl::bool_t<false>)
|
||||
{
|
||||
python::detail::force_instantiate(
|
||||
objects::class_wrapper<
|
||||
Ptr
|
||||
, type
|
||||
, make_instance<T,type> >());
|
||||
|
||||
python::detail::force_instantiate(
|
||||
instance_finder<Ptr>::registration);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template <class T, class Held>
|
||||
struct select_holder
|
||||
{
|
||||
static inline std::size_t additional_size()
|
||||
{
|
||||
return additional_size_helper(execute((Held*)0));
|
||||
}
|
||||
|
||||
static inline detail::select_value_holder<T,T>
|
||||
execute(python::detail::not_specified*)
|
||||
{
|
||||
return detail::select_value_holder<T,T>();
|
||||
}
|
||||
|
||||
static inline detail::select_value_holder<T, Held>
|
||||
execute(T*)
|
||||
{
|
||||
return detail::select_value_holder<T, Held>();
|
||||
}
|
||||
|
||||
static inline detail::select_pointer_holder<T,Held>
|
||||
execute(void*)
|
||||
{
|
||||
return detail::select_pointer_holder<T,Held>();
|
||||
}
|
||||
|
||||
private:
|
||||
template <class Selector>
|
||||
static inline std::size_t additional_size_helper(Selector const&)
|
||||
{
|
||||
typedef typename Selector::type holder;
|
||||
return additional_instance_size<holder>::value;
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // SELECT_HOLDER_DWA2002322_HPP
|
||||
131
include/boost/python/object/value_holder.hpp
Normal file
131
include/boost/python/object/value_holder.hpp
Normal file
@@ -0,0 +1,131 @@
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
# ifndef VALUE_HOLDER_DWA20011215_HPP
|
||||
# define VALUE_HOLDER_DWA20011215_HPP
|
||||
|
||||
# include <boost/python/object/value_holder_fwd.hpp>
|
||||
# include <boost/python/instance_holder.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/object/inheritance.hpp>
|
||||
# include <boost/python/object/find_instance.hpp>
|
||||
# include <boost/python/object/forward.hpp>
|
||||
# include <boost/python/detail/force_instantiate.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
# define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) (typename unforward<A##n>::type)(a##n)
|
||||
|
||||
template <class Held>
|
||||
struct value_holder : instance_holder
|
||||
{
|
||||
typedef Held value_type;
|
||||
|
||||
// Forward construction to the held object
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/value_holder.hpp>, 1))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(type_info);
|
||||
|
||||
private: // data members
|
||||
Held m_held;
|
||||
};
|
||||
|
||||
template <class Held, class BackReferenceType>
|
||||
struct value_holder_back_reference : instance_holder
|
||||
{
|
||||
typedef Held value_type;
|
||||
|
||||
// Forward construction to the held object
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/value_holder.hpp>, 2))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(type_info);
|
||||
|
||||
private: // data members
|
||||
BackReferenceType m_held;
|
||||
};
|
||||
|
||||
# undef BOOST_PYTHON_UNFORWARD_LOCAL
|
||||
|
||||
template <class Held>
|
||||
void* value_holder<Held>::holds(type_info dst_t)
|
||||
{
|
||||
type_info src_t = python::type_id<Held>();
|
||||
return src_t == dst_t ? &m_held
|
||||
: find_static_type(&m_held, src_t, dst_t);
|
||||
}
|
||||
|
||||
template <class Held, class BackReferenceType>
|
||||
void* value_holder_back_reference<Held,BackReferenceType>::holds(
|
||||
type_info dst_t)
|
||||
{
|
||||
type_info src_t = python::type_id<Held>();
|
||||
Held* x = &m_held;
|
||||
|
||||
if (dst_t == src_t)
|
||||
return x;
|
||||
else if (dst_t == python::type_id<BackReferenceType>())
|
||||
return &m_held;
|
||||
else
|
||||
return find_static_type(x, src_t, dst_t);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
# endif // VALUE_HOLDER_DWA20011215_HPP
|
||||
|
||||
// --------------- value_holder ---------------
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
|
||||
# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
# if (N != 0)
|
||||
template <BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
# endif
|
||||
value_holder(
|
||||
PyObject* BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a))
|
||||
: m_held(
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
|
||||
)
|
||||
{}
|
||||
|
||||
# undef N
|
||||
|
||||
// --------------- value_holder_back_reference ---------------
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
|
||||
# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder_back_reference))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
# if (N != 0)
|
||||
template <BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
# endif
|
||||
value_holder_back_reference(
|
||||
PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a))
|
||||
: m_held(
|
||||
p BOOST_PP_COMMA_IF(N)
|
||||
BOOST_PP_REPEAT(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
# undef N
|
||||
|
||||
#endif
|
||||
22
include/boost/python/object_call.hpp
Normal file
22
include/boost/python/object_call.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
# // Copyright David Abrahams 2002. Permission to copy, use,
|
||||
# // modify, sell and distribute this software is granted provided this
|
||||
# // copyright notice appears in all copies. This software is provided
|
||||
# // "as is" without express or implied warranty, and with no claim as
|
||||
# // to its suitability for any purpose.
|
||||
|
||||
#if !defined(BOOST_PP_IS_ITERATING)
|
||||
# error Boost.Python - do not include this file!
|
||||
#endif
|
||||
|
||||
#define N BOOST_PP_ITERATION()
|
||||
|
||||
template <BOOST_PYTHON_UNARY_ENUM(N, class A)>
|
||||
typename detail::dependent<object, A0>::type
|
||||
operator()(BOOST_PYTHON_BINARY_ENUM(N, A, const& a)) const
|
||||
{
|
||||
typedef typename detail::dependent<object, A0>::type obj;
|
||||
U const& self = *static_cast<U const*>(this);
|
||||
return call<obj>(get_managed_object(self, tag), BOOST_PYTHON_UNARY_ENUM(N, a));
|
||||
}
|
||||
|
||||
#undef N
|
||||
386
include/boost/python/object_core.hpp
Executable file
386
include/boost/python/object_core.hpp
Executable file
@@ -0,0 +1,386 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef OBJECT_CORE_DWA2002615_HPP
|
||||
# define OBJECT_CORE_DWA2002615_HPP
|
||||
|
||||
# include <boost/type.hpp>
|
||||
|
||||
# include <boost/python/call.hpp>
|
||||
# include <boost/python/handle_fwd.hpp>
|
||||
# include <boost/python/errors.hpp>
|
||||
# include <boost/python/slice_nil.hpp>
|
||||
# include <boost/python/detail/raw_pyobject.hpp>
|
||||
# include <boost/python/refcount.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/python/tag.hpp>
|
||||
# include <boost/python/detail/dependent.hpp>
|
||||
|
||||
# include <boost/preprocessor/iterate.hpp>
|
||||
# include <boost/preprocessor/debug/line.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace converter
|
||||
{
|
||||
template <class T> struct arg_to_python;
|
||||
}
|
||||
|
||||
// Put this in an inner namespace so that the generalized operators won't take over
|
||||
namespace api
|
||||
{
|
||||
|
||||
// This file contains the definition of the object class and enough to
|
||||
// construct/copy it, but not enough to do operations like
|
||||
// attribute/item access or addition.
|
||||
|
||||
template <class Policies> class proxy;
|
||||
|
||||
struct const_attribute_policies;
|
||||
struct attribute_policies;
|
||||
struct const_item_policies;
|
||||
struct item_policies;
|
||||
struct const_slice_policies;
|
||||
struct slice_policies;
|
||||
|
||||
typedef proxy<const_attribute_policies> const_object_attribute;
|
||||
typedef proxy<attribute_policies> object_attribute;
|
||||
typedef proxy<const_item_policies> const_object_item;
|
||||
typedef proxy<item_policies> object_item;
|
||||
typedef proxy<const_slice_policies> const_object_slice;
|
||||
typedef proxy<slice_policies> object_slice;
|
||||
|
||||
//
|
||||
// is_proxy -- proxy type detection
|
||||
//
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T>
|
||||
struct is_proxy
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
template <class T>
|
||||
struct is_proxy<proxy<T> >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
# else
|
||||
typedef char yes_proxy;
|
||||
typedef char (&no_proxy)[2];
|
||||
template <class T>
|
||||
yes_proxy is_proxy_helper(boost::type<proxy<T> >*);
|
||||
no_proxy is_proxy_helper(...);
|
||||
template <class T>
|
||||
struct is_proxy
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (sizeof(is_proxy_helper((boost::type<T>*)0))
|
||||
== sizeof(yes_proxy)));
|
||||
};
|
||||
# endif
|
||||
|
||||
template <bool is_proxy, bool is_object_manager> struct object_initializer;
|
||||
|
||||
class object;
|
||||
typedef PyObject* (object::*bool_type)() const;
|
||||
|
||||
template <class U>
|
||||
class object_operators
|
||||
{
|
||||
protected:
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1200
|
||||
typedef object const& object_cref;
|
||||
# else
|
||||
typedef object object_cref;
|
||||
# endif
|
||||
public:
|
||||
// function call
|
||||
//
|
||||
object operator()() const;
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PYTHON_MAX_ARITY, <boost/python/object_call.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
// truth value testing
|
||||
//
|
||||
operator bool_type() const;
|
||||
bool operator!() const; // needed for vc6
|
||||
|
||||
// Attribute access
|
||||
//
|
||||
const_object_attribute attr(char const*) const;
|
||||
object_attribute attr(char const*);
|
||||
|
||||
// item access
|
||||
//
|
||||
const_object_item operator[](object_cref) const;
|
||||
object_item operator[](object_cref);
|
||||
|
||||
template <class T>
|
||||
const_object_item
|
||||
operator[](T const& key) const
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
|
||||
;
|
||||
# else
|
||||
{
|
||||
return (*this)[object(key)];
|
||||
}
|
||||
# endif
|
||||
|
||||
template <class T>
|
||||
object_item
|
||||
operator[](T const& key)
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
|
||||
;
|
||||
# else
|
||||
{
|
||||
return (*this)[object(key)];
|
||||
}
|
||||
# endif
|
||||
|
||||
// slicing
|
||||
//
|
||||
const_object_slice slice(object_cref, object_cref) const;
|
||||
object_slice slice(object_cref, object_cref);
|
||||
|
||||
const_object_slice slice(slice_nil, object_cref) const;
|
||||
object_slice slice(slice_nil, object_cref);
|
||||
|
||||
const_object_slice slice(object_cref, slice_nil) const;
|
||||
object_slice slice(object_cref, slice_nil);
|
||||
|
||||
template <class T, class V>
|
||||
const_object_slice
|
||||
slice(T const& start, V const& end) const
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
|
||||
;
|
||||
# else
|
||||
{
|
||||
return this->slice(
|
||||
slice_bound<T>::type(start)
|
||||
, slice_bound<V>::type(end));
|
||||
}
|
||||
# endif
|
||||
|
||||
template <class T, class V>
|
||||
object_slice
|
||||
slice(T const& start, V const& end)
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
|
||||
;
|
||||
# else
|
||||
{
|
||||
return this->slice(
|
||||
slice_bound<T>::type(start)
|
||||
, slice_bound<V>::type(end));
|
||||
}
|
||||
# endif
|
||||
private:
|
||||
// there is a confirmed CWPro8 codegen bug here. We prevent the
|
||||
// early destruction of a temporary by binding a named object
|
||||
// instead.
|
||||
# if __MWERKS__ < 0x3000 || __MWERKS__ > 0x3001
|
||||
typedef object const& object_cref2;
|
||||
# else
|
||||
typedef object const object_cref2;
|
||||
# endif
|
||||
};
|
||||
|
||||
// VC6 and VC7 require this base class in order to generate the
|
||||
// correct copy constructor for object. We can't define it there
|
||||
// explicitly or it will complain of ambiguity.
|
||||
struct object_base : object_operators<object>
|
||||
{
|
||||
// copy constructor without NULL checking, for efficiency.
|
||||
inline object_base(object_base const&);
|
||||
inline object_base(PyObject* ptr);
|
||||
|
||||
object_base& operator=(object_base const& rhs);
|
||||
~object_base();
|
||||
|
||||
// Underlying object access -- returns a borrowed reference
|
||||
PyObject* ptr() const;
|
||||
|
||||
private:
|
||||
PyObject* m_ptr;
|
||||
};
|
||||
|
||||
class object : public object_base
|
||||
{
|
||||
public:
|
||||
// default constructor creates a None object
|
||||
object();
|
||||
// explicit conversion from any C++ object to Python
|
||||
template <class T>
|
||||
explicit object(T const& x)
|
||||
: object_base(
|
||||
object_initializer<
|
||||
is_proxy<T>::value
|
||||
, converter::is_object_manager<T>::value
|
||||
>::get(&x, detail::convertible<object const*>::check(&x)))
|
||||
{
|
||||
}
|
||||
|
||||
// Throw error_already_set() if the handle is null.
|
||||
BOOST_PYTHON_DECL explicit object(handle<> const&);
|
||||
|
||||
public: // implementation detail -- for internal use only
|
||||
explicit object(detail::borrowed_reference);
|
||||
explicit object(detail::new_reference);
|
||||
explicit object(detail::new_non_null_reference);
|
||||
};
|
||||
|
||||
// Macros for forwarding constructors in classes derived from
|
||||
// object. Derived classes will usually want these as an
|
||||
// implementation detail
|
||||
# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_(derived) \
|
||||
inline explicit derived(python::detail::borrowed_reference p) \
|
||||
: object(p) {} \
|
||||
inline explicit derived(python::detail::new_reference p) \
|
||||
: object(p) {} \
|
||||
inline explicit derived(python::detail::new_non_null_reference p) \
|
||||
: object(p) {}
|
||||
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1200
|
||||
# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_
|
||||
# else
|
||||
// MSVC6 has a bug which causes an explicit template constructor to
|
||||
// be preferred over an appropriate implicit conversion operator
|
||||
// declared on the argument type. Normally, that would cause a
|
||||
// runtime failure when using extract<T> to extract a type with a
|
||||
// templated constructor. This additional constructor will turn that
|
||||
// runtime failure into an ambiguity error at compile-time due to
|
||||
// the lack of partial ordering, or at least a link-time error if no
|
||||
// generalized template constructor is declared.
|
||||
# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(derived) \
|
||||
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_(derived) \
|
||||
template <class T> \
|
||||
explicit derived(extract<T> const&);
|
||||
# endif
|
||||
|
||||
//
|
||||
// object_initializer -- get the handle to construct the object with,
|
||||
// based on whether T is a proxy or derived from object
|
||||
//
|
||||
template <bool is_proxy = false, bool is_object_manager = false>
|
||||
struct object_initializer
|
||||
{
|
||||
static PyObject*
|
||||
get(object const* x, detail::yes_convertible)
|
||||
{
|
||||
return python::incref(x->ptr());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static PyObject*
|
||||
get(T const* x, detail::no_convertible)
|
||||
{
|
||||
return python::incref(converter::arg_to_python<T>(*x).get());
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_initializer<true, false>
|
||||
{
|
||||
template <class Policies>
|
||||
static PyObject*
|
||||
get(proxy<Policies> const* x, detail::no_convertible)
|
||||
{
|
||||
return python::incref(x->operator object().ptr());
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_initializer<false, true>
|
||||
{
|
||||
template <class T>
|
||||
static PyObject*
|
||||
get(T const* x, ...)
|
||||
{
|
||||
return python::incref(get_managed_object(*x, tag));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_initializer<true, true>
|
||||
{}; // empty implementation should cause an error
|
||||
}
|
||||
using api::object;
|
||||
template <class T> struct extract;
|
||||
|
||||
//
|
||||
// implementation
|
||||
//
|
||||
|
||||
inline object::object()
|
||||
: object_base(python::incref(Py_None))
|
||||
{}
|
||||
|
||||
// copy constructor without NULL checking, for efficiency
|
||||
inline api::object_base::object_base(object_base const& rhs)
|
||||
: m_ptr(python::incref(rhs.m_ptr))
|
||||
{}
|
||||
|
||||
inline api::object_base::object_base(PyObject* p)
|
||||
: m_ptr(p)
|
||||
{}
|
||||
|
||||
inline api::object_base& api::object_base::operator=(api::object_base const& rhs)
|
||||
{
|
||||
Py_INCREF(rhs.m_ptr);
|
||||
Py_DECREF(this->m_ptr);
|
||||
this->m_ptr = rhs.m_ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline api::object_base::~object_base()
|
||||
{
|
||||
Py_DECREF(m_ptr);
|
||||
}
|
||||
|
||||
inline object::object(detail::borrowed_reference p)
|
||||
: object_base(python::incref((PyObject*)p))
|
||||
{}
|
||||
|
||||
inline object::object(detail::new_reference p)
|
||||
: object_base(expect_non_null((PyObject*)p))
|
||||
{}
|
||||
|
||||
inline object::object(detail::new_non_null_reference p)
|
||||
: object_base((PyObject*)p)
|
||||
{}
|
||||
|
||||
inline PyObject* api::object_base::ptr() const
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
//
|
||||
// Converter specialization implementations
|
||||
//
|
||||
namespace converter
|
||||
{
|
||||
template <class T> struct object_manager_traits;
|
||||
|
||||
template <>
|
||||
struct object_manager_traits<object>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, is_specialized = true);
|
||||
static bool check(PyObject*) { return true; }
|
||||
|
||||
static python::detail::new_non_null_reference adopt(PyObject* x)
|
||||
{
|
||||
return python::detail::new_non_null_reference(x);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
inline PyObject* get_managed_object(object const& x, tag_t)
|
||||
{
|
||||
return x.ptr();
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // OBJECT_CORE_DWA2002615_HPP
|
||||
17
include/boost/python/object_fwd.hpp
Normal file
17
include/boost/python/object_fwd.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef OBJECT_FWD_DWA2002724_HPP
|
||||
# define OBJECT_FWD_DWA2002724_HPP
|
||||
|
||||
namespace boost { namespace python {
|
||||
namespace api
|
||||
{
|
||||
class object;
|
||||
}
|
||||
using api::object;
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // OBJECT_FWD_DWA2002724_HPP
|
||||
94
include/boost/python/object_operators.hpp
Normal file
94
include/boost/python/object_operators.hpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef OBJECT_OPERATORS_DWA2002617_HPP
|
||||
# define OBJECT_OPERATORS_DWA2002617_HPP
|
||||
|
||||
# include <boost/python/object_core.hpp>
|
||||
# include <boost/python/call.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace api {
|
||||
|
||||
template <class U>
|
||||
object object_operators<U>::operator()() const
|
||||
{
|
||||
object_cref2 f = *static_cast<U const*>(this);
|
||||
return call<object>(f.ptr());
|
||||
}
|
||||
|
||||
|
||||
template <class U>
|
||||
inline
|
||||
object_operators<U>::operator bool_type() const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
return PyObject_IsTrue(x.ptr()) ? &object::ptr : 0;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline bool
|
||||
object_operators<U>::operator!() const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
return !PyObject_IsTrue(x.ptr());
|
||||
}
|
||||
|
||||
# define BOOST_PYTHON_COMPARE_OP(op, opid) \
|
||||
template <class L, class R> \
|
||||
bool operator op(L const& l, R const& r) \
|
||||
{ \
|
||||
return PyObject_RichCompareBool( \
|
||||
object(l).ptr(), object(r).ptr(), opid); \
|
||||
}
|
||||
BOOST_PYTHON_COMPARE_OP(>, Py_GT)
|
||||
BOOST_PYTHON_COMPARE_OP(>=, Py_GE)
|
||||
BOOST_PYTHON_COMPARE_OP(<, Py_LT)
|
||||
BOOST_PYTHON_COMPARE_OP(<=, Py_LE)
|
||||
BOOST_PYTHON_COMPARE_OP(==, Py_EQ)
|
||||
BOOST_PYTHON_COMPARE_OP(!=, Py_NE)
|
||||
# undef BOOST_PYTHON_COMPARE_OP
|
||||
|
||||
# define BOOST_PYTHON_BINARY_OPERATOR(op) \
|
||||
BOOST_PYTHON_DECL object operator op(object const& l, object const& r); \
|
||||
template <class L, class R> \
|
||||
object operator op(L const& l, R const& r) \
|
||||
{ \
|
||||
return object(l) op object(r); \
|
||||
}
|
||||
BOOST_PYTHON_BINARY_OPERATOR(+)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(-)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(*)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(/)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(%)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(<<)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(>>)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(&)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(^)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(|)
|
||||
# undef BOOST_PYTHON_BINARY_OPERATOR
|
||||
|
||||
|
||||
# define BOOST_PYTHON_INPLACE_OPERATOR(op) \
|
||||
BOOST_PYTHON_DECL object& operator op(object& l, object const& r); \
|
||||
template <class R> \
|
||||
object& operator op(object& l, R const& r) \
|
||||
{ \
|
||||
return l op object(r); \
|
||||
}
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(+=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(-=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(*=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(/=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(%=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(<<=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(>>=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(&=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(^=)
|
||||
BOOST_PYTHON_INPLACE_OPERATOR(|=)
|
||||
# undef BOOST_PYTHON_INPLACE_OPERATOR
|
||||
|
||||
}}} // namespace boost::python
|
||||
|
||||
#endif // OBJECT_OPERATORS_DWA2002617_HPP
|
||||
80
include/boost/python/object_protocol.hpp
Executable file
80
include/boost/python/object_protocol.hpp
Executable file
@@ -0,0 +1,80 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef OBJECT_PROTOCOL_DWA2002615_HPP
|
||||
# define OBJECT_PROTOCOL_DWA2002615_HPP
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/object_protocol_core.hpp>
|
||||
# include <boost/python/object_core.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace api {
|
||||
|
||||
template <class Target, class Key>
|
||||
object getattr(Target const& target, Key const& key)
|
||||
{
|
||||
return getattr(object(target), object(key));
|
||||
}
|
||||
|
||||
template <class Target, class Key, class Default>
|
||||
object getattr(Target const& target, Key const& key, Default const& default_)
|
||||
{
|
||||
return getattr(object(target), object(key), object(default_));
|
||||
}
|
||||
|
||||
|
||||
template <class Key, class Value>
|
||||
void setattr(object const& target, Key const& key, Value const& value)
|
||||
{
|
||||
return setattr(target, object(key), object(value));
|
||||
}
|
||||
|
||||
template <class Key>
|
||||
void delattr(object const& target, Key const& key)
|
||||
{
|
||||
delattr(target, object(key));
|
||||
}
|
||||
|
||||
template <class Target, class Key>
|
||||
object getitem(Target const& target, Key const& key)
|
||||
{
|
||||
return getitem(object(target), object(key));
|
||||
}
|
||||
|
||||
|
||||
template <class Key, class Value>
|
||||
void setitem(object const& target, Key const& key, Value const& value)
|
||||
{
|
||||
return setitem(target, object(key), object(value));
|
||||
}
|
||||
|
||||
template <class Key>
|
||||
void delitem(object const& target, Key const& key)
|
||||
{
|
||||
delitem(target, object(key));
|
||||
}
|
||||
|
||||
template <class Target, class Begin, class End>
|
||||
object getslice(Target const& target, Begin const& begin, End const& end)
|
||||
{
|
||||
return getslice(object(target), object(begin), object(end));
|
||||
}
|
||||
|
||||
template <class Begin, class End, class Value>
|
||||
void setslice(object const& target, Begin const& begin, End const& end, Value const& value)
|
||||
{
|
||||
return setslice(target, object(begin), object(end), object(value));
|
||||
}
|
||||
|
||||
template <class Begin, class End>
|
||||
void delslice(object const& target, Begin const& begin, End const& end)
|
||||
{
|
||||
delslice(target, object(begin), object(end));
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::api
|
||||
|
||||
#endif // OBJECT_PROTOCOL_DWA2002615_HPP
|
||||
52
include/boost/python/object_protocol_core.hpp
Executable file
52
include/boost/python/object_protocol_core.hpp
Executable file
@@ -0,0 +1,52 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef OBJECT_PROTOCOL_CORE_DWA2002615_HPP
|
||||
# define OBJECT_PROTOCOL_CORE_DWA2002615_HPP
|
||||
|
||||
# include <boost/python/handle_fwd.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace api
|
||||
{
|
||||
class object;
|
||||
|
||||
BOOST_PYTHON_DECL object getattr(object const& target, object const& key);
|
||||
BOOST_PYTHON_DECL object getattr(object const& target, object const& key, object const& default_);
|
||||
BOOST_PYTHON_DECL void setattr(object const& target, object const& key, object const& value);
|
||||
BOOST_PYTHON_DECL void delattr(object const& target, object const& key);
|
||||
|
||||
// These are defined for efficiency, since attributes are commonly
|
||||
// accessed through literal strings.
|
||||
BOOST_PYTHON_DECL object getattr(object const& target, char const* key);
|
||||
BOOST_PYTHON_DECL object getattr(object const& target, char const* key, object const& default_);
|
||||
BOOST_PYTHON_DECL void setattr(object const& target, char const* key, object const& value);
|
||||
BOOST_PYTHON_DECL void delattr(object const& target, char const* key);
|
||||
|
||||
BOOST_PYTHON_DECL object getitem(object const& target, object const& key);
|
||||
BOOST_PYTHON_DECL void setitem(object const& target, object const& key, object const& value);
|
||||
BOOST_PYTHON_DECL void delitem(object const& target, object const& key);
|
||||
|
||||
BOOST_PYTHON_DECL object getslice(object const& target, handle<> const& begin, handle<> const& end);
|
||||
BOOST_PYTHON_DECL void setslice(object const& target, handle<> const& begin, handle<> const& end, object const& value);
|
||||
BOOST_PYTHON_DECL void delslice(object const& target, handle<> const& begin, handle<> const& end);
|
||||
}
|
||||
|
||||
using api::getattr;
|
||||
using api::setattr;
|
||||
using api::delattr;
|
||||
|
||||
using api::getitem;
|
||||
using api::setitem;
|
||||
using api::delitem;
|
||||
|
||||
using api::getslice;
|
||||
using api::setslice;
|
||||
using api::delslice;
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // OBJECT_PROTOCOL_CORE_DWA2002615_HPP
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user