mirror of
https://github.com/boostorg/python.git
synced 2026-01-22 17:32:55 +00:00
This commit was manufactured by cvs2svn to create branch 'mpl_v2'.
[SVN r13495]
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
// 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/mpl/type_list.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
// A type list for specifying arguments
|
||||
template < BOOST_MPL_LIST_DEFAULT_PARAMETERS(typename A, ::boost::mpl::null_argument) >
|
||||
struct args : ::boost::mpl::type_list< BOOST_MPL_LIST_PARAMETERS(A) >::type
|
||||
{};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // ARGS_DWA2002323_HPP
|
||||
@@ -1,49 +0,0 @@
|
||||
// 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/python/converter/callback.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/enum.hpp>
|
||||
# include <boost/preprocessor/enum_params.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
# include <boost/type.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
# ifndef BOOST_PYTHON_GENERATE_CODE
|
||||
# include <boost/python/preprocessed/call.hpp>
|
||||
# endif
|
||||
|
||||
# define BOOST_PYTHON_CALL_FUNCTION(nargs,ignored) \
|
||||
template < \
|
||||
class R \
|
||||
BOOST_PP_COMMA_IF(nargs) BOOST_PP_ENUM_PARAMS(nargs, class A) \
|
||||
> \
|
||||
typename converter::callback_from_python<R>::result_type \
|
||||
call(PyObject* callable \
|
||||
BOOST_PP_COMMA_IF(nargs) BOOST_PYTHON_ENUM_PARAMS2(nargs, (A,const& a)) \
|
||||
, boost::type<R>* = 0 \
|
||||
) \
|
||||
{ \
|
||||
converter::callback_from_python<R> converter; \
|
||||
return converter( \
|
||||
PyEval_CallFunction( \
|
||||
callable \
|
||||
, const_cast<char*>(BOOST_PYTHON_ARG_STRING(nargs)) \
|
||||
BOOST_PP_COMMA_IF(nargs) \
|
||||
BOOST_PP_ENUM(nargs,BOOST_PYTHON_CALLBACK_TO_PYTHON_GET,nil) \
|
||||
)); \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CALL_FUNCTION,data)
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CALL_DWA2002411_HPP
|
||||
@@ -1,50 +0,0 @@
|
||||
// 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/python/converter/callback.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/enum.hpp>
|
||||
# include <boost/preprocessor/enum_params.hpp>
|
||||
# include <boost/preprocessor/repeat.hpp>
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
# include <boost/type.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
# ifndef BOOST_PYTHON_GENERATE_CODE
|
||||
# include <boost/python/preprocessed/call_method.hpp>
|
||||
# endif
|
||||
|
||||
# define BOOST_PYTHON_CALL_METHOD_FUNCTION(nargs,ignored) \
|
||||
template < \
|
||||
class R \
|
||||
BOOST_PP_COMMA_IF(nargs) BOOST_PP_ENUM_PARAMS(nargs, class A) \
|
||||
> \
|
||||
typename converter::callback_from_python<R>::result_type \
|
||||
call_method(PyObject* self, char const* name \
|
||||
BOOST_PP_COMMA_IF(nargs) BOOST_PYTHON_ENUM_PARAMS2(nargs, (A,const& a)) \
|
||||
, boost::type<R>* = 0 \
|
||||
) \
|
||||
{ \
|
||||
converter::callback_from_python<R> converter; \
|
||||
return converter( \
|
||||
PyEval_CallMethod( \
|
||||
self \
|
||||
, const_cast<char*>(name) \
|
||||
, const_cast<char*>(BOOST_PYTHON_ARG_STRING(nargs)) \
|
||||
BOOST_PP_COMMA_IF(nargs) \
|
||||
BOOST_PP_ENUM(nargs,BOOST_PYTHON_CALLBACK_TO_PYTHON_GET,nil) \
|
||||
)); \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CALL_METHOD_FUNCTION,data)
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CALL_METHOD_DWA2002411_HPP
|
||||
@@ -1,288 +0,0 @@
|
||||
// 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/bases.hpp>
|
||||
# include <boost/python/args.hpp>
|
||||
# include <boost/python/reference.hpp>
|
||||
# include <boost/python/object/class.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/detail/wrap_function.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/data_members.hpp>
|
||||
# include <boost/utility.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;
|
||||
|
||||
// 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 Holder>
|
||||
static inline void register_copy_constructor(mpl::bool_t<true> const&, Holder*, ref const& obj, T* = 0)
|
||||
{
|
||||
objects::class_wrapper<T,Holder> x(obj);
|
||||
}
|
||||
|
||||
// Tag dispatched to have no effect.
|
||||
template <class T, class Holder>
|
||||
static inline void register_copy_constructor(mpl::bool_t<false> const&, Holder*, ref const&, T* = 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
{
|
||||
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;
|
||||
|
||||
public:
|
||||
// Automatically derive the class name - only works on some
|
||||
// compilers because type_info::name is sometimes mangled (gcc)
|
||||
class_();
|
||||
|
||||
// Construct with the class name. [ Would have used a default
|
||||
// argument but gcc-2.95.2 choked on typeid(T).name() as a default
|
||||
// parameter value]
|
||||
class_(char const* name);
|
||||
|
||||
|
||||
// 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)
|
||||
{
|
||||
// Use function::add_to_namespace to achieve overloading if
|
||||
// appropriate.
|
||||
objects::function::add_to_namespace(
|
||||
this->object(), name,
|
||||
ref(detail::wrap_function(
|
||||
// This bit of nastiness casts F to a member function of T if possible.
|
||||
detail::member_function_cast<T,F>::stage1(f).stage2((T*)0).stage3(f)
|
||||
)));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Fn, class CallPolicy>
|
||||
self& def(char const* name, Fn fn, CallPolicy policy)
|
||||
{
|
||||
this->def(name
|
||||
, boost::python::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)
|
||||
, policy)
|
||||
);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Define the constructor with the given Args, which should be an
|
||||
// MPL sequence of types.
|
||||
template <class Args>
|
||||
self& def_init(Args const&)
|
||||
{
|
||||
def("__init__",
|
||||
make_constructor<Args>(
|
||||
// Using runtime type selection works around a CWPro7 bug.
|
||||
objects::select_holder<T,held_type>((held_type*)0).get()
|
||||
)
|
||||
);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Args, class CallPolicy>
|
||||
self& def_init(Args const&, CallPolicy policy)
|
||||
{
|
||||
def("__init__",
|
||||
make_constructor<Args>(
|
||||
policy
|
||||
// Using runtime type selection works around a CWPro7 bug.
|
||||
, objects::select_holder<T,held_type>((held_type*)0).get()
|
||||
)
|
||||
);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
ref fget(make_getter(pm));
|
||||
this->add_property(name, fget);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class D>
|
||||
self& def_readwrite(char const* name, D T::*pm)
|
||||
{
|
||||
ref fget(make_getter(pm));
|
||||
ref fset(make_setter(pm));
|
||||
this->add_property(name, fget, fset);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// return the underlying object
|
||||
// ref object() const;
|
||||
|
||||
private: // types
|
||||
typedef objects::class_id class_id;
|
||||
|
||||
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
|
||||
{
|
||||
typedef objects::class_id class_id;
|
||||
id_vector()
|
||||
{
|
||||
// Stick the derived class id into the first element of the array
|
||||
ids[0] = converter::undecorated_type_id<T>();
|
||||
|
||||
// Write the rest of the elements into succeeding positions.
|
||||
class_id* 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);
|
||||
class_id ids[size];
|
||||
};
|
||||
friend struct id_vector;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline class_<T,X1,X2,X3>::class_()
|
||||
: class_base(typeid(T).name(), id_vector::size, id_vector().ids)
|
||||
{
|
||||
// register converters
|
||||
objects::register_class_from_python<T,bases>();
|
||||
|
||||
detail::register_copy_constructor<T>(
|
||||
mpl::bool_t<is_copyable>()
|
||||
, objects::select_holder<T,held_type>((held_type*)0).get()
|
||||
, this->object());
|
||||
}
|
||||
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline class_<T,X1,X2,X3>::class_(char const* name)
|
||||
: class_base(name, id_vector::size, id_vector().ids)
|
||||
{
|
||||
// register converters
|
||||
objects::register_class_from_python<T,bases>();
|
||||
|
||||
detail::register_copy_constructor<T>(
|
||||
mpl::bool_t<is_copyable>()
|
||||
, objects::select_holder<T,held_type>((held_type*)0).get()
|
||||
, this->object());
|
||||
}
|
||||
|
||||
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(converter::undecorated_type_id_t** p)
|
||||
{
|
||||
*(*p)++ = converter::undecorated_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
|
||||
@@ -1,27 +0,0 @@
|
||||
// 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_FWD_DWA200222_HPP
|
||||
# define CLASS_FWD_DWA200222_HPP
|
||||
# include <boost/python/detail/not_specified.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct empty_list;
|
||||
}
|
||||
|
||||
template <
|
||||
class T // class being wrapped
|
||||
, class X1 = detail::not_specified
|
||||
, class X2 = detail::not_specified
|
||||
, class X3 = detail::not_specified
|
||||
>
|
||||
class class_;
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // CLASS_FWD_DWA200222_HPP
|
||||
@@ -1,104 +0,0 @@
|
||||
// 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/reference.hpp>
|
||||
# include <string>
|
||||
# include <complex>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
// Provide specializations of to_python_value
|
||||
template <class T> struct to_python_value;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct builtin_to_python
|
||||
{
|
||||
static bool convertible() { return true; }
|
||||
};
|
||||
}
|
||||
|
||||
namespace converter
|
||||
{
|
||||
template <class T> struct callback_to_python;
|
||||
BOOST_PYTHON_DECL PyObject* do_call_to_python(char);
|
||||
BOOST_PYTHON_DECL PyObject* do_call_to_python(char const*);
|
||||
BOOST_PYTHON_DECL PyObject* do_call_to_python(PyObject*);
|
||||
BOOST_PYTHON_DECL PyObject* do_callback_to_python(PyObject*);
|
||||
}
|
||||
|
||||
# define BOOST_PYTHON_CALL_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
template <> struct to_python_value<T&> \
|
||||
: detail::builtin_to_python \
|
||||
{ \
|
||||
PyObject* operator()(T const& x) const \
|
||||
{ \
|
||||
return (expr); \
|
||||
} \
|
||||
}; \
|
||||
template <> struct to_python_value<T const&> \
|
||||
: detail::builtin_to_python \
|
||||
{ \
|
||||
PyObject* operator()(T const& x) const \
|
||||
{ \
|
||||
return (expr); \
|
||||
} \
|
||||
};
|
||||
|
||||
# define BOOST_PYTHON_CALLBACK_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
namespace converter \
|
||||
{ \
|
||||
template <> struct callback_to_python< T > \
|
||||
{ \
|
||||
callback_to_python(T const& x) \
|
||||
: m_held(expr) {} \
|
||||
PyObject* get() const \
|
||||
{ return m_held.get(); } \
|
||||
private: \
|
||||
ref m_held; \
|
||||
}; \
|
||||
}
|
||||
|
||||
# define BOOST_PYTHON_TO_PYTHON_BY_VALUE(T, expr) \
|
||||
BOOST_PYTHON_CALL_TO_PYTHON_BY_VALUE(T,expr) \
|
||||
BOOST_PYTHON_CALLBACK_TO_PYTHON_BY_VALUE(T,expr)
|
||||
|
||||
# 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))
|
||||
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, PyInt_FromLong(x))
|
||||
BOOST_PYTHON_TO_INT(char)
|
||||
BOOST_PYTHON_TO_INT(short)
|
||||
BOOST_PYTHON_TO_INT(int)
|
||||
BOOST_PYTHON_TO_INT(long)
|
||||
# undef BOOST_TO_PYTHON_INT
|
||||
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_call_to_python(x))
|
||||
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_call_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_CALL_TO_PYTHON_BY_VALUE(PyObject*, converter::do_call_to_python(x))
|
||||
BOOST_PYTHON_CALLBACK_TO_PYTHON_BY_VALUE(PyObject*, converter::do_callback_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
|
||||
@@ -1,237 +0,0 @@
|
||||
// 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_DWA2002127_HPP
|
||||
# define FROM_PYTHON_DWA2002127_HPP
|
||||
|
||||
# include <boost/python/converter/find_from_python.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/converter/from_python_data.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/lvalue_from_python_chain.hpp>
|
||||
# include <boost/python/converter/rvalue_from_python_chain.hpp>
|
||||
# include <boost/python/detail/void_ptr.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct from_python_base
|
||||
{
|
||||
public: // member functions
|
||||
from_python_base(void* result);
|
||||
from_python_base(PyObject*, lvalue_from_python_registration const* chain);
|
||||
bool convertible() const;
|
||||
|
||||
protected: // member functions
|
||||
void*const& result() const;
|
||||
|
||||
private: // data members
|
||||
void* m_result;
|
||||
};
|
||||
|
||||
// Used when T == U*const&
|
||||
template <class T>
|
||||
struct pointer_const_reference_from_python
|
||||
{
|
||||
pointer_const_reference_from_python(PyObject*);
|
||||
T operator()(PyObject*) const;
|
||||
bool convertible() const;
|
||||
|
||||
private:
|
||||
typename detail::referent_storage<T>::type m_result;
|
||||
};
|
||||
|
||||
// Used when T == U*
|
||||
template <class T>
|
||||
struct pointer_from_python : from_python_base
|
||||
{
|
||||
pointer_from_python(PyObject*);
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
// Used when T == U& and (T != V const& or T == W volatile&)
|
||||
template <class T>
|
||||
struct reference_from_python : from_python_base
|
||||
{
|
||||
reference_from_python(PyObject*);
|
||||
T operator()(PyObject*) const;
|
||||
};
|
||||
|
||||
// ------- rvalue converters ---------
|
||||
|
||||
// Used for the case where T is a non-pointer, non-reference type OR
|
||||
// is a const non-volatile reference to a non-pointer type.
|
||||
template <class T>
|
||||
class rvalue_from_python
|
||||
{
|
||||
typedef typename boost::add_reference<
|
||||
typename boost::add_const<T>::type
|
||||
>::type result_type;
|
||||
|
||||
public:
|
||||
rvalue_from_python(PyObject*);
|
||||
bool convertible() const;
|
||||
|
||||
result_type operator()(PyObject*);
|
||||
|
||||
private:
|
||||
rvalue_data<result_type> m_data;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct select_from_python
|
||||
{
|
||||
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);
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
ptr
|
||||
, pointer_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
ptr_cref
|
||||
, pointer_const_reference_from_python<T>
|
||||
, typename mpl::select_type<
|
||||
ref
|
||||
, reference_from_python<T>
|
||||
, rvalue_from_python<T>
|
||||
>::type
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
inline from_python_base::from_python_base(void* result)
|
||||
: m_result(result)
|
||||
{
|
||||
}
|
||||
|
||||
inline from_python_base::from_python_base(
|
||||
PyObject* source
|
||||
, lvalue_from_python_registration const* chain)
|
||||
: m_result(find(source, chain))
|
||||
{
|
||||
}
|
||||
|
||||
inline bool from_python_base::convertible() const
|
||||
{
|
||||
return m_result != 0;
|
||||
}
|
||||
|
||||
inline void*const& from_python_base::result() const
|
||||
{
|
||||
return m_result;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
namespace detail
|
||||
{
|
||||
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_const_reference_from_python<T>::pointer_const_reference_from_python(PyObject* p)
|
||||
{
|
||||
python::detail::write_void_ptr_reference(
|
||||
m_result.bytes
|
||||
, p == Py_None ? p : find(p, lvalue_from_python_chain<T>::value)
|
||||
, (T(*)())0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool pointer_const_reference_from_python<T>::convertible() const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0) != 0;
|
||||
}
|
||||
template <class T>
|
||||
inline T pointer_const_reference_from_python<T>::operator()(PyObject* p) const
|
||||
{
|
||||
return (p == Py_None)
|
||||
? detail::null_ptr_reference((T(*)())0)
|
||||
: python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0);
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
template <class T>
|
||||
inline pointer_from_python<T>::pointer_from_python(PyObject* p)
|
||||
: from_python_base(p == Py_None ? p : find(p, lvalue_from_python_chain<T>::value))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T pointer_from_python<T>::operator()(PyObject* p) const
|
||||
{
|
||||
return (p == Py_None) ? 0 : T(result());
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
template <class T>
|
||||
inline reference_from_python<T>::reference_from_python(PyObject* p)
|
||||
: from_python_base(find(p,lvalue_from_python_chain<T>::value))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T reference_from_python<T>::operator()(PyObject*) const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(result(), (T(*)())0);
|
||||
}
|
||||
|
||||
// -------
|
||||
|
||||
template <class T>
|
||||
inline rvalue_from_python<T>::rvalue_from_python(PyObject* obj)
|
||||
: m_data(find(obj, rvalue_from_python_chain<T>::value))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool rvalue_from_python<T>::convertible() const
|
||||
{
|
||||
return m_data.stage1.convertible != 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typename rvalue_from_python<T>::result_type
|
||||
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);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // FROM_PYTHON_DWA2002127_HPP
|
||||
@@ -1,50 +0,0 @@
|
||||
// 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/from_python_data.hpp>
|
||||
# include <boost/python/converter/from_python_stage1_data.hpp>
|
||||
# include <boost/python/converter/registrations.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
template <class Source, class Target>
|
||||
struct implicit
|
||||
{
|
||||
static void* convertible(PyObject* obj)
|
||||
{
|
||||
// Find a converter registration which can produce a Source
|
||||
// instance from obj
|
||||
return const_cast<rvalue_from_python_registration*>(
|
||||
find_chain(obj, rvalue_from_python_chain<Source>::value));
|
||||
}
|
||||
|
||||
static void construct(PyObject* obj, rvalue_stage1_data* data)
|
||||
{
|
||||
// This is the registration we got from the convertible step
|
||||
rvalue_from_python_registration const* registration
|
||||
= static_cast<rvalue_from_python_registration*>(data->convertible);
|
||||
|
||||
// Call the convertible function again
|
||||
rvalue_data<Source> intermediate_data(registration->convertible(obj));
|
||||
|
||||
// Use the result to construct the source type if the first
|
||||
// converter was an rvalue converter.
|
||||
if (registration->construct != 0)
|
||||
registration->construct(obj, &intermediate_data.stage1);
|
||||
|
||||
void* storage = ((rvalue_base_data<Target>*)data)->storage.bytes;
|
||||
new (storage) Target(*static_cast<Source*>(intermediate_data.stage1.convertible));
|
||||
|
||||
// record successful construction
|
||||
data->convertible = storage;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // IMPLICIT_DWA2002326_HPP
|
||||
@@ -1,69 +0,0 @@
|
||||
// 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 POINTER_TYPE_ID_DWA2002222_HPP
|
||||
# define POINTER_TYPE_ID_DWA2002222_HPP
|
||||
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <bool is_ref = false>
|
||||
struct pointer_typeid_select
|
||||
{
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pointer_typeid_select<true>
|
||||
{
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T* const volatile&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*volatile&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*const&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Usage: pointer_type_id<T>()
|
||||
//
|
||||
// Returns an undecorated_type_id_t associated with the type pointed
|
||||
// to by T, which may be a pointer or a reference to a pointer.
|
||||
template <class T>
|
||||
undecorated_type_id_t pointer_type_id(T(*)() = 0)
|
||||
{
|
||||
return detail::pointer_typeid_select<
|
||||
is_reference<T>::value
|
||||
>::execute((T(*)())0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // POINTER_TYPE_ID_DWA2002222_HPP
|
||||
@@ -1,28 +0,0 @@
|
||||
// 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/converter/from_python_function.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct lvalue_from_python_registration
|
||||
{
|
||||
void* (*convert)(PyObject* source);
|
||||
lvalue_from_python_registration* next;
|
||||
};
|
||||
|
||||
struct rvalue_from_python_registration
|
||||
{
|
||||
void* (*convertible)(PyObject*);
|
||||
constructor_function construct;
|
||||
rvalue_from_python_registration* next;
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTRATIONS_DWA2002223_HPP
|
||||
@@ -1,53 +0,0 @@
|
||||
// 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/converter/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/from_python_function.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
struct lvalue_from_python_registration;
|
||||
struct rvalue_from_python_registration;
|
||||
|
||||
// This namespace acts as a sort of singleton
|
||||
namespace registry
|
||||
{
|
||||
BOOST_PYTHON_DECL lvalue_from_python_registration*& lvalue_converters(undecorated_type_id_t);
|
||||
BOOST_PYTHON_DECL rvalue_from_python_registration*& rvalue_converters(undecorated_type_id_t);
|
||||
|
||||
BOOST_PYTHON_DECL to_python_function_t const&
|
||||
get_to_python_function(undecorated_type_id_t);
|
||||
|
||||
BOOST_PYTHON_DECL void insert(to_python_function_t, undecorated_type_id_t);
|
||||
|
||||
// Insert an lvalue from_python converter
|
||||
BOOST_PYTHON_DECL void insert(void* (*convert)(PyObject*), undecorated_type_id_t);
|
||||
|
||||
// Insert an rvalue from_python converter
|
||||
BOOST_PYTHON_DECL void insert(
|
||||
void* (*convertible)(PyObject*)
|
||||
, constructor_function
|
||||
, undecorated_type_id_t
|
||||
);
|
||||
|
||||
// Insert an rvalue from_python converter at the tail of the
|
||||
// chain. Used for implicit conversions
|
||||
BOOST_PYTHON_DECL void push_back(
|
||||
void* (*convertible)(PyObject*)
|
||||
, constructor_function
|
||||
, undecorated_type_id_t
|
||||
);
|
||||
|
||||
BOOST_PYTHON_DECL PyTypeObject*& class_object(undecorated_type_id_t key);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // REGISTRY_DWA20011127_HPP
|
||||
@@ -1,111 +0,0 @@
|
||||
// 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/python/object/function.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_mutable_reference.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)
|
||||
{
|
||||
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
|
||||
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;
|
||||
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>
|
||||
objects::function* make_getter(D C::*pm)
|
||||
{
|
||||
typedef return_value_policy<copy_mutable_reference> default_policy;
|
||||
return new objects::function(
|
||||
objects::py_function(
|
||||
::boost::bind(
|
||||
&detail::member<D,C,default_policy>::get, pm, _1, _2
|
||||
, default_policy()))
|
||||
, 1);
|
||||
}
|
||||
|
||||
template <class C, class D, class Policies>
|
||||
objects::function* make_getter(D C::*pm, Policies const& policies)
|
||||
{
|
||||
return new objects::function(
|
||||
objects::py_function(
|
||||
::boost::bind(
|
||||
&detail::member<D,C,Policies>::get, pm, _1, _2
|
||||
, policies))
|
||||
, 1);
|
||||
}
|
||||
|
||||
template <class C, class D>
|
||||
objects::function* make_setter(D C::*pm)
|
||||
{
|
||||
return new objects::function(
|
||||
objects::py_function(
|
||||
::boost::bind(
|
||||
&detail::member<D,C,default_call_policies>::set, pm, _1, _2
|
||||
, default_call_policies()))
|
||||
, 2);
|
||||
}
|
||||
|
||||
template <class C, class D, class Policies>
|
||||
objects::function* make_setter(D C::*pm, Policies const& policies)
|
||||
{
|
||||
return new objects::function(
|
||||
objects::py_function(
|
||||
::boost::bind(
|
||||
&detail::member<D,C,Policies>::set, pm, _1, _2
|
||||
, policies))
|
||||
, 2);
|
||||
}
|
||||
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // DATA_MEMBERS_DWA2002328_HPP
|
||||
@@ -1,90 +0,0 @@
|
||||
// (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/mpl/aux_/preprocessor.hpp>
|
||||
# include <boost/preprocessor/comma_if.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;
|
||||
|
||||
// Include the pre-expanded version of the code
|
||||
# ifndef BOOST_PYTHON_GENERATE_CODE
|
||||
# include <boost/python/preprocessed/arg_tuple_size.hpp>
|
||||
# endif
|
||||
|
||||
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
|
||||
// Specializations for function pointers
|
||||
# define BOOST_PYTHON_ARG_TUPLE_SIZE_PF(args, ignored) \
|
||||
template <class R BOOST_PP_COMMA_IF(args) BOOST_MPL_TEMPLATE_PARAMETERS(0, args, class A)> \
|
||||
struct arg_tuple_size<BOOST_PYTHON_FN(*,0,args)> \
|
||||
{ \
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = args); \
|
||||
};
|
||||
|
||||
// Specializations for member function pointers
|
||||
# define BOOST_PYTHON_ARG_TUPLE_SIZE_PMF(args, cv) \
|
||||
template <class R, BOOST_MPL_TEMPLATE_PARAMETERS(0, args, class A)> \
|
||||
struct arg_tuple_size<BOOST_PYTHON_FN(A0::*,1,args) cv()> \
|
||||
{ \
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = args); \
|
||||
};
|
||||
|
||||
# else
|
||||
|
||||
// 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.
|
||||
|
||||
# define BOOST_PYTHON_ARG_TUPLE_SIZE_PF(args, ignored) \
|
||||
template <class R BOOST_PP_COMMA_IF(args) BOOST_MPL_TEMPLATE_PARAMETERS(0, args, class A)> \
|
||||
char_array<args> arg_tuple_size_helper(BOOST_PYTHON_FN(*,0,args));
|
||||
|
||||
# define BOOST_PYTHON_ARG_TUPLE_SIZE_PMF(args, cv) \
|
||||
template <class R, BOOST_MPL_TEMPLATE_PARAMETERS(0, args, class A)> \
|
||||
char_array<args> arg_tuple_size_helper(BOOST_PYTHON_FN(A0::*,1,args)cv());
|
||||
|
||||
# endif
|
||||
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_ARG_TUPLE_SIZE_PF, nil)
|
||||
|
||||
// Generate a series for each cv-qualification
|
||||
BOOST_PYTHON_REPEAT_MF_CV_2ND(BOOST_PYTHON_ARG_TUPLE_SIZE_PMF)
|
||||
|
||||
# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) || defined(__BORLANDC__)
|
||||
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
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
// 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 CALLER_DWA20011214_HPP
|
||||
# define CALLER_DWA20011214_HPP
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/returning.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/mpl/aux_/preprocessor.hpp>
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
|
||||
namespace boost { namespace python
|
||||
{
|
||||
template <class T> struct to_python;
|
||||
}}
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct caller
|
||||
{
|
||||
typedef PyObject* result_type;
|
||||
|
||||
# ifndef BOOST_PYTHON_GENERATE_CODE
|
||||
# include <boost/python/preprocessed/caller.hpp>
|
||||
# endif
|
||||
|
||||
# define BOOST_PYTHON_CALLER_PF(args_, ignored) \
|
||||
template < \
|
||||
class P \
|
||||
, class R \
|
||||
BOOST_PP_COMMA_IF(args_) BOOST_MPL_TEMPLATE_PARAMETERS(0, args_, class A) \
|
||||
> \
|
||||
PyObject* operator()( \
|
||||
BOOST_PYTHON_FN(*f,0,args_) \
|
||||
, PyObject* args, PyObject* keywords \
|
||||
, P const& policies \
|
||||
) const \
|
||||
{ \
|
||||
return returning<R>::call(f, args, keywords,&policies); \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CALLER_PF, nil)
|
||||
|
||||
// Member functions
|
||||
# define BOOST_PYTHON_CALLER_PMF(args_, cv) \
|
||||
template <class P, class R, BOOST_MPL_TEMPLATE_PARAMETERS(0, args_, class A)> \
|
||||
PyObject* operator()( \
|
||||
BOOST_PYTHON_FN(A0::*f,1,args_)cv() \
|
||||
, PyObject* args, PyObject* keywords \
|
||||
, P const& policies \
|
||||
) const \
|
||||
{ \
|
||||
return returning<R>::call(f, args, keywords,&policies); \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_REPEAT_MF_ALL_CV_2ND(BOOST_PYTHON_CALLER_PMF)
|
||||
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // CALLER_DWA20011214_HPP
|
||||
@@ -1,130 +0,0 @@
|
||||
// (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.
|
||||
|
||||
// Revision History:
|
||||
// 04 Mar 01 Some fixes so it will compile with Intel C++ (Dave Abrahams)
|
||||
|
||||
#ifndef CONFIG_DWA052200_H_
|
||||
# define CONFIG_DWA052200_H_
|
||||
|
||||
# include <boost/config.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
# ifdef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||
// A gcc bug forces some symbols into the global namespace
|
||||
# define BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
|
||||
# define BOOST_PYTHON_END_CONVERSION_NAMESPACE
|
||||
# define BOOST_PYTHON_CONVERSION
|
||||
# define BOOST_PYTHON_IMPORT_CONVERSION(x) using ::x
|
||||
# else
|
||||
# define BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE namespace boost { namespace python {
|
||||
# define BOOST_PYTHON_END_CONVERSION_NAMESPACE }} // namespace boost::python
|
||||
# define BOOST_PYTHON_CONVERSION boost::python
|
||||
# define BOOST_PYTHON_IMPORT_CONVERSION(x) void never_defined() // so we can follow the macro with a ';'
|
||||
# endif
|
||||
|
||||
# if defined(BOOST_MSVC)
|
||||
# if _MSC_VER <= 1200
|
||||
# define BOOST_MSVC6_OR_EARLIER 1
|
||||
# endif
|
||||
|
||||
# pragma warning (disable : 4786)
|
||||
|
||||
# elif defined(__ICL) && __ICL < 600 // Intel C++ 5
|
||||
|
||||
# pragma warning(disable: 985) // identifier was truncated in debug information
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
// Work around the broken library implementation/strict ansi checking on some
|
||||
// EDG-based compilers (e.g. alpha), which incorrectly warn that the result of
|
||||
// offsetof() is not an integer constant expression.
|
||||
# if defined(__DECCXX_VER) && __DECCXX_VER <= 60290024
|
||||
# define BOOST_OFFSETOF(s_name, s_member) \
|
||||
((size_t)__INTADDR__(&(((s_name *)0)->s_member)))
|
||||
# else
|
||||
# define BOOST_OFFSETOF(s_name, s_member) \
|
||||
offsetof(s_name, s_member)
|
||||
# endif
|
||||
|
||||
// The STLport puts all of the standard 'C' library names in std (as far as the
|
||||
// user is concerned), but without it you need a fix if you're using MSVC or
|
||||
// Intel C++
|
||||
# if defined(BOOST_MSVC_STD_ITERATOR)
|
||||
# define BOOST_CSTD_
|
||||
# else
|
||||
# define BOOST_CSTD_ std
|
||||
# endif
|
||||
|
||||
# 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()
|
||||
# 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
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Set up dll import/export options:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
// backwards compatibility:
|
||||
#ifdef BOOST_PYTHON_STATIC_LIB
|
||||
# define BOOST_PYTHON_STATIC_LINK
|
||||
# elif !defined(BOOST_PYTHON_DYNAMIC_LIB)
|
||||
# define BOOST_PYTHON_DYNAMIC_LIB
|
||||
#endif
|
||||
|
||||
#if defined(__MWERKS__) \
|
||||
|| (defined(__DECCXX_VER) && __DECCXX_VER <= 60590002) \
|
||||
|| (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
|
||||
# define BOOST_PYTHON_NO_TEMPLATE_EXPORT
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_PYTHON_DYNAMIC_LIB) && defined(_WIN32)
|
||||
# if defined(BOOST_PYTHON_SOURCE)
|
||||
# define BOOST_PYTHON_DECL __declspec(dllexport)
|
||||
# define BOOST_PYTHON_BUILD_DLL
|
||||
# else
|
||||
# define BOOST_PYTHON_DECL __declspec(dllimport)
|
||||
# endif
|
||||
|
||||
// MinGW, at least, has some problems exporting template instantiations
|
||||
# if defined(__GNUC__) && __GNUC__ < 3 && !defined(__CYGWIN__)
|
||||
# define BOOST_PYTHON_NO_TEMPLATE_EXPORT
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_PYTHON_DECL
|
||||
# define BOOST_PYTHON_DECL
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_PYTHON_EXPORT
|
||||
# define BOOST_PYTHON_EXPORT extern
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_PYTHON_NO_TEMPLATE_EXPORT)
|
||||
# define BOOST_PYTHON_EXPORT_CLASS_TEMPLATE(instantiation) BOOST_PYTHON_EXPORT template class BOOST_PYTHON_DECL instantiation
|
||||
#else
|
||||
# define BOOST_PYTHON_EXPORT_CLASS_TEMPLATE(instantiation) struct ThIsTyPeNeVeRuSeD
|
||||
#endif
|
||||
|
||||
#if defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730
|
||||
// Work around a compiler bug.
|
||||
// boost::python::detail::function has to be seen by the compiler before the
|
||||
// boost::function class template.
|
||||
namespace boost { namespace python { namespace detail {
|
||||
class function;
|
||||
}}}
|
||||
#endif
|
||||
|
||||
#endif // CONFIG_DWA052200_H_
|
||||
@@ -1,83 +0,0 @@
|
||||
// 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_reference_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_reference(void* p, T(*)() = 0)
|
||||
{
|
||||
destroy_reference_impl(p, (T(*)())0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // DESTROY_DWA2002221_HPP
|
||||
@@ -1,257 +0,0 @@
|
||||
// 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/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 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*>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_pointer_to_function<T const*>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_pointer_to_function<T volatile*>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_pointer_to_function<T const volatile*>
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
# 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;
|
||||
};
|
||||
|
||||
# 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));
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
typename is_const_help<V>::type reference_to_const_helper(V&);
|
||||
outer_no_type
|
||||
reference_to_const_helper(...);
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_const
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (is_reference<T>::value
|
||||
&& sizeof(reference_to_const_helper(t)) == sizeof(inner_yes_type)));
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_non_const
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (is_reference<T>::value
|
||||
&& sizeof(reference_to_const_helper(t)) == sizeof(inner_no_type)));
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
typename is_volatile_help<V>::type reference_to_volatile_helper(V&);
|
||||
outer_no_type reference_to_volatile_helper(...);
|
||||
|
||||
template <class T>
|
||||
struct is_reference_to_volatile
|
||||
{
|
||||
static T t;
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value
|
||||
= (is_reference<T>::value
|
||||
&& sizeof(reference_to_volatile_helper(t)) == sizeof(inner_yes_type)));
|
||||
};
|
||||
|
||||
|
||||
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))
|
||||
);
|
||||
};
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // INDIRECT_TRAITS_DWA2002131_HPP
|
||||
@@ -1,95 +0,0 @@
|
||||
// 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/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/mpl/aux_/preprocessor.hpp>
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
# include <boost/preprocessor/dec.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
|
||||
# ifndef BOOST_PYTHON_GENERATE_CODE
|
||||
# include <boost/python/preprocessed/member_function_cast.hpp>
|
||||
# endif
|
||||
|
||||
# define BOOST_PYTHON_MEMBER_FUNCTION_CAST_STAGE1(args, cv) \
|
||||
template < \
|
||||
class S \
|
||||
, class R \
|
||||
BOOST_PP_COMMA_IF(BOOST_PP_DEC(args)) BOOST_MPL_TEMPLATE_PARAMETERS(1, args, class A) \
|
||||
> \
|
||||
static cast_helper<S,BOOST_PYTHON_FN(T::*,1,args)cv()> \
|
||||
stage1(BOOST_PYTHON_FN(S::*,1,args)cv()) \
|
||||
{ \
|
||||
return cast_helper<S,BOOST_PYTHON_FN(T::*,1,args)cv()>(); \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_REPEAT_MF_ALL_CV_2ND(BOOST_PYTHON_MEMBER_FUNCTION_CAST_STAGE1)
|
||||
};
|
||||
|
||||
|
||||
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
|
||||
@@ -1,44 +0,0 @@
|
||||
// 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/reference.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(const char* name);
|
||||
~module_base();
|
||||
|
||||
// Add elements to the module
|
||||
void setattr(const char* name, PyObject*);
|
||||
void setattr(const char* name, ref const&);
|
||||
void add(PyTypeObject* x); // just use the type's name
|
||||
void add_type(ref);
|
||||
|
||||
// Return a reference to the Python module object being built
|
||||
inline ref object() const;
|
||||
|
||||
private:
|
||||
ref m_module;
|
||||
static PyMethodDef initial_methods[1];
|
||||
};
|
||||
|
||||
//
|
||||
// inline implementations
|
||||
//
|
||||
inline ref module_base::object() const
|
||||
{
|
||||
return m_module;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // MODULE_BASE_DWA2002227_HPP
|
||||
@@ -1,100 +0,0 @@
|
||||
// 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 MSVC_TYPEINFO_DWA200222_HPP
|
||||
# define MSVC_TYPEINFO_DWA200222_HPP
|
||||
|
||||
#include <boost/type.hpp>
|
||||
#include <typeinfo>
|
||||
#include <boost/type_traits/array_traits.hpp>
|
||||
#include <boost/type_traits/reference_traits.hpp>
|
||||
//
|
||||
// Fix for MSVC's broken typeid() implementation which doesn't strip
|
||||
// decoration. This fix doesn't handle cv-qualified array types. It
|
||||
// could probably be done, but I haven't figured it out yet.
|
||||
//
|
||||
|
||||
# if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(BOOST_INTEL_CXX_VERSION) && BOOST_INTEL_CXX_VERSION <= 600
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
typedef std::type_info const& typeinfo;
|
||||
|
||||
template<int>struct value_id_accessor;
|
||||
|
||||
template<>
|
||||
struct value_id_accessor<0>
|
||||
{
|
||||
template <class T>
|
||||
static typeinfo get(T*) { return typeid(T); }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct value_id_accessor<1>
|
||||
{
|
||||
template <class T>
|
||||
static typeinfo get(T const*) { return typeid(T); }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct value_id_accessor<2>
|
||||
{
|
||||
template <class T>
|
||||
static typeinfo get(T volatile*) { return typeid(T); }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct value_id_accessor<3>
|
||||
{
|
||||
template <class T>
|
||||
static typeinfo get(T const volatile*) { return typeid(T); }
|
||||
};
|
||||
|
||||
template <bool> struct bool_t{};
|
||||
|
||||
template <class T>
|
||||
inline typeinfo typeid_nonref(boost::type<T>* = 0)
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, c = is_const<T>::value);
|
||||
BOOST_STATIC_CONSTANT(bool, v = is_volatile<T>::value);
|
||||
return value_id_accessor<(2 * v + c)>::get((T*)0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typeinfo typeid_ref(T&(*)())
|
||||
{
|
||||
return typeid_nonref<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typeinfo array_ref_typeid(bool_t<true>, bool_t<false>, boost::type<T>* = 0)
|
||||
{
|
||||
return typeid_ref((T&(*)())0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typeinfo array_ref_typeid(bool_t<false>, bool_t<true>, boost::type<T>* = 0)
|
||||
{
|
||||
return typeid_ref((T(*)())0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typeinfo array_ref_typeid(bool_t<false>, bool_t<false>, boost::type<T>* = 0)
|
||||
{
|
||||
return typeid_ref((T&(*)())0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline typeinfo msvc_typeid(boost::type<T>* = 0)
|
||||
{
|
||||
typedef bool_t<is_array<T>::value> array_tag;
|
||||
typedef bool_t<is_reference<T>::value> ref_tag;
|
||||
return array_ref_typeid(array_tag(), ref_tag(), (boost::type<T>*)0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
# endif // BOOST_MSVC
|
||||
#endif // MSVC_TYPEINFO_DWA200222_HPP
|
||||
@@ -1,36 +0,0 @@
|
||||
// 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 POINTEE_DWA2002323_HPP
|
||||
# define POINTEE_DWA2002323_HPP
|
||||
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <bool is_ptr = true>
|
||||
struct pointee_impl
|
||||
{
|
||||
template <class T> struct apply : remove_pointer<T> {};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pointee_impl<false>
|
||||
{
|
||||
template <class T> struct apply
|
||||
{
|
||||
typedef typename T::element_type type;
|
||||
};
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct pointee
|
||||
: pointee_impl<is_pointer<T>::value>::template apply<T>
|
||||
{
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // POINTEE_DWA2002323_HPP
|
||||
@@ -1,99 +0,0 @@
|
||||
// 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/config.hpp>
|
||||
# include <boost/preprocessor/tuple/to_list.hpp>
|
||||
# include <boost/preprocessor/tuple/elem.hpp>
|
||||
# include <boost/preprocessor/list/for_each.hpp>
|
||||
# include <boost/preprocessor/repeat_from_to_2nd.hpp>
|
||||
# include <boost/preprocessor/inc.hpp>
|
||||
# include <boost/preprocessor/empty.hpp>
|
||||
# include <boost/preprocessor/enum.hpp>
|
||||
# include <boost/preprocessor/expr_if.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
# define BOOST_PYTHON_CONST() const
|
||||
# define BOOST_PYTHON_VOLATILE() volatile
|
||||
# define BOOST_PYTHON_CONST_VOLATILE() const volatile
|
||||
|
||||
# define BOOST_PYTHON_ALL_CV \
|
||||
BOOST_PP_TUPLE_TO_LIST(4, (BOOST_PP_EMPTY \
|
||||
, BOOST_PYTHON_CONST \
|
||||
, BOOST_PYTHON_VOLATILE \
|
||||
, BOOST_PYTHON_CONST_VOLATILE))
|
||||
|
||||
# if !defined(__MWERKS__) || __MWERKS__ > 0x2407
|
||||
# define BOOST_PYTHON_MEMBER_FUNCTION_CV BOOST_PYTHON_ALL_CV
|
||||
# else
|
||||
# define BOOST_PYTHON_MEMBER_FUNCTION_CV BOOST_PP_TUPLE_TO_LIST(1, (BOOST_PP_EMPTY))
|
||||
# endif
|
||||
|
||||
#ifndef BOOST_PYTHON_DEBUGGABLE_ARITY
|
||||
# define BOOST_PYTHON_DEBUGGABLE_ARITY 10
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_PYTHON_MAX_ARITY
|
||||
# if !defined(__EDG_VERSION__) || __EDG_VERSION__ > 245
|
||||
// Generate at least two more arguments just to test the syntax
|
||||
# define BOOST_PYTHON_MAX_ARITY 12
|
||||
# else
|
||||
// Current EDG compilers have a really slow preprocessor which makes
|
||||
// it important not to generate new functions with it unless
|
||||
// absolutely neccessary
|
||||
# define BOOST_PYTHON_MAX_ARITY BOOST_PYTHON_DEBUGGABLE_ARITY
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_PYTHON_GENERATE_CODE
|
||||
# undef BOOST_STATIC_CONSTANT
|
||||
# define BOOST_PYTHON_ARITY_START 0
|
||||
# define BOOST_PYTHON_ARITY_FINISH BOOST_PYTHON_DEBUGGABLE_ARITY
|
||||
# define BOOST_PYTHON_MF_ARITY_START 1
|
||||
# define BOOST_PYTHON_MF_ARITY_FINISH BOOST_PP_INC(BOOST_PYTHON_DEBUGGABLE_ARITY)
|
||||
#else
|
||||
# define BOOST_PYTHON_ARITY_START BOOST_PYTHON_DEBUGGABLE_ARITY
|
||||
# define BOOST_PYTHON_ARITY_FINISH BOOST_PYTHON_MAX_ARITY
|
||||
# define BOOST_PYTHON_MF_ARITY_START BOOST_PP_INC(BOOST_PYTHON_DEBUGGABLE_ARITY)
|
||||
# define BOOST_PYTHON_MF_ARITY_FINISH BOOST_PP_INC(BOOST_PYTHON_MAX_ARITY)
|
||||
#endif
|
||||
|
||||
# define BOOST_PYTHON_FN(inner,start,count) \
|
||||
R(inner)(BOOST_MPL_TEMPLATE_PARAMETERS(start,count,A))
|
||||
|
||||
# define BOOST_PYTHON_REPEAT_ARITY_2ND(function,data) \
|
||||
BOOST_PP_REPEAT_FROM_TO_2ND( \
|
||||
BOOST_PYTHON_ARITY_START, BOOST_PYTHON_ARITY_FINISH \
|
||||
, function, data)
|
||||
|
||||
# define BOOST_PYTHON_REPEAT_MF_ARITY_2ND(function,data) \
|
||||
BOOST_PP_REPEAT_FROM_TO_2ND( \
|
||||
BOOST_PYTHON_MF_ARITY_START, BOOST_PYTHON_MF_ARITY_FINISH \
|
||||
, function, data)
|
||||
|
||||
# define BOOST_PYTHON_REPEAT_PMF_CV(index, function, cv) \
|
||||
BOOST_PYTHON_REPEAT_MF_ARITY_2ND(function,cv)
|
||||
|
||||
# define BOOST_PYTHON_REPEAT_MF_CV_2ND(function) \
|
||||
BOOST_PP_LIST_FOR_EACH(BOOST_PYTHON_REPEAT_PMF_CV,function,BOOST_PYTHON_MEMBER_FUNCTION_CV)
|
||||
|
||||
# define BOOST_PYTHON_REPEAT_MF_ALL_CV_2ND(function) \
|
||||
BOOST_PP_LIST_FOR_EACH(BOOST_PYTHON_REPEAT_PMF_CV,function,BOOST_PYTHON_ALL_CV)
|
||||
|
||||
#define BOOST_PYTHON_NUMBER_PAIR(Index, Pair) \
|
||||
BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2,0,Pair),Index) \
|
||||
BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2,1,Pair),Index)
|
||||
|
||||
#define BOOST_PYTHON_ENUM_PARAMS2(N, Pair) BOOST_PP_ENUM(N, BOOST_PYTHON_NUMBER_PAIR, Pair)
|
||||
|
||||
# define BOOST_PYTHON_PROJECT_1ST(a1,a2) a1
|
||||
# define BOOST_PYTHON_PROJECT_2ND(a1,a2) a2
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // PREPROCESSOR_DWA200247_HPP
|
||||
@@ -1,171 +0,0 @@
|
||||
// (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/python/detail/wrap_python.hpp>
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/python/detail/none.hpp>
|
||||
# include <boost/python/from_python.hpp>
|
||||
# include <boost/mpl/apply.hpp>
|
||||
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/preprocessor/enum_params.hpp>
|
||||
# include <boost/preprocessor/enum.hpp>
|
||||
# include <boost/preprocessor/enum_shifted.hpp>
|
||||
# include <boost/preprocessor/expr_if.hpp>
|
||||
# include <boost/preprocessor/repeat_from_to.hpp>
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
|
||||
// Calling C++ from Python
|
||||
template <class R>
|
||||
struct returning
|
||||
{
|
||||
|
||||
# ifndef BOOST_PYTHON_GENERATE_CODE
|
||||
# include <boost/python/preprocessed/returning_non_void.hpp>
|
||||
# endif
|
||||
|
||||
# define BOOST_PYTHON_ARG_CONVERTIBLE(index,ignored) \
|
||||
from_python<BOOST_PP_CAT(A,index)> \
|
||||
BOOST_PP_CAT(c,index)(PyTuple_GET_ITEM(args_, index)); \
|
||||
if (!BOOST_PP_CAT(c,index).convertible()) return 0;
|
||||
|
||||
# define BOOST_PYTHON_GET_ARG(index,ignored) \
|
||||
BOOST_PP_CAT(c,index)(PyTuple_GET_ITEM(args_, index))
|
||||
|
||||
# define BOOST_PYTHON_RETURNING_NON_VOID_MF(args,cv) \
|
||||
template <class P, BOOST_PP_ENUM_PARAMS(args,class A)> \
|
||||
static PyObject* call( \
|
||||
BOOST_PYTHON_FN(A0::*pmf,1,args) cv() \
|
||||
, PyObject* args_, PyObject* \
|
||||
, P const* policies) \
|
||||
{ \
|
||||
/* check that each of the arguments is convertible */ \
|
||||
/* self argument is special */ \
|
||||
from_python<A0 cv()*> c0(PyTuple_GET_ITEM(args_, 0)); \
|
||||
if (!c0.convertible()) return 0; \
|
||||
\
|
||||
/* Unroll a loop for the rest of them */ \
|
||||
BOOST_PP_REPEAT_FROM_TO(1,args,BOOST_PYTHON_ARG_CONVERTIBLE,nil) \
|
||||
\
|
||||
/* find the result converter */ \
|
||||
typedef typename P::result_converter result_converter; \
|
||||
typename mpl::apply1<result_converter,R>::type cr; \
|
||||
if (!cr.convertible()) return 0; \
|
||||
\
|
||||
if (!policies->precall(args_)) return 0; \
|
||||
\
|
||||
PyObject* result = cr( \
|
||||
((BOOST_PYTHON_GET_ARG(0,nil))->*pmf)( \
|
||||
BOOST_PP_ENUM_SHIFTED(args,BOOST_PYTHON_GET_ARG,nil)) \
|
||||
); \
|
||||
\
|
||||
return policies->postcall(args_, result); \
|
||||
}
|
||||
|
||||
// Generate a series for each cv-qualification
|
||||
BOOST_PYTHON_REPEAT_MF_ALL_CV_2ND(BOOST_PYTHON_RETURNING_NON_VOID_MF)
|
||||
|
||||
# define BOOST_PYTHON_RETURNING_NON_VOID_FN(args,ignored) \
|
||||
template <class P BOOST_PP_COMMA_IF(args) BOOST_PP_ENUM_PARAMS(args,class A)> \
|
||||
static PyObject* call( \
|
||||
BOOST_PYTHON_FN(*pf,0,args) \
|
||||
, PyObject* args_ \
|
||||
, PyObject* \
|
||||
, P const* policies) \
|
||||
{ \
|
||||
/* check that each of the arguments is convertible */ \
|
||||
BOOST_PP_REPEAT(args,BOOST_PYTHON_ARG_CONVERTIBLE,nil) \
|
||||
\
|
||||
/* find the result converter */ \
|
||||
typedef typename P::result_converter result_converter; \
|
||||
typename mpl::apply1<result_converter,R>::type cr; \
|
||||
if (!cr.convertible()) return 0; \
|
||||
\
|
||||
if (!policies->precall(args_)) return 0; \
|
||||
\
|
||||
PyObject* result = cr( \
|
||||
(*pf)(BOOST_PP_ENUM(args,BOOST_PYTHON_GET_ARG,nil)) \
|
||||
); \
|
||||
\
|
||||
return policies->postcall(args_, result); \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_RETURNING_NON_VOID_FN, nil)
|
||||
};
|
||||
|
||||
template <>
|
||||
struct returning<void>
|
||||
{
|
||||
typedef void R;
|
||||
|
||||
# ifndef BOOST_PYTHON_GENERATE_CODE
|
||||
# include <boost/python/preprocessed/returning_void.hpp>
|
||||
# endif
|
||||
|
||||
#define BOOST_PYTHON_RETURNING_VOID_MF(args,cv) \
|
||||
template<class P,BOOST_PP_ENUM_PARAMS(args,class A)> \
|
||||
static PyObject*call( \
|
||||
BOOST_PYTHON_FN(A0::*pmf,1,args) cv() \
|
||||
, PyObject*args_ \
|
||||
, PyObject* \
|
||||
, P const* policies) \
|
||||
{ \
|
||||
/* check that each of the arguments is convertible */ \
|
||||
/* self argument is special */ \
|
||||
from_python<A0 cv()*>c0(PyTuple_GET_ITEM(args_,0)); \
|
||||
if (!c0.convertible()) return 0; \
|
||||
\
|
||||
/* Unroll a loop for the rest of them */ \
|
||||
BOOST_PP_REPEAT_FROM_TO(1,args,BOOST_PYTHON_ARG_CONVERTIBLE,nil) \
|
||||
\
|
||||
if (!policies->precall(args_)) return 0; \
|
||||
\
|
||||
((c0(PyTuple_GET_ITEM(args_,0)))->*pmf)( \
|
||||
BOOST_PP_ENUM_SHIFTED(args,BOOST_PYTHON_GET_ARG,nil) \
|
||||
); \
|
||||
\
|
||||
return policies->postcall(args_,detail::none()); \
|
||||
}
|
||||
|
||||
//Generate a series for each cv-qualification
|
||||
BOOST_PYTHON_REPEAT_MF_ALL_CV_2ND(BOOST_PYTHON_RETURNING_VOID_MF)
|
||||
|
||||
#define BOOST_PYTHON_RETURNING_VOID_FN(args,ignored) \
|
||||
template<class P BOOST_PP_COMMA_IF(args) BOOST_PP_ENUM_PARAMS(args,class A)> \
|
||||
static PyObject*call( \
|
||||
BOOST_PYTHON_FN(*pf,0,args) \
|
||||
, PyObject*args_ \
|
||||
, PyObject* \
|
||||
, P const* policies) \
|
||||
{ \
|
||||
/*check that each of the arguments is convertible*/ \
|
||||
BOOST_PP_REPEAT(args,BOOST_PYTHON_ARG_CONVERTIBLE,nil) \
|
||||
\
|
||||
BOOST_PP_EXPR_IF(args,if (!policies->precall(args_)) return 0;) \
|
||||
\
|
||||
(*pf)(BOOST_PP_ENUM(args,BOOST_PYTHON_GET_ARG,nil)); \
|
||||
\
|
||||
return policies->postcall(args_,detail::none()); \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_RETURNING_VOID_FN,nil)
|
||||
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif//RETURNING_DWA20011201_HPP
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
// 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 UNWIND_TYPE_DWA200222_HPP
|
||||
# define UNWIND_TYPE_DWA200222_HPP
|
||||
|
||||
# include <boost/python/detail/cv_category.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <class Generator, class U>
|
||||
inline typename Generator::result_type
|
||||
unwind_type_cv(U* p, cv_unqualified, Generator* = 0)
|
||||
{
|
||||
return Generator::execute(p);
|
||||
}
|
||||
|
||||
template <class Generator, class U>
|
||||
inline typename Generator::result_type
|
||||
unwind_type_cv(U const* p, const_, Generator* = 0)
|
||||
{
|
||||
return unwind_type(const_cast<U*>(p), (Generator*)0);
|
||||
}
|
||||
|
||||
template <class Generator, class U>
|
||||
inline typename Generator::result_type
|
||||
unwind_type_cv(U volatile* p, volatile_, Generator* = 0)
|
||||
{
|
||||
return unwind_type(const_cast<U*>(p), (Generator*)0);
|
||||
}
|
||||
|
||||
template <class Generator, class U>
|
||||
inline typename Generator::result_type
|
||||
unwind_type_cv(U const volatile* p, const_volatile_, Generator* = 0)
|
||||
{
|
||||
return unwind_type(const_cast<U*>(p), (Generator*)0);
|
||||
}
|
||||
|
||||
template <class Generator, class U>
|
||||
inline typename Generator::result_type
|
||||
unwind_ptr_type(U* p, Generator* = 0)
|
||||
{
|
||||
typedef typename cv_category<U>::type tag;
|
||||
return unwind_type_cv<Generator>(p, tag());
|
||||
}
|
||||
|
||||
template <bool is_ptr>
|
||||
struct unwind_helper
|
||||
{
|
||||
template <class Generator, class U>
|
||||
static typename Generator::result_type
|
||||
execute(U p, Generator* = 0)
|
||||
{
|
||||
return unwind_ptr_type(p, (Generator*)0);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct unwind_helper<false>
|
||||
{
|
||||
template <class Generator, class U>
|
||||
static typename Generator::result_type
|
||||
execute(U& p, Generator* = 0)
|
||||
{
|
||||
return unwind_ptr_type(&p, (Generator*)0);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Generator, class U>
|
||||
inline typename Generator::result_type
|
||||
unwind_type(U const& p, Generator* = 0)
|
||||
{
|
||||
return unwind_helper<is_pointer<U>::value>::execute(p, (Generator*)0);
|
||||
}
|
||||
|
||||
enum { direct_ = 0, pointer_ = 1, reference_ = 2, reference_to_pointer_ = 3 };
|
||||
template <int indirection> struct unwind_helper2;
|
||||
|
||||
template <>
|
||||
struct unwind_helper2<direct_>
|
||||
{
|
||||
template <class Generator, class U>
|
||||
static typename Generator::result_type
|
||||
execute(U(*)(), Generator* = 0)
|
||||
{
|
||||
return unwind_ptr_type((U*)0, (Generator*)0);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct unwind_helper2<pointer_>
|
||||
{
|
||||
template <class Generator, class U>
|
||||
static typename Generator::result_type
|
||||
execute(U*(*)(), Generator* = 0)
|
||||
{
|
||||
return unwind_ptr_type((U*)0, (Generator*)0);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct unwind_helper2<reference_>
|
||||
{
|
||||
template <class Generator, class U>
|
||||
static typename Generator::result_type
|
||||
execute(U&(*)(), Generator* = 0)
|
||||
{
|
||||
return unwind_ptr_type((U*)0, (Generator*)0);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct unwind_helper2<reference_to_pointer_>
|
||||
{
|
||||
template <class Generator, class U>
|
||||
static typename Generator::result_type
|
||||
execute(U&(*)(), Generator* = 0)
|
||||
{
|
||||
return unwind_ptr_type(U(0), (Generator*)0);
|
||||
}
|
||||
};
|
||||
|
||||
// Call this one with both template parameters explicitly specified
|
||||
// and no function arguments:
|
||||
//
|
||||
// return unwind_type<my_generator,T>();
|
||||
//
|
||||
// Doesn't work if T is an array type; we could handle that case, but
|
||||
// why bother?
|
||||
template <class Generator, class U>
|
||||
inline typename Generator::result_type
|
||||
unwind_type(type<U>*p = 0, Generator* = 0)
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(int, indirection
|
||||
= (is_pointer<U>::value ? pointer_ : 0)
|
||||
+ (is_reference_to_pointer<U>::value
|
||||
? reference_to_pointer_
|
||||
: is_reference<U>::value
|
||||
? reference_
|
||||
: 0));
|
||||
|
||||
return unwind_helper2<indirection>::execute((U(*)())0,(Generator*)0);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // UNWIND_TYPE_DWA200222_HPP
|
||||
@@ -1,120 +0,0 @@
|
||||
// (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)
|
||||
|
||||
|
||||
#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__)
|
||||
# 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
|
||||
# if !defined(__CYGWIN__) && (__GNUC__ < 3 || __GNUC__ == 3 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ < 3)
|
||||
# define WITH_THREAD
|
||||
# endif
|
||||
# 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
|
||||
# elif defined(_MSC_VER)
|
||||
# ifdef __cplusplus
|
||||
# include <limits> // prevents Python.h from defining LONGLONG_MAX, LONGLONG_MIN, and ULONGLONG_MAX
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#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
|
||||
@@ -1,51 +0,0 @@
|
||||
// (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.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 PyObject* expect_non_null(PyObject* x);
|
||||
|
||||
template <class T>
|
||||
T* expect_non_null(T* x)
|
||||
{
|
||||
return (T*)expect_non_null((PyObject*)x);
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL void throw_argument_error();
|
||||
BOOST_PYTHON_DECL void throw_error_already_set();
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // ERRORS_DWA052500_H_
|
||||
@@ -1,28 +0,0 @@
|
||||
// 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_DWA2002325_HPP
|
||||
# define IMPLICIT_DWA2002325_HPP
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/python/converter/implicit.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class Source, class Target>
|
||||
void implicitly_convertible(boost::type<Source>* = 0, boost::type<Target>* = 0)
|
||||
{
|
||||
typedef converter::implicit<Source,Target> functions;
|
||||
|
||||
converter::registry::push_back(
|
||||
&functions::convertible
|
||||
, &functions::construct
|
||||
, converter::undecorated_type_id<Target>());
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // IMPLICIT_DWA2002325_HPP
|
||||
@@ -1,68 +0,0 @@
|
||||
// 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.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/function.hpp>
|
||||
# include <boost/bind.hpp>
|
||||
# include <boost/python/default_call_policies.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class F>
|
||||
objects::function* make_function(F f)
|
||||
{
|
||||
return new objects::function(
|
||||
objects::py_function(
|
||||
::boost::bind<PyObject*>(detail::caller(), f, _1, _2, default_call_policies()))
|
||||
, detail::arg_tuple_size<F>::value);
|
||||
}
|
||||
|
||||
template <class F, class Policies>
|
||||
objects::function* make_function(F f, Policies const& policies)
|
||||
{
|
||||
return new objects::function(
|
||||
objects::py_function(
|
||||
::boost::bind<PyObject*>(detail::caller(), f, _1, _2, policies))
|
||||
, detail::arg_tuple_size<F>::value);
|
||||
}
|
||||
|
||||
template <class ArgList, class Holder>
|
||||
objects::function* make_constructor(Holder* = 0, ArgList* = 0)
|
||||
{
|
||||
enum { nargs = mpl::size<ArgList>::value };
|
||||
|
||||
return new objects::function(
|
||||
objects::py_function(
|
||||
::boost::bind<PyObject*>(detail::caller(),
|
||||
objects::make_holder<nargs>
|
||||
::template apply<Holder,ArgList>::execute
|
||||
, _1, _2, default_call_policies()))
|
||||
, nargs + 1);
|
||||
}
|
||||
|
||||
template <class ArgList, class Holder, class Policies>
|
||||
objects::function* make_constructor(Policies const& policies, Holder* = 0, ArgList* = 0)
|
||||
{
|
||||
enum { nargs = mpl::size<ArgList>::value };
|
||||
|
||||
return new objects::function(
|
||||
objects::py_function(
|
||||
::boost::bind<PyObject*>(detail::caller(),
|
||||
objects::make_holder<nargs>
|
||||
::template apply<Holder,ArgList>::execute
|
||||
, _1, _2, policies))
|
||||
, nargs + 1);
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // MAKE_FUNCTION_DWA20011221_HPP
|
||||
@@ -1,42 +0,0 @@
|
||||
// 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 MANAGE_NEW_OBJECT_DWA200222_HPP
|
||||
# define MANAGE_NEW_OBJECT_DWA200222_HPP
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/python/to_python_indirect.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class R>
|
||||
struct manage_new_object_requires_a_pointer_return_type
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
|
||||
{}
|
||||
# endif
|
||||
;
|
||||
}
|
||||
|
||||
template <class T> struct to_python_value;
|
||||
|
||||
struct manage_new_object
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
boost::is_pointer<T>::value
|
||||
, to_python_indirect<T, detail::make_owning_holder>
|
||||
, detail::manage_new_object_requires_a_pointer_return_type<T>
|
||||
>::type type;
|
||||
};
|
||||
};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // MANAGE_NEW_OBJECT_DWA200222_HPP
|
||||
@@ -1,83 +0,0 @@
|
||||
// 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/objects.hpp>
|
||||
# include <boost/python/class_fwd.hpp>
|
||||
# include <boost/python/detail/module_base.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
class module : public detail::module_base
|
||||
{
|
||||
public:
|
||||
module(const char* name)
|
||||
: module_base(name) {}
|
||||
|
||||
// Add elements to the module
|
||||
module& setattr(const char* name, PyObject*);
|
||||
module& setattr(const char* name, PyTypeObject*);
|
||||
module& setattr(const char* name, ref const&);
|
||||
module& add(PyTypeObject* x); // just use the type's name
|
||||
|
||||
template <class T, class Bases, class HolderGenerator>
|
||||
module& add(class_<T,Bases,HolderGenerator> const& c)
|
||||
{
|
||||
Py_INCREF(c.object());
|
||||
this->add_type(c.object());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Fn>
|
||||
module& def(char const* name, Fn fn)
|
||||
{
|
||||
this->setattr(name, boost::python::make_function(fn));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <class Fn, class ResultHandler>
|
||||
module& def(char const* name, Fn fn, ResultHandler handler)
|
||||
{
|
||||
this->setattr(name, boost::python::make_function(fn, handler));
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// inline implementations
|
||||
//
|
||||
inline module& module::setattr(const char* name, PyObject* x)
|
||||
{
|
||||
this->module_base::setattr(name, x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline module& module::setattr(const char* name, PyTypeObject* x)
|
||||
{
|
||||
this->module_base::setattr(name, (PyObject*)x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline module& module::setattr(const char* name, ref const& x)
|
||||
{
|
||||
this->module_base::setattr(name, x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline module& module::add(PyTypeObject* x)
|
||||
{
|
||||
this->module_base::add(x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // MODULE_DWA20011221_HPP
|
||||
@@ -1,75 +0,0 @@
|
||||
// (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 MODULE_DWA051000_H_
|
||||
# define MODULE_DWA051000_H_
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/reference.hpp>
|
||||
# include <boost/python/objects.hpp>
|
||||
# include <boost/python/detail/functions.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
class BOOST_PYTHON_DECL module_builder_base
|
||||
{
|
||||
public:
|
||||
// Create a module. REQUIRES: only one module_builder is created per module.
|
||||
module_builder_base(const char* name);
|
||||
~module_builder_base();
|
||||
|
||||
// Add elements to the module
|
||||
void add(detail::function* x, const char* name);
|
||||
void add(PyTypeObject* x, const char* name = 0);
|
||||
void add(ref x, const char*name);
|
||||
|
||||
// Return true iff a module is currently being built.
|
||||
static bool initializing();
|
||||
|
||||
// Return the name of the module currently being built.
|
||||
// REQUIRES: initializing() == true
|
||||
static string name();
|
||||
|
||||
// Return a pointer to the Python module object being built
|
||||
PyObject* module() const;
|
||||
|
||||
private:
|
||||
PyObject* m_module;
|
||||
static PyMethodDef initial_methods[1];
|
||||
};
|
||||
|
||||
class module_builder : public module_builder_base
|
||||
{
|
||||
public:
|
||||
module_builder(const char* name)
|
||||
: module_builder_base(name) {}
|
||||
|
||||
template <class Fn>
|
||||
void def_raw(Fn fn, const char* name)
|
||||
{
|
||||
add(detail::new_raw_arguments_function(fn), name);
|
||||
}
|
||||
|
||||
template <class Fn>
|
||||
void def(Fn fn, const char* name)
|
||||
{
|
||||
add(detail::new_wrapped_function(fn), name);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// inline implementations
|
||||
//
|
||||
inline PyObject* module_builder_base::module() const
|
||||
{
|
||||
return m_module;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif
|
||||
@@ -1,85 +0,0 @@
|
||||
// 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/converter/type_id.hpp>
|
||||
# include <boost/python/reference.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
class module;
|
||||
|
||||
namespace objects {
|
||||
|
||||
template <class T> struct holder;
|
||||
|
||||
// To identify a class, we don't need cv/reference decorations
|
||||
typedef converter::undecorated_type_id_t class_id;
|
||||
|
||||
struct BOOST_PYTHON_DECL class_base : private noncopyable
|
||||
{
|
||||
// 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
|
||||
, class_id const*const types // this is wrapping. The rest are the types of
|
||||
// any bases.
|
||||
);
|
||||
|
||||
// Retrieve the underlying object
|
||||
ref object() const { return m_object; }
|
||||
void add_property(char const* name, ref const& fget);
|
||||
void add_property(char const* name, ref const& fget, ref const& fset);
|
||||
private:
|
||||
ref m_object;
|
||||
};
|
||||
|
||||
// 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(converter::undecorated_type_id_t) = 0;
|
||||
|
||||
void install(PyObject* inst) 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)
|
||||
|
||||
// Each extension instance will be one of these
|
||||
struct instance
|
||||
{
|
||||
PyObject_HEAD
|
||||
instance_holder* objects;
|
||||
};
|
||||
|
||||
BOOST_PYTHON_DECL ref class_metatype();
|
||||
BOOST_PYTHON_DECL ref class_type();
|
||||
|
||||
//
|
||||
// implementation
|
||||
//
|
||||
inline instance_holder* instance_holder::next() const
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // CLASS_DWA20011214_HPP
|
||||
@@ -1,93 +0,0 @@
|
||||
// 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_CONVERTERS_DWA2002119_HPP
|
||||
# define CLASS_CONVERTERS_DWA2002119_HPP
|
||||
|
||||
# include <boost/python/object/class_wrapper.hpp>
|
||||
# include <boost/mpl/for_each.hpp>
|
||||
# include <boost/python/reference.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/object/find_instance.hpp>
|
||||
# include <boost/python/object/inheritance.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// register_base_of<T> -
|
||||
// A BinaryMetaFunction object which registers a single base
|
||||
// class of T, and the corresponding cast(s)
|
||||
//
|
||||
|
||||
|
||||
// register_downcast/do_nothing -
|
||||
// Helpers for register_base_of<> which take care of registering
|
||||
// down-casts
|
||||
template <class Base, class Derived>
|
||||
struct register_downcast
|
||||
{
|
||||
static void execute()
|
||||
{
|
||||
register_conversion<Base, Derived>(true);
|
||||
}
|
||||
};
|
||||
|
||||
struct do_nothing
|
||||
{
|
||||
static void execute() { }
|
||||
};
|
||||
|
||||
// Here's where the real work gets done:
|
||||
template <class Derived>
|
||||
struct register_base_of
|
||||
{
|
||||
// Ignored is needed because mpl::for_each is still actually
|
||||
// accumulate. We're not using any state so it just sits there.
|
||||
template <class Ignored, class Base>
|
||||
struct apply
|
||||
{
|
||||
typedef void type; // 'type' needs to be defined for the same reasons
|
||||
|
||||
// Here's the runtime part:
|
||||
static void execute()
|
||||
{
|
||||
// Register the Base class
|
||||
register_dynamic_id<Base>();
|
||||
// Register the up-cast
|
||||
register_conversion<Derived,Base>(false);
|
||||
|
||||
// Register the down-cast, if appropriate.
|
||||
mpl::select_type<
|
||||
is_polymorphic<Base>::value
|
||||
, register_downcast<Base,Derived>
|
||||
, do_nothing
|
||||
>::type::execute();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// Brings into existence all converters associated with a class Bases
|
||||
// is expected to be an mpl sequence of base types.
|
||||
template <class Derived, class Bases>
|
||||
inline void register_class_from_python(Derived* = 0, Bases* = 0)
|
||||
{
|
||||
// cause the static registration to be instantiated. Can't just
|
||||
// cast it to void on all compilers; some will skip its
|
||||
// initialization.
|
||||
void const* ignored = &instance_finder<Derived>::registration;
|
||||
(void)ignored;
|
||||
|
||||
// register all up/downcasts here
|
||||
register_dynamic_id<Derived>();
|
||||
|
||||
// register each base in the sequence
|
||||
mpl::for_each<Bases, void, register_base_of<Derived> >::execute();
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // CLASS_CONVERTERS_DWA2002119_HPP
|
||||
@@ -1,60 +0,0 @@
|
||||
// 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/reference.hpp>
|
||||
# include <boost/python/to_python_converter.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
template <class T, class Holder>
|
||||
struct class_wrapper
|
||||
: to_python_converter<T,class_wrapper<T,Holder> >
|
||||
{
|
||||
class_wrapper(ref const& type_)
|
||||
: m_class_object_keeper(type_)
|
||||
{
|
||||
assert(type_->ob_type == (PyTypeObject*)class_metatype().get());
|
||||
m_class_object = (PyTypeObject*)type_.get();
|
||||
}
|
||||
|
||||
static PyObject* convert(T const& x)
|
||||
{
|
||||
// Don't call the type directly to do the construction, since
|
||||
// that would require the registration of an appropriate
|
||||
// __init__ function.
|
||||
PyObject* raw_result = m_class_object->tp_alloc(m_class_object, 0);
|
||||
|
||||
if (raw_result == 0)
|
||||
return 0;
|
||||
|
||||
// Everything's OK; Bypass NULL checks but guard against
|
||||
// exceptions.
|
||||
ref result(raw_result, ref::allow_null());
|
||||
|
||||
// Build a value_holder to contain the object using the copy
|
||||
// constructor
|
||||
Holder* p = new Holder(raw_result, cref(x));
|
||||
|
||||
// Install it in the instance
|
||||
p->install(raw_result);
|
||||
|
||||
// Return the new result
|
||||
return result.release();
|
||||
}
|
||||
|
||||
private:
|
||||
ref m_class_object_keeper;
|
||||
static PyTypeObject* m_class_object;
|
||||
};
|
||||
|
||||
template <class T, class Holder>
|
||||
PyTypeObject* class_wrapper<T,Holder>::m_class_object;
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // CLASS_WRAPPER_DWA20011221_HPP
|
||||
@@ -1,40 +0,0 @@
|
||||
// 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_INSTANCE_DWA2002312_HPP
|
||||
# define FIND_INSTANCE_DWA2002312_HPP
|
||||
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
// Given an undecorated type_id, find the instance data which
|
||||
// corresponds to it, or return 0 in case no such type is held.
|
||||
BOOST_PYTHON_DECL void* find_instance_impl(PyObject*, converter::undecorated_type_id_t);
|
||||
|
||||
// This produces a function with the right signature for use in from_python conversions
|
||||
template <class T>
|
||||
struct instance_finder
|
||||
{
|
||||
instance_finder()
|
||||
{
|
||||
converter::registry::insert(&execute, converter::undecorated_type_id<T>());
|
||||
}
|
||||
|
||||
static instance_finder const registration;
|
||||
private:
|
||||
static inline void* execute(PyObject* p)
|
||||
{
|
||||
return find_instance_impl(p, converter::undecorated_type_id<T>());
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
instance_finder<T> const instance_finder<T>::registration;
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // FIND_INSTANCE_DWA2002312_HPP
|
||||
@@ -1,108 +0,0 @@
|
||||
// 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 FORWARD_DWA20011215_HPP
|
||||
# define FORWARD_DWA20011215_HPP
|
||||
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/ref.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
template <class T>
|
||||
struct reference_to_value
|
||||
{
|
||||
typedef typename add_reference<typename add_const<T>::type>::type reference;
|
||||
|
||||
reference_to_value(reference x) : m_value(x) {}
|
||||
operator reference() const { return m_value; }
|
||||
private:
|
||||
reference m_value;
|
||||
};
|
||||
|
||||
// A little metaprogram which selects the type to pass through an
|
||||
// intermediate forwarding function when the destination argument type
|
||||
// is T.
|
||||
template <class T>
|
||||
struct forward
|
||||
: mpl::select_type<
|
||||
is_scalar<T>::value
|
||||
, T
|
||||
, reference_to_value<T> >
|
||||
{
|
||||
};
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template<typename T>
|
||||
class unforward
|
||||
{
|
||||
public:
|
||||
typedef typename unwrap_reference<T>::type& type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class unforward<reference_to_value<T> >
|
||||
{
|
||||
public:
|
||||
typedef T type;
|
||||
};
|
||||
# else // no partial specialization
|
||||
|
||||
namespace detail
|
||||
{
|
||||
typedef char (&yes_reference_to_value_t)[1];
|
||||
typedef char (&no_reference_to_value_t)[2];
|
||||
|
||||
no_reference_to_value_t is_reference_to_value_test(...);
|
||||
|
||||
template<typename T>
|
||||
yes_reference_to_value_t is_reference_to_value_test(type< reference_to_value<T> >);
|
||||
|
||||
template<bool wrapped>
|
||||
struct unforwarder
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename unwrap_reference<T>::type& type;
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
struct unforwarder<true>
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename T::reference type;
|
||||
};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class is_reference_to_value
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
sizeof(is_reference_to_value_test(type<T>()))
|
||||
== sizeof(yes_reference_to_value_t)));
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class unforward
|
||||
: public detail::unforwarder<
|
||||
detail::is_reference_to_value<T>::value
|
||||
>::template apply<T>
|
||||
{};
|
||||
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // FORWARD_DWA20011215_HPP
|
||||
@@ -1,49 +0,0 @@
|
||||
// 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/reference.hpp>
|
||||
# include <boost/function.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
// We use boost::function to avoid generating lots of virtual tables
|
||||
typedef boost::function2<PyObject*, PyObject*, PyObject*> py_function;
|
||||
|
||||
struct BOOST_PYTHON_DECL function : PyObject
|
||||
{
|
||||
function(py_function, unsigned min_args, unsigned max_args = 0);
|
||||
~function();
|
||||
|
||||
PyObject* call(PyObject*, PyObject*) const;
|
||||
|
||||
// Add an attributeto 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(
|
||||
ref const& name_space, char const* name, ref const& attribute);
|
||||
|
||||
private: // helper functions
|
||||
void argument_error(PyObject* args, PyObject* keywords) const;
|
||||
void add_overload(function*);
|
||||
|
||||
private: // data members
|
||||
py_function m_fn;
|
||||
unsigned m_min_args;
|
||||
unsigned m_max_args;
|
||||
function* m_overloads;
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // FUNCTION_DWA20011214_HPP
|
||||
@@ -1,165 +0,0 @@
|
||||
// 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 INHERITANCE_DWA200216_HPP
|
||||
# define INHERITANCE_DWA200216_HPP
|
||||
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/shared_ptr.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
typedef converter::undecorated_type_id_t class_id;
|
||||
using converter::undecorated_type_id;
|
||||
|
||||
// Types used to get address and id of most derived type
|
||||
typedef std::pair<void*,class_id> dynamic_id_t;
|
||||
typedef dynamic_id_t (*dynamic_id_function)(void*);
|
||||
|
||||
BOOST_PYTHON_DECL void register_dynamic_id_aux(
|
||||
class_id static_id, dynamic_id_function get_dynamic_id);
|
||||
|
||||
BOOST_PYTHON_DECL void add_cast(
|
||||
class_id src_t, class_id dst_t, void* (*cast)(void*), bool polymorphic);
|
||||
|
||||
BOOST_PYTHON_DECL void* find_static_type(void* p, class_id src, class_id dst);
|
||||
|
||||
BOOST_PYTHON_DECL void* find_dynamic_type(void* p, class_id src, class_id dst);
|
||||
|
||||
// is_polymorphic test from John Maddock
|
||||
template <class T>
|
||||
struct is_polymorphic
|
||||
{
|
||||
struct d1 : public T
|
||||
{
|
||||
d1();
|
||||
char padding[256];
|
||||
};
|
||||
struct d2 : public T
|
||||
{
|
||||
d2();
|
||||
virtual ~d2();
|
||||
virtual void foo();
|
||||
char padding[256];
|
||||
};
|
||||
BOOST_STATIC_CONSTANT(bool, value = (sizeof(d2) == sizeof(d1)));
|
||||
};
|
||||
|
||||
//
|
||||
// a generator with an execute() function which, given a source type
|
||||
// and a pointer to an object of that type, returns its most-derived
|
||||
// /reachable/ type identifier and object pointer.
|
||||
//
|
||||
|
||||
// first, the case where T has virtual functions
|
||||
template <class T>
|
||||
struct polymorphic_id_generator
|
||||
{
|
||||
static dynamic_id_t execute(void* p_)
|
||||
{
|
||||
T* p = static_cast<T*>(p_);
|
||||
return std::make_pair(dynamic_cast<void*>(p), class_id(typeid(*p)));
|
||||
}
|
||||
};
|
||||
|
||||
// now, the non-polymorphic case.
|
||||
template <class T>
|
||||
struct non_polymorphic_id_generator
|
||||
{
|
||||
static dynamic_id_t execute(void* p_)
|
||||
{
|
||||
return std::make_pair(p_, converter::undecorated_type_id<T>());
|
||||
}
|
||||
};
|
||||
|
||||
// Now the generalized selector
|
||||
template <class T>
|
||||
struct dynamic_id_generator
|
||||
{
|
||||
typedef typename mpl::select_type<
|
||||
is_polymorphic<T>::value
|
||||
, polymorphic_id_generator<T>
|
||||
, non_polymorphic_id_generator<T> >::type type;
|
||||
};
|
||||
|
||||
// Register the dynamic id function for T with the type-conversion
|
||||
// system.
|
||||
template <class T>
|
||||
void register_dynamic_id(T* = 0)
|
||||
{
|
||||
typedef typename dynamic_id_generator<T>::type generator;
|
||||
register_dynamic_id_aux(
|
||||
converter::undecorated_type_id<T>(), &generator::execute);
|
||||
}
|
||||
|
||||
//
|
||||
// a generator with an execute() function which, given a void*
|
||||
// pointing to an object of type Source will attempt to convert it to
|
||||
// an object of type Target.
|
||||
//
|
||||
|
||||
template <class Source, class Target>
|
||||
struct dynamic_cast_generator
|
||||
{
|
||||
static void* execute(void* source)
|
||||
{
|
||||
return dynamic_cast<Target*>(
|
||||
static_cast<Source*>(source));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <class Source, class Target>
|
||||
struct implicit_cast_generator
|
||||
{
|
||||
static void* execute(void* source)
|
||||
{
|
||||
Target* result = static_cast<Source*>(source);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Source, class Target>
|
||||
struct cast_generator
|
||||
{
|
||||
// CWPro7 will return false sometimes, but that's OK since we can
|
||||
// always cast up with dynamic_cast<>
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, is_upcast = (
|
||||
is_base_and_derived<Target,Source>::value
|
||||
));
|
||||
|
||||
typedef typename mpl::select_type<
|
||||
is_upcast
|
||||
# if defined(__MWERKS__) && __MWERKS__ <= 0x2406
|
||||
// grab a few more implicit_cast cases for CodeWarrior
|
||||
|| !is_polymorphic<Source>::value
|
||||
|| !is_polymorphic<Target>::value
|
||||
# endif
|
||||
, implicit_cast_generator<Source,Target>
|
||||
, dynamic_cast_generator<Source,Target>
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <class Source, class Target>
|
||||
inline void register_conversion(
|
||||
// We need this parameter because CWPro7 can't determine
|
||||
// which is the base reliably.
|
||||
bool is_downcast = !cast_generator<Source,Target>::is_upcast
|
||||
|
||||
// These parameters shouldn't be used, they're an MSVC bug workaround
|
||||
, Source* = 0, Target* = 0)
|
||||
{
|
||||
typedef typename cast_generator<Source,Target>::type generator;
|
||||
|
||||
add_cast(converter::undecorated_type_id<Source>()
|
||||
, converter::undecorated_type_id<Target>()
|
||||
, &generator::execute
|
||||
, is_downcast);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::object
|
||||
|
||||
#endif // INHERITANCE_DWA200216_HPP
|
||||
@@ -1,168 +0,0 @@
|
||||
// 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/mpl/at.hpp>
|
||||
# include <boost/python/object/forward.hpp>
|
||||
# include <boost/python/object/class.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
template <int nargs> struct make_holder;
|
||||
|
||||
template <>
|
||||
struct make_holder<0>
|
||||
{
|
||||
template <class Holder, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
static void execute(
|
||||
PyObject* p)
|
||||
{
|
||||
(new Holder(p))->install(p);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct make_holder<1>
|
||||
{
|
||||
template <class Holder, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::at<0,ArgList>::type t0;
|
||||
typedef typename forward<t0>::type f0;
|
||||
|
||||
static void execute(
|
||||
PyObject* p
|
||||
, t0 a0)
|
||||
{
|
||||
(new Holder(p, f0(a0)))->install(p);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct make_holder<2>
|
||||
{
|
||||
template <class Holder, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::at<0,ArgList>::type t0;
|
||||
typedef typename forward<t0>::type f0;
|
||||
typedef typename mpl::at<1,ArgList>::type t1;
|
||||
typedef typename forward<t1>::type f1;
|
||||
|
||||
static void execute(
|
||||
PyObject* p, t0 a0, t1 a1)
|
||||
{
|
||||
(new Holder(p, f0(a0), f1(a1)))->install(p);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct make_holder<3>
|
||||
{
|
||||
template <class Holder, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::at<0,ArgList>::type t0;
|
||||
typedef typename forward<t0>::type f0;
|
||||
typedef typename mpl::at<1,ArgList>::type t1;
|
||||
typedef typename forward<t1>::type f1;
|
||||
typedef typename mpl::at<2,ArgList>::type t2;
|
||||
typedef typename forward<t2>::type f2;
|
||||
|
||||
static void execute(
|
||||
PyObject* p, t0 a0, t1 a1, t2 a2)
|
||||
{
|
||||
(new Holder(p, f0(a0), f1(a1), f2(a2)))->install(p);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct make_holder<4>
|
||||
{
|
||||
template <class Holder, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::at<0,ArgList>::type t0;
|
||||
typedef typename forward<t0>::type f0;
|
||||
typedef typename mpl::at<1,ArgList>::type t1;
|
||||
typedef typename forward<t1>::type f1;
|
||||
typedef typename mpl::at<2,ArgList>::type t2;
|
||||
typedef typename forward<t2>::type f2;
|
||||
typedef typename mpl::at<3,ArgList>::type t3;
|
||||
typedef typename forward<t3>::type f3;
|
||||
|
||||
static void execute(
|
||||
PyObject* p, t0 a0, t1 a1, t2 a2, t3 a3)
|
||||
{
|
||||
(new Holder(p, f0(a0), f1(a1), f2(a2), f3(a3)))->install(p);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct make_holder<5>
|
||||
{
|
||||
template <class Holder, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::at<0,ArgList>::type t0;
|
||||
typedef typename forward<t0>::type f0;
|
||||
typedef typename mpl::at<1,ArgList>::type t1;
|
||||
typedef typename forward<t1>::type f1;
|
||||
typedef typename mpl::at<2,ArgList>::type t2;
|
||||
typedef typename forward<t2>::type f2;
|
||||
typedef typename mpl::at<3,ArgList>::type t3;
|
||||
typedef typename forward<t3>::type f3;
|
||||
typedef typename mpl::at<4,ArgList>::type t4;
|
||||
typedef typename forward<t4>::type f4;
|
||||
|
||||
static void execute(
|
||||
PyObject* p, t0 a0, t1 a1, t2 a2, t3 a3, t4 a4)
|
||||
{
|
||||
(new Holder(p, f0(a0), f1(a1), f2(a2), f3(a3), f4(a4)))->install(p);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct make_holder<6>
|
||||
{
|
||||
template <class Holder, class ArgList>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::at<0,ArgList>::type t0;
|
||||
typedef typename forward<t0>::type f0;
|
||||
typedef typename mpl::at<1,ArgList>::type t1;
|
||||
typedef typename forward<t1>::type f1;
|
||||
typedef typename mpl::at<2,ArgList>::type t2;
|
||||
typedef typename forward<t2>::type f2;
|
||||
typedef typename mpl::at<3,ArgList>::type t3;
|
||||
typedef typename forward<t3>::type f3;
|
||||
typedef typename mpl::at<4,ArgList>::type t4;
|
||||
typedef typename forward<t4>::type f4;
|
||||
typedef typename mpl::at<5,ArgList>::type t5;
|
||||
typedef typename forward<t5>::type f5;
|
||||
|
||||
static void execute(
|
||||
PyObject* p, t0 a0, t1 a1, t2 a2, t3 a3, t4 a4, t5 a5)
|
||||
{
|
||||
(new Holder(p, f0(a0), f1(a1), f2(a2), f3(a3), f4(a4), f5(a5)))->install(p);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // MAKE_HOLDER_DWA20011215_HPP
|
||||
@@ -1,132 +0,0 @@
|
||||
// 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/python/object/class.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/object/inheritance.hpp>
|
||||
# include <boost/python/object/find_instance.hpp>
|
||||
# include <boost/python/object/forward.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/mpl/apply.hpp>
|
||||
# include <boost/python/detail/pointee.hpp>
|
||||
# include <boost/python/detail/preprocessor.hpp>
|
||||
# include <boost/preprocessor/enum_params.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
template <class Pointer, class Value>
|
||||
struct pointer_holder : instance_holder
|
||||
{
|
||||
pointer_holder(Pointer);
|
||||
|
||||
// Forward construction to the held object
|
||||
# ifndef BOOST_PYTHON_GENERATE_CODE
|
||||
# include <boost/python/preprocessed/pointer_holder.hpp>
|
||||
# endif
|
||||
|
||||
|
||||
# define BOOST_PYTHON_CONSTRUCT_POINTER_HOLDER(nargs, ignored) \
|
||||
BOOST_PP_EXPR_IF(nargs, template <) \
|
||||
BOOST_PP_ENUM_PARAMS(nargs, class A) \
|
||||
BOOST_PP_EXPR_IF(nargs, >) \
|
||||
pointer_holder(PyObject* \
|
||||
BOOST_PP_COMMA_IF(nargs) \
|
||||
BOOST_PYTHON_ENUM_PARAMS2(nargs, (A,a))) \
|
||||
: m_p(new Value( \
|
||||
BOOST_PP_ENUM(nargs, BOOST_PYTHON_UNFORWARD, nil) \
|
||||
)) \
|
||||
{}
|
||||
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CONSTRUCT_POINTER_HOLDER,nil)
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(converter::undecorated_type_id_t);
|
||||
|
||||
private: // data members
|
||||
Pointer m_p;
|
||||
};
|
||||
|
||||
template <class Pointer, class Value>
|
||||
struct pointer_holder_back_reference : instance_holder
|
||||
{
|
||||
private:
|
||||
typedef typename python::detail::pointee<Pointer>::type held_type;
|
||||
public:
|
||||
|
||||
pointer_holder_back_reference(Pointer);
|
||||
|
||||
// Forward construction to the held object
|
||||
# ifndef BOOST_PYTHON_GENERATE_CODE
|
||||
# include <boost/python/preprocessed/pointer_holder_back_reference.hpp>
|
||||
# endif
|
||||
|
||||
# define BOOST_PYTHON_CONSTRUCT_POINTER_HOLDER_BACK_REFERENCE(nargs, ignored) \
|
||||
BOOST_PP_EXPR_IF(nargs, template <) \
|
||||
BOOST_PP_ENUM_PARAMS(nargs, class A) \
|
||||
BOOST_PP_EXPR_IF(nargs, >) \
|
||||
pointer_holder_back_reference(PyObject* p \
|
||||
BOOST_PP_COMMA_IF(nargs) \
|
||||
BOOST_PYTHON_ENUM_PARAMS2(nargs, (A,a))) \
|
||||
: m_p(new held_type( \
|
||||
p BOOST_PP_COMMA_IF(nargs) \
|
||||
BOOST_PP_ENUM(nargs, BOOST_PYTHON_UNFORWARD, nil) \
|
||||
)) \
|
||||
{ \
|
||||
void const* x = &instance_finder<held_type>::registration; (void)x; \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CONSTRUCT_POINTER_HOLDER_BACK_REFERENCE,nil)
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(converter::undecorated_type_id_t);
|
||||
|
||||
private: // data members
|
||||
Pointer m_p;
|
||||
};
|
||||
|
||||
template <class Pointer, class Value>
|
||||
pointer_holder<Pointer,Value>::pointer_holder(Pointer p)
|
||||
: m_p(p)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Pointer, class Value>
|
||||
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(converter::undecorated_type_id_t dst_t)
|
||||
{
|
||||
if (dst_t == converter::undecorated_type_id<Pointer>())
|
||||
return &this->m_p;
|
||||
|
||||
converter::type_id_t src_t = converter::undecorated_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(converter::undecorated_type_id_t dst_t)
|
||||
{
|
||||
if (dst_t == converter::undecorated_type_id<Pointer>())
|
||||
return &this->m_p;
|
||||
|
||||
if (dst_t == converter::undecorated_type_id<held_type>())
|
||||
return &*this->m_p;
|
||||
|
||||
converter::type_id_t src_t = converter::undecorated_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
|
||||
@@ -1,73 +0,0 @@
|
||||
// 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/detail/pointee.hpp>
|
||||
# include <boost/python/detail/if_else.hpp>
|
||||
# include <boost/python/object/value_holder.hpp>
|
||||
# include <boost/python/object/pointer_holder.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
|
||||
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 holder;
|
||||
|
||||
static holder* get() { return 0; }
|
||||
};
|
||||
|
||||
template <class T,class Ptr>
|
||||
struct select_pointer_holder
|
||||
{
|
||||
typedef typename python::detail::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 holder;
|
||||
|
||||
static holder* get() { return 0; }
|
||||
};
|
||||
}
|
||||
|
||||
template <class T, class NotSpecified>
|
||||
inline detail::select_value_holder<T,T> select_holder(python::detail::not_specified*, T* = 0, NotSpecified* = 0)
|
||||
{
|
||||
return detail::select_value_holder<T,T>();
|
||||
}
|
||||
|
||||
template <class T, class Held>
|
||||
inline detail::select_value_holder<T, Held> select_holder(T*, Held* = 0)
|
||||
{
|
||||
return detail::select_value_holder<T, Held>();
|
||||
}
|
||||
|
||||
|
||||
template <class T, class Ptr>
|
||||
detail::select_pointer_holder<T,Ptr> select_holder(void*, Ptr* = 0, T* = 0)
|
||||
{
|
||||
return detail::select_pointer_holder<T,Ptr>();
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // SELECT_HOLDER_DWA2002322_HPP
|
||||
@@ -1,108 +0,0 @@
|
||||
// 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/object/class.hpp>
|
||||
# include <boost/python/converter/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/preprocessor.hpp>
|
||||
# include <boost/preprocessor/enum_params.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
template <class Held>
|
||||
struct value_holder : instance_holder
|
||||
{
|
||||
// Forward construction to the held object
|
||||
# ifndef BOOST_PYTHON_GENERATE_CODE
|
||||
# include <boost/python/preprocessed/value_holder.hpp>
|
||||
# endif
|
||||
|
||||
# define BOOST_PYTHON_CONSTRUCT_VALUE_HOLDER(nargs, ignored) \
|
||||
BOOST_PP_EXPR_IF(nargs, template <) \
|
||||
BOOST_PP_ENUM_PARAMS(nargs, class A) \
|
||||
BOOST_PP_EXPR_IF(nargs, >) \
|
||||
value_holder(PyObject* \
|
||||
BOOST_PP_COMMA_IF(nargs) \
|
||||
BOOST_PYTHON_ENUM_PARAMS2(nargs, (A,a))) \
|
||||
: m_held( \
|
||||
BOOST_PP_ENUM(nargs, BOOST_PYTHON_UNFORWARD, nil) \
|
||||
) \
|
||||
{}
|
||||
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CONSTRUCT_VALUE_HOLDER,nil)
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(converter::undecorated_type_id_t);
|
||||
|
||||
private: // data members
|
||||
Held m_held;
|
||||
};
|
||||
|
||||
template <class Held, class BackReferenceType>
|
||||
struct value_holder_back_reference : instance_holder
|
||||
{
|
||||
// Forward construction to the held object
|
||||
# ifndef BOOST_PYTHON_GENERATE_CODE
|
||||
# include <boost/python/preprocessed/value_holder_back_reference.hpp>
|
||||
# endif
|
||||
|
||||
# define BOOST_PYTHON_CONSTRUCT_VALUE_HOLDER_BACK_REFERENCE(nargs, ignored) \
|
||||
BOOST_PP_EXPR_IF(nargs, template <) \
|
||||
BOOST_PP_ENUM_PARAMS(nargs, class A) \
|
||||
BOOST_PP_EXPR_IF(nargs, >) \
|
||||
value_holder_back_reference(PyObject* p \
|
||||
BOOST_PP_COMMA_IF(nargs) \
|
||||
BOOST_PYTHON_ENUM_PARAMS2(nargs, (A,a))) \
|
||||
: m_held( \
|
||||
p BOOST_PP_COMMA_IF(nargs) \
|
||||
BOOST_PP_ENUM(nargs, BOOST_PYTHON_UNFORWARD, nil) \
|
||||
) \
|
||||
{ \
|
||||
void const* x = &instance_finder<BackReferenceType>::registration; (void)x; \
|
||||
}
|
||||
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CONSTRUCT_VALUE_HOLDER_BACK_REFERENCE,nil)
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(converter::undecorated_type_id_t);
|
||||
|
||||
private: // data members
|
||||
BackReferenceType m_held;
|
||||
};
|
||||
|
||||
template <class Held>
|
||||
void* value_holder<Held>::holds(converter::undecorated_type_id_t dst_t)
|
||||
{
|
||||
converter::undecorated_type_id_t src_t = converter::undecorated_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(
|
||||
converter::undecorated_type_id_t dst_t)
|
||||
{
|
||||
converter::undecorated_type_id_t src_t = converter::undecorated_type_id<Held>();
|
||||
if (src_t == dst_t)
|
||||
{
|
||||
Held* x = &m_held;
|
||||
return x;
|
||||
}
|
||||
|
||||
src_t = converter::undecorated_type_id<BackReferenceType>();
|
||||
return src_t == dst_t
|
||||
? &m_held
|
||||
: find_static_type(&m_held, src_t, dst_t);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // VALUE_HOLDER_DWA20011215_HPP
|
||||
@@ -1,395 +0,0 @@
|
||||
// (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 OBJECTS_DWA051100_H_
|
||||
# define OBJECTS_DWA051100_H_
|
||||
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/reference.hpp>
|
||||
# include "boost/operators.hpp"
|
||||
# include <utility>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
class BOOST_PYTHON_DECL object
|
||||
{
|
||||
public:
|
||||
explicit object(ref p);
|
||||
|
||||
// Return a reference to the held object
|
||||
ref reference() const;
|
||||
|
||||
// Return a raw pointer to the held object
|
||||
PyObject* get() const;
|
||||
|
||||
private:
|
||||
ref m_p;
|
||||
};
|
||||
|
||||
class tuple;
|
||||
|
||||
class BOOST_PYTHON_DECL tuple_base : public object
|
||||
{
|
||||
public:
|
||||
explicit tuple_base(std::size_t n = 0);
|
||||
explicit tuple_base(ref p);
|
||||
|
||||
static PyTypeObject* type_obj();
|
||||
static bool accepts(ref p);
|
||||
std::size_t size() const;
|
||||
ref operator[](std::size_t pos) const;
|
||||
|
||||
void set_item(std::size_t pos, const ref& rhs);
|
||||
|
||||
tuple slice(int low, int high) const;
|
||||
|
||||
friend BOOST_PYTHON_DECL tuple operator+(const tuple&, const tuple&);
|
||||
friend BOOST_PYTHON_DECL tuple& operator+=(tuple&, const tuple&);
|
||||
};
|
||||
|
||||
class tuple : public tuple_base
|
||||
{
|
||||
public:
|
||||
explicit tuple(std::size_t n = 0) : tuple_base(n) {}
|
||||
explicit tuple(ref p) : tuple_base(p) {}
|
||||
|
||||
template <class First, class Second>
|
||||
tuple(const std::pair<First,Second>& x)
|
||||
: tuple_base(ref(PyTuple_New(2)))
|
||||
{
|
||||
set_item(0, x.first);
|
||||
set_item(1, x.second);
|
||||
}
|
||||
|
||||
template <class First, class Second>
|
||||
tuple(const First& first, const Second& second)
|
||||
: tuple_base(ref(PyTuple_New(2)))
|
||||
{
|
||||
set_item(0, first);
|
||||
set_item(1, second);
|
||||
}
|
||||
|
||||
template <class First, class Second, class Third>
|
||||
tuple(const First& first, const Second& second, const Third& third)
|
||||
: tuple_base(ref(PyTuple_New(3)))
|
||||
{
|
||||
set_item(0, first);
|
||||
set_item(1, second);
|
||||
set_item(2, third);
|
||||
}
|
||||
|
||||
template <class First, class Second, class Third, class Fourth>
|
||||
tuple(const First& first, const Second& second, const Third& third, const Fourth& fourth)
|
||||
: tuple_base(ref(PyTuple_New(4)))
|
||||
{
|
||||
set_item(0, first);
|
||||
set_item(1, second);
|
||||
set_item(2, third);
|
||||
set_item(3, fourth);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void set_item(std::size_t pos, const T& rhs)
|
||||
{
|
||||
this->set_item(pos, make_ref(rhs));
|
||||
}
|
||||
|
||||
void set_item(std::size_t pos, const ref& rhs)
|
||||
{
|
||||
tuple_base::set_item(pos, rhs);
|
||||
}
|
||||
};
|
||||
|
||||
class list;
|
||||
|
||||
struct BOOST_PYTHON_DECL list_proxy;
|
||||
struct BOOST_PYTHON_DECL list_slice_proxy;
|
||||
|
||||
class BOOST_PYTHON_DECL list_base : public object
|
||||
{
|
||||
protected:
|
||||
typedef list_proxy proxy;
|
||||
typedef list_slice_proxy slice_proxy;
|
||||
public:
|
||||
explicit list_base(ref p);
|
||||
explicit list_base(std::size_t sz = 0);
|
||||
static PyTypeObject* type_obj();
|
||||
static bool accepts(ref p);
|
||||
std::size_t size() const;
|
||||
ref operator[](std::size_t pos) const;
|
||||
proxy operator[](std::size_t pos);
|
||||
ref get_item(std::size_t pos) const;
|
||||
|
||||
void set_item(std::size_t pos, const ref& );
|
||||
|
||||
// void set_item(std::size_t pos, const object& );
|
||||
|
||||
void insert(std::size_t index, const ref& item);
|
||||
|
||||
void push_back(const ref& item);
|
||||
|
||||
void append(const ref& item);
|
||||
|
||||
list slice(int low, int high) const;
|
||||
slice_proxy slice(int low, int high);
|
||||
void sort();
|
||||
void reverse();
|
||||
tuple as_tuple() const;
|
||||
};
|
||||
|
||||
class list : public list_base
|
||||
{
|
||||
public:
|
||||
explicit list(ref p) : list_base(p) {}
|
||||
explicit list(std::size_t sz = 0) : list_base(sz) {}
|
||||
template <class T>
|
||||
void set_item(std::size_t pos, const T& x)
|
||||
{ this->set_item(pos, make_ref(x)); }
|
||||
template <class T>
|
||||
void insert(std::size_t index, const T& x)
|
||||
{ this->insert(index, make_ref(x)); }
|
||||
template <class T>
|
||||
void push_back(const T& item)
|
||||
{ this->push_back(make_ref(item)); }
|
||||
template <class T>
|
||||
void append(const T& item)
|
||||
{ this->append(make_ref(item)); }
|
||||
|
||||
void set_item(std::size_t pos, const ref& x) { list_base::set_item(pos, x); }
|
||||
void insert(std::size_t index, const ref& item) { list_base::insert(index, item); }
|
||||
void push_back(const ref& item) { list_base::push_back(item); }
|
||||
void append(const ref& item) { list_base::append(item); }
|
||||
};
|
||||
|
||||
class BOOST_PYTHON_DECL string
|
||||
: public object, public boost::multipliable2<string, unsigned int>
|
||||
{
|
||||
public:
|
||||
// Construct from an owned PyObject*.
|
||||
// Precondition: p must point to a python string.
|
||||
explicit string(ref p);
|
||||
explicit string(const char* s);
|
||||
string(const char* s, std::size_t length);
|
||||
string(const string& rhs);
|
||||
|
||||
enum interned_t { interned };
|
||||
string(const char* s, interned_t);
|
||||
|
||||
// Get the type object for Strings
|
||||
static PyTypeObject* type_obj();
|
||||
|
||||
// Return true if the given object is a python string
|
||||
static bool accepts(ref o);
|
||||
|
||||
// Return the length of the string.
|
||||
std::size_t size() const;
|
||||
|
||||
// Returns a null-terminated representation of the contents of string.
|
||||
// The pointer refers to the internal buffer of string, not a copy.
|
||||
// The data must not be modified in any way. It must not be de-allocated.
|
||||
const char* c_str() const;
|
||||
|
||||
string& operator*=(unsigned int repeat_count);
|
||||
string& operator+=(const string& rhs);
|
||||
friend string operator+(string x, string y);
|
||||
string& operator+=(const char* rhs);
|
||||
friend string operator+(string x, const char* y);
|
||||
friend string operator+(const char* x, string y);
|
||||
|
||||
void intern();
|
||||
|
||||
friend string operator%(const string& format, const tuple& args);
|
||||
};
|
||||
|
||||
class dictionary;
|
||||
|
||||
struct BOOST_PYTHON_DECL dictionary_proxy;
|
||||
|
||||
class BOOST_PYTHON_DECL dictionary_base : public object
|
||||
{
|
||||
protected:
|
||||
typedef dictionary_proxy proxy;
|
||||
|
||||
public:
|
||||
explicit dictionary_base(ref p);
|
||||
dictionary_base();
|
||||
void clear();
|
||||
|
||||
static PyTypeObject* type_obj();
|
||||
static bool accepts(ref p);
|
||||
|
||||
public:
|
||||
proxy operator[](ref key);
|
||||
ref operator[](ref key) const;
|
||||
ref get_item(const ref& key) const;
|
||||
ref get_item(const ref& key, const ref& default_) const;
|
||||
|
||||
void set_item(const ref& key, const ref& value);
|
||||
|
||||
void erase(ref key);
|
||||
|
||||
// proxy operator[](const object& key);
|
||||
// ref operator[](const object& key) const;
|
||||
|
||||
// ref get_item(const object& key, ref default_ = ref()) const;
|
||||
// void set_item(const object& key, const ref& value);
|
||||
|
||||
// void erase(const object& key);
|
||||
|
||||
list items() const;
|
||||
list keys() const;
|
||||
list values() const;
|
||||
|
||||
std::size_t size() const;
|
||||
// TODO: iterator support
|
||||
};
|
||||
|
||||
struct BOOST_PYTHON_DECL dictionary_proxy
|
||||
{
|
||||
template <class T>
|
||||
const ref& operator=(const T& rhs)
|
||||
{ return (*this) = make_ref(rhs); }
|
||||
const ref& operator=(const ref& rhs);
|
||||
|
||||
operator ref() const;
|
||||
private:
|
||||
friend class dictionary_base;
|
||||
dictionary_proxy(const ref& dict, const ref& key);
|
||||
|
||||
// This is needed to work around the very strange MSVC error report that the
|
||||
// return type of the built-in operator= differs from that of the ones
|
||||
// defined above. Couldn't hurt to make these un-assignable anyway, though.
|
||||
const ref& operator=(const dictionary_proxy&); // Not actually implemented
|
||||
private:
|
||||
ref m_dict;
|
||||
ref m_key;
|
||||
};
|
||||
|
||||
class dictionary : public dictionary_base
|
||||
{
|
||||
typedef dictionary_proxy proxy;
|
||||
public:
|
||||
explicit dictionary(ref p) : dictionary_base(p) {}
|
||||
dictionary() : dictionary_base() {}
|
||||
|
||||
template <class Key>
|
||||
proxy operator[](const Key& key)
|
||||
{ return this->operator[](make_ref(key)); }
|
||||
proxy operator[](ref key)
|
||||
{ return dictionary_base::operator[](key); }
|
||||
|
||||
template <class Key>
|
||||
ref operator[](const Key& key) const
|
||||
{ return this->operator[](make_ref(key)); }
|
||||
ref operator[](ref key) const
|
||||
{ return dictionary_base::operator[](key); }
|
||||
|
||||
template <class Key>
|
||||
ref get_item(const Key& key) const
|
||||
{ return this->get_item(make_ref(key)); }
|
||||
ref get_item(const ref& key) const
|
||||
{ return dictionary_base::get_item(key); }
|
||||
|
||||
template <class Key, class Default>
|
||||
ref get_item(const Key& key, const Default& default_) const
|
||||
{ return this->get_item(make_ref(key), make_ref(default_)); }
|
||||
ref get_item(const ref& key, const ref& default_) const
|
||||
{ return dictionary_base::get_item(key, default_); }
|
||||
|
||||
template <class Key, class Value>
|
||||
void set_item(const Key& key, const Value& value)
|
||||
{ this->set_item(make_ref(key), make_ref(value)); }
|
||||
void set_item(const ref& key, const ref& value)
|
||||
{ dictionary_base::set_item(key, value); }
|
||||
|
||||
template <class Key>
|
||||
void erase(const Key& key)
|
||||
{ this->erase(make_ref(key)); }
|
||||
void erase(ref key)
|
||||
{ dictionary_base::erase(key); }
|
||||
};
|
||||
|
||||
struct BOOST_PYTHON_DECL list_proxy
|
||||
{
|
||||
template <class T>
|
||||
const ref& operator=(const T& rhs)
|
||||
{ return (*this) = make_ref(rhs); }
|
||||
const ref& operator=(const ref& rhs);
|
||||
|
||||
operator ref() const;
|
||||
|
||||
private:
|
||||
friend class list_base;
|
||||
list_proxy(const ref& list, std::size_t index);
|
||||
|
||||
// This is needed to work around the very strange MSVC error report that the
|
||||
// return type of the built-in operator= differs from that of the ones
|
||||
// defined above. Couldn't hurt to make these un-assignable anyway, though.
|
||||
const ref& operator=(const list_proxy&); // Not actually implemented
|
||||
private:
|
||||
list m_list;
|
||||
std::size_t m_index;
|
||||
};
|
||||
|
||||
struct BOOST_PYTHON_DECL list_slice_proxy
|
||||
{
|
||||
const list& operator=(const list& rhs);
|
||||
operator ref() const;
|
||||
operator list() const;
|
||||
std::size_t size() const;
|
||||
ref operator[](std::size_t pos) const;
|
||||
private:
|
||||
friend class list_base;
|
||||
list_slice_proxy(const ref& list, int low, int high);
|
||||
private:
|
||||
ref m_list;
|
||||
int m_low, m_high;
|
||||
};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
# ifndef BOOST_PYTHON_V2
|
||||
|
||||
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
|
||||
|
||||
BOOST_PYTHON_DECL PyObject* to_python(const boost::python::tuple&);
|
||||
BOOST_PYTHON_DECL boost::python::tuple from_python(PyObject* p, boost::python::type<boost::python::tuple>);
|
||||
|
||||
inline boost::python::tuple from_python(PyObject* p, boost::python::type<const boost::python::tuple&>)
|
||||
{
|
||||
return from_python(p, boost::python::type<boost::python::tuple>());
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL PyObject* to_python(const boost::python::list&);
|
||||
BOOST_PYTHON_DECL boost::python::list from_python(PyObject* p, boost::python::type<boost::python::list>);
|
||||
|
||||
inline boost::python::list from_python(PyObject* p, boost::python::type<const boost::python::list&>)
|
||||
{
|
||||
return from_python(p, boost::python::type<boost::python::list>());
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL PyObject* to_python(const boost::python::string&);
|
||||
BOOST_PYTHON_DECL boost::python::string from_python(PyObject* p, boost::python::type<boost::python::string>);
|
||||
|
||||
inline boost::python::string from_python(PyObject* p, boost::python::type<const boost::python::string&>)
|
||||
{
|
||||
return from_python(p, boost::python::type<boost::python::string>());
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL PyObject* to_python(const boost::python::dictionary&);
|
||||
BOOST_PYTHON_DECL boost::python::dictionary from_python(PyObject* p, boost::python::type<boost::python::dictionary>);
|
||||
|
||||
inline boost::python::dictionary from_python(PyObject* p, boost::python::type<const boost::python::dictionary&>)
|
||||
{
|
||||
return from_python(p, boost::python::type<boost::python::dictionary>());
|
||||
}
|
||||
|
||||
BOOST_PYTHON_END_CONVERSION_NAMESPACE
|
||||
# endif
|
||||
#endif // OBJECTS_DWA051100_H_
|
||||
@@ -1,549 +0,0 @@
|
||||
// (C) Copyright Ullrich Koethe and David Abrahams 2000-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.
|
||||
//
|
||||
// The authors gratefully acknowlege the support of Dragon Systems, Inc., in
|
||||
// producing this work.
|
||||
//
|
||||
// Revision History:
|
||||
// 23 Jan 2001 - Another stupid typo fix by Ralf W. Grosse-Kunstleve (David Abrahams)
|
||||
// 20 Jan 2001 - Added a fix from Ralf W. Grosse-Kunstleve (David Abrahams)
|
||||
#ifndef OPERATORS_UK112000_H_
|
||||
#define OPERATORS_UK112000_H_
|
||||
|
||||
# include <boost/python/reference.hpp>
|
||||
# include <boost/python/detail/functions.hpp>
|
||||
|
||||
// When STLport is used with native streams, _STL::ostringstream().str() is not
|
||||
// _STL::string, but std::string. This confuses to_python(), so we'll use
|
||||
// strstream instead. Also, GCC 2.95.2 doesn't have sstream.
|
||||
# if defined(__SGI_STL_PORT) ? defined(__SGI_STL_OWN_IOSTREAMS) : (!defined(__GNUC__) || __GNUC__ > 2)
|
||||
# define BOOST_PYTHON_USE_SSTREAM
|
||||
# endif
|
||||
|
||||
#if defined(BOOST_PYTHON_USE_SSTREAM)
|
||||
# include <sstream>
|
||||
# else
|
||||
# include <strstream>
|
||||
# endif
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
BOOST_PYTHON_DECL tuple standard_coerce(ref l, ref r);
|
||||
|
||||
namespace detail {
|
||||
|
||||
// helper class for automatic operand type detection
|
||||
// during operator wrapping.
|
||||
struct auto_operand {};
|
||||
}
|
||||
|
||||
// Define operator ids that can be or'ed together
|
||||
// (boost::python::op_add | boost::python::op_sub | boost::python::op_mul).
|
||||
// This allows to wrap several operators in one line.
|
||||
enum operator_id
|
||||
{
|
||||
op_add = 0x1,
|
||||
op_sub = 0x2,
|
||||
op_mul = 0x4,
|
||||
op_div = 0x8,
|
||||
op_mod = 0x10,
|
||||
op_divmod =0x20,
|
||||
op_pow = 0x40,
|
||||
op_lshift = 0x80,
|
||||
op_rshift = 0x100,
|
||||
op_and = 0x200,
|
||||
op_xor = 0x400,
|
||||
op_or = 0x800,
|
||||
op_neg = 0x1000,
|
||||
op_pos = 0x2000,
|
||||
op_abs = 0x4000,
|
||||
op_invert = 0x8000,
|
||||
op_int = 0x10000,
|
||||
op_long = 0x20000,
|
||||
op_float = 0x40000,
|
||||
op_str = 0x80000,
|
||||
op_cmp = 0x100000,
|
||||
op_gt = 0x200000,
|
||||
op_ge = 0x400000,
|
||||
op_lt = 0x800000,
|
||||
op_le = 0x1000000,
|
||||
op_eq = 0x2000000,
|
||||
op_ne = 0x4000000
|
||||
};
|
||||
|
||||
// Wrap the operators given by "which". Usage:
|
||||
// foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>());
|
||||
template <long which, class operand = boost::python::detail::auto_operand>
|
||||
struct operators {};
|
||||
|
||||
// Wrap heterogeneous operators with given left operand type. Usage:
|
||||
// foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>(),
|
||||
// boost::python::left_operand<int>());
|
||||
template <class T>
|
||||
struct left_operand {};
|
||||
|
||||
// Wrap heterogeneous operators with given right operand type. Usage:
|
||||
// foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>(),
|
||||
// boost::python::right_operand<int>());
|
||||
template <class T>
|
||||
struct right_operand {};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class Specified>
|
||||
struct operand_select
|
||||
{
|
||||
template <class wrapped_type>
|
||||
struct wrapped
|
||||
{
|
||||
typedef Specified type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct operand_select<auto_operand>
|
||||
{
|
||||
template <class wrapped_type>
|
||||
struct wrapped
|
||||
{
|
||||
typedef const wrapped_type& type;
|
||||
};
|
||||
};
|
||||
|
||||
template <long> struct define_operator;
|
||||
|
||||
// Base class which grants access to extension_class_base::add_method() to its derived classes
|
||||
struct add_operator_base
|
||||
{
|
||||
protected:
|
||||
static inline void add_method(extension_class_base* target, function* method, const char* name)
|
||||
{ target->add_method(method, name); }
|
||||
};
|
||||
|
||||
//
|
||||
// choose_op, choose_unary_op, and choose_rop
|
||||
//
|
||||
// These templates use "poor man's partial specialization" to generate the
|
||||
// appropriate add_method() call (if any) for a given operator and argument set.
|
||||
//
|
||||
// Usage:
|
||||
// choose_op<(which & op_add)>::template args<left_t,right_t>::add(ext_class);
|
||||
//
|
||||
// (see extension_class<>::def_operators() for more examples).
|
||||
//
|
||||
template <long op_selector>
|
||||
struct choose_op
|
||||
{
|
||||
template <class Left, class Right = Left>
|
||||
struct args : add_operator_base
|
||||
{
|
||||
static inline void add(extension_class_base* target)
|
||||
{
|
||||
typedef define_operator<op_selector> def_op;
|
||||
add_method(target,
|
||||
new typename def_op::template operator_function<Left, Right>(),
|
||||
def_op::name());
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
// specialization for 0 has no effect
|
||||
template <>
|
||||
struct choose_op<0>
|
||||
{
|
||||
template <class Left, class Right = Left>
|
||||
struct args
|
||||
{
|
||||
static inline void add(extension_class_base*)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
template <long op_selector>
|
||||
struct choose_unary_op
|
||||
{
|
||||
template <class Operand>
|
||||
struct args : add_operator_base
|
||||
{
|
||||
static inline void add(extension_class_base* target)
|
||||
{
|
||||
typedef define_operator<op_selector> def_op;
|
||||
add_method(target,
|
||||
new typename def_op::template operator_function<Operand>(),
|
||||
def_op::name());
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
// specialization for 0 has no effect
|
||||
template <>
|
||||
struct choose_unary_op<0>
|
||||
{
|
||||
template <class Operand>
|
||||
struct args
|
||||
{
|
||||
static inline void add(extension_class_base*)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
template <long op_selector>
|
||||
struct choose_rop
|
||||
{
|
||||
template <class Left, class Right = Left>
|
||||
struct args : add_operator_base
|
||||
{
|
||||
static inline void add(extension_class_base* target)
|
||||
{
|
||||
typedef define_operator<op_selector> def_op;
|
||||
add_method(target,
|
||||
new typename def_op::template roperator_function<Right, Left>(),
|
||||
def_op::rname());
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
// specialization for 0 has no effect
|
||||
template <>
|
||||
struct choose_rop<0>
|
||||
{
|
||||
template <class Left, class Right = Left>
|
||||
struct args
|
||||
{
|
||||
static inline void add(extension_class_base*)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// Fully specialize define_operator for all operators defined in operator_id above.
|
||||
// Every specialization defines one function object for normal operator calls and one
|
||||
// for operator calls with operands reversed ("__r*__" function variants).
|
||||
// Specializations for most operators follow a standard pattern: execute the expression
|
||||
// that uses the operator in question. This standard pattern is realized by the following
|
||||
// macros so that the actual specialization can be done by just calling a macro.
|
||||
#define PY_DEFINE_BINARY_OPERATORS(id, oper) \
|
||||
template <> \
|
||||
struct define_operator<op_##id> \
|
||||
{ \
|
||||
template <class Left, class Right = Left> \
|
||||
struct operator_function : function \
|
||||
{ \
|
||||
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \
|
||||
{ \
|
||||
tuple args(ref(arguments, ref::increment_count)); \
|
||||
\
|
||||
return BOOST_PYTHON_CONVERSION::to_python( \
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>()) oper \
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>())); \
|
||||
} \
|
||||
\
|
||||
const char* description() const \
|
||||
{ return "__" #id "__"; } \
|
||||
}; \
|
||||
\
|
||||
template <class Right, class Left> \
|
||||
struct roperator_function : function \
|
||||
{ \
|
||||
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \
|
||||
{ \
|
||||
tuple args(ref(arguments, ref::increment_count)); \
|
||||
\
|
||||
return BOOST_PYTHON_CONVERSION::to_python( \
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>()) oper \
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>())); \
|
||||
} \
|
||||
\
|
||||
const char* description() const \
|
||||
{ return "__r" #id "__"; } \
|
||||
\
|
||||
}; \
|
||||
\
|
||||
static const char * name() { return "__" #id "__"; } \
|
||||
static const char * rname() { return "__r" #id "__"; } \
|
||||
}
|
||||
|
||||
#define PY_DEFINE_UNARY_OPERATORS(id, oper) \
|
||||
template <> \
|
||||
struct define_operator<op_##id> \
|
||||
{ \
|
||||
template <class operand> \
|
||||
struct operator_function : function \
|
||||
{ \
|
||||
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \
|
||||
{ \
|
||||
tuple args(ref(arguments, ref::increment_count)); \
|
||||
\
|
||||
return BOOST_PYTHON_CONVERSION::to_python( \
|
||||
oper(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<operand>()))); \
|
||||
} \
|
||||
\
|
||||
const char* description() const \
|
||||
{ return "__" #id "__"; } \
|
||||
}; \
|
||||
\
|
||||
static const char * name() { return "__" #id "__"; } \
|
||||
}
|
||||
|
||||
PY_DEFINE_BINARY_OPERATORS(add, +);
|
||||
PY_DEFINE_BINARY_OPERATORS(sub, -);
|
||||
PY_DEFINE_BINARY_OPERATORS(mul, *);
|
||||
PY_DEFINE_BINARY_OPERATORS(div, /);
|
||||
PY_DEFINE_BINARY_OPERATORS(mod, %);
|
||||
PY_DEFINE_BINARY_OPERATORS(lshift, <<);
|
||||
PY_DEFINE_BINARY_OPERATORS(rshift, >>);
|
||||
PY_DEFINE_BINARY_OPERATORS(and, &);
|
||||
PY_DEFINE_BINARY_OPERATORS(xor, ^);
|
||||
PY_DEFINE_BINARY_OPERATORS(or, |);
|
||||
PY_DEFINE_BINARY_OPERATORS(gt, >);
|
||||
PY_DEFINE_BINARY_OPERATORS(ge, >=);
|
||||
PY_DEFINE_BINARY_OPERATORS(lt, <);
|
||||
PY_DEFINE_BINARY_OPERATORS(le, <=);
|
||||
PY_DEFINE_BINARY_OPERATORS(eq, ==);
|
||||
PY_DEFINE_BINARY_OPERATORS(ne, !=);
|
||||
|
||||
PY_DEFINE_UNARY_OPERATORS(neg, -);
|
||||
PY_DEFINE_UNARY_OPERATORS(pos, +);
|
||||
PY_DEFINE_UNARY_OPERATORS(abs, abs);
|
||||
PY_DEFINE_UNARY_OPERATORS(invert, ~);
|
||||
PY_DEFINE_UNARY_OPERATORS(int, long);
|
||||
PY_DEFINE_UNARY_OPERATORS(long, PyLong_FromLong);
|
||||
PY_DEFINE_UNARY_OPERATORS(float, double);
|
||||
|
||||
#undef PY_DEFINE_BINARY_OPERATORS
|
||||
#undef PY_DEFINE_UNARY_OPERATORS
|
||||
|
||||
// Some operators need special treatment, e.g. because there is no corresponding
|
||||
// expression in C++. These are specialized manually.
|
||||
|
||||
// pow(): Manual specialization needed because an error message is required if this
|
||||
// function is called with three arguments. The "power modulo" operator is not
|
||||
// supported by define_operator, but can be wrapped manually (see special.html).
|
||||
template <>
|
||||
struct define_operator<op_pow>
|
||||
{
|
||||
template <class Left, class Right = Left>
|
||||
struct operator_function : function
|
||||
{
|
||||
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const
|
||||
{
|
||||
tuple args(ref(arguments, ref::increment_count));
|
||||
|
||||
if (args.size() == 3 && args[2]->ob_type != Py_None->ob_type)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected 2 arguments, got 3");
|
||||
throw_argument_error();
|
||||
}
|
||||
|
||||
return BOOST_PYTHON_CONVERSION::to_python(
|
||||
pow(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>()),
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>())));
|
||||
}
|
||||
|
||||
const char* description() const
|
||||
{ return "__pow__"; }
|
||||
|
||||
};
|
||||
|
||||
template <class Right, class Left>
|
||||
struct roperator_function : function
|
||||
{
|
||||
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const
|
||||
{
|
||||
tuple args(ref(arguments, ref::increment_count));
|
||||
|
||||
if (args.size() == 3 && args[2]->ob_type != Py_None->ob_type)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "bad operand type(s) for pow()");
|
||||
throw_argument_error();
|
||||
}
|
||||
|
||||
return BOOST_PYTHON_CONVERSION::to_python(
|
||||
pow(BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>()),
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>())));
|
||||
}
|
||||
|
||||
const char* description() const
|
||||
{ return "__rpow__"; }
|
||||
|
||||
};
|
||||
|
||||
static const char * name() { return "__pow__"; }
|
||||
static const char * rname() { return "__rpow__"; }
|
||||
};
|
||||
|
||||
// divmod(): Manual specialization needed because we must actually call two operators and
|
||||
// return a tuple containing both results
|
||||
template <>
|
||||
struct define_operator<op_divmod>
|
||||
{
|
||||
template <class Left, class Right = Left>
|
||||
struct operator_function : function
|
||||
{
|
||||
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const
|
||||
{
|
||||
tuple args(ref(arguments, ref::increment_count));
|
||||
PyObject * res = PyTuple_New(2);
|
||||
|
||||
PyTuple_SET_ITEM(res, 0,
|
||||
BOOST_PYTHON_CONVERSION::to_python(
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>()) /
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>())));
|
||||
PyTuple_SET_ITEM(res, 1,
|
||||
BOOST_PYTHON_CONVERSION::to_python(
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>()) %
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>())));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
const char* description() const
|
||||
{ return "__divmod__"; }
|
||||
|
||||
};
|
||||
|
||||
template <class Right, class Left>
|
||||
struct roperator_function : function
|
||||
{
|
||||
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const
|
||||
{
|
||||
tuple args(ref(arguments, ref::increment_count));
|
||||
PyObject * res = PyTuple_New(2);
|
||||
|
||||
PyTuple_SET_ITEM(res, 0,
|
||||
BOOST_PYTHON_CONVERSION::to_python(
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>()) /
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>())));
|
||||
PyTuple_SET_ITEM(res, 1,
|
||||
BOOST_PYTHON_CONVERSION::to_python(
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>()) %
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>())));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
const char* description() const
|
||||
{ return "__rdivmod__"; }
|
||||
|
||||
};
|
||||
|
||||
static const char * name() { return "__divmod__"; }
|
||||
static const char * rname() { return "__rdivmod__"; }
|
||||
};
|
||||
|
||||
// cmp(): Manual specialization needed because there is no three-way compare in C++.
|
||||
// It is implemented by two one-way comparisons with operators reversed in the second.
|
||||
template <>
|
||||
struct define_operator<op_cmp>
|
||||
{
|
||||
template <class Left, class Right = Left>
|
||||
struct operator_function : function
|
||||
{
|
||||
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const
|
||||
{
|
||||
tuple args(ref(arguments, ref::increment_count));
|
||||
|
||||
return BOOST_PYTHON_CONVERSION::to_python(
|
||||
(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>()) <
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>())) ?
|
||||
- 1 :
|
||||
(BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>()) <
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>())) ?
|
||||
1 :
|
||||
0) ;
|
||||
}
|
||||
|
||||
const char* description() const
|
||||
{ return "__cmp__"; }
|
||||
|
||||
};
|
||||
|
||||
template <class Right, class Left>
|
||||
struct roperator_function : function
|
||||
{
|
||||
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const
|
||||
{
|
||||
tuple args(ref(arguments, ref::increment_count));
|
||||
|
||||
return BOOST_PYTHON_CONVERSION::to_python(
|
||||
(BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>()) <
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>())) ?
|
||||
- 1 :
|
||||
(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>()) <
|
||||
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>())) ?
|
||||
1 :
|
||||
0) ;
|
||||
}
|
||||
|
||||
const char* description() const
|
||||
{ return "__rcmp__"; }
|
||||
|
||||
};
|
||||
|
||||
static const char * name() { return "__cmp__"; }
|
||||
static const char * rname() { return "__rcmp__"; }
|
||||
};
|
||||
|
||||
# ifndef BOOST_PYTHON_USE_SSTREAM
|
||||
class unfreezer {
|
||||
public:
|
||||
unfreezer(std::ostrstream& s) : m_stream(s) {}
|
||||
~unfreezer() { m_stream.freeze(false); }
|
||||
private:
|
||||
std::ostrstream& m_stream;
|
||||
};
|
||||
# endif
|
||||
|
||||
// str(): Manual specialization needed because the string conversion does not follow
|
||||
// the standard pattern relized by the macros.
|
||||
template <>
|
||||
struct define_operator<op_str>
|
||||
{
|
||||
template <class operand>
|
||||
struct operator_function : function
|
||||
{
|
||||
PyObject* do_call(PyObject* arguments, PyObject*) const
|
||||
{
|
||||
tuple args(ref(arguments, ref::increment_count));
|
||||
|
||||
// When STLport is used with native streams, _STL::ostringstream().str() is not
|
||||
// _STL::string, but std::string.
|
||||
# ifdef BOOST_PYTHON_USE_SSTREAM
|
||||
std::ostringstream s;
|
||||
s << BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<operand>());
|
||||
return BOOST_PYTHON_CONVERSION::to_python(s.str());
|
||||
# else
|
||||
std::ostrstream s;
|
||||
s << BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<operand>()) << char();
|
||||
auto unfreezer unfreeze(s);
|
||||
return BOOST_PYTHON_CONVERSION::to_python(const_cast<char const *>(s.str()));
|
||||
# endif
|
||||
}
|
||||
|
||||
const char* description() const
|
||||
{ return "__str__"; }
|
||||
|
||||
};
|
||||
|
||||
static const char * name() { return "__str__"; }
|
||||
};
|
||||
|
||||
|
||||
} // namespace detail
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
# undef BOOST_PYTHON_USE_SSTREAM
|
||||
#endif /* OPERATORS_UK112000_H_ */
|
||||
@@ -1,127 +0,0 @@
|
||||
#ifndef BOOST_PTR_HPP_INCLUDED
|
||||
# define BOOST_PTR_HPP_INCLUDED
|
||||
// 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.
|
||||
//
|
||||
// Based on boost/ref.hpp, thus:
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2001 Peter Dimov
|
||||
|
||||
# if _MSC_VER+0 >= 1020
|
||||
# pragma once
|
||||
# endif
|
||||
|
||||
# include <boost/config.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template<class Ptr> class pointer_wrapper
|
||||
{
|
||||
public:
|
||||
typedef Ptr type;
|
||||
|
||||
explicit pointer_wrapper(Ptr x): p_(x) {}
|
||||
operator Ptr() const { return p_; }
|
||||
Ptr get() const { return p_; }
|
||||
private:
|
||||
Ptr p_;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
inline pointer_wrapper<T> ptr(T t)
|
||||
{
|
||||
return pointer_wrapper<T>(t);
|
||||
}
|
||||
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template<typename T>
|
||||
class is_pointer_wrapper
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class is_pointer_wrapper<pointer_wrapper<T> >
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class unwrap_pointer
|
||||
{
|
||||
public:
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class unwrap_pointer<pointer_wrapper<T> >
|
||||
{
|
||||
public:
|
||||
typedef T type;
|
||||
};
|
||||
# else // no partial specialization
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#include <boost/type.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
typedef char (&yes_pointer_wrapper_t)[1];
|
||||
typedef char (&no_pointer_wrapper_t)[2];
|
||||
|
||||
no_pointer_wrapper_t is_pointer_wrapper_test(...);
|
||||
|
||||
template<typename T>
|
||||
yes_pointer_wrapper_t is_pointer_wrapper_test(type< pointer_wrapper<T> >);
|
||||
|
||||
template<bool wrapped>
|
||||
struct pointer_unwrapper
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pointer_unwrapper<true>
|
||||
{
|
||||
template <class T>
|
||||
struct apply
|
||||
{
|
||||
typedef typename T::type type;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class is_pointer_wrapper
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
sizeof(detail::is_pointer_wrapper_test(type<T>()))
|
||||
== sizeof(detail::yes_pointer_wrapper_t)));
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class unwrap_pointer
|
||||
: public detail::pointer_unwrapper<
|
||||
is_pointer_wrapper<T>::value
|
||||
>::template apply<T>
|
||||
{};
|
||||
|
||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // #ifndef BOOST_PTR_HPP_INCLUDED
|
||||
@@ -1,241 +0,0 @@
|
||||
// (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 PYPTR_DWA050400_H_
|
||||
# define PYPTR_DWA050400_H_
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/operators.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/cast.hpp>
|
||||
# include <cassert>
|
||||
# include <cstddef>
|
||||
# include <boost/python/detail/signatures.hpp>
|
||||
# include <boost/python/errors.hpp>
|
||||
# include <boost/python/detail/cast.hpp>
|
||||
|
||||
# ifndef BOOST_PYTHON_V2
|
||||
# include <boost/python/conversions.hpp>
|
||||
|
||||
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
|
||||
|
||||
template <class T, class Value, class Base = boost::detail::empty_base>
|
||||
struct py_ptr_conversions : Base
|
||||
{
|
||||
inline friend T from_python(PyObject* x, boost::python::type<const T&>)
|
||||
{ return T(boost::python::downcast<Value>(x).get(), T::increment_count); }
|
||||
|
||||
inline friend T from_python(PyObject* x, boost::python::type<T>)
|
||||
{ return T(boost::python::downcast<Value>(x).get(), T::increment_count); }
|
||||
|
||||
inline friend PyObject* to_python(T x)
|
||||
{ return boost::python::as_object(x.release()); }
|
||||
|
||||
};
|
||||
|
||||
BOOST_PYTHON_END_CONVERSION_NAMESPACE
|
||||
# endif
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
# ifndef BOOST_PYTHON_V2
|
||||
BOOST_PYTHON_IMPORT_CONVERSION(py_ptr_conversions);
|
||||
# endif
|
||||
|
||||
template <class T>
|
||||
class reference
|
||||
# ifndef BOOST_PYTHON_V2
|
||||
: public py_ptr_conversions<reference<T>, T>
|
||||
# endif
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
|
||||
reference(const reference& rhs)
|
||||
: m_p(rhs.m_p)
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
Py_XINCREF(m_p);
|
||||
}
|
||||
|
||||
reference() : m_p(0) {}
|
||||
|
||||
// These are two ways of spelling the same thing, that we need to increment
|
||||
// the reference count on the pointer when we're initialized.
|
||||
enum increment_count_t { increment_count };
|
||||
|
||||
enum allow_null { null_ok };
|
||||
|
||||
template <class T2>
|
||||
explicit reference(T2* x)
|
||||
: m_p(expect_non_null(x))
|
||||
{
|
||||
assert(m_p->ob_refcnt > 0);
|
||||
}
|
||||
|
||||
template <class T2>
|
||||
reference(T2* x, increment_count_t)
|
||||
: m_p(expect_non_null(x))
|
||||
{
|
||||
assert(m_p->ob_refcnt > 0);
|
||||
Py_INCREF(m_p);
|
||||
}
|
||||
|
||||
template <class T2>
|
||||
reference(T2* x, allow_null)
|
||||
: m_p(x)
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
}
|
||||
|
||||
template <class T2>
|
||||
reference(T2* x, allow_null, increment_count_t)
|
||||
: m_p(x)
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
Py_XINCREF(m_p);
|
||||
}
|
||||
|
||||
template <class T2>
|
||||
reference(T2* x, increment_count_t, allow_null)
|
||||
: m_p(x)
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
Py_XINCREF(m_p);
|
||||
}
|
||||
|
||||
reference& operator=(const reference& rhs)
|
||||
{
|
||||
assert(rhs.m_p == 0 || rhs.m_p->ob_refcnt > 0);
|
||||
Py_XINCREF(static_cast<PyObject*>(rhs.m_p));
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
Py_XDECREF(m_p);
|
||||
m_p = rhs.m_p;
|
||||
return *this;
|
||||
}
|
||||
|
||||
~reference()
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
Py_XDECREF(m_p);
|
||||
}
|
||||
|
||||
T& operator*() const
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
return *m_p;
|
||||
}
|
||||
|
||||
// MSVC doesn't like boost::dereferencable unless T has a default
|
||||
// constructor, so operator-> must be defined by hand :(
|
||||
T* operator->() const
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
return &**this;
|
||||
}
|
||||
|
||||
T* get() const
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
return m_p;
|
||||
}
|
||||
|
||||
T* release()
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
T* p = m_p;
|
||||
m_p = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
Py_XDECREF(m_p);
|
||||
m_p = 0;
|
||||
}
|
||||
|
||||
template <class T2>
|
||||
void reset(T2* x)
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
Py_XDECREF(m_p);
|
||||
m_p = expect_non_null(x);
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
}
|
||||
|
||||
template <class T2>
|
||||
void reset(T2* x, increment_count_t)
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
Py_XINCREF(x);
|
||||
Py_XDECREF(m_p);
|
||||
m_p = expect_non_null(x);
|
||||
assert(m_p->ob_refcnt > 0);
|
||||
}
|
||||
|
||||
template <class T2>
|
||||
void reset(T2* x, allow_null)
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
Py_XDECREF(m_p);
|
||||
m_p = x;
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
}
|
||||
|
||||
template <class T2>
|
||||
void reset(T2* x, allow_null, increment_count_t)
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
Py_XINCREF(x);
|
||||
Py_XDECREF(m_p);
|
||||
m_p = x;
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
}
|
||||
|
||||
template <class T2>
|
||||
void reset(T2* x, increment_count_t, allow_null)
|
||||
{
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
Py_XINCREF(x);
|
||||
Py_XDECREF(m_p);
|
||||
m_p = x;
|
||||
assert(m_p == 0 || m_p->ob_refcnt > 0);
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
||||
private:
|
||||
template<typename Y> friend class shared_ptr;
|
||||
#endif
|
||||
|
||||
inline PyObject* object() const
|
||||
{
|
||||
#ifdef BOOST_PYTHON_V2
|
||||
return (PyObject*)(
|
||||
(char*)&m_p->ob_type - offsetof(PyObject,ob_type));
|
||||
#else
|
||||
return as_object(m_p);
|
||||
#endif
|
||||
}
|
||||
|
||||
T* m_p;
|
||||
};
|
||||
|
||||
typedef reference<PyObject> ref;
|
||||
|
||||
#ifndef BOOST_PYTHON_V2
|
||||
template <class T>
|
||||
ref make_ref(const T& x)
|
||||
{
|
||||
return ref(to_python(x));
|
||||
}
|
||||
#endif
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // PYPTR_DWA050400_H_
|
||||
@@ -1,42 +0,0 @@
|
||||
// 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_INTERNAL_REFERENCE_DWA2002131_HPP
|
||||
# define RETURN_INTERNAL_REFERENCE_DWA2002131_HPP
|
||||
|
||||
# include <boost/python/default_call_policies.hpp>
|
||||
# include <boost/python/reference_existing_object.hpp>
|
||||
# include <boost/python/with_custodian_and_ward.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <std::size_t>
|
||||
struct return_internal_reference_owner_arg_must_be_greater_than_zero
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
|
||||
{}
|
||||
# endif
|
||||
;
|
||||
}
|
||||
|
||||
template <std::size_t owner_arg = 1, class Base = default_call_policies>
|
||||
struct return_internal_reference
|
||||
: with_custodian_and_ward_postcall<0, owner_arg, Base>
|
||||
{
|
||||
private:
|
||||
BOOST_STATIC_CONSTANT(bool, legal = owner_arg > 0);
|
||||
public:
|
||||
typedef typename mpl::select_type<
|
||||
legal
|
||||
, reference_existing_object
|
||||
, detail::return_internal_reference_owner_arg_must_be_greater_than_zero<owner_arg>
|
||||
>::type result_converter;
|
||||
};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // RETURN_INTERNAL_REFERENCE_DWA2002131_HPP
|
||||
@@ -1,20 +0,0 @@
|
||||
// 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_VALUE_POLICY_DWA2002131_HPP
|
||||
# define RETURN_VALUE_POLICY_DWA2002131_HPP
|
||||
# include <boost/python/default_call_policies.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class ResultConverterGenerator, class Base = default_call_policies>
|
||||
struct return_value_policy : Base
|
||||
{
|
||||
typedef ResultConverterGenerator result_converter;
|
||||
};
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // RETURN_VALUE_POLICY_DWA2002131_HPP
|
||||
@@ -1,39 +0,0 @@
|
||||
// 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 TO_PYTHON_CONVERTER_DWA200221_HPP
|
||||
# define TO_PYTHON_CONVERTER_DWA200221_HPP
|
||||
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/to_python_function.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T, class Conversion>
|
||||
struct to_python_converter
|
||||
{
|
||||
to_python_converter();
|
||||
};
|
||||
|
||||
//
|
||||
// implementation
|
||||
//
|
||||
|
||||
template <class T, class Conversion>
|
||||
to_python_converter<T,Conversion>::to_python_converter()
|
||||
{
|
||||
typedef converter::as_to_python_function<
|
||||
T, Conversion
|
||||
> normalized;
|
||||
|
||||
converter::registry::insert(
|
||||
&normalized::convert
|
||||
, converter::undecorated_type_id<T>());
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // TO_PYTHON_CONVERTER_DWA200221_HPP
|
||||
@@ -1,131 +0,0 @@
|
||||
// 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 TO_PYTHON_INDIRECT_DWA200221_HPP
|
||||
# define TO_PYTHON_INDIRECT_DWA200221_HPP
|
||||
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/python/object/pointer_holder.hpp>
|
||||
# include <boost/python/object/class_object.hpp>
|
||||
# include <boost/python/detail/unwind_type.hpp>
|
||||
# include <boost/shared_ptr.hpp>
|
||||
# include <memory>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T, class MakeHolder>
|
||||
struct to_python_indirect
|
||||
{
|
||||
static bool convertible();
|
||||
PyObject* operator()(T ptr) const;
|
||||
private:
|
||||
static PyTypeObject* type();
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
namespace detail
|
||||
{
|
||||
struct make_owning_holder
|
||||
{
|
||||
typedef objects::instance_holder* result_type;
|
||||
template <class T>
|
||||
static result_type execute(T* p)
|
||||
{
|
||||
// can't use auto_ptr with Intel 5 for some reason
|
||||
# if defined(__ICL) && __ICL < 600
|
||||
typedef boost::shared_ptr<T> smart_pointer;
|
||||
# else
|
||||
typedef std::auto_ptr<T> smart_pointer;
|
||||
# endif
|
||||
|
||||
return new objects::pointer_holder<smart_pointer, T>(
|
||||
smart_pointer(p));
|
||||
}
|
||||
};
|
||||
|
||||
struct make_reference_holder
|
||||
{
|
||||
typedef objects::instance_holder* result_type;
|
||||
template <class T>
|
||||
static result_type execute(T* p)
|
||||
{
|
||||
return new objects::pointer_holder<T*, T>(p);
|
||||
}
|
||||
};
|
||||
|
||||
struct get_pointer_class
|
||||
{
|
||||
typedef PyTypeObject* result_type;
|
||||
template <class T>
|
||||
static result_type execute(T* p)
|
||||
{
|
||||
BOOST_STATIC_ASSERT(is_class<T>::value);
|
||||
return python::objects::class_object<T>::reference;
|
||||
}
|
||||
};
|
||||
|
||||
// null_pointer_to_none -- return none() for null pointers and 0 for all other types/values
|
||||
//
|
||||
// Uses simulated partial ordering
|
||||
template <class T>
|
||||
inline PyObject* null_pointer_to_none(T&, int)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// overload for pointers
|
||||
template <class T>
|
||||
inline PyObject* null_pointer_to_none(T* x, long)
|
||||
{
|
||||
return x == 0 ? python::detail::none() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T, class MakeHolder>
|
||||
inline bool to_python_indirect<T,MakeHolder>::convertible()
|
||||
{
|
||||
BOOST_STATIC_ASSERT(is_pointer<T>::value || is_reference<T>::value);
|
||||
return type() != 0;
|
||||
}
|
||||
|
||||
template <class T, class MakeHolder>
|
||||
inline PyObject* to_python_indirect<T,MakeHolder>::operator()(T x) const
|
||||
{
|
||||
PyObject* const null_result = detail::null_pointer_to_none(x, 1L);
|
||||
if (null_result != 0)
|
||||
return null_result;
|
||||
|
||||
PyObject* raw_result = type()->tp_alloc(type(), 0);
|
||||
|
||||
if (raw_result == 0)
|
||||
return 0;
|
||||
|
||||
// Everything's OK; Bypass NULL checks but guard against
|
||||
// exceptions.
|
||||
ref result(raw_result, ref::allow_null());
|
||||
|
||||
// Build a value_holder to contain the object using the copy
|
||||
// constructor
|
||||
objects::instance_holder* p =
|
||||
detail::unwind_type<MakeHolder>(x);
|
||||
|
||||
// Install it in the instance
|
||||
p->install(raw_result);
|
||||
|
||||
// Return the new result
|
||||
return result.release();
|
||||
}
|
||||
|
||||
template <class T, class MakeHolder>
|
||||
inline PyTypeObject* to_python_indirect<T,MakeHolder>::type()
|
||||
{
|
||||
return detail::unwind_type<detail::get_pointer_class,T>();
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // TO_PYTHON_INDIRECT_DWA200221_HPP
|
||||
@@ -1,46 +0,0 @@
|
||||
// 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 TO_PYTHON_VALUE_DWA200221_HPP
|
||||
# define TO_PYTHON_VALUE_DWA200221_HPP
|
||||
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/to_python_function.hpp>
|
||||
# include <boost/python/converter/builtin_converters.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <class T>
|
||||
struct to_python_value
|
||||
{
|
||||
typedef typename add_reference<
|
||||
typename add_const<T>::type
|
||||
>::type argument_type;
|
||||
|
||||
static bool convertible();
|
||||
PyObject* operator()(argument_type) const;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
bool to_python_value<T>::convertible()
|
||||
{
|
||||
// if this assert fires, our static variable hasn't been set up yet.
|
||||
return converter::to_python_function<argument_type>::value != 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
PyObject* to_python_value<T>::operator()(argument_type x) const
|
||||
{
|
||||
// This might be further optimized on platforms which dynamically
|
||||
// link without specific imports/exports
|
||||
return converter::to_python_function<argument_type>::value(&x);
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // TO_PYTHON_VALUE_DWA200221_HPP
|
||||
@@ -1,78 +0,0 @@
|
||||
// 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 WITH_CUSTODIAN_AND_WARD_DWA2002131_HPP
|
||||
# define WITH_CUSTODIAN_AND_WARD_DWA2002131_HPP
|
||||
|
||||
# include <boost/python/default_call_policies.hpp>
|
||||
# include <boost/python/object/life_support.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
template <std::size_t custodian, std::size_t ward, class Base = default_call_policies>
|
||||
struct with_custodian_and_ward : Base
|
||||
{
|
||||
static bool precall(PyObject* args);
|
||||
};
|
||||
|
||||
template <std::size_t custodian, std::size_t ward, class Base = default_call_policies>
|
||||
struct with_custodian_and_ward_postcall : Base
|
||||
{
|
||||
static PyObject* postcall(PyObject* args, PyObject* result);
|
||||
};
|
||||
|
||||
//
|
||||
// implementations
|
||||
//
|
||||
template <std::size_t custodian, std::size_t ward, class Base>
|
||||
bool with_custodian_and_ward<custodian,ward,Base>::precall(PyObject* args_)
|
||||
{
|
||||
BOOST_STATIC_ASSERT(custodian != ward);
|
||||
BOOST_STATIC_ASSERT(custodian > 0);
|
||||
BOOST_STATIC_ASSERT(ward > 0);
|
||||
|
||||
PyObject* patient = PyTuple_GetItem(args_, ward - 1);
|
||||
if (patient == 0) return false;
|
||||
PyObject* nurse = PyTuple_GetItem(args_, custodian - 1);
|
||||
if (nurse == 0) return false;
|
||||
|
||||
PyObject* life_support = python::objects::make_nurse_and_patient(nurse, patient);
|
||||
if (life_support == 0)
|
||||
return false;
|
||||
|
||||
bool result = Base::precall(args_);
|
||||
|
||||
if (!result)
|
||||
Py_XDECREF(life_support);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <std::size_t custodian, std::size_t ward, class Base>
|
||||
PyObject* with_custodian_and_ward_postcall<custodian,ward,Base>::postcall(PyObject* args_, PyObject* result)
|
||||
{
|
||||
BOOST_STATIC_ASSERT(custodian != ward);
|
||||
|
||||
PyObject* patient = ward > 0 ? PyTuple_GetItem(args_, ward - 1) : result;
|
||||
if (patient == 0) return 0;
|
||||
|
||||
PyObject* nurse = custodian > 0 ? PyTuple_GetItem(args_, custodian - 1) : result;
|
||||
if (nurse == 0) return 0;
|
||||
|
||||
result = Base::postcall(args_, result);
|
||||
if (result == 0)
|
||||
return 0;
|
||||
|
||||
if (python::objects::make_nurse_and_patient(nurse, patient) == 0)
|
||||
{
|
||||
Py_XDECREF(result);
|
||||
return 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // WITH_CUSTODIAN_AND_WARD_DWA2002131_HPP
|
||||
Reference in New Issue
Block a user